From 3a871b9edbc7904ed68037d74dca60cd6ab2e068 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 16 Jan 2013 20:10:17 +0100 Subject: [PATCH] Added EGL errors to output, added EGL init to Win32. --- src/egl_context.c | 77 ++++++++++++++++++++++++++++++++++++++++---- src/wgl_context.c | 19 +++++++++++ src/win32_init.c | 5 +++ src/win32_platform.h | 2 ++ 4 files changed, 96 insertions(+), 7 deletions(-) diff --git a/src/egl_context.c b/src/egl_context.c index 6a0cbe94..c0f0b4b0 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -53,6 +53,58 @@ static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL; +//======================================================================== +// Return a description of the specified EGL error +//======================================================================== + +static const char* getErrorString(EGLint error) +{ + switch (error) + { + case EGL_SUCCESS: + return "Success"; + case EGL_NOT_INITIALIZED: + return "EGL is not or could not be initialized"; + case EGL_BAD_ACCESS: + return "EGL cannot access a requested resource"; + case EGL_BAD_ALLOC: + return "EGL failed to allocate resources for the requested operation"; + case EGL_BAD_ATTRIBUTE: + return "An unrecognized attribute or attribute value was passed " + "in the attribute list"; + case EGL_BAD_CONTEXT: + return "An EGLContext argument does not name a valid EGL " + "rendering context"; + case EGL_BAD_CONFIG: + return "An EGLConfig argument does not name a valid EGL frame " + "buffer configuration"; + case EGL_BAD_CURRENT_SURFACE: + return "The current surface of the calling thread is a window, pixel " + "buffer or pixmap that is no longer valid"; + case EGL_BAD_DISPLAY: + return "An EGLDisplay argument does not name a valid EGL display " + "connection"; + case EGL_BAD_SURFACE: + return "An EGLSurface argument does not name a valid surface " + "configured for GL rendering"; + case EGL_BAD_MATCH: + return "Arguments are inconsistent"; + case EGL_BAD_PARAMETER: + return "One or more argument values are invalid"; + case EGL_BAD_NATIVE_PIXMAP: + return "A NativePixmapType argument does not refer to a valid " + "native pixmap"; + case EGL_BAD_NATIVE_WINDOW: + return "A NativeWindowType argument does not refer to a valid " + "native window"; + case EGL_CONTEXT_LOST: + return "The application must destroy all contexts and reinitialise"; + } + + return "UNKNOWN EGL ERROR"; +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// @@ -66,7 +118,9 @@ int _glfwInitOpenGL(void) _glfw.egl.display = eglGetDisplay(_GLFW_EGL_NATIVE_DISPLAY); if (_glfw.egl.display == EGL_NO_DISPLAY) { - _glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to get EGL display"); + _glfwInputError(GLFW_API_UNAVAILABLE, + "EGL: Failed to get EGL display: %s", + getErrorString(eglGetError())); return GL_FALSE; } @@ -74,7 +128,9 @@ int _glfwInitOpenGL(void) &_glfw.egl.versionMajor, &_glfw.egl.versionMinor)) { - _glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Failed to initialize EGL"); + _glfwInputError(GLFW_API_UNAVAILABLE, + "EGL: Failed to initialize EGL: %s", + getErrorString(eglGetError())); return GL_FALSE; } @@ -150,7 +206,8 @@ int _glfwCreateContext(_GLFWwindow* window, if (!count) { _glfwInputError(GLFW_PLATFORM_ERROR, - "EGL: Failed to find a suitable EGLConfig"); + "EGL: Failed to find a suitable EGLConfig: %s", + getErrorString(eglGetError())); return GL_FALSE; } } @@ -209,7 +266,8 @@ int _glfwCreateContext(_GLFWwindow* window, if (!eglBindAPI(EGL_OPENGL_ES_API)) { _glfwInputError(GLFW_PLATFORM_ERROR, - "EGL: OpenGL ES is not supported"); + "EGL: Failed to bind OpenGL ES: %s", + getErrorString(eglGetError())); return GL_FALSE; } } @@ -217,7 +275,9 @@ int _glfwCreateContext(_GLFWwindow* window, { if (!eglBindAPI(EGL_OPENGL_API)) { - _glfwInputError(GLFW_PLATFORM_ERROR, "EGL: OpenGL is not supported"); + _glfwInputError(GLFW_PLATFORM_ERROR, + "EGL: Failed to bind OpenGL: %s", + getErrorString(eglGetError())); return GL_FALSE; } } @@ -284,7 +344,9 @@ int _glfwCreateContext(_GLFWwindow* window, { // TODO: Handle all the various error codes here - _glfwInputError(GLFW_PLATFORM_ERROR, "EGL: Failed to create context"); + _glfwInputError(GLFW_PLATFORM_ERROR, + "EGL: Failed to create context: %s", + getErrorString(eglGetError())); return GL_FALSE; } @@ -357,7 +419,8 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) if (window->egl.surface == EGL_NO_SURFACE) { _glfwInputError(GLFW_PLATFORM_ERROR, - "EGL: Failed to create window surface"); + "EGL: Failed to create window surface: %s", + getErrorString(eglGetError())); } } diff --git a/src/wgl_context.c b/src/wgl_context.c index f2d5dd05..1dc781c3 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -149,6 +149,25 @@ static void initWGLExtensions(_GLFWwindow* window) ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Initialize WGL +//======================================================================== + +int _glfwInitOpenGL(void) +{ + return GL_TRUE; +} + + +//======================================================================== +// Terminate WGL +//======================================================================== + +void _glfwTerminateOpenGL(void) +{ +} + + //======================================================================== // Prepare for creation of the OpenGL context //======================================================================== diff --git a/src/win32_init.c b/src/win32_init.c index a77422a1..6f55a45b 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -190,6 +190,9 @@ int _glfwPlatformInit(void) _glfwPlatformGetGammaRamp(&_glfw.originalRamp); _glfw.currentRamp = _glfw.originalRamp; + if (!_glfwInitOpenGL()) + return GL_FALSE; + _glfwInitTimer(); _glfwInitJoysticks(); @@ -214,6 +217,8 @@ void _glfwPlatformTerminate(void) _glfw.win32.classAtom = 0; } + _glfwTerminateOpenGL(); + _glfwTerminateJoysticks(); freeLibraries(); diff --git a/src/win32_platform.h b/src/win32_platform.h index 7f5d63bc..9da32f99 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -214,6 +214,8 @@ void _glfwInitJoysticks(void); void _glfwTerminateJoysticks(void); // OpenGL support +int _glfwInitOpenGL(void); +void _glfwTerminateOpenGL(void); int _glfwCreateContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig);