]> git.cworth.org Git - apitrace/commitdiff
gles: Fix retrace of eglCreateContext for GLES contexts
authorChia-I Wu <olvaffe@gmail.com>
Tue, 8 Nov 2011 21:31:58 +0000 (14:31 -0700)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 17 Nov 2011 15:50:26 +0000 (15:50 +0000)
Check the current API and the attribute list to determine the profile of the
context.

glretrace_egl.cpp

index 1c7697a0c6c88dfc4acfd0c1384e78a0a8c99420..4e549a3446401111d6a65d7b94a838ed65683b8a 100644 (file)
@@ -37,6 +37,7 @@
 #define EGL_OPENGL_ES_API              0x30A0
 #define EGL_OPENVG_API                 0x30A1
 #define EGL_OPENGL_API                 0x30A2
+#define EGL_CONTEXT_CLIENT_VERSION     0x3098
 #endif
 
 
@@ -98,16 +99,55 @@ static void retrace_eglBindAPI(trace::Call &call) {
 }
 
 static void retrace_eglCreateContext(trace::Call &call) {
-    if (current_api != EGL_OPENGL_API) {
-        retrace::warning(call) << "only OpenGL is supported.  Aborting...\n";
-        os::abort();
-        return;
-    }
-
     unsigned long long orig_context = call.ret->toUIntPtr();
     glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
+    trace::Array *attrib_array = dynamic_cast<trace::Array *>(&call.arg(3));
+    glws::Profile profile;
+
+    switch (current_api) {
+    case EGL_OPENGL_API:
+        profile = glws::PROFILE_COMPAT;
+        break;
+    case EGL_OPENGL_ES_API:
+    default:
+        profile = glws::PROFILE_ES1;
+        if (attrib_array) {
+            for (int i = 0; i < attrib_array->values.size(); i += 2) {
+                int v = attrib_array->values[i]->toSInt();
+                if (v == EGL_CONTEXT_CLIENT_VERSION) {
+                    v = attrib_array->values[i + 1]->toSInt();
+                    if (v == 2)
+                        profile = glws::PROFILE_ES2;
+                    break;
+                }
+            }
+        }
+        break;
+    }
+
+
+    glws::Context *context = glws::createContext(glretrace::visual, share_context, profile);
+    if (!context) {
+        const char *name;
+        switch (profile) {
+        case glws::PROFILE_COMPAT:
+            name = "OpenGL";
+            break;
+        case glws::PROFILE_ES1:
+            name = "OpenGL ES 1.1";
+            break;
+        case glws::PROFILE_ES2:
+            name = "OpenGL ES 2.0";
+            break;
+        default:
+            name = "unknown";
+            break;
+        }
+
+        retrace::warning(call) << "Failed to create " << name << " context.\n";
+        os::abort();
+    }
 
-    glws::Context *context = glws::createContext(glretrace::visual, share_context);
     context_map[orig_context] = context;
 }