EGL and WGL working

This commit is contained in:
Henrique 2013-02-28 05:20:03 -03:00 committed by Eduardo Bart
parent 96bbe20588
commit ab9351196c
9 changed files with 48 additions and 42 deletions

View File

@ -380,11 +380,15 @@ if(FRAMEWORK_GRAPHICS)
else() else()
if(WIN32) if(WIN32)
set(framework_SOURCES ${framework_SOURCES} 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.cpp
${CMAKE_CURRENT_LIST_DIR}/platform/win32window.h ${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() else()
set(framework_SOURCES ${framework_SOURCES} set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp

View File

@ -185,7 +185,9 @@ bool Graphics::isPainterEngineAvailable(Graphics::PainterEngine painterEngine)
bool Graphics::selectPainterEngine(PainterEngine painterEngine) bool Graphics::selectPainterEngine(PainterEngine painterEngine)
{ {
// TODO: remove this // TODO: remove this
painterEngine = Painter_OpenGL2; #ifdef DIRECTX
painterEngine = Painter_DirectX9;
#endif
Painter *painter = nullptr; Painter *painter = nullptr;
Painter *fallbackPainter = nullptr; Painter *fallbackPainter = nullptr;

View File

@ -21,7 +21,12 @@
*/ */
#include "graphicscontextegl.h" #include "graphicscontextegl.h"
#ifdef WIN32
#include <framework/platform/win32window.h>
#else
#include <framework/platform/x11window.h> #include <framework/platform/x11window.h>
#endif
GraphicsContextEGL::GraphicsContextEGL() : GraphicsContextEGL::GraphicsContextEGL() :
GraphicsContext("EGL") GraphicsContext("EGL")
@ -35,7 +40,7 @@ GraphicsContextEGL::GraphicsContextEGL() :
void GraphicsContextEGL::create() void GraphicsContextEGL::create()
{ {
#ifdef WIN32 #ifdef WIN32
// TODO HDC display = g_win32Window.getDisplay();
#else #else
Display *display = g_x11Window.getDisplay(); Display *display = g_x11Window.getDisplay();
#endif #endif
@ -62,22 +67,17 @@ void GraphicsContextEGL::create()
EGLint numConfig; 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)) if(!eglChooseConfig(m_eglDisplay, configList, &m_eglConfig, 1, &numConfig))
g_logger.fatal("Failed to choose EGL config"); g_logger.fatal("Failed to choose EGL config");
if(numConfig != 1) if(numConfig != 1)
g_logger.warning("Didn't got the exact EGL config"); g_logger.warning("Didn't got the exact EGL config");
#ifndef WIN32
EGLint vid; EGLint vid;
if(!eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_NATIVE_VISUAL_ID, &vid)) if(!eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_NATIVE_VISUAL_ID, &vid))
g_logger.fatal("Unable to get visual EGL visual id"); g_logger.fatal("Unable to get visual EGL visual id");
#ifndef WIN32
XVisualInfo visTemplate; XVisualInfo visTemplate;
int numVisuals; int numVisuals;
memset(&visTemplate, 0, sizeof(visTemplate)); memset(&visTemplate, 0, sizeof(visTemplate));
@ -99,6 +99,7 @@ void GraphicsContextEGL::create()
}; };
#ifdef WIN32 #ifdef WIN32
HWND window = g_win32Window.getWindow();
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, window, NULL); m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, window, NULL);
if(m_eglSurface == EGL_NO_SURFACE) if(m_eglSurface == EGL_NO_SURFACE)
g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError())); g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError()));

View File

@ -21,6 +21,7 @@
*/ */
#include "graphicscontextwgl.h" #include "graphicscontextwgl.h"
#include <framework/platform/win32window.h>
GraphicsContextWGL::GraphicsContextWGL() : GraphicsContextWGL::GraphicsContextWGL() :
GraphicsContext("WGL") GraphicsContext("WGL")
@ -28,10 +29,9 @@ GraphicsContextWGL::GraphicsContextWGL() :
m_wglContext = 0; m_wglContext = 0;
} }
void GraphicsContextWGL::create(WindowType window, DisplayType display) void GraphicsContextWGL::create()
{ {
m_window = window; HDC display = g_win32Window.getDisplay();
m_display = display;
uint pixelFormat; uint pixelFormat;
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
@ -75,7 +75,7 @@ void GraphicsContextWGL::destroy()
void GraphicsContextWGL::restore() 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"); g_logger.fatal("Unable to make current WGL context");
} }
@ -100,7 +100,7 @@ void *GraphicsContextWGL::getExtensionProcAddress(const char *ext)
void GraphicsContextWGL::swapBuffers() void GraphicsContextWGL::swapBuffers()
{ {
SwapBuffers(m_display); SwapBuffers(g_win32Window.getDisplay());
} }
void GraphicsContextWGL::setVerticalSync(bool enable) void GraphicsContextWGL::setVerticalSync(bool enable)

View File

