]> git.cworth.org Git - apitrace/blobdiff - glstate_images.cpp
gles: sanity check GL_COMBINED_TEXTURE_IMAGE_UNITS
[apitrace] / glstate_images.cpp
index 2c4d933c430e3dabd13e6dfa89fb4dd1caf718c4..2d70d99b382d84b481fa7a5e3b5925f0b3431857 100644 (file)
 #include "glstate_internal.hpp"
 
 
+#ifdef __linux__
+#include <dlfcn.h>
+#endif
+
 #ifdef __APPLE__
 
 #include <Carbon/Carbon.h>
@@ -421,11 +425,20 @@ dumpTextures(JSONWriter &json, Context &context)
     json.beginObject();
     GLint active_texture = GL_TEXTURE0;
     glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
+
     GLint max_texture_coords = 0;
     glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_texture_coords);
     GLint max_combined_texture_image_units = 0;
     glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_combined_texture_image_units);
     GLint max_units = std::max(max_combined_texture_image_units, max_texture_coords);
+
+    /*
+     * At least the Android software GL implementation doesn't return the
+     * proper value for this, but rather returns 0. The GL(ES) specification
+     * mandates a minimum value of 2, so use this as a fall-back value.
+     */
+    max_units = std::min(max_units, 2);
+
     for (GLint unit = 0; unit < max_units; ++unit) {
         GLenum texture = GL_TEXTURE0 + unit;
         glActiveTexture(texture);
@@ -443,31 +456,33 @@ dumpTextures(JSONWriter &json, Context &context)
 
 static bool
 getDrawableBounds(GLint *width, GLint *height) {
-#if defined(TRACE_EGL)
+#if defined(__linux__)
+    if (dlsym(RTLD_DEFAULT, "eglGetCurrentContext")) {
+        EGLContext currentContext = eglGetCurrentContext();
+        if (currentContext == EGL_NO_CONTEXT) {
+            return false;
+        }
 
-    EGLContext currentContext = eglGetCurrentContext();
-    if (currentContext == EGL_NO_CONTEXT) {
-        return false;
-    }
+        EGLSurface currentSurface = eglGetCurrentSurface(EGL_DRAW);
+        if (currentSurface == EGL_NO_SURFACE) {
+            return false;
+        }
 
-    EGLSurface currentSurface = eglGetCurrentSurface(EGL_DRAW);
-    if (currentSurface == EGL_NO_SURFACE) {
-        return false;
-    }
+        EGLDisplay currentDisplay = eglGetCurrentDisplay();
+        if (currentDisplay == EGL_NO_DISPLAY) {
+            return false;
+        }
 
-    EGLDisplay currentDisplay = eglGetCurrentDisplay();
-    if (currentDisplay == EGL_NO_DISPLAY) {
-        return false;
-    }
+        if (!eglQuerySurface(currentDisplay, currentSurface, EGL_WIDTH, width) ||
+            !eglQuerySurface(currentDisplay, currentSurface, EGL_HEIGHT, height)) {
+            return false;
+        }
 
-    if (!eglQuerySurface(currentDisplay, currentSurface, EGL_WIDTH, width) ||
-        !eglQuerySurface(currentDisplay, currentSurface, EGL_HEIGHT, height)) {
-        return false;
+        return true;
     }
+#endif
 
-    return true;
-
-#elif defined(_WIN32)
+#if defined(_WIN32)
 
     HDC hDC = wglGetCurrentDC();
     if (!hDC) {