stw_wgl_pixelformat.c File Reference

Include dependency graph for stw_wgl_pixelformat.c:

Go to the source code of this file.

Functions

WINGDIAPI int APIENTRY wglChoosePixelFormat (HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd)
WINGDIAPI int APIENTRY wglDescribePixelFormat (HDC hdc, int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd)
WINGDIAPI int APIENTRY wglGetPixelFormat (HDC hdc)
WINGDIAPI BOOL APIENTRY wglSetPixelFormat (HDC hdc, int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)

Variables

static uint currentpixelformat = 0


Function Documentation

WINGDIAPI int APIENTRY wglChoosePixelFormat ( HDC  hdc,
CONST PIXELFORMATDESCRIPTOR *  ppfd 
)

Definition at line 38 of file stw_wgl_pixelformat.c.

References pixelformat_info::alpha, pixelformat_alpha_info::alphabits, pixelformat_color_info::bluebits, pixelformat_info::color, pixelformat_info::depth, pixelformat_depth_info::depthbits, pixelformat_info::flags, pixelformat_color_info::greenbits, PF_FLAG_DOUBLEBUFFER, pixelformat_get_count(), pixelformat_get_info(), pixelformat_color_info::redbits, and pixelformat_depth_info::stencilbits.

00041 {
00042    uint count;
00043    uint index;
00044    uint bestindex;
00045    uint bestdelta;
00046 
00047    (void) hdc;
00048 
00049    count = pixelformat_get_count();
00050    bestindex = count;
00051    bestdelta = 0xffffffff;
00052 
00053    if (ppfd->nSize != sizeof( PIXELFORMATDESCRIPTOR ) || ppfd->nVersion != 1)
00054       return 0;
00055    if (ppfd->iPixelType != PFD_TYPE_RGBA)
00056       return 0;
00057    if (!(ppfd->dwFlags & PFD_DRAW_TO_WINDOW))
00058       return 0;
00059    if (!(ppfd->dwFlags & PFD_SUPPORT_OPENGL))
00060       return 0;
00061    if (ppfd->dwFlags & PFD_DRAW_TO_BITMAP)
00062       return 0;
00063    if (ppfd->dwFlags & PFD_SUPPORT_GDI)
00064       return 0;
00065    if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE) && (ppfd->dwFlags & PFD_STEREO))
00066       return 0;
00067 
00068    for (index = 0; index < count; index++) {
00069       uint delta = 0;
00070       const struct pixelformat_info *pf = pixelformat_get_info( index );
00071 
00072       if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE)) {
00073          if ((ppfd->dwFlags & PFD_DOUBLEBUFFER) && !(pf->flags & PF_FLAG_DOUBLEBUFFER))
00074             continue;
00075          if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER) && (pf->flags & PF_FLAG_DOUBLEBUFFER))
00076             continue;
00077       }
00078 
00079       if (ppfd->cColorBits != pf->color.redbits + pf->color.greenbits + pf->color.bluebits)
00080          delta += 8;
00081 
00082       if (ppfd->cDepthBits != pf->depth.depthbits)
00083          delta += 4;
00084 
00085       if (ppfd->cStencilBits != pf->depth.stencilbits)
00086          delta += 2;
00087 
00088       if (ppfd->cAlphaBits != pf->alpha.alphabits)
00089          delta++;
00090 
00091       if (delta < bestdelta) {
00092          bestindex = index;
00093          bestdelta = delta;
00094          if (bestdelta == 0)
00095             break;
00096       }
00097    }
00098 
00099    if (bestindex == count)
00100       return 0;
00101    return bestindex + 1;
00102 }

WINGDIAPI int APIENTRY wglDescribePixelFormat ( HDC  hdc,
int  iPixelFormat,
UINT  nBytes,
LPPIXELFORMATDESCRIPTOR  ppfd 
)

Definition at line 105 of file stw_wgl_pixelformat.c.

