diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 03d58505..bf0343da 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -304,18 +304,24 @@ endif() if(FRAMEWORK_GRAPHICS) set(OPENGLES "OFF" CACHE "Use OpenGL ES 1.0 or 2.0 (for mobiles devices)" STRING) - if(OPENGLES STREQUAL "2.0") - find_package(OpenGLES2 REQUIRED) - find_package(EGL REQUIRED) - set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=2) - set(framework_INCLUDE_DIRS ${framework_INCLUDE_DIRS} ${EGL_INCLUDE_DIR} ${OPENGLES2_INCLUDE_DIR}) - set(framework_LIBRARIES ${framework_LIBRARIES} ${EGL_LIBRARY} ${OPENGLES2_LIBRARY}) - ELSEif(OPENGLES STREQUAL "1.0") - find_package(OpenGLES1 REQUIRED) - find_package(EGL REQUIRED) - set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=1) - set(framework_INCLUDE_DIRS ${framework_INCLUDE_DIRS} ${EGL_INCLUDE_DIR} ${OPENGLES1_INCLUDE_DIR}) - set(framework_LIBRARIES ${framework_LIBRARIES} ${EGL_LIBRARY} ${OPENGLES1_LIBRARY}) + if(OPENGLES) + set(framework_SOURCES ${framework_SOURCES} + ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextegl.cpp + ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextegl.h + ) + if(OPENGLES STREQUAL "2.0") + find_package(OpenGLES2 REQUIRED) + find_package(EGL REQUIRED) + set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=2) + set(framework_INCLUDE_DIRS ${framework_INCLUDE_DIRS} ${EGL_INCLUDE_DIR} ${OPENGLES2_INCLUDE_DIR}) + set(framework_LIBRARIES ${framework_LIBRARIES} ${EGL_LIBRARY} ${OPENGLES2_LIBRARY}) + elseif(OPENGLES STREQUAL "1.0") + find_package(OpenGLES1 REQUIRED) + find_package(EGL REQUIRED) + set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=1) + set(framework_INCLUDE_DIRS ${framework_INCLUDE_DIRS} ${EGL_INCLUDE_DIR} ${OPENGLES1_INCLUDE_DIR}) + set(framework_LIBRARIES ${framework_LIBRARIES} ${EGL_LIBRARY} ${OPENGLES1_LIBRARY}) + endif() else() ## TODO: CMake Documentation says that this is not the right # Thing for Mac OS X, but it works for now. @@ -381,11 +387,15 @@ if(FRAMEWORK_GRAPHICS) ) else() set(framework_SOURCES ${framework_SOURCES} - ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextglx.cpp - ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextglx.h ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.h ) + if(NOT OPENGLES) + set(framework_SOURCES ${framework_SOURCES} + ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextglx.cpp + ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextglx.h + ) + endif() endif() endif() diff --git a/src/framework/graphics/glutil.h b/src/framework/graphics/glutil.h index a0f73b8d..bd33c006 100644 --- a/src/framework/graphics/glutil.h +++ b/src/framework/graphics/glutil.h @@ -44,6 +44,7 @@ typedef char GLchar; // define OpenGL ES 2.0 API just to make compile, it wont actually be used +inline void glBlendEquation (GLenum mode) { } inline void glBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) { } inline void glBindFramebuffer (GLenum target, GLuint framebuffer) { } inline void glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers) { } diff --git a/src/framework/graphics/graphicscontext.h b/src/framework/graphics/graphicscontext.h index 7953b4bb..23d36582 100644 --- a/src/framework/graphics/graphicscontext.h +++ b/src/framework/graphics/graphicscontext.h @@ -25,7 +25,7 @@ #include "declarations.h" -class GraphicsContext +class GraphicsContext : public stdext::shared_object { public: GraphicsContext(const std::string& name); diff --git a/src/framework/graphics/ogl/graphicscontextegl.cpp b/src/framework/graphics/ogl/graphicscontextegl.cpp index a7095e38..66487007 100644 --- a/src/framework/graphics/ogl/graphicscontextegl.cpp +++ b/src/framework/graphics/ogl/graphicscontextegl.cpp @@ -21,6 +21,7 @@ */ #include "graphicscontextegl.h" +#include GraphicsContextEGL::GraphicsContextEGL() : GraphicsContext("EGL") @@ -31,10 +32,13 @@ GraphicsContextEGL::GraphicsContextEGL() : m_eglSurface = 0; } -void GraphicsContextEGL::create(WindowType window, DisplayType display) +void GraphicsContextEGL::create() { - m_window = window; - m_display = display; +#ifdef WIN32 + // TODO +#else + Display *display = g_x11Window.getDisplay(); +#endif m_eglDisplay = eglGetDisplay(display); if(m_eglDisplay == EGL_NO_DISPLAY) @@ -58,8 +62,10 @@ void GraphicsContextEGL::create(WindowType window, DisplayType display) EGLint numConfig; +#ifdef WIN32 if(!eglGetConfigs(m_eglDisplay, NULL, 0, &numConfig)) g_logger.fatal("No valid GL configurations"); +#endif if(!eglChooseConfig(m_eglDisplay, configList, &m_eglConfig, 1, &numConfig)) g_logger.fatal("Failed to choose EGL config"); @@ -67,6 +73,22 @@ void GraphicsContextEGL::create(WindowType window, DisplayType display) if(numConfig != 1) g_logger.warning("Didn't got the exact EGL config"); + EGLint vid; + if(!eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_NATIVE_VISUAL_ID, &vid)) + g_logger.fatal("Unable to get visual EGL visual id"); + +#ifndef WIN32 + XVisualInfo visTemplate; + int numVisuals; + memset(&visTemplate, 0, sizeof(visTemplate)); + visTemplate.visualid = vid; + g_x11Window.setVisual(XGetVisualInfo(display, VisualIDMask, &visTemplate, &numVisuals)); + if(!g_x11Window.getVisual()) + g_logger.fatal("Couldn't choose RGBA, double buffered visual"); + + g_x11Window.setRootWindow(DefaultRootWindow(display)); +#endif + EGLint contextAtrrList[] = { #if OPENGL_ES==2 EGL_CONTEXT_CLIENT_VERSION, 2, @@ -76,9 +98,11 @@ void GraphicsContextEGL::create(WindowType window, DisplayType display) EGL_NONE }; +#ifdef WIN32 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())); +#endif m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, contextAtrrList); if(m_eglContext == EGL_NO_CONTEXT ) @@ -103,6 +127,13 @@ void GraphicsContextEGL::destroy() void GraphicsContextEGL::restore() { +#ifndef WIN32 + Window window = g_x11Window.getWindow(); + 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())); +#endif + if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext)) g_logger.fatal("Unable to make current EGL context"); } diff --git a/src/framework/graphics/ogl/graphicscontextegl.h b/src/framework/graphics/ogl/graphicscontextegl.h index cb7abb1d..875e05ed 100644 --- a/src/framework/graphics/ogl/graphicscontextegl.h +++ b/src/framework/graphics/ogl/graphicscontextegl.h @@ -31,7 +31,7 @@ class GraphicsContextEGL : public GraphicsContext public: GraphicsContextEGL(); - void create(WindowType window, DisplayType display); + void create(); void destroy(); void restore(); diff --git a/src/framework/graphics/ogl/graphicscontextglx.cpp b/src/framework/graphics/ogl/graphicscontextglx.cpp index c0172a16..51d2fe81 100644 --- a/src/framework/graphics/ogl/graphicscontextglx.cpp +++ b/src/framework/graphics/ogl/graphicscontextglx.cpp @@ -22,7 +22,6 @@ #include "graphicscontextglx.h" - GraphicsContextGLX::GraphicsContextGLX() : GraphicsContext("GLX"), m_window(dynamic_cast(g_window)) { @@ -32,6 +31,9 @@ GraphicsContextGLX::GraphicsContextGLX() : void GraphicsContextGLX::create() { + if(!glXQueryExtension(m_window.getDisplay(), NULL, NULL)) + g_logger.fatal("GLX not supported"); + static int attrList[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DOUBLEBUFFER, True, diff --git a/src/framework/graphics/ogl/painterogl.cpp b/src/framework/graphics/ogl/painterogl.cpp index fd908e66..17f1751e 100644 --- a/src/framework/graphics/ogl/painterogl.cpp +++ b/src/framework/graphics/ogl/painterogl.cpp @@ -303,6 +303,7 @@ void PainterOGL::updateGlBlendEquation() { if(!g_graphics.canUseBlendEquation()) return; + if(m_blendEquation == BlendEquation_Add) glBlendEquation(0x8006); // GL_FUNC_ADD else if(m_blendEquation == BlendEquation_Max) diff --git a/src/framework/platform/platformwindow.cpp b/src/framework/platform/platformwindow.cpp index 9b358719..2d467c1f 100644 --- a/src/framework/platform/platformwindow.cpp +++ b/src/framework/platform/platformwindow.cpp @@ -33,6 +33,7 @@ WIN32Window window; #include "x11window.h" #include X11Window window; +X11Window& g_x11Window = window; #endif #endif diff --git a/src/framework/platform/platformwindow.h b/src/framework/platform/platformwindow.h index 4b23bcc4..11fc211c 100644 --- a/src/framework/platform/platformwindow.h +++ b/src/framework/platform/platformwindow.h @@ -97,9 +97,6 @@ public: void setOnInputEvent(const OnInputEventCallback& onInputEvent) { m_onInputEvent = onInputEvent; } protected: - virtual void internalCreateContext() = 0; - virtual void internalDestroyContext() = 0; - virtual void internalRestoreContext() = 0; virtual int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot) = 0; void updateUnmaximizedCoords(); diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index 0a37b2d8..dc70463e 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8))) @@ -43,9 +44,11 @@ X11Window::X11Window() m_wmDelete = 0; m_minimumSize = Size(600,480); m_size = Size(600,480); +#ifndef OPENGL_ES m_graphicsContext = GraphicsContextPtr(new GraphicsContextGLX); - dump << GraphicsContextPtr(new GraphicsContextGLX())->getName().c_str(); - dump << (new GraphicsContextGLX())->getName().c_str(); +#else + m_graphicsContext = GraphicsContextPtr(new GraphicsContextEGL); +#endif m_keyMap[XK_Escape] = Fw::KeyEscape; m_keyMap[XK_Tab] = Fw::KeyTab; @@ -203,9 +206,7 @@ X11Window::X11Window() void X11Window::init() { internalOpenDisplay(); - internalCheckGL(); - internalChooseGLVisual(); - internalCreateContext(); + m_graphicsContext->create(); internalCreateWindow(); } @@ -235,7 +236,7 @@ void X11Window::terminate() m_colormap = 0; } - internalDestroyContext(); + m_graphicsContext->destroy(); if(m_visual) { XFree(m_visual); @@ -323,7 +324,7 @@ void X11Window::internalCreateWindow() if(!internalSetupWindowInput()) g_logger.warning("Input of special keys may be messed up, because window input initialization failed"); - internalRestoreContext(); + m_graphicsContext->restore(); } bool X11Window::internalSetupWindowInput() @@ -350,78 +351,6 @@ bool X11Window::internalSetupWindowInput() return true; } -void X11Window::internalCheckGL() -{ -#ifdef OPENGL_ES - m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)m_display); - if(m_eglDisplay == EGL_NO_DISPLAY) - g_logger.fatal("EGL not supported"); - - if(!eglInitialize(m_eglDisplay, NULL, NULL)) - g_logger.fatal("Unable to initialize EGL"); -#else - if(!glXQueryExtension(m_display, NULL, NULL)) - g_logger.fatal("GLX not supported"); -#endif -} - -void X11Window::internalChooseGLVisual() -{ -#ifdef OPENGL_ES - static int attrList[] = { -#if OPENGL_ES==2 - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, -#else - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, -#endif - EGL_RED_SIZE, 4, - EGL_GREEN_SIZE, 4, - EGL_BLUE_SIZE, 4, - EGL_ALPHA_SIZE, 4, - EGL_NONE - }; - - EGLint numConfig; - XVisualInfo visTemplate; - int numVisuals; - - if(!eglChooseConfig(m_eglDisplay, attrList, &m_eglConfig, 1, &numConfig)) - g_logger.fatal("Failed to choose EGL config"); - - if(numConfig != 1) - g_logger.warning("Didn't got the exact EGL config"); - - EGLint vid; - if(!eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_NATIVE_VISUAL_ID, &vid)) - g_logger.fatal("Unable to get visual EGL visual id"); - - memset(&visTemplate, 0, sizeof(visTemplate)); - visTemplate.visualid = vid; - m_visual = XGetVisualInfo(m_display, VisualIDMask, &visTemplate, &numVisuals); - if(!m_visual) - g_logger.fatal("Couldn't choose RGBA, double buffered visual"); - - m_rootWindow = DefaultRootWindow(m_display); -#else - -#endif -} - -void X11Window::internalCreateContext() -{ - m_graphicsContext->create(); -} - -void X11Window::internalDestroyContext() -{ - m_graphicsContext->destroy(); -} - -void X11Window::internalRestoreContext() -{ - m_graphicsContext->restore(); -} - void X11Window::move(const Point& pos) { m_position = pos; diff --git a/src/framework/platform/x11window.h b/src/framework/platform/x11window.h index 5dde1156..e39c0a0c 100644 --- a/src/framework/platform/x11window.h +++ b/src/framework/platform/x11window.h @@ -38,12 +38,6 @@ class X11Window : public PlatformWindow void internalCreateWindow(); bool internalSetupWindowInput(); - void internalCheckGL(); - void internalChooseGLVisual(); - void internalCreateContext(); - void internalDestroyContext(); - void internalRestoreContext(); - public: X11Window(); @@ -99,5 +93,7 @@ private: std::string m_clipboardText; }; +extern X11Window& g_x11Window; + #endif