opengl32: Get WGL function definitions from the XML files.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
diff --git a/dlls/gdi32/dibdrv/opengl.c b/dlls/gdi32/dibdrv/opengl.c
index 77d6320..20cfc02 100644
--- a/dlls/gdi32/dibdrv/opengl.c
+++ b/dlls/gdi32/dibdrv/opengl.c
@@ -214,10 +214,10 @@
 /***********************************************************************
  *		dibdrv_wglDeleteContext
  */
-static void dibdrv_wglDeleteContext( struct wgl_context *context )
+static BOOL dibdrv_wglDeleteContext( struct wgl_context *context )
 {
     pOSMesaDestroyContext( context->context );
-    HeapFree( GetProcessHeap(), 0, context );
+    return HeapFree( GetProcessHeap(), 0, context );
 }
 
 /***********************************************************************
diff --git a/dlls/opengl32/make_opengl b/dlls/opengl32/make_opengl
index a3148d8..502b9ae 100755
--- a/dlls/opengl32/make_opengl
+++ b/dlls/opengl32/make_opengl
@@ -180,7 +180,19 @@
      "GLintptrARB" =>      [ "long", "INT_PTR" ],
      "GLsizeiptrARB" =>    [ "long", "INT_PTR" ],
      "GLhalfNV" =>         [ "long", "unsigned short" ],
-     "GLvdpauSurfaceNV" => [ "long", "INT_PTR" ]);
+     "GLvdpauSurfaceNV" => [ "long", "INT_PTR" ],
+     "HDC" =>              [ "long" ],
+     "HGLRC" =>            [ "long" ],
+     "HENHMETAFILE" =>     [ "long" ],
+     "LPGLYPHMETRICSFLOAT" => [ "ptr" ],
+     "LPCSTR" =>           [ "str" ],
+     "int" =>              [ "long" ],
+     "INT" =>              [ "long" ],
+     "BOOL" =>             [ "long" ],
+     "DWORD" =>            [ "long" ],
+     "FLOAT" =>            [ "float" ],
+     "UINT" =>             [ "long" ],
+    );
 
 #
 # Used to convert some types
@@ -358,9 +370,29 @@
     return $ret;
 }
 
+sub generate_spec_entry($$)
+{
+    my ($name, $func) = @_;
+    my $args=" ";
+    foreach my $arg (@{$func->[1]})
+    {
+        my $type = $arg->[0];
+        if ($type =~ /\*/) {
+            $args .= "ptr ";
+        } elsif (defined($arg_conv{$type})) {
+            $args .= "$@$arg_conv{$type}[0] ";
+        } else {
+            die "No conversion for func $name type $type\n";
+        }
+    }
+    $args = substr($args,1,-1);
+    return "@ stdcall $_($args)";
+}
+
 sub get_func_proto($$$)
 {
     my ($format, $name, $func) = @_;
+    die "unknown func $name" unless defined $func->[0];
     my $ret = sprintf "%-10s", ConvertType($func->[0]);
     $ret .= " " . sprintf($format,$name) . "(";
     for (my $i = 0; $i < @{$func->[1]}; $i++)
@@ -445,29 +477,33 @@
 #
 my %norm_functions;
 my %ext_functions;
+my %wgl_functions;
 
-my %wgl_functions =
-   (
-    "wglCopyContext" => [ "BOOL", [ [ "struct wgl_context *", "src" ],
-                                    [ "struct wgl_context *", "dst" ],
-                                    [ "UINT", "mask" ] ] ],
-    "wglCreateContext" => [ "struct wgl_context *", [ [ "HDC", "hdc" ] ] ],
-    "wglDeleteContext" => [ "void", [ [ "struct wgl_context *", "context" ] ] ],
-    "wglDescribePixelFormat" => [ "INT", [ [ "HDC", "hdc" ],
-                                           [ "INT", "format" ],
-                                           [ "UINT", "size" ],
-                                           [ "PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
-    "wglGetPixelFormat" => [ "INT", [ [ "HDC", "hdc" ] ] ],
-    "wglGetProcAddress" => [ "PROC", [ [ "LPCSTR", "name" ] ] ],
-    "wglMakeCurrent" => [ "BOOL", [ [ "HDC", "hdc" ],
-                                    [ "struct wgl_context *", "context" ] ] ],
-    "wglSetPixelFormat" => [ "BOOL", [ [ "HDC", "hdc" ],
-                                       [ "INT", "format" ],
-                                       [ "const PIXELFORMATDESCRIPTOR *", "descr" ] ] ],
-    "wglShareLists" => [ "BOOL", [ [ "struct wgl_context *", "org" ],
-                                   [ "struct wgl_context *", "dst" ] ] ],
-    "wglSwapBuffers" => [ "BOOL", [ [ "HDC", "hdc" ] ] ],
-   );
+my %supported_wgl_functions =
+    (
+     "wglCopyContext" => 1,
+     "wglCreateContext" => 1,
+     "wglDeleteContext" => 1,
+     "wglDescribePixelFormat" => 1,
+     "wglGetPixelFormat" => 1,
+     "wglGetProcAddress" => 1,
+     "wglMakeCurrent" => 1,
+     "wglSetPixelFormat" => 1,
+     "wglShareLists" => 1,
+     "wglSwapBuffers" => 1,
+    );
+
+my %remapped_wgl_functions =
+    (
+     "ChoosePixelFormat" => "wglChoosePixelFormat",
+     "DescribePixelFormat" => "wglDescribePixelFormat",
+     "GetPixelFormat" => "wglGetPixelFormat",
+     "GetEnhMetaFilePixelFormat" => 0,
+     "SetPixelFormat" => "wglSetPixelFormat",
+     "SwapBuffers" => "wglSwapBuffers",
+     "wglUseFontBitmaps" => 0,
+     "wglUseFontOutlines" => 0,
+    );
 
 my %supported_wgl_extensions =
    (
@@ -578,6 +614,19 @@
                 }
             }
         }
+        elsif ($v->{api} eq "wgl")
+        {
+            for my $req (@{$v->{require}}) {
+                for (keys %{$req->{command}}) {
+                    if (defined $remapped_wgl_functions{$_}) {
+                        $wgl_functions{$remapped_wgl_functions{$_}} = $functions{$_} if $remapped_wgl_functions{$_};
+                    }
+                    else {
+                        $wgl_functions{$_} = $functions{$_};
+                    }
+                }
+            }
+        }
     }
 
     # generate extension functions
@@ -643,6 +692,7 @@
 print HEADER "    struct\n    {\n";
 foreach (sort keys %wgl_functions)
 {
+    next unless defined $supported_wgl_functions{$_};
     printf HEADER "        %s;\n", get_func_proto("(WINE_GLAPI *p_%s)", $_, $wgl_functions{$_});
 }
 print HEADER "    } wgl;\n\n";
@@ -690,6 +740,7 @@
 
 foreach (sort keys %arg_conv)
 {
+    next unless $arg_conv{$_}[1];
     printf HEADER "typedef %-22s %s;\n", $arg_conv{$_}[1], $_;
 }
 print HEADER "\n";
@@ -716,46 +767,11 @@
 open(SPEC, ">$spec_file") or die "cannot create $spec_file";
 
 foreach (sort keys %norm_functions) {
-    my $args=" ";
-    for (my $i = 0; $i < @{$norm_functions{$_}->[1]}; $i++) {
-        my $type = $norm_functions{$_}->[1]->[$i]->[0];
-        if ($type =~ /\*/) {
-            $args .= "ptr ";
-        } elsif (defined($arg_conv{$type})) {
-            $args .= "$@$arg_conv{$type}[0] ";
-        } else {
-            die "No conversion for GL type $type...\n";
-        }
-    }
-    $args = substr($args,1,-1);
-    print SPEC "@ stdcall $_($args)\n";
+    printf SPEC "%s\n", generate_spec_entry( $_, $norm_functions{$_} );
 }
-
-print SPEC "@ stdcall wglChoosePixelFormat(long ptr)
-@ stdcall wglCopyContext(long long long)
-@ stdcall wglCreateContext(long)
-@ stdcall wglCreateLayerContext(long long)
-@ stdcall wglDeleteContext(long)
-@ stdcall wglDescribeLayerPlane(long long long long ptr)
-@ stdcall wglDescribePixelFormat(long long long ptr)
-@ stdcall wglGetCurrentContext()
-@ stdcall wglGetCurrentDC()
-@ stub    wglGetDefaultProcAddress
-@ stdcall wglGetLayerPaletteEntries(long long long long ptr)
-@ stdcall wglGetPixelFormat(long)
-@ stdcall wglGetProcAddress(str)
-@ stdcall wglMakeCurrent(long long)
-@ stdcall wglRealizeLayerPalette(long long long)
-@ stdcall wglSetLayerPaletteEntries(long long long long ptr)
-@ stdcall wglSetPixelFormat(long long ptr)
-@ stdcall wglShareLists(long long)
-@ stdcall wglSwapBuffers(long)
-@ stdcall wglSwapLayerBuffers(long long)
-@ stdcall wglUseFontBitmapsA(long long long long)
-@ stdcall wglUseFontBitmapsW(long long long long)
-@ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
-@ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
-";
+foreach (sort keys %wgl_functions) {
+    printf SPEC "%s\n", generate_spec_entry( $_, $wgl_functions{$_} );
+}
 
 close(SPEC);
 
@@ -783,6 +799,7 @@
 }
 
 foreach (sort keys %wgl_functions) {
+    next unless defined $supported_wgl_functions{$_};
     print NORM generate_null_func($_, $wgl_functions{$_});
 }
 foreach (sort keys %norm_functions) {
@@ -793,7 +810,11 @@
 }
 
 print NORM "\nstruct opengl_funcs null_opengl_funcs =\n{\n    {\n";
