From 77995a2e88fdc83f862e3e61ecbab2e8ec7c1388 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Thu, 28 Feb 2013 02:39:35 -0300 Subject: [PATCH] Compiling on linux again --- src/framework/graphics/graphics.cpp | 2 +- src/framework/graphics/graphicscontext.cpp | 6 +-- src/framework/graphics/graphicscontext.h | 14 +------ .../graphics/ogl/graphicscontextglx.cpp | 41 ++++++++++++++----- .../graphics/ogl/graphicscontextglx.h | 4 +- src/framework/platform/platformwindow.cpp | 7 ++-- src/framework/platform/unixplatform.cpp | 2 +- src/framework/platform/x11window.cpp | 23 ++--------- src/framework/platform/x11window.h | 6 +++ 9 files changed, 50 insertions(+), 55 deletions(-) diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index f3af8ec6..4ba64ee8 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -238,7 +238,7 @@ bool Graphics::selectPainterEngine(PainterEngine painterEngine) if(g_painter) g_painter->unbind(); painter->bind(); - //g_window.setGraphicsContext(painter->getGraphicsContext()); + g_window.setGraphicsContext(painter->getGraphicsContext()); g_painter = painter; } diff --git a/src/framework/graphics/graphicscontext.cpp b/src/framework/graphics/graphicscontext.cpp index cc6d6521..cec445b6 100644 --- a/src/framework/graphics/graphicscontext.cpp +++ b/src/framework/graphics/graphicscontext.cpp @@ -22,9 +22,7 @@ #include "graphicscontext.h" -GraphicsContext::GraphicsContext(const std::string& name) +GraphicsContext::GraphicsContext(const std::string& name) : + m_name(name) { - std::cout << "lal1: \"" << name.c_str() << "\" aa" << std::endl; - m_name = name; - std::cout << "lal2: \"" << getName().c_str() << "\" aa" << std::endl; } diff --git a/src/framework/graphics/graphicscontext.h b/src/framework/graphics/graphicscontext.h index 15203487..7953b4bb 100644 --- a/src/framework/graphics/graphicscontext.h +++ b/src/framework/graphics/graphicscontext.h @@ -25,16 +25,6 @@ #include "declarations.h" -#ifdef WIN32 -#include -typedef HWND WindowType; -typedef HDC DisplayType; -#else -#include -typedef Window WindowType; -typedef Display *DisplayType; -#endif - class GraphicsContext { public: @@ -43,7 +33,7 @@ public: std::string getName() { return m_name; } - virtual void create(WindowType window, DisplayType display) = 0; + virtual void create() = 0; virtual void destroy() = 0; virtual void restore() = 0; @@ -53,8 +43,6 @@ public: protected: std::string m_name; - WindowType m_window; - DisplayType m_display; }; diff --git a/src/framework/graphics/ogl/graphicscontextglx.cpp b/src/framework/graphics/ogl/graphicscontextglx.cpp index 1b9e9c3d..c0172a16 100644 --- a/src/framework/graphics/ogl/graphicscontextglx.cpp +++ b/src/framework/graphics/ogl/graphicscontextglx.cpp @@ -22,45 +22,64 @@ #include "graphicscontextglx.h" + GraphicsContextGLX::GraphicsContextGLX() : - GraphicsContext("GLX") + GraphicsContext("GLX"), m_window(dynamic_cast(g_window)) { m_fbConfig = 0; m_glxContext = 0; } -void GraphicsContextGLX::create(WindowType window, DisplayType display) +void GraphicsContextGLX::create() { - m_window = window; - m_display = display; + static int attrList[] = { + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DOUBLEBUFFER, True, + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, + GLX_ALPHA_SIZE, 8, + None + }; - m_glxContext = glXCreateContext(m_display, m_visual, NULL, True); + int nelements; + m_fbConfig = glXChooseFBConfig(m_window.getDisplay(), m_window.getScreen(), attrList, &nelements); + if(!m_fbConfig) + g_logger.fatal("Couldn't choose RGBA, double buffered fbconfig"); + + m_window.setVisual(glXGetVisualFromFBConfig(m_window.getDisplay(), *m_fbConfig)); + if(!m_window.getDisplay()) + g_logger.fatal("Couldn't choose RGBA, double buffered visual"); + + m_window.setRootWindow(RootWindow(m_window.getDisplay(), m_window.getVisual()->screen)); + + m_glxContext = glXCreateContext(m_window.getDisplay(), m_window.getVisual(), NULL, True); if(!m_glxContext) g_logger.fatal("Unable to create GLX context"); - if(!glXIsDirect(m_display, m_glxContext)) + if(!glXIsDirect(m_window.getDisplay(), m_glxContext)) g_logger.warning("GL direct rendering is not possible"); } void GraphicsContextGLX::destroy() { if(m_glxContext) { - glXMakeCurrent(m_display, None, NULL); - glXDestroyContext(m_display, m_glxContext); + glXMakeCurrent(m_window.getDisplay(), None, NULL); + glXDestroyContext(m_window.getDisplay(), m_glxContext); m_glxContext = 0; } } void GraphicsContextGLX::restore() { - if(!glXMakeCurrent(m_display, m_window, m_glxContext)) + if(!glXMakeCurrent(m_window.getDisplay(), m_window.getWindow(), 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, DefaultScreen(m_display)); + const char *exts = glXQueryExtensionsString(m_window.getDisplay(), m_window.getScreen()); if(strstr(exts, ext)) return true; return false; @@ -73,7 +92,7 @@ void *GraphicsContextGLX::getExtensionProcAddress(const char *ext) void GraphicsContextGLX::swapBuffers() { - glXSwapBuffers(m_display, m_window); + glXSwapBuffers(m_window.getDisplay(), m_window.getWindow()); } void GraphicsContextGLX::setVerticalSync(bool enable) diff --git a/src/framework/graphics/ogl/graphicscontextglx.h b/src/framework/graphics/ogl/graphicscontextglx.h index 95ae5a60..e2fb0b0e 100644 --- a/src/framework/graphics/ogl/graphicscontextglx.h +++ b/src/framework/graphics/ogl/graphicscontextglx.h @@ -24,6 +24,7 @@ #define GRAPHICSCONTEXTGLX_H #include +#include #include class GraphicsContextGLX : public GraphicsContext @@ -31,7 +32,7 @@ class GraphicsContextGLX : public GraphicsContext public: GraphicsContextGLX(); - void create(WindowType window, DisplayType display); + void create(); void destroy(); void restore(); @@ -43,6 +44,7 @@ public: void setVerticalSync(bool enable); private: + X11Window& m_window; GLXContext m_glxContext; GLXFBConfig *m_fbConfig; }; diff --git a/src/framework/platform/platformwindow.cpp b/src/framework/platform/platformwindow.cpp index 08c1a51d..9b358719 100644 --- a/src/framework/platform/platformwindow.cpp +++ b/src/framework/platform/platformwindow.cpp @@ -65,16 +65,15 @@ int PlatformWindow::loadMouseCursor(const std::string& file, const Point& hotSpo void PlatformWindow::setGraphicsContext(const GraphicsContextPtr& graphicsContext) { - // TODO if(m_graphicsContext && m_graphicsContext->getName() == graphicsContext->getName()) return; if(m_graphicsContext) - internalDestroyContext(); + m_graphicsContext->destroy(); m_graphicsContext = graphicsContext; - internalCreateContext(); - internalRestoreContext(); + m_graphicsContext->create(); + m_graphicsContext->restore(); } void PlatformWindow::updateUnmaximizedCoords() diff --git a/src/framework/platform/unixplatform.cpp b/src/framework/platform/unixplatform.cpp index 613ce4ec..02761e52 100644 --- a/src/framework/platform/unixplatform.cpp +++ b/src/framework/platform/unixplatform.cpp @@ -30,7 +30,7 @@ void Platform::processArgs(std::vector& args) { - //nothing todo, linux args are already utf8 encoded + //nothing to do, linux args are already utf8 encoded } bool Platform::spawnProcess(std::string process, const std::vector& args) diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index d8d64e3f..0a37b2d8 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -44,6 +44,8 @@ X11Window::X11Window() m_minimumSize = Size(600,480); m_size = Size(600,480); m_graphicsContext = GraphicsContextPtr(new GraphicsContextGLX); + dump << GraphicsContextPtr(new GraphicsContextGLX())->getName().c_str(); + dump << (new GraphicsContextGLX())->getName().c_str(); m_keyMap[XK_Escape] = Fw::KeyEscape; m_keyMap[XK_Tab] = Fw::KeyTab; @@ -401,32 +403,13 @@ void X11Window::internalChooseGLVisual() m_rootWindow = DefaultRootWindow(m_display); #else - static int attrList[] = { - GLX_RENDER_TYPE, GLX_RGBA_BIT, - GLX_DOUBLEBUFFER, True, - GLX_RED_SIZE, 8, - GLX_GREEN_SIZE, 8, - GLX_BLUE_SIZE, 8, - GLX_ALPHA_SIZE, 8, - None - }; - int nelements; - m_fbConfig = glXChooseFBConfig(m_display, m_screen, attrList, &nelements); - if(!m_fbConfig) - g_logger.fatal("Couldn't choose RGBA, double buffered fbconfig"); - - m_visual = glXGetVisualFromFBConfig(m_display, *m_fbConfig); - if(!m_visual) - g_logger.fatal("Couldn't choose RGBA, double buffered visual"); - - m_rootWindow = RootWindow(m_display, m_visual->screen); #endif } void X11Window::internalCreateContext() { - m_graphicsContext->create(m_window, m_display); + m_graphicsContext->create(); } void X11Window::internalDestroyContext() diff --git a/src/framework/platform/x11window.h b/src/framework/platform/x11window.h index 5e423103..5dde1156 100644 --- a/src/framework/platform/x11window.h +++ b/src/framework/platform/x11window.h @@ -69,10 +69,16 @@ public: void setVerticalSync(bool enable); void setIcon(const std::string& file); void setClipboardText(const std::string& text); + void setVisual(XVisualInfo *visual) { m_visual = visual; } + void setRootWindow(const Window& window) { m_rootWindow = window; } Size getDisplaySize(); std::string getClipboardText(); std::string getPlatformType(); + Window getWindow() { return m_window; } + Display *getDisplay() { return m_display; } + int getScreen() { return m_screen; } + XVisualInfo *getVisual() { return m_visual; } protected: int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);