stw_wgl_pixelformat.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028 #include <windows.h>
00029 
00030 #include "pipe/p_compiler.h"
00031 #include "pipe/p_debug.h"
00032 #include "stw_pixelformat.h"
00033 #include "stw_wgl.h"
00034 
00035 static uint currentpixelformat = 0;
00036 
00037 WINGDIAPI int APIENTRY
00038 wglChoosePixelFormat(
00039    HDC hdc,
00040    CONST PIXELFORMATDESCRIPTOR *ppfd )
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 }
00103 
00104 WINGDIAPI int APIENTRY
00105 wglDescribePixelFormat(
00106    HDC hdc,
00107    int iPixelFormat,
00108    UINT nBytes,
00109    LPPIXELFORMATDESCRIPTOR ppfd )
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 }
00158 
00159 WINGDIAPI int APIENTRY
00160 wglGetPixelFormat(
00161    HDC hdc )
00162 {
00163    (void) hdc;
00164 
00165    return currentpixelformat;
00166 }
00167 
00168 WINGDIAPI BOOL APIENTRY
00169 wglSetPixelFormat(
00170    HDC hdc,
00171    int iPixelFormat,
00172    const PIXELFORMATDESCRIPTOR *ppfd )
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 }

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