-foreach (sort keys %wgl_functions) { print NORM "        null_$_,\n"; }
+foreach (sort keys %wgl_functions)
+{
+    next unless defined $supported_wgl_functions{$_};
+    print NORM "        null_$_,\n";
+}
 print NORM "    },\n    {\n";
 foreach (sort keys %norm_functions) { print NORM "        null_$_,\n" unless $_ eq "glDebugEntry"; }
 print NORM "    },\n    {\n";
diff --git a/dlls/opengl32/opengl32.spec b/dlls/opengl32/opengl32.spec
index f620ac4..4d4288c 100644
--- a/dlls/opengl32/opengl32.spec
+++ b/dlls/opengl32/opengl32.spec
@@ -344,7 +344,6 @@
 @ stdcall wglDescribePixelFormat(long long long ptr)
 @ stdcall wglGetCurrentContext()
 @ stdcall wglGetCurrentDC()
-@ stub    wglGetDefaultProcAddress
 @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
 @ stdcall wglGetPixelFormat(long)
 @ stdcall wglGetProcAddress(str)
@@ -357,5 +356,5 @@
 @ stdcall wglSwapLayerBuffers(long long)
 @ stdcall wglUseFontBitmapsA(long long long long)
 @ stdcall wglUseFontBitmapsW(long long long long)
