]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix extension functions on Windows
authorMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 18:55:10 +0000 (20:55 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 21:23:00 +0000 (23:23 +0200)
They have to be marked with APIENTRY for the correct calling convention.
OpenGL 1.0 and 1.1 functions are not available through wglGetProcAddress,
so link them directly.

scripts/extgen.py
source/gl.h

index c5bc219a392e35db1d823a61df8dc3b927e28c88..ec57e2efb912fd9287185d7d5f0ab5bd9aa8609c 100755 (executable)
@@ -386,7 +386,7 @@ namespace GL {
 if funcs or enums:
        if funcs:
                for f in funcs:
-                       out.write("typedef %s (*%s)(%s);\n"%(f.return_type, f.typedef, ", ".join(f.params)))
+                       out.write("typedef %s (APIENTRY *%s)(%s);\n"%(f.return_type, f.typedef, ", ".join(f.params)))
                out.write("\n")
 
        if enums:
@@ -430,10 +430,16 @@ out.write("#include \"%s.h\"\n"%target_ext.name.lower())
 if funcs:
        out.write("""
 #ifdef __APPLE__
-#define GET_PROC_ADDRESS(x) ::x
+#define GET_PROC_ADDRESS(x) &::x
 #else
 #define GET_PROC_ADDRESS(x) get_proc_address(#x)
 #endif
+
+#ifdef WIN32
+#define GET_PROC_ADDRESS_1_1(x) &::x
+#else
+#define GET_PROC_ADDRESS_1_1(x) GET_PROC_ADDRESS(x)
+#endif
 """)
 out.write("""
 namespace Msp {
@@ -452,7 +458,10 @@ if core_version:
        out.write(")\n\t{\n")
        for f in funcs:
                if target_api in f.supported_apis:
-                       out.write("\t\t%s = reinterpret_cast<%s>(GET_PROC_ADDRESS(%s));\n"%(f.name, f.typedef, f.name))
+                       gpa_suffix = ""
+                       if f.version<=[1, 1]:
+                               gpa_suffix = "_1_1"
+                       out.write("\t\t%s = reinterpret_cast<%s>(GET_PROC_ADDRESS%s(%s));\n"%(f.name, f.typedef, gpa_suffix, f.name))
        out.write("\t\treturn Extension::CORE;\n")
        out.write("\t}\n")
 if source_ext and source_ext!=backport_ext:
index ae145457dff857d112a44c0b26d4ac7d9299df71..f7cba6b7aeaa098ff9ff6811c63cff6fa583ef4a 100644 (file)
@@ -18,4 +18,8 @@ typedef double GLdouble;
 #include <GL/glext.h>
 #endif
 
+#ifndef APIENTRY
+#define APIENTRY
+#endif
+
 #endif