gsdx ogl: factorize common context init code

This commit is contained in:
Gregory Hainaut 2017-07-03 20:02:16 +02:00
parent 66a87ce4d0
commit 2204885fbb
8 changed files with 36 additions and 43 deletions

View File

@ -183,3 +183,11 @@ void GSWndGL::PopulateGlFunction()
// renderer/device // renderer/device
GLLoader::check_gl_requirements(); GLLoader::check_gl_requirements();
} }
void GSWndGL::FullContextInit()
{
CreateContext(3, 3);
AttachContext();
PopulateGlFunction();
PopulateWndGlFunction();
}

View File

@ -62,6 +62,10 @@ protected:
bool m_ctx_attached; bool m_ctx_attached;
bool IsContextAttached() const { return m_ctx_attached; } bool IsContextAttached() const { return m_ctx_attached; }
void PopulateGlFunction();
virtual void PopulateWndGlFunction() = 0;
void FullContextInit();
virtual void CreateContext(int major, int minor) = 0;
public: public:
GSWndGL() : m_ctx_attached(false) {}; GSWndGL() : m_ctx_attached(false) {};
@ -85,6 +89,4 @@ public:
virtual void HideFrame() = 0; virtual void HideFrame() = 0;
virtual void Flip() = 0; virtual void Flip() = 0;
virtual void SetVSync(int vsync) = 0; virtual void SetVSync(int vsync) = 0;
void PopulateGlFunction();
}; };

View File

@ -153,6 +153,10 @@ void GSWndEGL::DetachContext()
} }
} }
void GSWndEGL::PopulateWndGlFunction()
{
}
void GSWndEGL::BindAPI() void GSWndEGL::BindAPI()
{ {
eglBindAPI(EGL_OPENGL_API); eglBindAPI(EGL_OPENGL_API);
@ -171,11 +175,7 @@ bool GSWndEGL::Attach(void* handle, bool managed)
OpenEGLDisplay(); OpenEGLDisplay();
CreateContext(3, 3); FullContextInit();
AttachContext();
PopulateGlFunction();
return true; return true;
} }
@ -209,11 +209,7 @@ bool GSWndEGL::Create(const string& title, int w, int h)
m_native_window = CreateNativeWindow(w, h); m_native_window = CreateNativeWindow(w, h);
CreateContext(3, 3); FullContextInit();
AttachContext();
PopulateGlFunction();
return true; return true;
} }

View File

@ -38,6 +38,7 @@ class GSWndEGL : public GSWndGL
int m_platform; int m_platform;
void PopulateWndGlFunction();
void CreateContext(int major, int minor); void CreateContext(int major, int minor);
void BindAPI(); void BindAPI();

View File

@ -122,6 +122,12 @@ void GSWndOGL::DetachContext()
} }
} }
void GSWndOGL::PopulateWndGlFunction()
{
m_swapinterval_ext = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((const GLubyte*) "glXSwapIntervalEXT");
m_swapinterval_mesa = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA");
}
bool GSWndOGL::Attach(void* handle, bool managed) bool GSWndOGL::Attach(void* handle, bool managed)
{ {
m_NativeWindow = *(Window*)handle; m_NativeWindow = *(Window*)handle;
@ -129,14 +135,7 @@ bool GSWndOGL::Attach(void* handle, bool managed)
m_NativeDisplay = XOpenDisplay(NULL); m_NativeDisplay = XOpenDisplay(NULL);
CreateContext(3, 3); FullContextInit();
AttachContext();
m_swapinterval_ext = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((const GLubyte*) "glXSwapIntervalEXT");
m_swapinterval_mesa = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA");
PopulateGlFunction();
return true; return true;
} }
@ -175,14 +174,7 @@ bool GSWndOGL::Create(const string& title, int w, int h)
if (m_NativeWindow == 0) if (m_NativeWindow == 0)
throw GSDXRecoverableError(); throw GSDXRecoverableError();
CreateContext(3, 3); FullContextInit();
AttachContext();
m_swapinterval_ext = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddress((const GLubyte*) "glXSwapIntervalEXT");
m_swapinterval_mesa = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA");
PopulateGlFunction();
return true; return true;
} }

View File

@ -34,6 +34,7 @@ class GSWndOGL final : public GSWndGL
PFNGLXSWAPINTERVALEXTPROC m_swapinterval_ext; PFNGLXSWAPINTERVALEXTPROC m_swapinterval_ext;
PFNGLXSWAPINTERVALMESAPROC m_swapinterval_mesa; PFNGLXSWAPINTERVALMESAPROC m_swapinterval_mesa;
void PopulateWndGlFunction();
void CreateContext(int major, int minor); void CreateContext(int major, int minor);
public: public:

View File

@ -139,6 +139,11 @@ void GSWndWGL::DetachContext()
} }
} }
void GSWndWGL::PopulateWndGlFunction()
{
m_swapinterval = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
}
bool GSWndWGL::Attach(void* handle, bool managed) bool GSWndWGL::Attach(void* handle, bool managed)
{ {
m_NativeWindow = (HWND)handle; m_NativeWindow = (HWND)handle;
@ -146,13 +151,7 @@ bool GSWndWGL::Attach(void* handle, bool managed)
OpenWGLDisplay(); OpenWGLDisplay();
CreateContext(3, 3); FullContextInit();
AttachContext();
m_swapinterval = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
PopulateGlFunction();
UpdateWindow(m_NativeWindow); UpdateWindow(m_NativeWindow);
@ -288,16 +287,9 @@ bool GSWndWGL::Create(const string& title, int w, int h)
OpenWGLDisplay(); OpenWGLDisplay();
CreateContext(3, 3); FullContextInit();
AttachContext();
m_swapinterval = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
PopulateGlFunction();
return true; return true;
} }
//Same as DX //Same as DX

View File

@ -31,6 +31,7 @@ class GSWndWGL : public GSWndGL
PFNWGLSWAPINTERVALEXTPROC m_swapinterval; PFNWGLSWAPINTERVALEXTPROC m_swapinterval;
void PopulateWndGlFunction();
void CreateContext(int major, int minor); void CreateContext(int major, int minor);
void CloseWGLDisplay(); void CloseWGLDisplay();