-@ stdcall wglUseFontOutlinesA(long long long long long long long ptr)
-@ stdcall wglUseFontOutlinesW(long long long long long long long ptr)
+@ stdcall wglUseFontOutlinesA(long long long long float float long ptr)
+@ stdcall wglUseFontOutlinesW(long long long long float float long ptr)
diff --git a/dlls/opengl32/opengl_norm.c b/dlls/opengl32/opengl_norm.c
index d974cb4..1640b17 100644
--- a/dlls/opengl32/opengl_norm.c
+++ b/dlls/opengl32/opengl_norm.c
@@ -2014,15 +2014,15 @@
   TRACE("(%d, %d, %d, %d)\n", x, y, width, height );
   funcs->gl.p_glViewport( x, y, width, height );
 }
-static BOOL null_wglCopyContext( struct wgl_context * src, struct wgl_context * dst, UINT mask ) { return 0; }
-static struct wgl_context * null_wglCreateContext( HDC hdc ) { return 0; }
-static void null_wglDeleteContext( struct wgl_context * context ) { }
-static INT null_wglDescribePixelFormat( HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR * descr ) { return 0; }
-static INT null_wglGetPixelFormat( HDC hdc ) { return 0; }
-static PROC null_wglGetProcAddress( LPCSTR name ) { return 0; }
-static BOOL null_wglMakeCurrent( HDC hdc, struct wgl_context * context ) { return 0; }
-static BOOL null_wglSetPixelFormat( HDC hdc, INT format, const PIXELFORMATDESCRIPTOR * descr ) { return 0; }
-static BOOL null_wglShareLists( struct wgl_context * org, struct wgl_context * dst ) { return 0; }
+static BOOL null_wglCopyContext( struct wgl_context * hglrcSrc, struct wgl_context * hglrcDst, UINT mask ) { return 0; }
+static struct wgl_context * null_wglCreateContext( HDC hDc ) { return 0; }
+static BOOL null_wglDeleteContext( struct wgl_context * oldContext ) { return 0; }
+static int null_wglDescribePixelFormat( HDC hdc, int ipfd, UINT cjpfd, PIXELFORMATDESCRIPTOR* ppfd ) { return 0; }
+static int null_wglGetPixelFormat( HDC hdc ) { return 0; }
+static PROC null_wglGetProcAddress( LPCSTR lpszProc ) { return 0; }
+static BOOL null_wglMakeCurrent( HDC hDc, struct wgl_context * newContext ) { return 0; }
+static BOOL null_wglSetPixelFormat( HDC hdc, int ipfd, const PIXELFORMATDESCRIPTOR* ppfd ) { return 0; }
+static BOOL null_wglShareLists( struct wgl_context * hrcSrvShare, struct wgl_context * hrcSrvSource ) { return 0; }
 static BOOL null_wglSwapBuffers( HDC hdc ) { return 0; }
 static void null_glAccum( GLenum op, GLfloat value ) { }
 static void null_glAlphaFunc( GLenum func, GLfloat ref ) { }
