Final touches of OS X support
authorMikko Rasa <tdb@tdb.fi>
Thu, 3 Oct 2013 08:02:04 +0000 (11:02 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 3 Oct 2013 08:02:04 +0000 (11:02 +0300)
.gitignore
scripts/extgen.py
source/extension.cpp
source/gl.h

index 62e48cab2a7d02f942034474cd4dcf19c18c2be2..cff6fec50fccf0ed2270736f5e607ef36fd2bd6a 100644 (file)
@@ -4,6 +4,7 @@ temp
 /desertpillars
 /libmspgl.a
 /libmspgl.so
+/libmspgl.dylib
 /mesh2c
 /mspgl.pc
 /shaders
index 4333cf37345f176d06fdf52abe2e6f30d8cc1f0c..eef6475adbdad5506ad39068286e2efa03b3922a 100755 (executable)
@@ -247,8 +247,13 @@ if funcs or enums:
        for e in enums:
                out.write("#define %s 0x%04X\n"%(e.name, e.value))
        out.write("#endif\n\n")
+
+       # Apple's OpenGL implementation doesn't have a GetProcAddress function; link
+       # directly to the OpenGL library
+       out.write("\n#if !defined(__APPLE__) || !defined(GL_%s)\n"%ext)
        for f in funcs:
                out.write("extern %s %s;\n"%(f.typedef, f.name))
+       out.write("#endif\n")
 
 out.write("\nextern Extension %s;\n"%ext)
 
@@ -268,9 +273,10 @@ namespace GL {
 """)
 
 if funcs:
-       out.write("\n")
-for f in funcs:
-       out.write("%s %s = 0;\n"%(f.typedef, f.name))
+       out.write("\n#if !defined(__APPLE__) || !defined(GL_%s)\n"%ext)
+       for f in funcs:
+               out.write("%s %s = 0;\n"%(f.typedef, f.name))
+       out.write("\n#endif\n")
 
 out.write("\nExtension::SupportLevel init_%s()\n{\n"%ext.lower())
 out.write("#ifdef GL_%s\n"%ext)
@@ -279,17 +285,23 @@ if ver:
        if backport_ext:
                out.write(" || is_supported(\"GL_%s\")"%backport_ext)
        out.write(")\n\t{\n")
-       for f in funcs:
-               out.write("\t\t%s = reinterpret_cast<%s>(get_proc_address(\"%s\"));\n"%(f.name, f.typedef, f.name))
+       if funcs:
+               out.write("#ifndef __APPLE__\n")
+               for f in funcs:
+                       out.write("\t\t%s = reinterpret_cast<%s>(get_proc_address(\"%s\"));\n"%(f.name, f.typedef, f.name))
+               out.write("#endif\n")
        out.write("\t\treturn Extension::CORE;\n")
        out.write("\t}\n")
 if ext!=backport_ext:
        out.write("\tif(is_supported(\"GL_%s\"))\n\t{\n"%(ext))
-       for f in funcs:
-               n = f.name
-               if f.source:
-                       n = f.source.name
-               out.write("\t\t%s = reinterpret_cast<%s>(get_proc_address(\"%s\"));\n"%(f.name, f.typedef, n))
+       if funcs:
+               out.write("#ifndef __APPLE__\n")
+               for f in funcs:
+                       n = f.name
+                       if f.source:
+                               n = f.source.name
+                       out.write("\t\t%s = reinterpret_cast<%s>(get_proc_address(\"%s\"));\n"%(f.name, f.typedef, n))
+               out.write("#endif\n")
        out.write("\t\treturn Extension::EXTENSION;\n")
        out.write("\t}\n")
 out.write("#endif\n")
index d4acedaf1213ac55817b6d30715db1b7364c95d1..56f96d4ecee2136dcde2d42f5fbdfa7bbf8b421b 100644 (file)
@@ -1,5 +1,5 @@
 #include <set>
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__APPLE__)
 #define GLX_GLXEXT_PROTOTYPES
 #include <GL/glx.h>
 #endif
@@ -92,10 +92,13 @@ bool is_version_at_least(unsigned a, unsigned b)
 
 ExtFunc *get_proc_address(const string &name)
 {
-#ifndef WIN32
-       return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));
-#else
+#if defined(WIN32)
        return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));
+#elif defined(__APPLE__)
+       (void)name;
+       return 0;  // Not supported
+#else
+       return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));
 #endif
 }
 
index 2c77d6809456e8a8ba65276359e16c4943ab1ff3..05844ba5f4666e5b048209ab9340bff69a601d68 100644 (file)
@@ -4,7 +4,12 @@
 #ifdef WIN32
 #include <windows.h>
 #endif
+#ifdef __APPLE__
+#include <OpenGL/gl.h>
+#include <OpenGL/glext.h>
+#else
 #include <GL/gl.h>
 #include <GL/glext.h>
+#endif
 
 #endif