]> git.cworth.org Git - apitrace/commitdiff
Implement GL_GREMEDY_string_marker and GL_GREMEDY_frame_terminator.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 15 Jul 2011 09:15:19 +0000 (10:15 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 15 Jul 2011 09:15:19 +0000 (10:15 +0100)
CMakeLists.txt
glcaps.cpp [new file with mode: 0644]
gltrace.hpp [new file with mode: 0644]
gltrace.py

index 6f22249cf38e1f702694a7053b002662350226ff..8098441401bd10ea60249b923455a224d1c8e8a8 100755 (executable)
@@ -246,7 +246,13 @@ if (WIN32)
         COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/wgltrace.cpp
         DEPENDS wgltrace.py gltrace.py trace.py wglapi.py wglenum.py glapi.py glparams.py gltypes.py winapi.py stdapi.py
     )
-    add_library (wgltrace MODULE opengl32.def wgltrace.cpp trace_writer.cpp os_win32.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
+    add_library (wgltrace MODULE opengl32.def
+        wgltrace.cpp
+        glcaps.cpp
+        trace_writer.cpp
+        os_win32.cpp
+        ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
+    )
     set_target_properties (wgltrace PROPERTIES
         PREFIX ""
         OUTPUT_NAME opengl32
@@ -266,7 +272,13 @@ elseif (APPLE)
         DEPENDS cgltrace.py gltrace.py trace.py cglapi.py glapi.py glparams.py gltypes.py stdapi.py
     )
 
-    add_library (cgltrace SHARED cgltrace.cpp trace_writer.cpp os_posix.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
+    add_library (cgltrace SHARED
+        cgltrace.cpp
+        glcaps.cpp
+        trace_writer.cpp
+        os_posix.cpp
+        ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
+    )
 
     set_target_properties (cgltrace PROPERTIES
         # OpenGL framework name
@@ -291,6 +303,7 @@ else ()
     add_library (glxtrace SHARED
         ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
         glxtrace.cpp
+        glcaps.cpp
         glsnapshot.cpp
         trace_writer.cpp
         image.cpp
diff --git a/glcaps.cpp b/glcaps.cpp
new file mode 100644 (file)
index 0000000..51a5954
--- /dev/null
@@ -0,0 +1,88 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <string>
+#include <map>
+
+#include "gltrace.hpp"
+
+
+namespace gltrace {
+
+
+typedef std::map<std::string, const char *> ExtensionsMap;
+
+// Cache of the translated extensions strings
+static ExtensionsMap extensionsMap;
+
+
+// Additional extensions to be advertised
+const char extra_extensions[] =
+    "GL_GREMEDY_string_marker "
+    "GL_GREMEDY_frame_terminator "
+;
+
+
+/**
+ * Translate the GL extensions string, adding new extensions.
+ */
+const char *
+translateExtensionsString(const char *extensions)
+{
+    ExtensionsMap::const_iterator it = extensionsMap.find(extensions);
+    if (it != extensionsMap.end()) {
+        return it->second;
+    }
+
+    size_t extensions_len = strlen(extensions);
+
+    char *new_extensions = (char *)malloc(extensions_len + 1 + sizeof extra_extensions);
+    if (!new_extensions) {
+        return extensions;
+    }
+
+    if (extensions_len) {
+        memcpy(new_extensions, extensions, extensions_len);
+
+        // Add space separator if necessary
+        if (new_extensions[extensions_len - 1] != ' ') {
+            new_extensions[extensions_len++] = ' ';
+        }
+    }
+
+    memcpy(new_extensions + extensions_len, extra_extensions, sizeof extra_extensions);
+
+    extensionsMap[extensions] = new_extensions;
+
+    return new_extensions;
+}
+
+
+} /* namespace gltrace */
+
diff --git a/gltrace.hpp b/gltrace.hpp
new file mode 100644 (file)
index 0000000..5675c06
--- /dev/null
@@ -0,0 +1,49 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef _GLTRACE_HPP_
+#define _GLTRACE_HPP_
+
+
+#include "glimports.hpp"
+
+
+namespace gltrace {
+
+
+const char *
+translateExtensionsString(const char *extensions);
+
+
+inline const GLubyte *
+translateExtensionsString(const GLubyte *extensions) {
+    return (const GLubyte *)translateExtensionsString((const char *)extensions);
+}
+
+
+} /* namespace gltrace */
+
+
+#endif /* _GLRETRACE_HPP_ */
index 8c29a7bb0d833ec2591d1b0ae7e3ee86b183730b..32e77a75034b84f05a3e0317752a17c2a90944eb 100644 (file)
@@ -107,6 +107,8 @@ class GlTracer(Tracer):
     def header(self, api):
         Tracer.header(self, api)
 
+        print '#include "gltrace.hpp"'
+        print
         print '// Whether user arrays were used'
         print 'static bool __user_arrays = false;'
         print 'static bool __user_arrays_arb = false;'
@@ -497,6 +499,10 @@ class GlTracer(Tracer):
             # These functions have been dispatched already
             return
 
+        # We implement the GREMEDY extensions, not the driver
+        if function.name in ('glStringMarkerGREMEDY', 'glFrameTerminatorGREMEDY'):
+            return
+
         Tracer.dispatch_function(self, function)
 
     def emit_memcpy(self, dest, src, length):
@@ -523,6 +529,17 @@ class GlTracer(Tracer):
 
     def wrap_ret(self, function, instance):
         Tracer.wrap_ret(self, function, instance)
+
+        if function.name == 'glGetString':
+            print '    if (__result) {'
+            print '        switch (name) {'
+            print '        case GL_EXTENSIONS:'
+            print '            __result = gltrace::translateExtensionsString(__result);'
+            print '            break;'
+            print '        default:'
+            print '            break;'
+            print '        }'
+            print '    }'
             
         if function.name in ('glMapBuffer', 'glMapBufferARB'):
             print '    struct buffer_mapping *mapping = get_buffer_mapping(target);'