Remove CVS keywords.
[mesa.git] / src / mesa / drivers / windows / gdi / wgl.c
index 47e32c579fc7b89ad2181d0bcf4a6af190545775..6e00d08abafa616147887db685e090e0aafebb00 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: wgl.c,v 1.11 2006/01/25 06:02:55 kschultz Exp $ */
 
 /*
  * This library is free software; you can redistribute it and/or
 
 /* We're essentially building part of GDI here, so define this so that
  * we get the right export linkage. */
+#ifdef __MINGW32__
+
+#include <stdarg.h>
+#include <windef.h>
+#include <wincon.h>
+#include <winbase.h>
+
+#  if defined(BUILD_GL32)
+#    define WINGDIAPI __declspec(dllexport)    
+#  else
+#    define __W32API_USE_DLLIMPORT__
+#  endif
+
+#include <wingdi.h>
+#include "GL/mesa_wgl.h"
+#include <stdlib.h>
+
+#else
+
 #define _GDI32_
 #include <windows.h>
-#include "glapi.h"
 
-#include "GL/wmesa.h"   /* protos for wmesa* functions */
+#endif
 
-typedef struct wmesa_context *PWMC;
+#include "glapi.h"
+#include "GL/wmesa.h"   /* protos for wmesa* functions */
 
 /*
  * Pixel Format Descriptors
@@ -143,7 +161,6 @@ int npfd = sizeof(pfd) / sizeof(pfd[0]);
 
 typedef struct {
     WMesaContext ctx;
-    HDC hdc;
 } MesaWglCtx;
 
 #define MESAWGL_CTX_MAX_COUNT 20
@@ -154,13 +171,15 @@ static unsigned ctx_count = 0;
 static int ctx_current = -1;
 static unsigned curPFD = 0;
 
+static HDC CurrentHDC = 0;
+
+
 WINGDIAPI HGLRC GLAPIENTRY wglCreateContext(HDC hdc)
 {
     int i = 0;
     if (!ctx_count) {
        for(i=0;i<MESAWGL_CTX_MAX_COUNT;i++) {
            wgl_ctx[i].ctx = NULL;
-           wgl_ctx[i].hdc = NULL;
        }
     }
     for( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ ) {
@@ -173,7 +192,6 @@ WINGDIAPI HGLRC GLAPIENTRY wglCreateContext(HDC hdc)
                                   GL_TRUE : GL_FALSE) );
             if (wgl_ctx[i].ctx == NULL)
                 break;
-            wgl_ctx[i].hdc = hdc;
             ctx_count++;
             return ((HGLRC)wgl_ctx[i].ctx);
         }
@@ -186,11 +204,10 @@ WINGDIAPI BOOL GLAPIENTRY wglDeleteContext(HGLRC hglrc)
 {
     int i;
     for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ ) {
-       if ( wgl_ctx[i].ctx == (PWMC) hglrc ){
-            WMesaMakeCurrent((PWMC) hglrc);
-            WMesaDestroyContext();
+       if ( wgl_ctx[i].ctx == (WMesaContext) hglrc ){
+            WMesaMakeCurrent((WMesaContext) hglrc, NULL);
+            WMesaDestroyContext(wgl_ctx[i].ctx);
             wgl_ctx[i].ctx = NULL;
-            wgl_ctx[i].hdc = NULL;
             ctx_count--;
             return(TRUE);
        }
@@ -209,26 +226,24 @@ WINGDIAPI HGLRC GLAPIENTRY wglGetCurrentContext(VOID)
 
 WINGDIAPI HDC GLAPIENTRY wglGetCurrentDC(VOID)
 {
-    if (ctx_current < 0)
-       return 0;
-    else
-       return wgl_ctx[ctx_current].hdc;
+    return CurrentHDC;
 }
 
-WINGDIAPI BOOL GLAPIENTRY wglMakeCurrent(HDC hdc,HGLRC hglrc)
+WINGDIAPI BOOL GLAPIENTRY wglMakeCurrent(HDC hdc, HGLRC hglrc)
 {
     int i;
     
+    CurrentHDC = hdc;
+
     if (!hdc || !hglrc) {
-       WMesaMakeCurrent(NULL);
+       WMesaMakeCurrent(NULL, NULL);
        ctx_current = -1;
        return TRUE;
     }
     
     for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ ) {
-       if ( wgl_ctx[i].ctx == (PWMC) hglrc ) {
-           wgl_ctx[i].hdc = hdc;
-           WMesaMakeCurrent( (WMesaContext) hglrc );
+       if ( wgl_ctx[i].ctx == (WMesaContext) hglrc ) {
+           WMesaMakeCurrent( (WMesaContext) hglrc, hdc );
            ctx_current = i;
            return TRUE;
        }
@@ -338,7 +353,7 @@ WINGDIAPI int GLAPIENTRY wglGetPixelFormat(HDC hdc)
 }
 
 WINGDIAPI BOOL GLAPIENTRY wglSetPixelFormat(HDC hdc,int iPixelFormat,
-                                           PIXELFORMATDESCRIPTOR *ppfd)
+                                       const PIXELFORMATDESCRIPTOR *ppfd)
 {
     (void) hdc;
     
@@ -353,16 +368,8 @@ WINGDIAPI BOOL GLAPIENTRY wglSetPixelFormat(HDC hdc,int iPixelFormat,
 
 WINGDIAPI BOOL GLAPIENTRY wglSwapBuffers(HDC hdc)
 {
-    (void) hdc;
-    if (ctx_current < 0)
-       return FALSE;
-    
-    if(wgl_ctx[ctx_current].ctx == NULL) {
-       SetLastError(0);
-       return(FALSE);
-    }
-    WMesaSwapBuffers();
-    return(TRUE);
+    WMesaSwapBuffers(hdc);
+    return TRUE;
 }
 
 static FIXED FixedFromDouble(double d)
@@ -399,12 +406,12 @@ static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar,
     
     bitDevice = CreateCompatibleDC(fontDevice);
     
-    // Swap fore and back colors so the bitmap has the right polarity
+    /* Swap fore and back colors so the bitmap has the right polarity */
     tempColor = GetBkColor(bitDevice);
     SetBkColor(bitDevice, GetTextColor(bitDevice));
     SetTextColor(bitDevice, tempColor);
     
