fix GL_BACK color material bug
[mesa.git] / src / mesa / drivers / glide / fxwgl.c
index cbea79aecdac05a9a1007f5efc5b750f133ef022..1f0e16a95365d69f4c36fe804bb102c7c8def4f7 100644 (file)
@@ -1,26 +1,54 @@
-/* fxwgl.c - Microsoft wgl functions emulation for
- *           3Dfx VooDoo/Mesa interface
- */
+/* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
 
 /*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * Mesa 3-D graphics library
+ * Version:  3.3
+ *
+ * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
+ * terms stated above.
  *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Thank you for your contribution, David!
  *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Please make note of the above copyright/license statement.  If you
+ * contributed code or bug fixes to this code under the previous (GNU
+ * Library) license and object to the new license, your code will be
+ * removed at your request.  Please see the Mesa docs/COPYRIGHT file
+ * for more information.
  *
- * See the file fxapi.c for more informations about authors
+ * Additional Mesa/3Dfx driver developers:
+ *   Daryll Strauss <daryll@precisioninsight.com>
+ *   Keith Whitwell <keith@precisioninsight.com>
  *
+ * See fxapi.h for more revision/author details.
  */
 
+
+
+/* fxwgl.c - Microsoft wgl functions emulation for
+ *           3Dfx VooDoo/Mesa interface
+ */
+
+
 #ifdef __WIN32__
 
 #ifdef __cplusplus
@@ -28,15 +56,14 @@ extern "C" {
 #endif
 
 #include <windows.h>
-#include <GL/gl.h>
-#include <GL/glu.h>
+#include "GL/gl.h"
 
 #ifdef __cplusplus
            }
 #endif
 
 #include <stdio.h>
-#include <GL/fxmesa.h>
+#include "GL/fxmesa.h"
 #include "fxdrv.h"
 
 #define MAX_MESA_ATTRS  20
@@ -89,6 +116,40 @@ static struct __extensions__   ext[] = {
    { (PROC)glPointParameterfEXT,               "glPointParameterfEXT"          },
    { (PROC)glPointParameterfvEXT,              "glPointParameterfvEXT"         },
    { (PROC)glBlendFuncSeparateINGR,            "glBlendFuncSeparateINGR"       },
+   { (PROC)glActiveTextureARB,                  "glActiveTextureARB"           },
+   { (PROC)glClientActiveTextureARB,            "glClientActiveTextureARB"     },
+   { (PROC)glMultiTexCoord1dARB,                "glMultiTexCoord1dARB"         },
+   { (PROC)glMultiTexCoord1dvARB,               "glMultiTexCoord1dvARB"                },
+   { (PROC)glMultiTexCoord1fARB,                "glMultiTexCoord1fARB"         },
+   { (PROC)glMultiTexCoord1fvARB,               "glMultiTexCoord1fvARB"                },
+   { (PROC)glMultiTexCoord1iARB,                "glMultiTexCoord1iARB"         },
+   { (PROC)glMultiTexCoord1ivARB,               "glMultiTexCoord1ivARB"                },
+   { (PROC)glMultiTexCoord1sARB,                "glMultiTexCoord1sARB"         },
+   { (PROC)glMultiTexCoord1svARB,               "glMultiTexCoord1svARB"                },
+   { (PROC)glMultiTexCoord2dARB,                "glMultiTexCoord2dARB"         },
+   { (PROC)glMultiTexCoord2dvARB,               "glMultiTexCoord2dvARB"                },
+   { (PROC)glMultiTexCoord2fARB,                "glMultiTexCoord2fARB"         },
+   { (PROC)glMultiTexCoord2fvARB,               "glMultiTexCoord2fvARB"                },
+   { (PROC)glMultiTexCoord2iARB,                "glMultiTexCoord2iARB"         },
+   { (PROC)glMultiTexCoord2ivARB,               "glMultiTexCoord2ivARB"                },
+   { (PROC)glMultiTexCoord2sARB,                "glMultiTexCoord2sARB"         },
+   { (PROC)glMultiTexCoord2svARB,               "glMultiTexCoord2svARB"                },
+   { (PROC)glMultiTexCoord3dARB,                "glMultiTexCoord3dARB"         },
+   { (PROC)glMultiTexCoord3dvARB,               "glMultiTexCoord3dvARB"                },
+   { (PROC)glMultiTexCoord3fARB,                "glMultiTexCoord3fARB"         },
+   { (PROC)glMultiTexCoord3fvARB,               "glMultiTexCoord3fvARB"                },
+   { (PROC)glMultiTexCoord3iARB,                "glMultiTexCoord3iARB"         },
+   { (PROC)glMultiTexCoord3ivARB,               "glMultiTexCoord3ivARB"                },
+   { (PROC)glMultiTexCoord3sARB,                "glMultiTexCoord3sARB"         },
+   { (PROC)glMultiTexCoord3svARB,               "glMultiTexCoord3svARB"                },
+   { (PROC)glMultiTexCoord4dARB,                "glMultiTexCoord4dARB"         },
+   { (PROC)glMultiTexCoord4dvARB,               "glMultiTexCoord4dvARB"                },
+   { (PROC)glMultiTexCoord4fARB,                "glMultiTexCoord4fARB"         },
+   { (PROC)glMultiTexCoord4fvARB,               "glMultiTexCoord4fvARB"                },
+   { (PROC)glMultiTexCoord4iARB,                "glMultiTexCoord4iARB"         },
+   { (PROC)glMultiTexCoord4ivARB,               "glMultiTexCoord4ivARB"                },
+   { (PROC)glMultiTexCoord4sARB,                "glMultiTexCoord4sARB"         },
+   { (PROC)glMultiTexCoord4svARB,               "glMultiTexCoord4svARB"                },
    { (PROC)glLockArraysEXT,                    "glLockArraysEXT"               },
    { (PROC)glUnlockArraysEXT,                  "glUnlockArraysEXT"             }
 };
