[SRUK] Check GLES version supported by driver, and handle 3.0 if driver supports it.
authormythri.venugopal <mythri.venugopal@samsung.com>
Tue, 11 Feb 2014 15:06:42 +0000 (15:06 +0000)
committermythri.venugopal <mythri.venugopal@samsung.com>
Tue, 11 Feb 2014 15:06:42 +0000 (15:06 +0000)
The GLES version is obtained by checking the presence of glReadBuffer symbol.

src/coregl.c
src/coregl_export.c
src/coregl_export.h
src/coregl_internal.h
src/headers/sym_gl.h
src/modules/fastpath/coregl_fastpath.c
src/modules/fastpath/coregl_fastpath_state.h
src/modules/tracepath/coregl_tracepath.c

index 643349b..f8f473d 100755 (executable)
@@ -11,6 +11,8 @@
 
 void               *egl_lib_handle;
 void               *gl_lib_handle;
+int                 driver_gl_version=COREGL_GLAPI_2;
+static int          api_gl_version=COREGL_GLAPI_2;
 
 #ifndef _COREGL_VENDOR_EGL_LIB_PATH
 #define _COREGL_VENDOR_EGL_LIB_PATH "/usr/lib/driver/libEGL.so" /* DEFAULT EGL PATH */
@@ -84,16 +86,20 @@ _sym_missing()
 }
 
 #define FINDSYM(libhandle, getproc, dst, sym) \
