ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

icd.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  6.1
00004  *
00005  * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00025 /*
00026  * File name: icd.c
00027  * Author:    Gregor Anich
00028  *
00029  * ICD (Installable Client Driver) interface.
00030  * Based on the windows GDI/WGL driver.
00031  */
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 #include <windows.h>
00038 #define GL_GLEXT_PROTOTYPES
00039 #include "GL/gl.h"
00040 #include "GL/glext.h"
00041 
00042 #ifdef __cplusplus
00043 }
00044 #endif
00045 
00046 #include <stdio.h>
00047 #include <tchar.h>
00048 #include "GL/wmesa.h"
00049 #include "mtypes.h"
00050 #include "glapi.h"
00051 
00052 typedef void *HPBUFFERARB;
00053 
00054 GLAPI const char * GLAPIENTRY wglGetExtensionsStringARB(HDC hdc);
00055 GLAPI const char * GLAPIENTRY wglGetExtensionsStringEXT (void);
00056 GLAPI BOOL GLAPIENTRY wglChoosePixelFormatARB (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
00057 GLAPI BOOL GLAPIENTRY wglSwapIntervalEXT (int interval);
00058 GLAPI int GLAPIENTRY wglGetSwapIntervalEXT (void);
00059 GLAPI BOOL GLAPIENTRY wglGetPixelFormatAttribivARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues);
00060 GLAPI BOOL GLAPIENTRY wglGetPixelFormatAttribfvARB (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, FLOAT *pfValues);
00061 GLAPI BOOL GLAPIENTRY wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
00062 GLAPI HANDLE GLAPIENTRY wglGetCurrentReadDCARB(void);
00063 GLAPI HPBUFFERARB GLAPIENTRY wglCreatePbufferARB (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
00064 GLAPI HDC GLAPIENTRY wglGetPbufferDCARB (HPBUFFERARB hPbuffer);
00065 GLAPI int GLAPIENTRY wglReleasePbufferDCARB (HPBUFFERARB hPbuffer, HDC hDC);
00066 GLAPI BOOL GLAPIENTRY wglDestroyPbufferARB (HPBUFFERARB hPbuffer);
00067 GLAPI BOOL GLAPIENTRY wglQueryPbufferARB (HPBUFFERARB hPbuffer, int iAttribute, int *piValue);
00068 GLAPI HANDLE GLAPIENTRY wglCreateBufferRegionARB(HDC hDC, int iLayerPlane, UINT uType);
00069 GLAPI VOID GLAPIENTRY wglDeleteBufferRegionARB(HANDLE hRegion);
00070 GLAPI BOOL GLAPIENTRY wglSaveBufferRegionARB(HANDLE hRegion, int x, int y, int width, int height);
00071 GLAPI BOOL GLAPIENTRY wglRestoreBufferRegionARB(HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc);
00072 GLAPI BOOL GLAPIENTRY wglSetPbufferAttribARB (HPBUFFERARB hPbuffer, const int *piAttribList);
00073 GLAPI BOOL GLAPIENTRY wglBindTexImageARB (HPBUFFERARB hPbuffer, int iBuffer);
00074 GLAPI BOOL GLAPIENTRY wglReleaseTexImageARB (HPBUFFERARB hPbuffer, int iBuffer);
00075 
00076 #define MAX_MESA_ATTRS  20
00077 
00078 typedef struct wmesa_context *PWMC;
00079 
00080 typedef struct _icdTable {
00081     DWORD size;
00082     PROC  table[418];
00083 } ICDTABLE, *PICDTABLE;
00084 
00085 #ifdef USE_MGL_NAMESPACE
00086 # define GL_FUNC(func) mgl##func
00087 #else
00088 # define GL_FUNC(func) gl##func
00089 #endif
00090 
00091 
00092 static ICDTABLE icdTable = { 418, {
00093 #define ICD_ENTRY(func) (PROC)GL_FUNC(func),
00094 #include "icdlist.h"
00095 #undef ICD_ENTRY
00096 } };
00097 
00098 struct __pixelformat__
00099 {
00100     PIXELFORMATDESCRIPTOR   pfd;
00101     GLboolean doubleBuffered;
00102 };
00103 
00104 struct __pixelformat__  pix[] =
00105 {
00106     /* Double Buffer, alpha */
00107     {   {   sizeof(PIXELFORMATDESCRIPTOR),  1,
00108         PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
00109         PFD_TYPE_RGBA,
00110         24, 8,  0,  8,  8,  8,  16, 8,  24,
00111         0,  0,  0,  0,  0,  16, 8,  0,  0,  0,  0,  0,  0 },
00112         GL_TRUE
00113     },
00114     /* Single Buffer, alpha */
00115     {   {   sizeof(PIXELFORMATDESCRIPTOR),  1,
00116         PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL, /* | PFD_SUPPORT_GDI ? */
00117         PFD_TYPE_RGBA,
00118         24, 8,  0,  8,  8,  8,  16, 8,  24,
00119         0,  0,  0,  0,  0,  16, 8,  0,  0,  0,  0,  0,  0 },
00120         GL_FALSE
00121     },
00122     /* Double Buffer, no alpha */
00123     {   {   sizeof(PIXELFORMATDESCRIPTOR),  1,
00124         PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
00125         PFD_TYPE_RGBA,
00126         24, 8,  0,  8,  8,  8,  16, 0,  0,
00127         0,  0,  0,  0,  0,  16, 8,  0,  0,  0,  0,  0,  0 },
00128         GL_TRUE
00129     },
00130     /* Single Buffer, no alpha */
00131     {   {   sizeof(PIXELFORMATDESCRIPTOR),  1,
00132         PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL, /* | PFD_SUPPORT_GDI ? */
00133         PFD_TYPE_RGBA,
00134         24, 8,  0,  8,  8,  8,  16, 0,  0,
00135         0,  0,  0,  0,  0,  16, 8,  0,  0,  0,  0,  0,  0 },
00136         GL_FALSE
00137     },
00138 };
00139 
00140 int qt_pix = sizeof(pix) / sizeof(pix[0]);
00141 
00142 typedef struct {
00143     WMesaContext ctx;
00144     HDC hdc;
00145 } MesaWglCtx;
00146 
00147 #define MESAWGL_CTX_MAX_COUNT 20
00148 
00149 static MesaWglCtx wgl_ctx[MESAWGL_CTX_MAX_COUNT];
00150 
00151 static unsigned ctx_count = 0;
00152 static int ctx_current = -1;
00153 static unsigned curPFD = 0;
00154 
00155 WGLAPI BOOL GLAPIENTRY DrvCopyContext(HGLRC hglrcSrc,HGLRC hglrcDst,UINT mask)
00156 {
00157     (void) hglrcSrc; (void) hglrcDst; (void) mask;
00158     return(FALSE);
00159 }
00160 
00161 WGLAPI HGLRC GLAPIENTRY DrvCreateContext(HDC hdc)
00162 {
00163     int i = 0;
00164 
00165     if (!ctx_count)
00166     {
00167         for(i=0;i<MESAWGL_CTX_MAX_COUNT;i++)
00168         {
00169             wgl_ctx[i].ctx = NULL;
00170             wgl_ctx[i].hdc = NULL;
00171         }
00172     }
00173     for( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
00174     {
00175         if ( wgl_ctx[i].ctx == NULL )
00176         {
00177             wgl_ctx[i].ctx = WMesaCreateContext( hdc, NULL, GL_TRUE,
00178                 pix[curPFD-1].doubleBuffered, 
00179                 pix[curPFD-1].pfd.cAlphaBits ? GL_TRUE : GL_FALSE);
00180             if (wgl_ctx[i].ctx == NULL)
00181                 break;
00182             wgl_ctx[i].hdc = hdc;
00183             ctx_count++;
00184             return ((HGLRC)wgl_ctx[i].ctx);
00185         }
00186     }
00187     SetLastError(0);
00188     return(NULL);
00189 }
00190 
00191 WGLAPI BOOL GLAPIENTRY DrvDeleteContext(HGLRC hglrc)
00192 {
00193     int i;
00194     for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
00195     {
00196         if ( wgl_ctx[i].ctx == (PWMC) hglrc )
00197         {
00198             WMesaMakeCurrent((PWMC) hglrc, NULL);
00199             WMesaDestroyContext(wgl_ctx[i].ctx);
00200             wgl_ctx[i].ctx = NULL;
00201             wgl_ctx[i].hdc = NULL;
00202             ctx_count--;
00203             return(TRUE);
00204         }
00205     }
00206     SetLastError(0);
00207     return(FALSE);
00208 }
00209 
00210 WGLAPI HGLRC GLAPIENTRY DrvCreateLayerContext(HDC hdc,int iLayerPlane)
00211 {
00212     if (iLayerPlane == 0)
00213       return DrvCreateContext(hdc);
00214     SetLastError(0);
00215     return(NULL);
00216 }
00217 
00218 WGLAPI PICDTABLE GLAPIENTRY DrvSetContext(HDC hdc,HGLRC hglrc,void *callback)
00219 {
00220     int i;
00221     (void) callback;
00222 
00223     /* new code suggested by Andy Sy */
00224     if (!hdc || !hglrc) {
00225        WMesaMakeCurrent(NULL, NULL);
00226        ctx_current = -1;
00227        return NULL;
00228     }
00229 
00230     for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
00231     {
00232         if ( wgl_ctx[i].ctx == (PWMC) hglrc )
00233         {
00234             wgl_ctx[i].hdc = hdc;
00235             WMesaMakeCurrent( (PWMC) hglrc , hdc);
00236             ctx_current = i;
00237             return &icdTable;
00238         }
00239     }
00240     return NULL;
00241 }
00242 
00243 WGLAPI void GLAPIENTRY DrvReleaseContext(HGLRC hglrc)
00244 {
00245     (void) hglrc;
00246     WMesaMakeCurrent(NULL, NULL);
00247     ctx_current = -1;
00248 }
00249 
00250 WGLAPI BOOL GLAPIENTRY DrvShareLists(HGLRC hglrc1,HGLRC hglrc2)
00251 {
00252     (void) hglrc1; (void) hglrc2;
00253     return(TRUE);
00254 }
00255 
00256 WGLAPI BOOL GLAPIENTRY DrvDescribeLayerPlane(HDC hdc,int iPixelFormat,
00257                                     int iLayerPlane,UINT nBytes,
00258                                     LPLAYERPLANEDESCRIPTOR plpd)
00259 {
00260     (void) hdc; (void) iPixelFormat; (void) iLayerPlane; (void) nBytes; (void) plpd;
00261     SetLastError(0);
00262     return(FALSE);
00263 }
00264 
00265 WGLAPI int GLAPIENTRY DrvSetLayerPaletteEntries(HDC hdc,int iLayerPlane,
00266                                        int iStart,int cEntries,
00267                                        CONST COLORREF *pcr)
00268 {
00269     (void) hdc; (void) iLayerPlane; (void) iStart; (void) cEntries; (void) pcr;
00270     SetLastError(0);
00271     return(0);
00272 }
00273 
00274 WGLAPI int GLAPIENTRY DrvGetLayerPaletteEntries(HDC hdc,int iLayerPlane,
00275                                        int iStart,int cEntries,
00276                                        COLORREF *pcr)
00277 {
00278     (void) hdc; (void) iLayerPlane; (void) iStart; (void) cEntries; (void) pcr;
00279     SetLastError(0);
00280     return(0);
00281 }
00282 
00283 WGLAPI BOOL GLAPIENTRY DrvRealizeLayerPalette(HDC hdc,int iLayerPlane,BOOL bRealize)
00284 {
00285     (void) hdc; (void) iLayerPlane; (void) bRealize;
00286     SetLastError(0);
00287     return(FALSE);
00288 }
00289 
00290 WGLAPI BOOL GLAPIENTRY DrvSwapLayerBuffers(HDC hdc,UINT fuPlanes)
00291 {
00292     (void) fuPlanes;
00293     if( !hdc )
00294     {
00295         WMesaSwapBuffers(hdc);
00296         return(TRUE);
00297     }
00298     SetLastError(0);
00299     return(FALSE);
00300 }
00301 
00302 WGLAPI int GLAPIENTRY DrvDescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes,
00303                                     LPPIXELFORMATDESCRIPTOR ppfd)
00304 {
00305     int qt_valid_pix;
00306     (void) hdc;
00307 
00308     qt_valid_pix = qt_pix;
00309     if( (nBytes != sizeof(PIXELFORMATDESCRIPTOR)) || (iPixelFormat < 1) || (iPixelFormat >qt_valid_pix) )
00310     {
00311         SetLastError(0);
00312         return(0);
00313     }
00314 
00315     if(ppfd==NULL)
00316     {
00317         return(qt_valid_pix);
00318     }
00319 
00320     *ppfd = pix[iPixelFormat - 1].pfd;
00321     return(qt_valid_pix);
00322 }
00323 
00324 /*
00325 * GetProcAddress - return the address of an appropriate extension
00326 */
00327 
00328 static struct {
00329    const char *name;
00330    PROC func;
00331 } wgl_ext[] = {
00332        {"wglGetExtensionsStringARB",    (PROC)wglGetExtensionsStringARB},
00333        {"wglGetExtensionsStringEXT",    (PROC)wglGetExtensionsStringEXT},
00334        {"wglSwapIntervalEXT",           (PROC)wglSwapIntervalEXT},
00335        {"wglGetSwapIntervalEXT",        (PROC)wglGetSwapIntervalEXT},
00336        {"wglGetPixelFormatAttribivARB", (PROC)wglGetPixelFormatAttribivARB},
00337        {"wglGetPixelFormatAttribfvARB", (PROC)wglGetPixelFormatAttribfvARB},
00338        {"wglChoosePixelFormatARB",      (PROC)wglChoosePixelFormatARB},
00339        {"wglCreatePbufferARB",          (PROC)wglCreatePbufferARB},
00340        {"wglGetPbufferDCARB",           (PROC)wglGetPbufferDCARB},
00341        {"wglReleasePbufferDCARB",       (PROC)wglReleasePbufferDCARB},
00342        {"wglDestroyPbufferARB",         (PROC)wglDestroyPbufferARB},
00343        {"wglQueryPbufferARB",           (PROC)wglQueryPbufferARB},
00344        {"wglSetPbufferAttribARB",       (PROC)wglSetPbufferAttribARB},
00345        {"wglBindTexImageARB",           (PROC)wglBindTexImageARB},
00346        {"wglReleaseTexImageARB",        (PROC)wglReleaseTexImageARB},
00347        {"wglCreateBufferRegionARB",     (PROC)wglCreateBufferRegionARB},
00348        {"wglDeleteBufferRegionARB",     (PROC)wglDeleteBufferRegionARB},
00349        {"wglSaveBufferRegionARB",       (PROC)wglSaveBufferRegionARB},
00350        {"wglRestoreBufferRegionARB",    (PROC)wglRestoreBufferRegionARB},
00351        {"wglMakeContextCurrentARB",     (PROC)wglMakeContextCurrentARB},
00352        {"wglGetCurrentReadDCARB",       (PROC)wglGetCurrentReadDCARB},
00353        {NULL, NULL}
00354 };
00355 
00356 WGLAPI PROC GLAPIENTRY DrvGetProcAddress(LPCSTR lpszProc)
00357 {
00358    int i;
00359    PROC p = (PROC) _glapi_get_proc_address((const char *) lpszProc);
00360    if (p)
00361       return p;
00362 
00363    for (i = 0; wgl_ext[i].name; i++)
00364    {
00365       if (!strcmp(lpszProc, wgl_ext[i].name))
00366       {
00367          return wgl_ext[i].func;
00368       }
00369    }
00370 
00371    SetLastError(0);
00372    return(NULL);
00373 }
00374 
00375 WGLAPI BOOL GLAPIENTRY DrvSetPixelFormat(HDC hdc,int iPixelFormat, const PIXELFORMATDESCRIPTOR *ppfd)
00376 {
00377    int qt_valid_pix;
00378 
00379    qt_valid_pix = qt_pix;
00380 
00381    if (iPixelFormat < 1 || iPixelFormat > qt_valid_pix) {
00382       if (ppfd == NULL) {
00383          PIXELFORMATDESCRIPTOR my_pfd;
00384          if (!DrvDescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &my_pfd)) {
00385             SetLastError(0);
00386             return FALSE;
00387          }
00388       } else if (ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR)) {
00389          SetLastError(0);
00390          return FALSE;
00391       }
00392    }
00393    curPFD = iPixelFormat;
00394 
00395    return TRUE;
00396 }
00397 
00398 WGLAPI BOOL GLAPIENTRY DrvSwapBuffers(HDC hdc)
00399 {
00400     (void) hdc;
00401     if (ctx_current < 0)
00402         return FALSE;
00403 
00404     if(wgl_ctx[ctx_current].ctx == NULL) {
00405         SetLastError(0);
00406         return(FALSE);
00407     }
00408     WMesaSwapBuffers(hdc);
00409     return(TRUE);
00410 }
00411 
00412 WGLAPI BOOL GLAPIENTRY DrvValidateVersion(DWORD version)
00413 {
00414     (void) version;
00415     return TRUE;
00416 }

Generated on Sun May 27 2012 04:20:00 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.