2
0
Эх сурвалжийг харах

GL2D::attachToCurrentThread implementaion for X11

paracelsus 12 жил өмнө
parent
commit
48a882901b

+ 4 - 4
client/Gfx/Animations.h

@@ -52,13 +52,13 @@ class CPalettedAnimation : CAnimation
 	CImage* frames[];
 
 protected:
+	CPalettedAnimation(const SH3DefFile& def, size_t fileSize);
+
+#pragma warning(disable : 4291)
 	inline void* operator new(size_t size, ui32 frCount) {
 		return ::operator new(size + frCount * sizeof(void*));
 	}
-	inline void operator delete(void* ptr, ui32 frCount) {
-		::operator delete(ptr);
-	}
-	CPalettedAnimation(const SH3DefFile& def, size_t fileSize);
+#pragma warning(default : 4291)
 
 public:
 	virtual ~CPalettedAnimation();

+ 29 - 1
client/UIFramework/GL2D.cpp

@@ -1,8 +1,15 @@
 #include "StdInc.h"
 #include <SDL.h>
 #include <SDL_video.h>
-#include "SDL_syswm.h"
+#include <SDL_syswm.h>
 #include <SDL_opengl.h>
+#if __unix__
+#	if !SDL_VIDEO_OPENGL_GLX
+#		error SDL_VIDEO_OPENGL_GLX required 
+#	endif
+#	include <GL/glx.h>
+#	define _GLX 1
+#endif
 #include "GL2D.h"
 
 
@@ -11,6 +18,9 @@ namespace GL2D
 
 // Variables initialized by initVideo, updated by setScreenRes:
 static SDL_SysWMinfo wmInfo;
+#if _GLX
+static GLXContext glxCtx;
+#endif
 ui32 screenWidth = 0, screenHeight = 0; // Screen/Window size
 
 // OpenGL 1.3 functions pointers
@@ -36,6 +46,7 @@ PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
 
 // Shaders' sources
 static const char frag_palette_bitmap[] = (
+"#version 150\n"
 "uniform usampler2DRect bitmap;"
 "uniform sampler1D palette;"
 "uniform ivec2 coordOffs;"
@@ -162,9 +173,21 @@ void initVideo(ui32 w, ui32 h, bool fullscreen)
 	glUniform1i(bitmap_uniform, 0);
 	glUniform1i(palette_uniform, 1);
 
+	// unhook OpenGL context from display context/window
 #ifdef _WIN32
 	wglMakeCurrent(NULL, NULL);
+#elif _GLX
+	glxCtx = glXGetCurrentContext();
+	if (glxCtx == nullptr)
+	{
+		throw std::runtime_error("SDL didn't create GLX context!\n");
+	}
+	if (!glXMakeCurrent(wmInfo.info.x11.display, None, nullptr))
+	{
+		throw std::runtime_error("glXMakeCurrent failed (unhook GL context)\n");
+	}
 #endif
+
 }
 
 
@@ -173,6 +196,11 @@ void attachToCurrentThread()
 #ifdef _WIN32
 	HDC hdc = GetDC(wmInfo.window);
 	wglMakeCurrent(hdc, wmInfo.hglrc);
+#elif _GLX
+	if (!glXMakeCurrent(wmInfo.info.x11.display, info.info.x11.window, glxCtx))
+	{
+		throw std::runtime_error("attachToCurrentThread: glXMakeCurrent failed\n");
+	}
 #endif
 }