-   if (!dst || (void *)dst == (void *)_sym_missing) \
-               if (getproc) dst = (__typeof__(dst))getproc(sym); \
-   if (!dst || (void *)dst == (void *)_sym_missing) \
-               dst = (__typeof__(dst))dlsym(libhandle, sym); \
-       if (!dst) dst = (__typeof__(dst))_sym_missing;
+   if(api_gl_version <= driver_gl_version) { \
+      if (!dst || (void *)dst == (void *)_sym_missing) \
+                 if (getproc) dst = (__typeof__(dst))getproc(sym); \
+      if (!dst || (void *)dst == (void *)_sym_missing) \
+                 dst = (__typeof__(dst))dlsym(libhandle, sym); \
+         if (!dst) dst = (__typeof__(dst))_sym_missing;\
+   }
 
 static int
 _glue_sym_init(void)
 {
 
+#define _COREGL_START_API(version)             api_gl_version = version;
+#define _COREGL_END_API(version)               api_gl_version = COREGL_GLAPI_2;
 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
     FINDSYM(egl_lib_handle, _sym_eglGetProcAddress, _sym_##FUNC_NAME, #FUNC_NAME);
 #define _COREGL_EXT_SYMBOL_ALIAS(FUNC_NAME, ALIAS_NAME) \
@@ -103,6 +109,8 @@ _glue_sym_init(void)
 
 #undef _COREGL_EXT_SYMBOL_ALIAS
 #undef _COREGL_SYMBOL
+#undef _COREGL_START_API
+#undef _COREGL_END_API
 
        return 1;
 }
@@ -111,6 +119,8 @@ static int
 _gl_sym_init(void)
 {
 
+#define _COREGL_START_API(version)             api_gl_version = version;
+#define _COREGL_END_API(version)               api_gl_version = COREGL_GLAPI_2;
 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
     FINDSYM(gl_lib_handle, _sym_eglGetProcAddress, _sym_##FUNC_NAME, #FUNC_NAME);
 #define _COREGL_EXT_SYMBOL_ALIAS(FUNC_NAME, ALIAS_NAME) \
@@ -120,6 +130,8 @@ _gl_sym_init(void)
 
 #undef _COREGL_EXT_SYMBOL_ALIAS
 #undef _COREGL_SYMBOL
+#undef _COREGL_START_API
+#undef _COREGL_END_API
 
        return 1;
 }
@@ -167,6 +179,16 @@ _gl_lib_init(void)
                COREGL_ERR("\E[40;31;1mInvalid library link! (Check linkage of libCOREGL -> %s)\E[0m\n", _COREGL_VENDOR_GL_LIB_PATH);
                return 0;
        }
+
+       // test for a GLES 3.0 symbol
+       if (dlsym(gl_lib_handle, "glReadBuffer"))
+       {
+               COREGL_LOG("[CoreGL] Driver GL version 3.0 \n");
+               driver_gl_version = COREGL_GLAPI_3;
+       }else {
+               COREGL_LOG("[CoreGL] Driver GL version 2.0 \n");
+       }
+
        //------------------------------------------------//
 
        if (!_glue_sym_init()) return 0;
index 166ccb0..a2082a0 100644 (file)
 #include <stdlib.h>
 
 int export_initialized = 0;
+static int api_gl_version;
 
 static void
 _clean_overrides()
 {
-#define OVERRIDE(f) COREGL_OVERRIDE_API(ovr_, f, _sym_)
+#define _COREGL_START_API(version) api_gl_version = version;
+#define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
+#define OVERRIDE(f) \
+       if(api_gl_version<=driver_gl_version) COREGL_OVERRIDE_API(ovr_, f, _sym_)
 
 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     OVERRIDE(FUNC_NAME);
 # include "headers/sym_egl.h"
@@ -25,6 +29,8 @@ _clean_overrides()
 #undef _COREGL_SYMBOL
 
 #undef OVERRIDE
+#undef _COREGL_START_API
+#undef _COREGL_END_API
 }
 
 void
index e694eac..537a313 100644 (file)
@@ -8,6 +8,7 @@
 #undef _COREGL_SYMBOL
 
 extern int export_initialized;
+extern int driver_gl_version;
 
 extern void     init_export();
 extern void     clean_overrides();
index dd89bc6..50dfccf 100644 (file)
@@ -68,6 +68,9 @@ static inline GLuint GET_UINT_FROM_FLOAT(GLfloat value) { return *((GLint *)&val
 typedef GLvoid *     GLvoidptr;
 typedef GLuint       GLuintmask;
 
+#define COREGL_GLAPI_3 3
+#define COREGL_GLAPI_2 2
+
 #define _COREGL_INT_INIT_VALUE -3
 
 #define COREGL_OVERRIDE_API(mangle, func, prefix) \
index b84ad45..c31468e 100644 (file)
 #define _COREGL_EXT_SYMBOL_FASTPATH_BLOCK(FUNC_NAME)
 #endif
 
+#ifndef _COREGL_START_API
+#define _COREGL_START_API(VERSION)
+#endif
+
+#ifndef _COREGL_END_API
+#define _COREGL_END_API(VERSION)
+#endif
 /* OpenGL ES 2.0 */
 _COREGL_SYMBOL(void, glActiveTexture, (GLenum texture))
 _COREGL_SYMBOL(void, glAttachShader, (GLuint program, GLuint shader))
@@ -174,6 +181,7 @@ _COREGL_SYMBOL(void, glVertexAttribPointer, (GLuint index, GLint size, GLenum ty
 _COREGL_SYMBOL(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height))
 
 /* OpenGL ES 3.0 */
+_COREGL_START_API(COREGL_GLAPI_3)
 _COREGL_SYMBOL(void, glReadBuffer, (GLenum mode))
 _COREGL_SYMBOL(void, glDrawRangeElements, (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices))
 _COREGL_SYMBOL(void, glTexImage3D, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels))
@@ -278,6 +286,7 @@ _COREGL_SYMBOL(void, glInvalidateSubFramebuffer, (GLenum target, GLsizei numAtta
 _COREGL_SYMBOL(void, glTexStorage2D, (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height))
 _COREGL_SYMBOL(void, glTexStorage3D, (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth))
 _COREGL_SYMBOL(void, glGetInternalformativ, (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params))
+_COREGL_END_API(COREGL_GLAPI_3)
 
 
 /* Extensions */
@@ -547,3 +556,10 @@ _COREGL_EXT_SYMBOL_FASTPATH_BLOCK(glBlitFramebuffer)
 #undef _COREGL_EXT_SYMBOL_FASTPATH_BLOCK
 #endif
 
+#ifdef _COREGL_START_API
+#undef _COREGL_START_API
+#endif
+
+#ifdef _COREGL_END_API
+#undef _COREGL_END_API
+#endif
index de995b5..7910ab6 100644 (file)
@@ -26,6 +26,7 @@ GLGlueContext      *initial_ctx = NULL;
 Mutex               ctx_list_access_mutex = MUTEX_INITIALIZER;
 
 GLContext_List     *glctx_list = NULL;
+static int          api_gl_version=COREGL_GLAPI_2;
 
 static void
 _state_get_texture_states(GLenum pname, GLint *params)
@@ -279,9 +280,15 @@ fastpath_apply_overrides_egl(int enable)
 void
 fastpath_apply_overrides_gl(int enable)
 {
-#define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
+#define _COREGL_START_API(version) api_gl_version = version;
+#define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
+#define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     \
+   if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_fastpath_, FUNC_NAME);
+
 # include "../../headers/sym_gl.h"
 #undef _COREGL_SYMBOL
+#undef _COREGL_START_API
+#undef _COREGL_END_API
 
        if (debug_nofp != 1)
        {
@@ -420,63 +427,66 @@ fastpath_apply_overrides_gl(int enable)
                COREGL_OVERRIDE(fastpath_, glEGLImageTargetTexture2DOES);
                COREGL_OVERRIDE(fastpath_, glFramebufferTexture3DOES);
 
-               COREGL_OVERRIDE(fastpath_, glReadBuffer);
-
-               COREGL_OVERRIDE(fastpath_, glGenQueries);
-               COREGL_OVERRIDE(fastpath_, glDeleteQueries);
-               COREGL_OVERRIDE(fastpath_, glIsQuery);
-               COREGL_OVERRIDE(fastpath_, glBeginQuery);
-               COREGL_OVERRIDE(fastpath_, glGetQueryiv);
-               COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
-               COREGL_OVERRIDE(fastpath_, glDrawBuffers);
-               COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
-
-               COREGL_OVERRIDE(fastpath_, glBindVertexArray);
-               COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
-               COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
-               COREGL_OVERRIDE(fastpath_, glIsVertexArray);
-
-               COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
-
-               COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
-               COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
-               COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
-               COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
-
-               COREGL_OVERRIDE(fastpath_, glBindBufferRange);
-               COREGL_OVERRIDE(fastpath_, glBindBufferBase);
-               COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
-               COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
-               COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
-               COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
-               COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
-               COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
-               COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
-               COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
-               COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
-               COREGL_OVERRIDE(fastpath_, glGetStringi);
-               COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
-               COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
-               COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
-               COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
-               COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
-               COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
-               COREGL_OVERRIDE(fastpath_, glGetInteger64v);
-               COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
-               COREGL_OVERRIDE(fastpath_, glGenSamplers);
-               COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
-               COREGL_OVERRIDE(fastpath_, glIsSampler);
-               COREGL_OVERRIDE(fastpath_, glBindSampler);
-               COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
-               COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
-               COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
-               COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
-               COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
-               COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
-               COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
-               COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
-               COREGL_OVERRIDE(fastpath_, glProgramBinary);
-               COREGL_OVERRIDE(fastpath_, glProgramParameteri);
+               /* Start overriding GLES 3.0 */
+               if(driver_gl_version >= COREGL_GLAPI_3) {
+                       COREGL_OVERRIDE(fastpath_, glReadBuffer);
+
+                       COREGL_OVERRIDE(fastpath_, glGenQueries);
+                       COREGL_OVERRIDE(fastpath_, glDeleteQueries);
+                       COREGL_OVERRIDE(fastpath_, glIsQuery);
+                       COREGL_OVERRIDE(fastpath_, glBeginQuery);
+                       COREGL_OVERRIDE(fastpath_, glGetQueryiv);
+                       COREGL_OVERRIDE(fastpath_, glGetQueryObjectuiv);
+                       COREGL_OVERRIDE(fastpath_, glDrawBuffers);
+                       COREGL_OVERRIDE(fastpath_, glFramebufferTextureLayer);
+
+                       COREGL_OVERRIDE(fastpath_, glBindVertexArray);
+                       COREGL_OVERRIDE(fastpath_, glDeleteVertexArrays);
+                       COREGL_OVERRIDE(fastpath_, glGenVertexArrays);
+                       COREGL_OVERRIDE(fastpath_, glIsVertexArray);
+
+                       COREGL_OVERRIDE(fastpath_, glGetIntegeri_v);
+
+                       COREGL_OVERRIDE(fastpath_, glBindTransformFeedback);
+                       COREGL_OVERRIDE(fastpath_, glDeleteTransformFeedbacks);
+                       COREGL_OVERRIDE(fastpath_, glGenTransformFeedbacks);
+                       COREGL_OVERRIDE(fastpath_, glIsTransformFeedback);
+
+                       COREGL_OVERRIDE(fastpath_, glBindBufferRange);
+                       COREGL_OVERRIDE(fastpath_, glBindBufferBase);
+                       COREGL_OVERRIDE(fastpath_, glTransformFeedbackVaryings);
+                       COREGL_OVERRIDE(fastpath_, glGetTransformFeedbackVarying);
+                       COREGL_OVERRIDE(fastpath_, glVertexAttribIPointer);
+                       COREGL_OVERRIDE(fastpath_, glVertexAttribI4i);
+                       COREGL_OVERRIDE(fastpath_, glVertexAttribI4ui);
+                       COREGL_OVERRIDE(fastpath_, glVertexAttribI4iv);
+                       COREGL_OVERRIDE(fastpath_, glVertexAttribI4uiv);
+                       COREGL_OVERRIDE(fastpath_, glGetUniformuiv);
+                       COREGL_OVERRIDE(fastpath_, glGetFragDataLocation);
+                       COREGL_OVERRIDE(fastpath_, glGetStringi);
+                       COREGL_OVERRIDE(fastpath_, glGetUniformIndices);
+                       COREGL_OVERRIDE(fastpath_, glGetActiveUniformsiv);
+                       COREGL_OVERRIDE(fastpath_, glGetUniformBlockIndex);
+                       COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockiv);
+                       COREGL_OVERRIDE(fastpath_, glGetActiveUniformBlockName);
+                       COREGL_OVERRIDE(fastpath_, glUniformBlockBinding);
+                       COREGL_OVERRIDE(fastpath_, glGetInteger64v);
+                       COREGL_OVERRIDE(fastpath_, glGetInteger64i_v);
+                       COREGL_OVERRIDE(fastpath_, glGenSamplers);
+                       COREGL_OVERRIDE(fastpath_, glDeleteSamplers);
+                       COREGL_OVERRIDE(fastpath_, glIsSampler);
+                       COREGL_OVERRIDE(fastpath_, glBindSampler);
+                       COREGL_OVERRIDE(fastpath_, glSamplerParameteri);
+                       COREGL_OVERRIDE(fastpath_, glSamplerParameteriv);
+                       COREGL_OVERRIDE(fastpath_, glSamplerParameterf);
+                       COREGL_OVERRIDE(fastpath_, glSamplerParameterfv);
+                       COREGL_OVERRIDE(fastpath_, glGetSamplerParameteriv);
+                       COREGL_OVERRIDE(fastpath_, glGetSamplerParameterfv);
+                       COREGL_OVERRIDE(fastpath_, glVertexAttribDivisor);
+                       COREGL_OVERRIDE(fastpath_, glGetProgramBinary);
+                       COREGL_OVERRIDE(fastpath_, glProgramBinary);
+                       COREGL_OVERRIDE(fastpath_, glProgramParameteri);
+               } // End of GLES 3.0
 
        }
        else
@@ -1242,31 +1252,37 @@ fastpath_dump_context_states(GLGlueContext *ctx, int force_output)
 
 #define PRINTF_CHAR(type) PRINTF_CHAR_##type
 
+#define _COREGL_START_API(version) api_gl_version = version;
+#define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
 #define INITIAL_CTX initial_ctx
 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)  \
    { \
       TYPE valuedata[SIZE]; \
       TYPE *value = NULL; \
-      value = valuedata; GET_STMT; value = valuedata; \
-      TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
-      for (int i = 0; i < SIZE; i++) \
-      { \
-         if (i > 0) { \
-            if (i % 4 == 0) \
-               TRACE("\n %-30.30s     ", "");\
-            else \
-               TRACE(", "); \
+      if(api_gl_version <= driver_gl_version) { \
+         value = valuedata; GET_STMT; value = valuedata; \
+         TRACE("\E[40;37;1m %-30.30s : (\E[0m ", #NAME); \
+         for (int i = 0; i < SIZE; i++) \
+         { \
+            if (i > 0) { \
+               if (i % 4 == 0) \
+                  TRACE("\n %-30.30s     ", "");\
+               else \
+                  TRACE(", "); \
+            } \
+            if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
+               TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
+               TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
+            if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
          } \
-         if (ctx->NAME[i] != value[i]) { TRACE("\E[40;31;1m"); } \
-         TRACE(PRINTF_CHAR(TYPE), ctx->NAME[i]); \
-         TRACE("["PRINTF_CHAR(TYPE)"]", value[i]); \
-         if (ctx->NAME[i] != value[i]) { TRACE("\E[0m"); } \
+         TRACE(" \E[40;37;1m)\E[0m\n"); \
       } \
-      TRACE(" \E[40;37;1m)\E[0m\n"); \
    }
 # include "coregl_fastpath_state.h"
 #undef GLUE_STATE
 #undef INITIAL_CTX
+#undef _COREGL_START_API
+#undef _COREGL_END_API
 
        TRACE("\E[0;40;34m========================================================================================================================\E[0m\n");
        TRACE("\n");
@@ -1300,6 +1316,8 @@ fastpath_init_context_states(GLGlueContext *ctx)
                AST(initial_ctx != NULL);
 
 //#define FORCE_DEFAULT_VALUE
+#define _COREGL_START_API(version) api_gl_version = version;
+#define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
 #ifdef FORCE_DEFAULT_VALUE
 # define INITIAL_CTX initial_ctx
 # define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)  \
@@ -1308,21 +1326,23 @@ fastpath_init_context_states(GLGlueContext *ctx)
          TYPE valuedata[SIZE]; \
          TYPE *value = NULL; \
          memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
-         value = valuedata; DEFAULT_STMT; value = valuedata; \
-         for (i = 0; i < SIZE; i++) \
-         { \
-            if (*((char *)(&value[i])) == 0xcc) \
+         if(api_gl_version <= driver_gl_version) { \
+            value = valuedata; DEFAULT_STMT; value = valuedata; \
+            for (i = 0; i < SIZE; i++) \
             { \
-               memset(&value[i], 0xaa, sizeof(TYPE)); \
-               value = valuedata; DEFAULT_STMT; value = valuedata; \
-               if (*((char *)(&value[i])) == 0xaa) \
+               if (*((char *)(&value[i])) == 0xcc) \
                { \
-                  COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
-                  break; \
+                  memset(&value[i], 0xaa, sizeof(TYPE)); \
+                  value = valuedata; DEFAULT_STMT; value = valuedata; \
+                  if (*((char *)(&value[i])) == 0xaa) \
+                  { \
+                     COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
+                     break; \
+                  } \
                } \
+               initial_ctx->NAME[i] = value[i]; \
             } \
-            initial_ctx->NAME[i] = value[i]; \
-         } \
+        }\
       }
 #  include "coregl_fastpath_state.h"
 # undef GLUE_STATE
@@ -1347,53 +1367,57 @@ fastpath_init_context_states(GLGlueContext *ctx)
          TYPE *value = NULL; \
          _sym_glGetError(); \
          memset(valuedata, 0xcc, sizeof(TYPE) * SIZE); \
-         do { \
-            try_step++; \
-            SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
-            if (_sym_glGetError() == GL_INVALID_ENUM) \
-            { \
-                                       initial_ctx->NAME##_used = 0; \
-                                       value = valuedata; DEFAULT_STMT; value = valuedata; \
-                   break; \
-            } \
-                               initial_ctx->NAME##_used = 1; \
-            for (i = 0; i < SIZE; i++) \
-            { \
-               if (*((char *)(&value[i])) == 0xcc) \
+         if(api_gl_version <= driver_gl_version) { \
+            do { \
+               try_step++; \
+               SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
+               if (_sym_glGetError() == GL_INVALID_ENUM) \
                { \
-                  memset(&value[i], 0xaa, sizeof(TYPE)); \
-                  SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
-                  if (*((char *)(&value[i])) == 0xaa) \
+                  initial_ctx->NAME##_used = 0; \
+                  value = valuedata; DEFAULT_STMT; value = valuedata; \
+                  break; \
+               } \
+               initial_ctx->NAME##_used = 1; \
+               for (i = 0; i < SIZE; i++) \
+               { \
+                  if (*((char *)(&value[i])) == 0xcc) \
                   { \
-                     try_step++; \
-                     if (try_step == 2) \
+                     memset(&value[i], 0xaa, sizeof(TYPE)); \
+                     SET_GLUE_VALUE(GET_STMT, DEFAULT_STMT); \
+                     if (*((char *)(&value[i])) == 0xaa) \
                      { \
-                        COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
+                        try_step++; \
+                        if (try_step == 2) \
+                        { \
+                           COREGL_WRN("\E[40;31;1mGL-state '"#NAME"' cannot be retrieved\E[0m\n"); \
+                        } \
+                        break; \
                      } \
-                     break; \
                   } \
+                  initial_ctx->NAME[i] = value[i]; \
                } \
-               initial_ctx->NAME[i] = value[i]; \
-            } \
-            if (try_step != 2) \
-            { \
-               value = valuedata; DEFAULT_STMT; value = valuedata; \
-               for (i = 0; i < SIZE; i++) \
+               if (try_step != 2) \
                { \
-                  if (initial_ctx->NAME[i] != value[i]) \
+                  value = valuedata; DEFAULT_STMT; value = valuedata; \
+                  for (i = 0; i < SIZE; i++) \
                   { \
-                     COREGL_WRN("GL-state '"#NAME"'[%d] value ["PRINTF_CHAR(TYPE)"] is different from SPEC-DEFAULT ["PRINTF_CHAR(TYPE)"]\n", i, initial_ctx->NAME[i], value[i]); \
+                     if (initial_ctx->NAME[i] != value[i]) \
+                     { \
+                        COREGL_WRN("GL-state '"#NAME"'[%d] value ["PRINTF_CHAR(TYPE)"] is different from SPEC-DEFAULT ["PRINTF_CHAR(TYPE)"]\n", i, initial_ctx->NAME[i], value[i]); \
+                     } \
                   } \
                } \
             } \
-         } \
-         while (try_step == 2); \
+            while (try_step == 2); \
+         }\
       }
 #  include "coregl_fastpath_state.h"
 # undef SET_GLUE_VALUE
 # undef GLUE_STATE
 # undef INITIAL_CTX
 #endif
+# undef _COREGL_END_API
+# undef _COREGL_START_API
 
                if (initial_ctx->gl_num_vertex_attribs[0] > MAX_VERTEX_ATTRIBS)
                {
@@ -1415,16 +1439,22 @@ fastpath_init_context_states(GLGlueContext *ctx)
 
        {
                int i;
+#define _COREGL_START_API(version) api_gl_version = version;
+#define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
 #define INITIAL_CTX initial_ctx
 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT)  \
+      if(api_gl_version <= driver_gl_version) { \
          for (i = 0; i < SIZE; i++) \
          { \
             ctx->NAME[i] = initial_ctx->NAME[i]; \
             ctx->NAME##_used = initial_ctx->NAME##_used; \
-         }
+         }\
+      }
 # include "coregl_fastpath_state.h"
 #undef GLUE_STATE
 #undef INITIAL_CTX
+#undef _COREGL_START_API
+#undef _COREGL_END_API
        }
 
        ctx->initialized = 1;
index 6f2080b..c56a410 100644 (file)
@@ -2,6 +2,15 @@
 #error GLUE_STATE_NOT_DEFINED
 #endif
 
+#ifndef _COREGL_START_API
+#define _COREGL_START_API(version)
+#endif
+
+#ifndef _COREGL_END_API
+#define _COREGL_END_API(version)
+#endif
+
+
 #define SET_1(v1)               value[0] = v1;
 #define SET_2(v1, v2)           value[0] = v1; value[1] = v2;
 #define SET_3(v1, v2, v3)       value[0] = v1; value[1] = v2; value[2] = v3;
@@ -45,6 +54,7 @@ GLUE_STATE(GLuint, gl_pixel_unpack_buffer_binding, 1, 1, SET_1(0), _sym_glGetInt
 GLUE_STATE(GLuint, gl_transform_feedback_buffer_binding, 1, 1, SET_1(0), _sym_glGetIntegerv(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, (GLint *)value);)
 GLUE_STATE(GLuint, gl_uniform_buffer_binding, 1, 1, SET_1(0), _sym_glGetIntegerv(GL_UNIFORM_BUFFER_BINDING, (GLint *)value);)
 
+_COREGL_START_API(COREGL_GLAPI_3)
 GLUE_STATE(GLuint, gl_transform_feedback_buffer_binding_array, INITIAL_CTX->gl_num_transform_feedback_separate_attribs[0], MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
        _state_get_transform_feedback_buffer_bindings(value); /* DEFAULT NOT EFFECT */,
        _state_get_transform_feedback_buffer_bindings(value);)
@@ -68,6 +78,7 @@ GLUE_STATE(GLintptr, gl_uniform_buffer_binding_array_offset, INITIAL_CTX->gl_num
 GLUE_STATE(GLsizeiptr, gl_uniform_buffer_binding_array_size, INITIAL_CTX->gl_num_uniform_buffer_bindings[0], MAX_UNIFORM_BUFFER_BINDINGS,
        _state_get_uniform_buffer_bindings_size(value); /* DEFAULT NOT EFFECT */,
        _state_get_uniform_buffer_bindings_size(value);)
+_COREGL_END_API(COREGL_GLAPI_3)
 
 GLUE_STATE(GLuint, gl_framebuffer_binding, 1, 1, SET_1(0), _sym_glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *)value);)
 GLUE_STATE(GLuint, gl_framebuffer_binding_read, 1, 1, SET_1(0), _sym_glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING_ANGLE, (GLint *)value);)
@@ -214,6 +225,8 @@ GLUE_STATE(GLvoidptr, gl_vertex_array_pointer, INITIAL_CTX->gl_num_vertex_attrib
 GLUE_STATE(GLfloat, gl_vertex_attrib_value, 4 * INITIAL_CTX->gl_num_vertex_attribs[0], MAX_VERTEX_ATTRIBS,
            SET_N(INITIAL_CTX->gl_num_vertex_attribs[0], 4, SET_4(0, 0, 0, 1)),
            SET_N(INITIAL_CTX->gl_num_vertex_attribs[0], 4, _sym_glGetVertexAttribfv(i, GL_CURRENT_VERTEX_ATTRIB, (GLfloat *)value);))
+
+_COREGL_START_API(COREGL_GLAPI_3)
 GLUE_STATE(GLint, gl_vertex_attrib_value_integer, 4 * INITIAL_CTX->gl_num_vertex_attribs[0], MAX_VERTEX_ATTRIBS,
            SET_N(INITIAL_CTX->gl_num_vertex_attribs[0], 4, SET_4(0, 0, 0, GET_INT_FROM_FLOAT(1.0f))),
            SET_N(INITIAL_CTX->gl_num_vertex_attribs[0], 4, _sym_glGetVertexAttribIiv(i, GL_CURRENT_VERTEX_ATTRIB, (GLint *)value);))
@@ -230,4 +243,5 @@ GLUE_STATE(GLuint, gl_vertex_array_binding, 1, 1, SET_1(0), _sym_glGetIntegerv(G
 GLUE_STATE(GLuint, gl_transform_feedback_binding, 1, 1, SET_1(0), _sym_glGetIntegerv(GL_TRANSFORM_FEEDBACK_BINDING, (GLint *)value);)
 GLUE_STATE(GLboolean, gl_transform_feedback_active, 1, 1, SET_1(0), _sym_glGetBooleanv(GL_TRANSFORM_FEEDBACK_ACTIVE, (GLboolean *)value);)
 GLUE_STATE(GLboolean, gl_transform_feedback_paused, 1, 1, SET_1(0), _sym_glGetBooleanv(GL_TRANSFORM_FEEDBACK_PAUSED, (GLboolean *)value);)
+_COREGL_END_API(COREGL_GLAPI_3)
 
index 6bf541d..3a84310 100755 (executable)
@@ -8,6 +8,8 @@
 #include <unistd.h>
 
 #include <dlfcn.h>
+static int         api_gl_version;
+
 
 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     RET_TYPE (*_orig_tracepath_##FUNC_NAME) PARAM_LIST = NULL;
 #include "../../headers/sym.h"
@@ -389,13 +391,19 @@ tracepath_apply_overrides_egl(int enable)
 void
 tracepath_apply_overrides_gl(int enable)
 {
-#define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     COREGL_INIT_ORIGINAL(_orig_tracepath_, FUNC_NAME);
+#define _COREGL_START_API(version) api_gl_version = version;
+#define _COREGL_END_API(version) api_gl_version = COREGL_GLAPI_2;
+#define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     \
+       if(api_gl_version <= driver_gl_version) COREGL_INIT_ORIGINAL(_orig_tracepath_, FUNC_NAME);
 # include "../../headers/sym_gl.h"
 #undef _COREGL_SYMBOL
 
-#define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     COREGL_OVERRIDE(tracepath_, FUNC_NAME);
+#define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
+       if(api_gl_version <= driver_gl_version) COREGL_OVERRIDE(tracepath_, FUNC_NAME);
 # include "../../headers/sym_gl.h"
 #undef _COREGL_SYMBOL
+#undef _COREGL_START_API
+#undef _COREGL_END_API
 }
 
 #undef OVERRIDE