Not sure it works correctly on Cocoa apps.
# 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)
#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_
#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED
#endif
-#ifdef _WIN32
+
+#if defined(_WIN32)
#include "glext/wglext.h"
#endif /* !WGL_SWAPMULTIPLE_MAX */
-#else /* !_WIN32 */
+#elif defined(__APPLE__)
+
+#include <OpenGL/OpenGL.h>
+
+#else
#include <GL/glx.h>
#include "glext/glxext.h"
/* Prevent collision with Trace::Bool */
#undef Bool
-#endif /* !_WIN32 */
-
-#ifdef __APPLE__
-
-#include <OpenGL/CGLCurrent.h>
+#endif
-#endif /* __APPLE__ */
#endif /* _GLIMPORTS_HPP_ */
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'
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
#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 {
*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
#include "glimports.hpp"
#include "glws.hpp"
+#include <X11/Xlib.h>
+#include <GL/glx.h>
+
namespace glws {