fixes in WIN32-EGL

This commit is contained in:
Eduardo Bart 2012-06-10 20:48:53 -03:00
parent 29dadb849e
commit e91f822f62
5 changed files with 47 additions and 58 deletions

View File

@ -85,6 +85,9 @@ void Graphics::init()
if(m_maxTextureSize == -1 || m_maxTextureSize > maxTextureSize) if(m_maxTextureSize == -1 || m_maxTextureSize > maxTextureSize)
m_maxTextureSize = maxTextureSize; m_maxTextureSize = maxTextureSize;
m_alphaBits = 0;
glGetIntegerv(GL_ALPHA_BITS, &m_alphaBits);
selectPainterEngine(m_prefferedPainterEngine); selectPainterEngine(m_prefferedPainterEngine);
m_emptyTexture = TexturePtr(new Texture); m_emptyTexture = TexturePtr(new Texture);
} }
@ -360,6 +363,8 @@ bool Graphics::canUseBlendFuncSeparate()
bool Graphics::canCacheBackbuffer() bool Graphics::canCacheBackbuffer()
{ {
if(!m_alphaBits)
return false;
#if OPENGL_ES==2 #if OPENGL_ES==2
return m_cacheBackbuffer; return m_cacheBackbuffer;
#elif OPENGL_ES==1 #elif OPENGL_ES==1

View File

@ -77,6 +77,7 @@ private:
TexturePtr m_emptyTexture; TexturePtr m_emptyTexture;
int m_maxTextureSize; int m_maxTextureSize;
int m_alphaBits;
Boolean<true> m_useDrawArrays; Boolean<true> m_useDrawArrays;
Boolean<true> m_useFBO; Boolean<true> m_useFBO;
Boolean<false> m_useHardwareBuffers; Boolean<false> m_useHardwareBuffers;

View File

@ -201,12 +201,8 @@ void WIN32Window::init()
{ {
m_instance = GetModuleHandle(NULL); m_instance = GetModuleHandle(NULL);
internalRegisterWindowClass();
internalCheckGL();
internalCreateWindow(); internalCreateWindow();
internalChooseGLVisual();
internalCreateGLContext(); internalCreateGLContext();
internalConnectGLContext();
} }
void WIN32Window::terminate() void WIN32Window::terminate()
@ -244,7 +240,7 @@ struct WindowProcProxy {
} }
}; };
void WIN32Window::internalRegisterWindowClass() void WIN32Window::internalCreateWindow()
{ {
m_defaultCursor = LoadCursor(NULL, IDC_ARROW); m_defaultCursor = LoadCursor(NULL, IDC_ARROW);
WNDCLASSA wc; WNDCLASSA wc;
@ -255,16 +251,12 @@ void WIN32Window::internalRegisterWindowClass()
wc.hInstance = m_instance; wc.hInstance = m_instance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = m_defaultCursor; wc.hCursor = m_defaultCursor;
wc.hbrBackground = NULL; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL; wc.lpszMenuName = NULL;
wc.lpszClassName = g_app->getName().c_str(); wc.lpszClassName = g_app->getName().c_str();
if(!RegisterClassA(&wc)) if(!RegisterClassA(&wc))
g_logger.fatal("Failed to register the window class."); g_logger.fatal("Failed to register the window class.");
}
void WIN32Window::internalCreateWindow()
{
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
DWORD dwStyle = WS_OVERLAPPEDWINDOW; DWORD dwStyle = WS_OVERLAPPEDWINDOW;
@ -299,40 +291,59 @@ void WIN32Window::internalCreateWindow()
g_logger.fatal("GetDC failed"); g_logger.fatal("GetDC failed");
} }
void WIN32Window::internalCheckGL() void WIN32Window::internalCreateGLContext()
{ {
#ifdef OPENGL_ES #ifdef OPENGL_ES
m_eglDisplay = eglGetDisplay(GetDC(m_window)); m_eglDisplay = eglGetDisplay(m_deviceContext);
if(m_eglDisplay == EGL_NO_DISPLAY) if(m_eglDisplay == EGL_NO_DISPLAY)
g_logger.fatal("EGL not supported"); g_logger.fatal("EGL not supported");
if(!eglInitialize(m_eglDisplay, NULL, NULL)) if(!eglInitialize(m_eglDisplay, NULL, NULL))
g_logger.fatal("Unable to initialize EGL"); g_logger.fatal("Unable to initialize EGL");
#endif
}
void WIN32Window::internalChooseGLVisual() static int configList[] = {
{
#ifdef OPENGL_ES
static int attrList[] = {
#if OPENGL_ES==2 #if OPENGL_ES==2
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#else #else
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
#endif #endif
EGL_RED_SIZE, 5, EGL_RED_SIZE, 4,
EGL_GREEN_SIZE, 6, EGL_GREEN_SIZE, 4,
EGL_BLUE_SIZE, 5, EGL_BLUE_SIZE, 4,
EGL_ALPHA_SIZE, 4,
EGL_NONE EGL_NONE
}; };
EGLint numConfig; EGLint numConfig;
if(!eglChooseConfig(m_eglDisplay, attrList, &m_eglConfig, 1, &numConfig)) if(!eglGetConfigs(m_eglDisplay, NULL, 0, &numConfig))
g_logger.fatal("No valid GL configurations");
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");
EGLint contextAtrrList[] = {
#if OPENGL_ES==2
EGL_CONTEXT_CLIENT_VERSION, 2,
#else
EGL_CONTEXT_CLIENT_VERSION, 1,
#endif
EGL_NONE
};
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL);
if(m_eglSurface == EGL_NO_SURFACE)
g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError()));
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, contextAtrrList);
if(m_eglContext == EGL_NO_CONTEXT )
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))
g_logger.fatal("Unable to make current EGL context");
#else #else
uint pixelFormat; uint pixelFormat;
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
@ -358,25 +369,7 @@ void WIN32Window::internalChooseGLVisual()
if(!SetPixelFormat(m_deviceContext, pixelFormat, &pfd)) if(!SetPixelFormat(m_deviceContext, pixelFormat, &pfd))
g_logger.fatal("Could not set the pixel format"); g_logger.fatal("Could not set the pixel format");
#endif
}
void WIN32Window::internalCreateGLContext()
{
#ifdef OPENGL_ES
EGLint attrList[] = {
#if OPENGL_ES==2
EGL_CONTEXT_CLIENT_VERSION, 2,
#else
EGL_CONTEXT_CLIENT_VERSION, 1,
#endif
EGL_NONE, EGL_NONE
};
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, attrList);
if(m_eglContext == EGL_NO_CONTEXT )
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
#else
if(!(m_wglContext = wglCreateContext(m_deviceContext))) if(!(m_wglContext = wglCreateContext(m_deviceContext)))
g_logger.fatal("Unable to create GL context"); g_logger.fatal("Unable to create GL context");
@ -411,17 +404,6 @@ void WIN32Window::internalDestroyGLContext()
#endif #endif
} }
void WIN32Window::internalConnectGLContext()
{
#ifdef OPENGL_ES
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL);
if(m_eglSurface == EGL_NO_SURFACE)
g_logger.fatal(stdext::format("Unable to create EGL surface: %s", eglGetError()));
if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))
g_logger.fatal("Unable to connect EGL context into X11 window");
#endif
}
bool WIN32Window::isExtensionSupported(const char *ext) bool WIN32Window::isExtensionSupported(const char *ext)
{ {
#ifdef OPENGL_ES #ifdef OPENGL_ES
@ -743,7 +725,11 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
void WIN32Window::swapBuffers() void WIN32Window::swapBuffers()
{ {
#ifdef OPENGL_ES
eglSwapBuffers(m_eglDisplay, m_eglSurface);
#else
SwapBuffers(m_deviceContext); SwapBuffers(m_deviceContext);
#endif
} }
void WIN32Window::restoreMouseCursor() void WIN32Window::restoreMouseCursor()
@ -856,7 +842,7 @@ void WIN32Window::setFullscreen(bool fullscreen)
void WIN32Window::setVerticalSync(bool enable) void WIN32Window::setVerticalSync(bool enable)
{ {
#ifdef OPENGL_ES #ifdef OPENGL_ES
//TODO eglSwapInterval(m_eglDisplay, enable ? 1 : 0);
#else #else
if(!isExtensionSupported("WGL_EXT_swap_control")) if(!isExtensionSupported("WGL_EXT_swap_control"))
return; return;

View File

@ -36,13 +36,8 @@ struct WindowProcProxy;
class WIN32Window : public PlatformWindow class WIN32Window : public PlatformWindow
{ {
void internalCreateWindow(); void internalCreateWindow();
void internalRegisterWindowClass();
void internalCheckGL();
void internalChooseGLVisual();
void internalCreateGLContext(); void internalCreateGLContext();
void internalDestroyGLContext(); void internalDestroyGLContext();
void internalConnectGLContext();
void *getExtensionProcAddress(const char *ext); void *getExtensionProcAddress(const char *ext);
bool isExtensionSupported(const char *ext); bool isExtensionSupported(const char *ext);

View File

@ -75,8 +75,10 @@ void MapView::draw(const Rect& rect)
if(m_mustCleanFramebuffer) { if(m_mustCleanFramebuffer) {
Rect clearRect = Rect(0, 0, m_drawDimension * m_tileSize); Rect clearRect = Rect(0, 0, m_drawDimension * m_tileSize);
g_painter->clearRect(Color::black, clearRect); g_painter->setColor(Color::black);
g_painter->drawFilledRect(clearRect);
} }
g_painter->setColor(Color::white);
auto it = m_cachedVisibleTiles.begin(); auto it = m_cachedVisibleTiles.begin();
auto end = m_cachedVisibleTiles.end(); auto end = m_cachedVisibleTiles.end();