diff --git a/dlls/opengl32/winegl.xml b/dlls/opengl32/winegl.xml
index 683e910..2461d35 100644
--- a/dlls/opengl32/winegl.xml
+++ b/dlls/opengl32/winegl.xml
@@ -276,6 +276,14 @@
 
     <commands namespace="WGL">
         <command>
+            <proto>int <name>wglDescribePixelFormat</name></proto>
+            <param><ptype>HDC</ptype> <name>hdc</name></param>
+            <param>int <name>ipfd</name></param>
+            <param><ptype>UINT</ptype> <name>cjpfd</name></param>
+            <!-- pixel format is wrongly specified 'const' in wgl.xml -->
+            <param><ptype>PIXELFORMATDESCRIPTOR</ptype> *<name>ppfd</name></param>
+        </command>
+        <command>
             <proto>BOOL <name>wglSetPixelFormatWINE</name></proto>
             <param><ptype>HDC</ptype> <name>hdc</name></param>
             <param>int <name>format</name></param>
@@ -310,6 +318,12 @@
         </require>
     </feature>
 
+    <feature api="wgl" name="WGL_VERSION_1_0" number="1.0">
+        <require>
+            <command name="wglDescribePixelFormat"/>
+        </require>
+    </feature>
+
     <enums namespace="WGL" group="RendererWINE">
         <enum value="0x8183" name="WGL_RENDERER_VENDOR_ID_WINE"/>
         <enum value="0x8184" name="WGL_RENDERER_DEVICE_ID_WINE"/>
diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c
index ec26000..d6cd93b 100644
--- a/dlls/wineandroid.drv/opengl.c
+++ b/dlls/wineandroid.drv/opengl.c
@@ -439,13 +439,13 @@
 /***********************************************************************
  *		android_wglDeleteContext
  */
