From 1b3d3752685cd15531c45e190c8ed55d31271127 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 15 Jul 2011 10:15:19 +0100 Subject: [PATCH] Implement GL_GREMEDY_string_marker and GL_GREMEDY_frame_terminator. --- CMakeLists.txt | 17 ++++++++-- glcaps.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ gltrace.hpp | 49 ++++++++++++++++++++++++++++ gltrace.py | 17 ++++++++++ 4 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 glcaps.cpp create mode 100644 gltrace.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f22249..8098441 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000..51a5954 --- /dev/null +++ b/glcaps.cpp @@ -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 +#include + +#include +#include + +#include "gltrace.hpp" + + +namespace gltrace { + + +typedef std::map 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 index 0000000..5675c06 --- /dev/null +++ b/gltrace.hpp @@ -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_ */ diff --git a/gltrace.py b/gltrace.py index 8c29a7b..32e77a7 100644 --- a/gltrace.py +++ b/gltrace.py @@ -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);' -- 2.43.0