diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index bf0343da..5394df45 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -380,11 +380,15 @@ if(FRAMEWORK_GRAPHICS) else() if(WIN32) set(framework_SOURCES ${framework_SOURCES} - ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextwgl.cpp - ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextwgl.h ${CMAKE_CURRENT_LIST_DIR}/platform/win32window.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/win32window.h ) + if(NOT OPENGLES) + set(framework_SOURCES ${framework_SOURCES} + ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextwgl.cpp + ${CMAKE_CURRENT_LIST_DIR}/graphics/ogl/graphicscontextwgl.h + ) + endif() else() set(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index 4ba64ee8..2799eb90 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -185,7 +185,9 @@ bool Graphics::isPainterEngineAvailable(Graphics::PainterEngine painterEngine) bool Graphics::selectPainterEngine(PainterEngine painterEngine) { // TODO: remove this - painterEngine = Painter_OpenGL2; +#ifdef DIRECTX + painterEngine = Painter_DirectX9; +#endif Painter *painter = nullptr; Painter *fallbackPainter = nullptr; diff --git a/src/framework/graphics/ogl/graphicscontextegl.cpp b/src/framework/graphics/ogl/graphicscontextegl.cpp index 66487007..4a56773b 100644 --- a/src/framework/graphics/ogl/graphicscontextegl.cpp +++ b/src/framework/graphics/ogl/graphicscontextegl.cpp @@ -21,7 +21,12 @@ */ #include "graphicscontextegl.h" + +#ifdef WIN32 +#include +#else #include +#endif GraphicsContextEGL::GraphicsContextEGL() : GraphicsContext("EGL") @@ -35,7 +40,7 @@ GraphicsContextEGL::GraphicsContextEGL() : void GraphicsContextEGL::create() { #ifdef WIN32 - // TODO + HDC display = g_win32Window.getDisplay(); #else Display *display = g_x11Window.getDisplay(); #endif @@ -62,22 +67,17 @@ void GraphicsContextEGL::create() 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"); if(numConfig != 1) g_logger.warning("Didn't got the exact EGL config"); +#ifndef WIN32 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)); @@ -99,6 +99,7 @@ void GraphicsContextEGL::create() }; #ifdef WIN32 + HWND window = g_win32Window.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())); diff --git a/src/framework/graphics/ogl/graphicscontextwgl.cpp b/src/framework/graphics/ogl/graphicscontextwgl.cpp index 36358cfd..988fa5a7 100644 --- a/src/framework/graphics/ogl/graphicscontextwgl.cpp +++ b/src/framework/graphics/ogl/graphicscontextwgl.cpp @@ -21,6 +21,7 @@ */ #include "graphicscontextwgl.h" +#include GraphicsContextWGL::GraphicsContextWGL() : GraphicsContext("WGL") @@ -28,10 +29,9 @@ GraphicsContextWGL::GraphicsContextWGL() : m_wglContext = 0; } -void GraphicsContextWGL::create(WindowType window, DisplayType display) +void GraphicsContextWGL::create() { - m_window = window; - m_display = display; + HDC display = g_win32Window.getDisplay(); uint pixelFormat; static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), @@ -75,7 +75,7 @@ void GraphicsContextWGL::destroy() void GraphicsContextWGL::restore() { - if(!wglMakeCurrent(m_display, m_wglContext)) + if(!wglMakeCurrent(g_win32Window.getDisplay(), m_wglContext)) g_logger.fatal("Unable to make current WGL context"); } @@ -100,7 +100,7 @@ void *GraphicsContextWGL::getExtensionProcAddress(const char *ext) void GraphicsContextWGL::swapBuffers() { - SwapBuffers(m_display); + SwapBuffers(g_win32Window.getDisplay()); } void GraphicsContextWGL::setVerticalSync(bool enable) diff --git a/src/framework/graphics/ogl/graphicscontextwgl.h b/src/framework/graphics/ogl/graphicscontextwgl.h index f0e725dd..3c011c98 100644 --- a/src/framework/graphics/ogl/graphicscontextwgl.h +++ b/src/framework/graphics/ogl/graphicscontextwgl.h @@ -31,7 +31,7 @@ class GraphicsContextWGL : public GraphicsContext public: GraphicsContextWGL(); - void create(WindowType window, DisplayType display); + void create(); void destroy(); void restore(); diff --git a/src/framework/platform/platformwindow.cpp b/src/framework/platform/platformwindow.cpp index 2d467c1f..c143202f 100644 --- a/src/framework/platform/platformwindow.cpp +++ b/src/framework/platform/platformwindow.cpp @@ -29,6 +29,7 @@ SDLWindow window; #ifdef WIN32 #include "win32window.h" WIN32Window window; +WIN32Window& g_win32Window = window; #else #include "x11window.h" #include diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index a54a1e9b..dc29bc63 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -24,7 +24,12 @@ #include #include #include + +#ifndef OPENGL_ES #include +#else +#include +#endif #define HSB_BIT_SET(p, n) (p[(n)/8] |= (128 >>((n)%8))) @@ -37,8 +42,12 @@ WIN32Window::WIN32Window() m_size = Size(600,480); m_hidden = true; m_deviceContext = 0; + +#ifndef OPENGL_ES m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL); - std::cout << "lal3: \"" << m_graphicsContext->getName().c_str() << "\" aa" << std::endl; +#else + m_graphicsContext = GraphicsContextPtr(new GraphicsContextEGL); +#endif m_keyMap[VK_ESCAPE] = Fw::KeyEscape; m_keyMap[VK_TAB] = Fw::KeyTab; @@ -196,8 +205,8 @@ void WIN32Window::init() { m_instance = GetModuleHandle(NULL); internalCreateWindow(); - internalCreateContext(); - internalRestoreContext(); + m_graphicsContext->create(); + m_graphicsContext->restore(); } void WIN32Window::terminate() @@ -212,7 +221,7 @@ void WIN32Window::terminate() DestroyCursor(cursor); m_cursors.clear(); - internalDestroyContext(); + m_graphicsContext->destroy(); if(m_deviceContext) { if(!ReleaseDC(m_window, m_deviceContext)) @@ -289,22 +298,6 @@ void WIN32Window::internalCreateWindow() g_logger.fatal("GetDC failed"); } -void WIN32Window::internalCreateContext() -{ - dump << m_graphicsContext->getName().c_str(); - m_graphicsContext->create(m_window, m_deviceContext); -} - -void WIN32Window::internalDestroyContext() -{ - m_graphicsContext->destroy(); -} - -void WIN32Window::internalRestoreContext() -{ - m_graphicsContext->restore(); -} - void WIN32Window::move(const Point& pos) { Rect clientRect(pos, getClientRect().size()); @@ -579,7 +572,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar } if(m_visible) - internalRestoreContext(); + m_graphicsContext->restore(); Size size = Size(LOWORD(lParam), HIWORD(lParam)); size.setWidth(std::max(std::min(size.width(), 7680), 32)); diff --git a/src/framework/platform/win32window.h b/src/framework/platform/win32window.h index abcad1a3..91b79276 100644 --- a/src/framework/platform/win32window.h +++ b/src/framework/platform/win32window.h @@ -31,9 +31,6 @@ struct WindowProcProxy; class WIN32Window : public PlatformWindow { void internalCreateWindow(); - void internalCreateContext(); - void internalDestroyContext(); - void internalRestoreContext(); LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); friend class WindowProcProxy; @@ -70,6 +67,8 @@ public: Size getDisplaySize(); std::string getClipboardText(); std::string getPlatformType(); + HWND getWindow() { return m_window; } + HDC getDisplay() { return m_deviceContext; } protected: int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot); @@ -88,4 +87,6 @@ private: bool m_hidden; }; +extern WIN32Window& g_win32Window; + #endif diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index dc70463e..129fc72d 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -23,10 +23,14 @@ #include "x11window.h" #include #include -#include -#include #include +#ifndef OPENGL_ES +#include +#else +#include +#endif + #define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8))) X11Window::X11Window()