-    // Place chars based on base line
+    /* Place chars based on base line */
     VERIFY(SetTextAlign(bitDevice, TA_BASELINE) != GDI_ERROR ? 1 : 0);
     
     for(i = 0; i < (int)numChars; i++) {
@@ -417,36 +424,36 @@ static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar,
        
        curChar = (char)(i + firstChar);
        
-       // Find how high/wide this character is
+       /* Find how high/wide this character is */
        VERIFY(GetTextExtentPoint32(bitDevice, &curChar, 1, &size));
        
-       // Create the output bitmap
+       /* Create the output bitmap */
        charWidth = size.cx;
        charHeight = size.cy;
-       // Round up to the next multiple of 32 bits
+       /* Round up to the next multiple of 32 bits */
        bmapWidth = ((charWidth + 31) / 32) * 32;   
        bmapHeight = charHeight;
        bitObject = CreateCompatibleBitmap(bitDevice,
                                           bmapWidth,
                                           bmapHeight);
-       //VERIFY(bitObject);
+       /* VERIFY(bitObject); */
        
-       // Assign the output bitmap to the device
+       /* Assign the output bitmap to the device */
        origBmap = SelectObject(bitDevice, bitObject);
        (void) VERIFY(origBmap);
        
        VERIFY( PatBlt( bitDevice, 0, 0, bmapWidth, bmapHeight,BLACKNESS ) );
        
-       // Use our source font on the device
+       /* Use our source font on the device */
        VERIFY(SelectObject(bitDevice, GetCurrentObject(fontDevice,OBJ_FONT)));
        
-       // Draw the character
+       /* Draw the character */
        VERIFY(TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1));
        
-       // Unselect our bmap object
+       /* Unselect our bmap object */
        VERIFY(SelectObject(bitDevice, origBmap));
        
-       // Convert the display dependant representation to a 1 bit deep DIB
+       /* Convert the display dependant representation to a 1 bit deep DIB */
        numBytes = (bmapWidth * bmapHeight) / 8;
        bmap = malloc(numBytes);
        dibInfo->bmiHeader.biWidth = bmapWidth;
@@ -454,24 +461,24 @@ static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar,
        res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap,
                        dibInfo,
                        DIB_RGB_COLORS);
-       //VERIFY(res);
+       /* VERIFY(res); */
        
-       // Create the GL object
+       /* Create the GL object */
        glNewList(i + listBase, GL_COMPILE);
        glBitmap(bmapWidth, bmapHeight, 0.0, (GLfloat)metric.tmDescent,
                 (GLfloat)charWidth, 0.0,
                 bmap);
        glEndList();
-       // CheckGL();
+       /* CheckGL(); */
        
-       // Destroy the bmap object
+       /* Destroy the bmap object */
        DeleteObject(bitObject);
        
-       // Deallocate the bitmap data
+       /* Deallocate the bitmap data */
        free(bmap);
     }
     
-    // Destroy the DC
+    /* Destroy the DC */
     VERIFY(DeleteDC(bitDevice));
     
     free(dibInfo);