@@ -210,11 +271,11 @@ LONG GLAPIENTRY __wglMonitor(HWND hwnd,UINT message,UINT wParam,LONG lParam)
         static int moving = 0;
         if (!moving) {
           if(fxQueryHardware()!=GR_SSTTYPE_VOODOO) {
-            if(!grSstControl(GR_CONTROL_RESIZE)) {
+            if(!FX_grSstControl(GR_CONTROL_RESIZE)) {
               moving = 1;
               SetWindowPos(hwnd, 0, 0, 0, 300, 300, SWP_NOMOVE|SWP_NOZORDER);
               moving = 0;
-              if(!grSstControl(GR_CONTROL_RESIZE)) {
+              if(!FX_grSstControl(GR_CONTROL_RESIZE)) {
                 /*MessageBox(0,_T("Error changing windowsize"),_T("fxMESA"),MB_OK);*/
                 PostMessage(hWND,WM_CLOSE,0,0);
               }
@@ -222,7 +283,7 @@ LONG GLAPIENTRY __wglMonitor(HWND hwnd,UINT message,UINT wParam,LONG lParam)
           }
 
           /* Do the clipping in the glide library */
-          grClipWindow(0,0,grSstScreenWidth(),grSstScreenHeight());
+          FX_grClipWindow(0,0,FX_grSstScreenWidth(),FX_grSstScreenHeight());
           /* And let the new size set in the context */
           fxMesaUpdateScreenSize(ctx);
         }
@@ -236,21 +297,22 @@ LONG GLAPIENTRY __wglMonitor(HWND hwnd,UINT message,UINT wParam,LONG lParam)
         BOOL fMinimized = (BOOL) HIWORD(wParam);
 
         if((fActive == WA_INACTIVE) || fMinimized)
-          grSstControl(GR_CONTROL_DEACTIVATE);
+          FX_grSstControl(GR_CONTROL_DEACTIVATE);
         else
-          grSstControl(GR_CONTROL_ACTIVATE);
+          FX_grSstControl(GR_CONTROL_ACTIVATE);
       }
       break;
     case WM_SHOWWINDOW:
       break;
+    case WM_SYSKEYDOWN:
     case WM_SYSCHAR:
       if(gdiWindowHackEna && (VK_RETURN == wParam)) {
         if(gdiWindowHack) {
           gdiWindowHack = GL_FALSE;
-          grSstControl(GR_CONTROL_ACTIVATE);
+          FX_grSstControl(GR_CONTROL_ACTIVATE);
         } else {
           gdiWindowHack = GL_TRUE;
-          grSstControl(GR_CONTROL_DEACTIVATE);
+          FX_grSstControl(GR_CONTROL_DEACTIVATE);
         }
       }
       break;
@@ -318,7 +380,7 @@ HGLRC GLAPIENTRY wglCreateContext(HDC hdc)
 
       hDC = GetDC(dibWnd);
 
-      dibBMI = (BITMAPINFO*) malloc( sizeof(BITMAPINFO) + (256*sizeof(RGBQUAD)));
+      dibBMI = (BITMAPINFO*) MALLOC( sizeof(BITMAPINFO) + (256*sizeof(RGBQUAD)));
 
       memset(dibBMI,0,sizeof(BITMAPINFO) + (256*sizeof(RGBQUAD)));
 
@@ -349,7 +411,7 @@ HGLRC GLAPIENTRY wglCreateContext(HDC hdc)
         gdiWindowHack = GL_FALSE;
       else {
         gdiWindowHack = GL_TRUE;
-        grSstControl(GR_CONTROL_DEACTIVATE);
+        FX_grSstControl(GR_CONTROL_DEACTIVATE);
       }
     }
   } else {
@@ -396,7 +458,7 @@ BOOL GLAPIENTRY wglDeleteContext(HGLRC hglrc)
   if(ctx && hglrc == (HGLRC)1) {
     if (gdiWindowHackEna) {
       DeleteObject(dibHBM);
-      free(dibBMI);
+      FREE(dibBMI);
 
       dibSurfacePtr = NULL;
       dibBMI = NULL;
@@ -509,7 +571,7 @@ BOOL GLAPIENTRY wglUseFontBitmaps(HDC fontDevice, DWORD firstChar, DWORD numChar
   SetTextColor(bitDevice, tempColor);
 
   // Place chars based on base line
-  VERIFY(SetTextAlign(bitDevice, TA_BASELINE) >= 0);
+  VERIFY(SetTextAlign(bitDevice, TA_BASELINE) >= 0 ? 1 : 0);
 
   for(i = 0; i < numChars; i++) {
     SIZE size;
@@ -551,7 +613,7 @@ BOOL GLAPIENTRY wglUseFontBitmaps(HDC fontDevice, DWORD firstChar, DWORD numChar
 
     // Convert the display dependant representation to a 1 bit deep DIB
     numBytes = (bmapWidth * bmapHeight) / 8;
-    bmap = malloc(numBytes);
+    bmap = MALLOC(numBytes);
     dibInfo->bmiHeader.biWidth = bmapWidth;
     dibInfo->bmiHeader.biHeight = bmapHeight;
     res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap,
@@ -571,13 +633,13 @@ BOOL GLAPIENTRY wglUseFontBitmaps(HDC fontDevice, DWORD firstChar, DWORD numChar
     DeleteObject(bitObject);
 
     // Deallocate the bitmap data
-    free(bmap);
+    FREE(bmap);
   }
 
   // Destroy the DC
   VERIFY(DeleteDC(bitDevice));
 
-  free(dibInfo);
+  FREE(dibInfo);
 
   return TRUE;
 #undef VERIFY
@@ -746,7 +808,7 @@ BOOL GLAPIENTRY wglSwapBuffers(HDC hdc)
     HDC hdcDIBSection  = CreateCompatibleDC(hdcScreen);
     HBITMAP holdBitmap = (HBITMAP) SelectObject(hdcDIBSection, dibHBM);
 
-    grLfbReadRegion(GR_BUFFER_FRONTBUFFER, 0, 0,
+    FX_grLfbReadRegion(GR_BUFFER_FRONTBUFFER, 0, 0,
                     width, height,
                     width * 2,
                     dibSurfacePtr);
@@ -766,6 +828,7 @@ BOOL GLAPIENTRY wglSwapBuffers(HDC hdc)
      * display. Obviously, it's performance hit will be higher on larger displays and
      * less on smaller displays. To support the window-hack display this is probably fine.
      */
+#if  FXMESA_USE_ARGB
     {
       unsigned long *pixel = dibSurfacePtr;
       unsigned long count = (width * height) / 2;
@@ -778,7 +841,8 @@ BOOL GLAPIENTRY wglSwapBuffers(HDC hdc)
             ;
         }
     }
-
+#endif
+    
     BitBlt(hdcScreen, 0, 0,
            width, height,
            hdcDIBSection,