References pixelformat_info::alpha, pixelformat_alpha_info::alphabits, pixelformat_alpha_info::alphashift, pixelformat_color_info::bluebits, pixelformat_color_info::blueshift, pixelformat_info::color, pixelformat_info::depth, pixelformat_depth_info::depthbits, pixelformat_info::flags, pixelformat_color_info::greenbits, pixelformat_color_info::greenshift, PF_FLAG_DOUBLEBUFFER, pixelformat_get_extended_count(), pixelformat_get_info(), pixelformat_color_info::redbits, pixelformat_color_info::redshift, and pixelformat_depth_info::stencilbits.

00110 {
00111    uint count;
00112    uint index;
00113    const struct pixelformat_info *pf;
00114 
00115    (void) hdc;
00116 
00117    count = pixelformat_get_extended_count();
00118    index = (uint) iPixelFormat - 1;
00119 
00120    if (ppfd == NULL)
00121       return count;
00122    if (index >= count || nBytes != sizeof( PIXELFORMATDESCRIPTOR ))
00123       return 0;
00124 
00125    pf = pixelformat_get_info( index );
00126 
00127    ppfd->nSize = sizeof( PIXELFORMATDESCRIPTOR );
00128    ppfd->nVersion = 1;
00129    ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
00130    if (pf->flags & PF_FLAG_DOUBLEBUFFER)
00131       ppfd->dwFlags |= PFD_DOUBLEBUFFER | PFD_SWAP_COPY;
00132    ppfd->iPixelType = PFD_TYPE_RGBA;
00133    ppfd->cColorBits = pf->color.redbits + pf->color.greenbits + pf->color.bluebits;
00134    ppfd->cRedBits = pf->color.redbits;
00135    ppfd->cRedShift = pf->color.redshift;
00136    ppfd->cGreenBits = pf->color.greenbits;
00137    ppfd->cGreenShift = pf->color.greenshift;
00138    ppfd->cBlueBits = pf->color.bluebits;
00139    ppfd->cBlueShift = pf->color.blueshift;
00140    ppfd->cAlphaBits = pf->alpha.alphabits;
00141    ppfd->cAlphaShift = pf->alpha.alphashift;
00142    ppfd->cAccumBits = 0;
00143    ppfd->cAccumRedBits = 0;
00144    ppfd->cAccumGreenBits = 0;
00145    ppfd->cAccumBlueBits = 0;
00146    ppfd->cAccumAlphaBits = 0;
00147    ppfd->cDepthBits = pf->depth.depthbits;
00148    ppfd->cStencilBits = pf->depth.stencilbits;
00149    ppfd->cAuxBuffers = 0;
00150    ppfd->iLayerType = 0;
00151    ppfd->bReserved = 0;
00152    ppfd->dwLayerMask = 0;
00153    ppfd->dwVisibleMask = 0;
00154    ppfd->dwDamageMask = 0;
00155 
00156    return count;
00157 }

WINGDIAPI int APIENTRY wglGetPixelFormat ( HDC  hdc  ) 

Definition at line 160 of file stw_wgl_pixelformat.c.

References currentpixelformat.

00162 {
00163    (void) hdc;
00164 
00165    return currentpixelformat;
00166 }

WINGDIAPI BOOL APIENTRY wglSetPixelFormat ( HDC  hdc,
int  iPixelFormat,
const PIXELFORMATDESCRIPTOR *  ppfd 
)

Definition at line 169 of file stw_wgl_pixelformat.c.

References currentpixelformat, FALSE, pixelformat_get_extended_count(), and TRUE.

00173 {
00174    uint count;
00175    uint index;
00176 
00177    (void) hdc;
00178 
00179    count = pixelformat_get_extended_count();
00180    index = (uint) iPixelFormat - 1;
00181 
00182    if (index >= count || ppfd->nSize != sizeof( PIXELFORMATDESCRIPTOR ))
00183       return FALSE;
00184 
00185    currentpixelformat = index + 1;
00186    return TRUE;
00187 }


Variable Documentation

uint currentpixelformat = 0 [static]

Definition at line 35 of file stw_wgl_pixelformat.c.


Generated on Tue Sep 29 06:25:56 2009 for Gallium3D by  doxygen 1.5.4