From 45eda6c5730fd6168fff93792377a472925bd28b Mon Sep 17 00:00:00 2001 From: Henrique Date: Tue, 26 Feb 2013 05:57:11 -0300 Subject: [PATCH] Now drawing on windows again --- src/framework/graphics/graphics.cpp | 7 ++++- src/framework/graphics/graphicscontext.cpp | 2 ++ .../graphics/ogl/graphicscontextwgl.cpp | 26 +++++++------------ .../graphics/ogl/graphicscontextwgl.h | 5 ++-- src/framework/platform/platformwindow.cpp | 4 +-- src/framework/platform/win32window.cpp | 26 ++++++++++--------- src/framework/platform/win32window.h | 4 +-- 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index 8279ed3f..f3af8ec6 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; } @@ -254,6 +254,11 @@ bool Graphics::selectPainterEngine(PainterEngine painterEngine) void Graphics::resize(const Size& size) { m_viewportSize = size; +#ifdef PAINTER_DX9 + if(g_painterDX9) + g_painterDX9->setResolution(size); +#endif + #ifdef PAINTER_OGL1 if(g_painterOGL1) g_painterOGL1->setResolution(size); diff --git a/src/framework/graphics/graphicscontext.cpp b/src/framework/graphics/graphicscontext.cpp index 1d638c79..cc6d6521 100644 --- a/src/framework/graphics/graphicscontext.cpp +++ b/src/framework/graphics/graphicscontext.cpp @@ -24,5 +24,7 @@ GraphicsContext::GraphicsContext(const std::string& 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/ogl/graphicscontextwgl.cpp b/src/framework/graphics/ogl/graphicscontextwgl.cpp index 5154dc25..36358cfd 100644 --- a/src/framework/graphics/ogl/graphicscontextwgl.cpp +++ b/src/framework/graphics/ogl/graphicscontextwgl.cpp @@ -25,15 +25,13 @@ GraphicsContextWGL::GraphicsContextWGL() : GraphicsContext("WGL") { - m_deviceContext = 0; m_wglContext = 0; } -void GraphicsContextWGL::create(WindowType window) +void GraphicsContextWGL::create(WindowType window, DisplayType display) { - m_deviceContext = GetDC(window); - if(!m_deviceContext) - g_logger.fatal("GetDC failed"); + m_window = window; + m_display = display; uint pixelFormat; static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), @@ -53,18 +51,18 @@ void GraphicsContextWGL::create(WindowType window) 0, // Reserved 0, 0, 0 }; // Layer Masks Ignored - pixelFormat = ChoosePixelFormat(m_deviceContext, &pfd); + pixelFormat = ChoosePixelFormat(display, &pfd); if(!pixelFormat) g_logger.fatal("Could not find a suitable pixel format"); - if(!SetPixelFormat(m_deviceContext, pixelFormat, &pfd)) + if(!SetPixelFormat(display, pixelFormat, &pfd)) g_logger.fatal("Could not set the pixel format"); - if(!(m_wglContext = wglCreateContext(m_deviceContext))) + if(!(m_wglContext = wglCreateContext(display))) g_logger.fatal("Unable to create GL context"); } -void GraphicsContextWGL::destroy(WindowType window) +void GraphicsContextWGL::destroy() { if(m_wglContext) { if(!wglMakeCurrent(NULL, NULL)) @@ -73,17 +71,11 @@ void GraphicsContextWGL::destroy(WindowType window) g_logger.error("Release rendering context failed."); m_wglContext = NULL; } - - if(m_deviceContext) { - if(!ReleaseDC(window, m_deviceContext)) - g_logger.error("Release device context failed."); - m_deviceContext = NULL; - } } void GraphicsContextWGL::restore() { - if(!wglMakeCurrent(m_deviceContext, m_wglContext)) + if(!wglMakeCurrent(m_display, m_wglContext)) g_logger.fatal("Unable to make current WGL context"); } @@ -108,7 +100,7 @@ void *GraphicsContextWGL::getExtensionProcAddress(const char *ext) void GraphicsContextWGL::swapBuffers() { - SwapBuffers(m_deviceContext); + SwapBuffers(m_display); } void GraphicsContextWGL::setVerticalSync(bool enable) diff --git a/src/framework/graphics/ogl/graphicscontextwgl.h b/src/framework/graphics/ogl/graphicscontextwgl.h index d15e2fbf..f0e725dd 100644 --- a/src/framework/graphics/ogl/graphicscontextwgl.h +++ b/src/framework/graphics/ogl/graphicscontextwgl.h @@ -31,8 +31,8 @@ class GraphicsContextWGL : public GraphicsContext public: GraphicsContextWGL(); - void create(WindowType window); - void destroy(WindowType window); + void create(WindowType window, DisplayType display); + void destroy(); void restore(); bool isExtensionSupported(const char *ext); @@ -43,7 +43,6 @@ public: void setVerticalSync(bool enable); private: - HDC m_deviceContext; HGLRC m_wglContext; }; diff --git a/src/framework/platform/platformwindow.cpp b/src/framework/platform/platformwindow.cpp index b662150f..08c1a51d 100644 --- a/src/framework/platform/platformwindow.cpp +++ b/src/framework/platform/platformwindow.cpp @@ -66,8 +66,8 @@ 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 && m_graphicsContext->getName() == graphicsContext->getName()) + return; if(m_graphicsContext) internalDestroyContext(); diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index 1790b925..a54a1e9b 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -36,7 +36,9 @@ WIN32Window::WIN32Window() m_minimumSize = Size(600,480); m_size = Size(600,480); m_hidden = true; + m_deviceContext = 0; m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL); + std::cout << "lal3: \"" << m_graphicsContext->getName().c_str() << "\" aa" << std::endl; m_keyMap[VK_ESCAPE] = Fw::KeyEscape; m_keyMap[VK_TAB] = Fw::KeyTab; @@ -212,6 +214,12 @@ void WIN32Window::terminate() internalDestroyContext(); + if(m_deviceContext) { + if(!ReleaseDC(m_window, m_deviceContext)) + g_logger.error("Release device context failed."); + m_deviceContext = NULL; + } + if(m_window) { if(!DestroyWindow(m_window)) g_logger.error("ERROR: Destroy window failed."); @@ -275,17 +283,21 @@ void WIN32Window::internalCreateWindow() g_logger.fatal("Unable to create window"); ShowWindow(m_window, SW_HIDE); + + m_deviceContext = GetDC(m_window); + if(!m_deviceContext) + g_logger.fatal("GetDC failed"); } void WIN32Window::internalCreateContext() { dump << m_graphicsContext->getName().c_str(); - m_graphicsContext->create(m_window); + m_graphicsContext->create(m_window, m_deviceContext); } void WIN32Window::internalDestroyContext() { - m_graphicsContext->destroy(m_window); + m_graphicsContext->destroy(); } void WIN32Window::internalRestoreContext() @@ -293,16 +305,6 @@ void WIN32Window::internalRestoreContext() m_graphicsContext->restore(); } -bool WIN32Window::isExtensionSupported(const char *ext) -{ - return m_graphicsContext->isExtensionSupported(ext); -} - -void *WIN32Window::getExtensionProcAddress(const char *ext) -{ - return m_graphicsContext->getExtensionProcAddress(ext); -} - void WIN32Window::move(const Point& pos) { Rect clientRect(pos, getClientRect().size()); diff --git a/src/framework/platform/win32window.h b/src/framework/platform/win32window.h index b7c881bd..abcad1a3 100644 --- a/src/framework/platform/win32window.h +++ b/src/framework/platform/win32window.h @@ -35,9 +35,6 @@ class WIN32Window : public PlatformWindow void internalDestroyContext(); void internalRestoreContext(); - void *getExtensionProcAddress(const char *ext); - bool isExtensionSupported(const char *ext); - LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); friend class WindowProcProxy; @@ -83,6 +80,7 @@ private: Rect adjustWindowRect(const Rect& rect); std::vector m_cursors; + HDC m_deviceContext; HWND m_window; HINSTANCE m_instance; HCURSOR m_cursor;