[PATCH 6/6] gles: Fix retrace of eglCreateContext for GLES contexts

Chia-I Wu olvaffe at gmail.com
Tue Nov 8 15:48:43 PST 2011


Check the current API and the attribute list to determine the profile of the
context.
---
 glretrace_egl.cpp |   54 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/glretrace_egl.cpp b/glretrace_egl.cpp
index b75aa4d..d88694b 100644
--- a/glretrace_egl.cpp
+++ b/glretrace_egl.cpp
@@ -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;
 }
 
-- 
1.7.6.3



More information about the apitrace mailing list