about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohannes Loher <johannes.loher@ccartists.de>2012-08-26 20:02:04 +0200
committeroy <Tom_Adams@web.de>2013-02-24 18:01:23 +0100
commit678b6faceb8f8bd550de32b8fe59f7c34e2a3172 (patch)
tree350aedc3d0755c4f6de7b7464f1708f679b286b5
parentd8ff437c5ecc4cc3e7f627d6ac6f20447e6efaf6 (diff)
downloadzcatch-678b6faceb8f8bd550de32b8fe59f7c34e2a3172.tar.gz
zcatch-678b6faceb8f8bd550de32b8fe59f7c34e2a3172.zip
Fixed threaded gfx and building on Mac OS X
-rw-r--r--src/engine/client/backend_sdl.cpp3
-rw-r--r--src/engine/client/backend_sdl.h52
2 files changed, 48 insertions, 7 deletions
diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp
index cb865bae..22c48e53 100644
--- a/src/engine/client/backend_sdl.cpp
+++ b/src/engine/client/backend_sdl.cpp
@@ -11,6 +11,9 @@
 
 void CGraphicsBackend_Threaded::ThreadFunc(void *pUser)
 {
+	#ifdef CONF_PLATFORM_MACOSX
+		CAutoreleasePool AutoreleasePool;
+	#endif
 	CGraphicsBackend_Threaded *pThis = (CGraphicsBackend_Threaded *)pUser;
 
 	while(!pThis->m_Shutdown)
diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h
index 2ef04a1f..619ba84d 100644
--- a/src/engine/client/backend_sdl.h
+++ b/src/engine/client/backend_sdl.h
@@ -28,7 +28,7 @@
 	static void GL_SwapBuffers(const SGLContext &Context) { SwapBuffers(Context.m_hDC); }
 #elif defined(CONF_PLATFORM_MACOSX)
 
-	#include <AGL/agl.h>
+	#include <objc/objc-runtime.h>
 
 	class semaphore
 	{
@@ -42,20 +42,58 @@
 
 	struct SGLContext
 	{
-		AGLContext m_Context;
+		id m_Context;
 	};
 
 	static SGLContext GL_GetCurrentContext()
 	{
 		SGLContext Context;
-		Context.m_Context = aglGetCurrentContext();
+		Class NSOpenGLContextClass = (Class) objc_getClass("NSOpenGLContext");
+		SEL selector = sel_registerName("currentContext");
+		Context.m_Context = objc_msgSend((objc_object*) NSOpenGLContextClass, selector);
 		return Context;
 	}
 
-	static void GL_MakeCurrent(const SGLContext &Context) { aglSetCurrentContext(Context.m_Context); }
-	static void GL_ReleaseContext(const SGLContext &Context) { aglSetCurrentContext(NULL); }
-	static void GL_SwapBuffers(const SGLContext &Context) { aglSwapBuffers(Context.m_Context); }
-		
+	static void GL_MakeCurrent(const SGLContext &Context)
+	{
+		SEL selector = sel_registerName("makeCurrentContext");
+		objc_msgSend(Context.m_Context, selector);
+	}
+
+	static void GL_ReleaseContext(const SGLContext &Context)
+	{
+		Class NSOpenGLContextClass = (Class) objc_getClass("NSOpenGLContext");
+		SEL selector = sel_registerName("clearCurrentContext");
+		objc_msgSend((objc_object*) NSOpenGLContextClass, selector);
+	}
+
+	static void GL_SwapBuffers(const SGLContext &Context)
+	{
+		SEL selector = sel_registerName("flushBuffer");
+		objc_msgSend(Context.m_Context, selector);
+	}
+
+	class CAutoreleasePool
+	{
+	private:
+		id m_Pool;
+
+	public:
+		CAutoreleasePool()
+		{
+			Class NSAutoreleasePoolClass = (Class) objc_getClass("NSAutoreleasePool");
+			m_Pool = class_createInstance(NSAutoreleasePoolClass, 0);
+			SEL selector = sel_registerName("init");
+			objc_msgSend(m_Pool, selector);
+		}
+
+		~CAutoreleasePool()
+		{
+			SEL selector = sel_registerName("drain");
+			objc_msgSend(m_Pool, selector);
+		}
+	};							
+
 #elif defined(CONF_FAMILY_UNIX)
 
 	#include <GL/glx.h>