]> git.cworth.org Git - apitrace/commitdiff
Determine drawable sizes on MacOSX.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 19 May 2011 16:57:18 +0000 (17:57 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 19 May 2011 16:57:18 +0000 (17:57 +0100)
Not sure it works correctly on Cocoa apps.

CMakeLists.txt
glimports.hpp
glproc.py
glstate.cpp
glws_glx.cpp

index 44b4c84a2bba93a97f199722ffbc9e671466cdf6..35eccca070e1f2fe7b8a30fa79800419ae9b4335 100755 (executable)
@@ -347,7 +347,8 @@ if (NOT WIN32)
     # We use GLX on MacOSX, which is in a separate library
     if (APPLE)
         find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
-        target_link_libraries (glretrace ${X11_GL_LIB})
+        find_library (APPLICATIONSERVICES ApplicationServices)
+        target_link_libraries (glretrace ${X11_GL_LIB} ${APPLICATIONSERVICES})
     endif (APPLE)
 endif (NOT WIN32)
 
index 720e48a105b93bb54563b8dfcc951386118fcb9d..5cb276db1d1529bdd311441f92f92b7e3f6bda8b 100644 (file)
@@ -30,7 +30,8 @@
 #ifndef _GLIMPORTS_HPP_
 #define _GLIMPORTS_HPP_
 
-#ifdef _WIN32
+
+#if defined(_WIN32)
 
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN 1
 
 #include <windows.h>
 
-#else /* !_WIN32 */
+#elif defined(__APPLE__)
+
+#else
 
 #include <X11/Xlib.h>
 
 #endif /* !_WIN32 */
 
+
 // Prevent including system's glext.h
 #define __glext_h_
 
@@ -57,7 +61,8 @@
 #define GL_TEXTURE_INDEX_SIZE_EXT         0x80ED
 #endif
 
-#ifdef _WIN32
+
+#if defined(_WIN32)
 
 #include "glext/wglext.h"
 
@@ -83,7 +88,11 @@ typedef struct _WGLSWAP
 
 #endif /* !WGL_SWAPMULTIPLE_MAX */
 
-#else /* !_WIN32 */
+#elif defined(__APPLE__)
+
+#include <OpenGL/OpenGL.h>
+
+#else
 
 #include <GL/glx.h>
 #include "glext/glxext.h"
@@ -91,12 +100,7 @@ typedef struct _WGLSWAP
 /* Prevent collision with Trace::Bool */
 #undef Bool
 
-#endif /* !_WIN32 */
-
-#ifdef __APPLE__
-
-#include <OpenGL/CGLCurrent.h>
+#endif
 
-#endif /* __APPLE__ */
 
 #endif /* _GLIMPORTS_HPP_ */
index 067017b7f9bdf9a89deb327ec21fde385fed48d8..b036b359b95e33f8aee1134ee0a7249fa66da4fe 100644 (file)
--- a/glproc.py
+++ b/glproc.py
@@ -411,8 +411,11 @@ class GlDispatcher(Dispatcher):
 
     def header(self):
         print '#ifdef RETRACE'
-        print '#  ifdef _WIN32'
+        print '#  if defined(_WIN32)'
         print '#    define __getPrivateProcAddress(name) wglGetProcAddress(name)'
+        print '#  elif defined(__APPLE__)'
+        print '#    include <dlfcn.h>'
+        print '#    define __getPrivateProcAddress(name) dlsym(RTLD_DEFAULT, name)'
         print '#  else'
         print '#    define __getPrivateProcAddress(name) glXGetProcAddressARB((const GLubyte *)(name))'
         print '#  endif'
@@ -450,17 +453,15 @@ if __name__ == '__main__':
     print
     dispatcher = GlDispatcher()
     dispatcher.header()
-    print '#ifdef _WIN32'
+    print '#if defined(_WIN32)'
     print
     dispatcher.dispatch_api(wglapi)
-    print '#else /* !_WIN32 */'
+    print '#elif defined(__APPLE__)'
+    dispatcher.dispatch_api(cglapi)
+    print '#else'
     print
     dispatcher.dispatch_api(glxapi)
-    print '#endif /* !_WIN32 */'
-    print
-    print '#ifdef __APPLE__'
-    dispatcher.dispatch_api(cglapi)
-    print '#endif /* __APPLE__ */'
+    print '#endif'
     print
     dispatcher.dispatch_api(glapi)
     print
index a60c687691f39ef317025a4ab5f8426b9f8dbaa0..6dc6f8063a2bf37c5c0b6896ac7f777214fa76bd 100644 (file)
 #include "glstate.hpp"
 
 
+#ifdef __APPLE__
+
+#include <Carbon/Carbon.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef int CGSConnectionID;
+typedef int CGSWindowID;
+typedef int CGSSurfaceID;
+
+CGLError CGLGetSurface(CGLContextObj, CGSConnectionID*, CGSWindowID*, CGSSurfaceID*);
+OSStatus CGSGetSurfaceBounds(CGSConnectionID, CGWindowID, CGSSurfaceID, CGRect *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPLE__ */
+
+
 namespace glstate {
 
 
@@ -328,10 +350,29 @@ getDrawableBounds(GLint *width, GLint *height) {
     *width  = rect.right  - rect.left;
     *height = rect.bottom - rect.top;
 
-#elif 0 /* __APPLE__ */
+#elif defined(__APPLE__)
+
+    CGLContextObj ctx = CGLGetCurrentContext();
+    if (ctx == NULL) {
+        return false;
+    }
+
+    CGSConnectionID cid;
+    CGSWindowID wid;
+    CGSSurfaceID sid;
+
+    if (CGLGetSurface(ctx, &cid, &wid, &sid) != kCGLNoError) {
+        return false;
+    }
+
+    CGRect rect;
+
+    if (CGSGetSurfaceBounds(cid, wid, sid, &rect) != 0) {
+        return false;
+    }
 
-    CGLError CGLGetSurface(CGLContextObj, CGSConnectionID*, CGSWindowID*, CGSSurfaceID*);
-    CGError CGSGetWindowBounds(CGSConnectionID, CGWindowID, CGRect *ret);
+    *width = rect.size.width;
+    *height = rect.size.height;
 
 #else
 
index 62bbb06e74c77905686708d1f6c7da088b0d24da..bba108a43a5d64c175368cc0cacfd1068c5d04f9 100644 (file)
@@ -29,6 +29,9 @@
 #include "glimports.hpp"
 #include "glws.hpp"
 
+#include <X11/Xlib.h>
+#include <GL/glx.h>
+
 
 namespace glws {