Преглед на файлове

Wrap egl calls aroung EGL_CHECK for improved error detection

Daniele Bartolini преди 12 години
родител
ревизия
0e0d26aa6c
променени са 1 файла, в които са добавени 51 реда и са изтрити 16 реда
  1. 51 16
      engine/renderers/gles/egl/GLContext.cpp

+ 51 - 16
engine/renderers/gles/egl/GLContext.cpp

@@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include <GLES2/gl2.h>
 
+#include "Config.h"
 #include "Assert.h"
 #include "GLContext.h"
 #include "Log.h"
@@ -33,7 +34,41 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-static ANativeWindow* awindow = NULL;
+static ANativeWindow* awindow;
+
+//-----------------------------------------------------------------------------
+static const char* egl_error_to_string(EGLint error)
+{
+    switch (error)
+    {
+        case EGL_NOT_INITIALIZED: return "EGL_NOT_INITIALIZED";
+        case EGL_BAD_ACCESS: return "EGL_BAD_ACCESS";
+        case EGL_BAD_ALLOC: return "EGL_BAD_ALLOC";
+        case EGL_BAD_ATTRIBUTE: return "EGL_BAD_ATTRIBUTE";
+        case EGL_BAD_CONTEXT: return "EGL_BAD_CONTEXT";
+        case EGL_BAD_CONFIG: return "EGL_BAD_CONFIG";
+        case EGL_BAD_CURRENT_SURFACE: return "EGL_BAD_CURRENT_SURFACE";
+        case EGL_BAD_DISPLAY: return "EGL_BAD_DISPLAY";
+        case EGL_BAD_SURFACE: return "EGL_BAD_SURFACE";
+        case EGL_BAD_MATCH: return "EGL_BAD_MATCH";
+        case EGL_BAD_PARAMETER: return "EGL_BAD_PARAMETER";
+        case EGL_BAD_NATIVE_PIXMAP: return "EGL_BAD_NATIVE_PIXMAP";
+        case EGL_BAD_NATIVE_WINDOW: return "EGL_BAD_NATIVE_WINDOW";
+        case EGL_CONTEXT_LOST: return "EGL_CONTEXT_LOST";
+        default: return "UNKNOWN_EGL_ERROR";
+    }
+}
+
+//-----------------------------------------------------------------------------
+#if defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT)
+    #define EGL_CHECK(function)\
+        function;\
+        do { EGLint error; CE_ASSERT((error = eglGetError()) == EGL_SUCCESS,\
+                "EGL error: %s", egl_error_to_string(error)); } while (0)
+#else
+    #define EGL_CHECK(function)\
+        function;
+#endif
 
 //-----------------------------------------------------------------------------
 void set_android_window(ANativeWindow* window)
@@ -52,8 +87,6 @@ GLContext::GLContext() :
 //-----------------------------------------------------------------------------
 void GLContext::create_context()
 {
-	EGLint format;
-
 	// Screen format rgbx8888 with no alpha channel,
 	// maybe it is wrong but is for testing
 	EGLint attrib_list[]= { EGL_RED_SIZE,        8,
@@ -66,23 +99,24 @@ void GLContext::create_context()
 
     EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
 
-    display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+    display = EGL_CHECK(eglGetDisplay(EGL_DEFAULT_DISPLAY));
 
-    eglInitialize(display, NULL, NULL);
+    EGL_CHECK(eglInitialize(display, NULL, NULL));
 
-    eglBindAPI(EGL_OPENGL_ES_API);
+    EGL_CHECK(eglBindAPI(EGL_OPENGL_ES_API));
 
-    eglChooseConfig(display, attrib_list, &config, 1, &num_configs);
+    EGL_CHECK(eglChooseConfig(display, attrib_list, &config, 1, &num_configs));
 
-	eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
+    EGLint format;
+	EGL_CHECK(eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format));
 
 	ANativeWindow_setBuffersGeometry(awindow, 0, 0, format);
 
-    context = eglCreateContext(display, config, EGL_NO_CONTEXT, attributes);
+    context = EGL_CHECK(eglCreateContext(display, config, EGL_NO_CONTEXT, attributes));
 
-	surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)awindow, NULL);
+	surface = EGL_CHECK(eglCreateWindowSurface(display, config, (EGLNativeWindowType)awindow, NULL));
 
-    eglMakeCurrent(display, surface, surface, context);
+    EGL_CHECK(eglMakeCurrent(display, surface, surface, context));
 
     Log::i("EGL context created");
 }
@@ -90,9 +124,10 @@ void GLContext::create_context()
 //-----------------------------------------------------------------------------
 void GLContext::destroy_context()
 {
- 	eglDestroyContext(display, context);
- 	eglDestroySurface(display, surface);
- 	eglTerminate(display);
+    EGL_CHECK(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
+ 	EGL_CHECK(eglDestroyContext(display, context));
+ 	EGL_CHECK(eglDestroySurface(display, surface));
+ 	EGL_CHECK(eglTerminate(display));
 
     Log::i("EGL context destroyed");
 }
@@ -100,7 +135,7 @@ void GLContext::destroy_context()
 //-----------------------------------------------------------------------------
 void GLContext::swap_buffers()
 {
-   	eglSwapBuffers(display, surface);
+   	EGL_CHECK(eglSwapBuffers(display, surface));
 }
 
-}
+}