-static void android_wglDeleteContext( struct wgl_context *ctx )
+static BOOL android_wglDeleteContext( struct wgl_context *ctx )
 {
     EnterCriticalSection( &drawable_section );
     list_remove( &ctx->entry );
     LeaveCriticalSection( &drawable_section );
     p_eglDestroyContext( display, ctx->context );
-    HeapFree( GetProcessHeap(), 0, ctx );
+    return HeapFree( GetProcessHeap(), 0, ctx );
 }
 
 /***********************************************************************
diff --git a/dlls/winemac.drv/opengl.c b/dlls/winemac.drv/opengl.c
index 6e1f151..a7a67de 100644
--- a/dlls/winemac.drv/opengl.c
+++ b/dlls/winemac.drv/opengl.c
@@ -4434,7 +4434,7 @@
 /***********************************************************************
  *              macdrv_wglDeleteContext
  */
-static void macdrv_wglDeleteContext(struct wgl_context *context)
+static BOOL macdrv_wglDeleteContext(struct wgl_context *context)
 {
     TRACE("deleting context %p/%p/%p\n", context, context->context, context->cglcontext);
 
@@ -4443,7 +4443,7 @@
     LeaveCriticalSection(&context_section);
 
     macdrv_dispose_opengl_context(context->context);
-    HeapFree(GetProcessHeap(), 0, context);
+    return HeapFree(GetProcessHeap(), 0, context);
 }
 
 /***********************************************************************
diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c
index 5eb70a8..f9faa4b 100644
--- a/dlls/winex11.drv/opengl.c
+++ b/dlls/winex11.drv/opengl.c
@@ -1841,7 +1841,7 @@
 /***********************************************************************
  *		glxdrv_wglDeleteContext
  */
-static void glxdrv_wglDeleteContext(struct wgl_context *ctx)
+static BOOL glxdrv_wglDeleteContext(struct wgl_context *ctx)
 {
     struct wgl_pbuffer *pb;
 
@@ -1860,7 +1860,7 @@
 
     if (ctx->ctx) pglXDestroyContext( gdi_display, ctx->ctx );
     if (ctx->vis) XFree( ctx->vis );
-    HeapFree( GetProcessHeap(), 0, ctx );
+    return HeapFree( GetProcessHeap(), 0, ctx );
 }
 
 /***********************************************************************
diff --git a/include/wine/wgl_driver.h b/include/wine/wgl_driver.h
index 16997e4..753d134 100644
--- a/include/wine/wgl_driver.h
+++ b/include/wine/wgl_driver.h
@@ -7,7 +7,7 @@
 #define WINE_GLAPI
 #endif
 
-#define WINE_WGL_DRIVER_VERSION 16
+#define WINE_WGL_DRIVER_VERSION 17
 
 struct wgl_context;
 struct wgl_pbuffer;
@@ -18,12 +18,12 @@
     {
         BOOL       (WINE_GLAPI *p_wglCopyContext)(struct wgl_context *,struct wgl_context *,UINT);
         struct wgl_context * (WINE_GLAPI *p_wglCreateContext)(HDC);
-        void       (WINE_GLAPI *p_wglDeleteContext)(struct wgl_context *);
-        INT        (WINE_GLAPI *p_wglDescribePixelFormat)(HDC,INT,UINT,PIXELFORMATDESCRIPTOR *);
-        INT        (WINE_GLAPI *p_wglGetPixelFormat)(HDC);
+        BOOL       (WINE_GLAPI *p_wglDeleteContext)(struct wgl_context *);
+        int        (WINE_GLAPI *p_wglDescribePixelFormat)(HDC,int,UINT,PIXELFORMATDESCRIPTOR*);
+        int        (WINE_GLAPI *p_wglGetPixelFormat)(HDC);
         PROC       (WINE_GLAPI *p_wglGetProcAddress)(LPCSTR);
         BOOL       (WINE_GLAPI *p_wglMakeCurrent)(HDC,struct wgl_context *);
-        BOOL       (WINE_GLAPI *p_wglSetPixelFormat)(HDC,INT,const PIXELFORMATDESCRIPTOR *);
+        BOOL       (WINE_GLAPI *p_wglSetPixelFormat)(HDC,int,const PIXELFORMATDESCRIPTOR*);
         BOOL       (WINE_GLAPI *p_wglShareLists)(struct wgl_context *,struct wgl_context *);
         BOOL       (WINE_GLAPI *p_wglSwapBuffers)(HDC);
     } wgl;