From c3c951ebbb865858822402bba89d4e53034ddb33 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Tue, 26 Feb 2013 05:21:43 -0300 Subject: [PATCH] More changes to context --- src/framework/graphics/graphicscontext.h | 14 +++-- .../graphics/ogl/graphicscontextegl.cpp | 21 ++----- .../graphics/ogl/graphicscontextegl.h | 5 +- .../graphics/ogl/graphicscontextglx.cpp | 17 +++++- .../graphics/ogl/graphicscontextglx.h | 2 +- src/framework/platform/x11window.cpp | 58 ++++--------------- src/framework/platform/x11window.h | 10 ++-- 7 files changed, 44 insertions(+), 83 deletions(-) diff --git a/src/framework/graphics/graphicscontext.h b/src/framework/graphics/graphicscontext.h index 303013e7..15203487 100644 --- a/src/framework/graphics/graphicscontext.h +++ b/src/framework/graphics/graphicscontext.h @@ -28,8 +28,11 @@ #ifdef WIN32 #include typedef HWND WindowType; +typedef HDC DisplayType; #else +#include typedef Window WindowType; +typedef Display *DisplayType; #endif class GraphicsContext @@ -40,19 +43,18 @@ public: std::string getName() { return m_name; } - virtual void create(WindowType window) = 0; - virtual void destroy(WindowType window) = 0; + virtual void create(WindowType window, DisplayType display) = 0; + virtual void destroy() = 0; virtual void restore() = 0; - virtual bool isExtensionSupported(const char *ext) = 0; - virtual void *getExtensionProcAddress(const char *ext) = 0; - virtual void swapBuffers() = 0; virtual void setVerticalSync(bool enable) = 0; -private: +protected: std::string m_name; + WindowType m_window; + DisplayType m_display; }; diff --git a/src/framework/graphics/ogl/graphicscontextegl.cpp b/src/framework/graphics/ogl/graphicscontextegl.cpp index 89f49eee..a7095e38 100644 --- a/src/framework/graphics/ogl/graphicscontextegl.cpp +++ b/src/framework/graphics/ogl/graphicscontextegl.cpp @@ -31,9 +31,12 @@ GraphicsContextEGL::GraphicsContextEGL() : m_eglSurface = 0; } -void GraphicsContextEGL::create() +void GraphicsContextEGL::create(WindowType window, DisplayType display) { - m_eglDisplay = eglGetDisplay(m_deviceContext); + m_window = window; + m_display = display; + + m_eglDisplay = eglGetDisplay(display); if(m_eglDisplay == EGL_NO_DISPLAY) g_logger.fatal("EGL not supported"); @@ -73,7 +76,7 @@ void GraphicsContextEGL::create() EGL_NONE }; - m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL); + m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, window, NULL); if(m_eglSurface == EGL_NO_SURFACE) g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError())); @@ -104,18 +107,6 @@ void GraphicsContextEGL::restore() g_logger.fatal("Unable to make current EGL context"); } -bool GraphicsContextEGL::isExtensionSupported(const char *ext) -{ - //TODO - return false; -} - -void *GraphicsContextEGL::getExtensionProcAddress(const char *ext) -{ - //TODO - return NULL; -} - void GraphicsContextEGL::swapBuffers() { eglSwapBuffers(m_eglDisplay, m_eglSurface); diff --git a/src/framework/graphics/ogl/graphicscontextegl.h b/src/framework/graphics/ogl/graphicscontextegl.h index 070e0ef4..cb7abb1d 100644 --- a/src/framework/graphics/ogl/graphicscontextegl.h +++ b/src/framework/graphics/ogl/graphicscontextegl.h @@ -31,13 +31,10 @@ class GraphicsContextEGL : public GraphicsContext public: GraphicsContextEGL(); - void create(); + void create(WindowType window, DisplayType display); void destroy(); void restore(); - bool isExtensionSupported(const char *ext); - void *getExtensionProcAddress(const char *ext); - void swapBuffers(); void setVerticalSync(bool enable); diff --git a/src/framework/graphics/ogl/graphicscontextglx.cpp b/src/framework/graphics/ogl/graphicscontextglx.cpp index 31bfa165..1b9e9c3d 100644 --- a/src/framework/graphics/ogl/graphicscontextglx.cpp +++ b/src/framework/graphics/ogl/graphicscontextglx.cpp @@ -29,9 +29,18 @@ GraphicsContextGLX::GraphicsContextGLX() : m_glxContext = 0; } -void GraphicsContextGLX::create() +void GraphicsContextGLX::create(WindowType window, DisplayType display) { + m_window = window; + m_display = display; + m_glxContext = glXCreateContext(m_display, m_visual, NULL, True); + + if(!m_glxContext) + g_logger.fatal("Unable to create GLX context"); + + if(!glXIsDirect(m_display, m_glxContext)) + g_logger.warning("GL direct rendering is not possible"); } void GraphicsContextGLX::destroy() @@ -45,14 +54,16 @@ void GraphicsContextGLX::destroy() void GraphicsContextGLX::restore() { - + if(!glXMakeCurrent(m_display, m_window, m_glxContext)) + g_logger.fatal("Unable to set GLX context on X11 window"); } bool GraphicsContextGLX::isExtensionSupported(const char *ext) { - const char *exts = glXQueryExtensionsString(m_display, m_screen); + const char *exts = glXQueryExtensionsString(m_display, DefaultScreen(m_display)); if(strstr(exts, ext)) return true; + return false; } void *GraphicsContextGLX::getExtensionProcAddress(const char *ext) diff --git a/src/framework/graphics/ogl/graphicscontextglx.h b/src/framework/graphics/ogl/graphicscontextglx.h index 4b70ec7e..95ae5a60 100644 --- a/src/framework/graphics/ogl/graphicscontextglx.h +++ b/src/framework/graphics/ogl/graphicscontextglx.h @@ -31,7 +31,7 @@ class GraphicsContextGLX : public GraphicsContext public: GraphicsContextGLX(); - void create(); + void create(WindowType window, DisplayType display); void destroy(); void restore(); diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index 9cc72b5a..d8d64e3f 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -23,6 +23,7 @@ #include "x11window.h" #include #include +#include #include #define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8))) @@ -42,6 +43,7 @@ X11Window::X11Window() m_wmDelete = 0; m_minimumSize = Size(600,480); m_size = Size(600,480); + m_graphicsContext = GraphicsContextPtr(new GraphicsContextGLX); m_keyMap[XK_Escape] = Fw::KeyEscape; m_keyMap[XK_Tab] = Fw::KeyTab; @@ -201,7 +203,7 @@ void X11Window::init() internalOpenDisplay(); internalCheckGL(); internalChooseGLVisual(); - internalCreateGLContext(); + internalCreateContext(); internalCreateWindow(); } @@ -231,7 +233,7 @@ void X11Window::terminate() m_colormap = 0; } - internalDestroyGLContext(); + internalDestroyContext(); if(m_visual) { XFree(m_visual); @@ -319,7 +321,7 @@ void X11Window::internalCreateWindow() if(!internalSetupWindowInput()) g_logger.warning("Input of special keys may be messed up, because window input initialization failed"); - internalConnectGLContext(); + internalRestoreContext(); } bool X11Window::internalSetupWindowInput() @@ -422,59 +424,19 @@ void X11Window::internalChooseGLVisual() #endif } -void X11Window::internalCreateGLContext() +void X11Window::internalCreateContext() { -#ifdef OPENGL_ES - EGLint attrList[] = { -#if OPENGL_ES==2 - EGL_CONTEXT_CLIENT_VERSION, 2, -#else - EGL_CONTEXT_CLIENT_VERSION, 1, -#endif - EGL_NONE - }; - - m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, attrList); - if(m_eglContext == EGL_NO_CONTEXT ) - g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError())); -#else - m_glxContext = glXCreateContext(m_display, m_visual, NULL, True); - - if(!m_glxContext) - g_logger.fatal("Unable to create GLX context"); - - if(!glXIsDirect(m_display, m_glxContext)) - g_logger.warning("GL direct rendering is not possible"); -#endif + m_graphicsContext->create(m_window, m_display); } -void X11Window::internalDestroyGLContext() +void X11Window::internalDestroyContext() { m_graphicsContext->destroy(); } -void X11Window::internalConnectGLContext() +void X11Window::internalRestoreContext() { -#ifdef OPENGL_ES - m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL); - if(m_eglSurface == EGL_NO_SURFACE) - g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError())); - if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext)) - g_logger.fatal("Unable to connect EGL context into X11 window"); -#else - if(!glXMakeCurrent(m_display, m_window, m_glxContext)) - g_logger.fatal("Unable to set GLX context on X11 window"); -#endif -} - -void *X11Window::getExtensionProcAddress(const char *ext) -{ - return m_graphicsContext->getExtensionProcAddress(ext); -} - -bool X11Window::isExtensionSupported(const char *ext) -{ - return m_graphicsContext->isExtensionSupported(ext); + m_graphicsContext->restore(); } void X11Window::move(const Point& pos) diff --git a/src/framework/platform/x11window.h b/src/framework/platform/x11window.h index a509fb15..5e423103 100644 --- a/src/framework/platform/x11window.h +++ b/src/framework/platform/x11window.h @@ -28,6 +28,7 @@ #include #include +#include typedef Window WindowType; @@ -39,12 +40,9 @@ class X11Window : public PlatformWindow void internalCheckGL(); void internalChooseGLVisual(); - void internalCreateGLContext(); - void internalDestroyGLContext(); - void internalConnectGLContext(); - - void *getExtensionProcAddress(const char *ext); - bool isExtensionSupported(const char *ext); + void internalCreateContext(); + void internalDestroyContext(); + void internalRestoreContext(); public: X11Window();