about summary refs log tree commit diff
path: root/src/engine/client/backend_sdl.h
diff options
context:
space:
mode:
authorTeetime <TeetimeTW@yahoo.de>2013-03-24 04:19:57 +0100
committerTeetime <TeetimeTW@yahoo.de>2013-03-24 04:19:57 +0100
commit4affc155a906b6091aafc3f9635acc3b8b0aed8a (patch)
tree43e4dc20b9c36599571f3caf2e9108a4bb3f5401 /src/engine/client/backend_sdl.h
parent6e73cd75bf24eb98781c68ae47d6527cc03262c8 (diff)
parent0914490bd994185caef6bfc3038f5cec737e31f3 (diff)
downloadzcatch-4affc155a906b6091aafc3f9635acc3b8b0aed8a.tar.gz
zcatch-4affc155a906b6091aafc3f9635acc3b8b0aed8a.zip
Merge branch 'master0.6' into zCatch
Conflicts:
	data/languages/index.txt
	src/game/server/entities/character.cpp
Diffstat (limited to 'src/engine/client/backend_sdl.h')
-rw-r--r--src/engine/client/backend_sdl.h94
1 files changed, 84 insertions, 10 deletions
diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h
index c6c2255a..e90f9455 100644
--- a/src/engine/client/backend_sdl.h
+++ b/src/engine/client/backend_sdl.h
@@ -28,24 +28,72 @@
 	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
+	{
+		SDL_sem *sem;
+	public:
+		semaphore() { sem = SDL_CreateSemaphore(0); }
+		~semaphore() { SDL_DestroySemaphore(sem); }
+		void wait() { SDL_SemWait(sem); }
+		void signal() { SDL_SemPost(sem); }
+	};
 
 	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>
@@ -119,11 +167,34 @@ public:
 // takes care of opengl related rendering
 class CCommandProcessorFragment_OpenGL
 {
-	GLuint m_aTextures[CCommandBuffer::MAX_TEXTURES];
+	struct CTexture
+	{
+		GLuint m_Tex;
+		int m_MemSize;
+	};
+	CTexture m_aTextures[CCommandBuffer::MAX_TEXTURES];
+	volatile int *m_pTextureMemoryUsage;
+
+public:
+	enum
+	{
+		CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_OPENGL,
+	};
+
+	struct SCommand_Init : public CCommandBuffer::SCommand
+	{
+		SCommand_Init() : SCommand(CMD_INIT) {}
+		volatile int *m_pTextureMemoryUsage;
+	};
+
+private:
 	static int TexFormatToOpenGLFormat(int TexFormat);
+	static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset, int ScaleW, int ScaleH, int Bpp);
+	static void *Rescale(int Width, int Height, int NewWidth, int NewHeight, int Format, const unsigned char *pData);
 
 	void SetState(const CCommandBuffer::SState &State);
 
+	void Cmd_Init(const SCommand_Init *pCommand);
 	void Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand);
 	void Cmd_Texture_Destroy(const CCommandBuffer::SCommand_Texture_Destroy *pCommand);
 	void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand);
@@ -145,7 +216,7 @@ class CCommandProcessorFragment_SDL
 public:
 	enum
 	{
-		CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM,
+		CMD_INIT = CCommandBuffer::CMDGROUP_PLATFORM_SDL,
 		CMD_SHUTDOWN,
 	};
 
@@ -187,10 +258,13 @@ class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded
 	SDL_Surface *m_pScreenSurface;
 	ICommandProcessor *m_pProcessor;
 	SGLContext m_GLContext;
+	volatile int m_TextureMemoryUsage;
 public:
-	virtual int Init(const char *pName, int Width, int Height, int FsaaSamples, int Flags);
+	virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags);
 	virtual int Shutdown();
 
+	virtual int MemoryUsage() const;
+
 	virtual void Minimize();
 	virtual void Maximize();
 	virtual int WindowActive();