@ -31,7 +31,7 @@ class GraphicsContextWGL : public GraphicsContext
public: public:
GraphicsContextWGL(); GraphicsContextWGL();
void create(WindowType window, DisplayType display); void create();
void destroy(); void destroy();
void restore(); void restore();

View File

@ -29,6 +29,7 @@ SDLWindow window;
#ifdef WIN32 #ifdef WIN32
#include "win32window.h" #include "win32window.h"
WIN32Window window; WIN32Window window;
WIN32Window& g_win32Window = window;
#else #else
#include "x11window.h" #include "x11window.h"
#include <framework/core/clock.h> #include <framework/core/clock.h>

View File

@ -24,7 +24,12 @@
#include <framework/graphics/image.h> #include <framework/graphics/image.h>
#include <framework/core/application.h> #include <framework/core/application.h>
#include <framework/core/resourcemanager.h> #include <framework/core/resourcemanager.h>
#ifndef OPENGL_ES
#include <framework/graphics/ogl/graphicscontextwgl.h> #include <framework/graphics/ogl/graphicscontextwgl.h>
#else
#include <framework/graphics/ogl/graphicscontextegl.h>
#endif
#define HSB_BIT_SET(p, n) (p[(n)/8] |= (128 >>((n)%8))) #define HSB_BIT_SET(p, n) (p[(n)/8] |= (128 >>((n)%8)))
@ -37,8 +42,12 @@ WIN32Window::WIN32Window()
m_size = Size(600,480); m_size = Size(600,480);
m_hidden = true; m_hidden = true;
m_deviceContext = 0; m_deviceContext = 0;
#ifndef OPENGL_ES
m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL); 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_ESCAPE] = Fw::KeyEscape;
m_keyMap[VK_TAB] = Fw::KeyTab; m_keyMap[VK_TAB] = Fw::KeyTab;
@ -196,8 +205,8 @@ void WIN32Window::init()
{ {
m_instance = GetModuleHandle(NULL); m_instance = GetModuleHandle(NULL);
internalCreateWindow(); internalCreateWindow();
internalCreateContext(); m_graphicsContext->create();
internalRestoreContext(); m_graphicsContext->restore();
} }
void WIN32Window::terminate() void WIN32Window::terminate()
@ -212,7 +221,7 @@ void WIN32Window::terminate()
DestroyCursor(cursor); DestroyCursor(cursor);
m_cursors.clear(); m_cursors.clear();
internalDestroyContext(); m_graphicsContext->destroy();
if(m_deviceContext) { if(m_deviceContext) {
if(!ReleaseDC(m_window, m_deviceContext)) if(!ReleaseDC(m_window, m_deviceContext))
@ -289,22 +298,6 @@ void WIN32Window::internalCreateWindow()
g_logger.fatal("GetDC failed"); 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) void WIN32Window::move(const Point& pos)
{ {
Rect clientRect(pos, getClientRect().size()); Rect clientRect(pos, getClientRect().size());
@ -579,7 +572,7 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
} }
if(m_visible) if(m_visible)
internalRestoreContext(); m_graphicsContext->restore();
Size size = Size(LOWORD(lParam), HIWORD(lParam)); Size size = Size(LOWORD(lParam), HIWORD(lParam));
size.setWidth(std::max(std::min(size.width(), 7680), 32)); size.setWidth(std::max(std::min(size.width(), 7680), 32));

View File

@ -31,9 +31,6 @@ struct WindowProcProxy;
class WIN32Window : public PlatformWindow class WIN32Window : public PlatformWindow
{ {
void internalCreateWindow(); void internalCreateWindow();
void internalCreateContext();
void internalDestroyContext();
void internalRestoreContext();
LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
friend class WindowProcProxy; friend class WindowProcProxy;
@ -70,6 +67,8 @@ public:
Size getDisplaySize(); Size getDisplaySize();
std::string getClipboardText(); std::string getClipboardText();
std::string getPlatformType(); std::string getPlatformType();
HWND getWindow() { return m_window; }
HDC getDisplay() { return m_deviceContext; }
protected: protected:
int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot); int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);
@ -88,4 +87,6 @@ private:
bool m_hidden; bool m_hidden;
}; };
extern WIN32Window& g_win32Window;
#endif #endif

View File

@ -23,10 +23,14 @@
#include "x11window.h" #include "x11window.h"
#include <framework/core/resourcemanager.h> #include <framework/core/resourcemanager.h>
#include <framework/graphics/image.h> #include <framework/graphics/image.h>
#include <framework/graphics/ogl/graphicscontextglx.h>
#include <framework/graphics/ogl/graphicscontextegl.h>
#include <unistd.h> #include <unistd.h>
#ifndef OPENGL_ES
#include <framework/graphics/ogl/graphicscontextglx.h>
#else
#include <framework/graphics/ogl/graphicscontextegl.h>
#endif
#define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8))) #define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8)))
X11Window::X11Window() X11Window::X11Window()