From 05c3d03723baba7e84457fffabebc05a58933d15 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 18 May 2011 09:33:37 +0100 Subject: [PATCH] Start making glstate an independent module. --- .gitignore | 2 +- CMakeLists.txt | 6 ++-- glretrace.hpp | 4 --- glretrace_main.cpp | 3 +- glstate.hpp | 42 ++++++++++++++++++++++++++ glstate.py | 73 ++++++++++++++++++++++++++++++++++++++++------ 6 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 glstate.hpp diff --git a/.gitignore b/.gitignore index da02775..5680977 100644 --- a/.gitignore +++ b/.gitignore @@ -35,7 +35,7 @@ dxsdk glproc.hpp glretrace glretrace_gl.cpp -glretrace_state.cpp +glstate.cpp glxtrace.cpp install_manifest.txt qapitrace diff --git a/CMakeLists.txt b/CMakeLists.txt index d41e89d..41bbd6d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,8 +306,8 @@ add_custom_command ( ) add_custom_command ( - OUTPUT glretrace_state.cpp - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_state.cpp + OUTPUT glstate.cpp + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate.cpp DEPENDS glstate.py glparams.py gltypes.py stdapi.py ) @@ -322,7 +322,7 @@ add_executable (glretrace glretrace_glx.cpp glretrace_wgl.cpp glretrace_main.cpp - glretrace_state.cpp + glstate.cpp retrace.cpp ${glws} image.cpp diff --git a/glretrace.hpp b/glretrace.hpp index dcac8f0..74eb674 100644 --- a/glretrace.hpp +++ b/glretrace.hpp @@ -26,8 +26,6 @@ #ifndef _GLRETRACE_HPP_ #define _GLRETRACE_HPP_ -#include - #include "trace_parser.hpp" #include "glws.hpp" @@ -63,8 +61,6 @@ void retrace_call_wgl(Trace::Call &call); void snapshot(unsigned call_no); void frame_complete(unsigned call_no); -void state_dump(std::ostream &os); - } /* namespace glretrace */ diff --git a/glretrace_main.cpp b/glretrace_main.cpp index b9a11b1..bfab151 100644 --- a/glretrace_main.cpp +++ b/glretrace_main.cpp @@ -29,6 +29,7 @@ #include "image.hpp" #include "retrace.hpp" #include "glproc.hpp" +#include "glstate.hpp" #include "glretrace.hpp" @@ -202,7 +203,7 @@ static void display(void) { if (!insideGlBeginEnd && drawable && context && call->no >= dump_state) { - state_dump(std::cout); + glstate::state_dump(std::cout); exit(0); } diff --git a/glstate.hpp b/glstate.hpp new file mode 100644 index 0000000..1342629 --- /dev/null +++ b/glstate.hpp @@ -0,0 +1,42 @@ +/************************************************************************** + * + * 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 _GLSTATE_HPP_ +#define _GLSTATE_HPP_ + + +#include + + +namespace glstate { + + +void state_dump(std::ostream &os); + + +} /* namespace glretrace */ + + +#endif /* _GLSTATE_HPP_ */ diff --git a/glstate.py b/glstate.py index 68437c1..859b3df 100644 --- a/glstate.py +++ b/glstate.py @@ -240,7 +240,7 @@ class StateDumper: print '#include "glimports.hpp"' print '#include "glproc.hpp"' print '#include "glsize.hpp"' - print '#include "glretrace.hpp"' + print '#include "glstate.hpp"' print print 'static const char *' @@ -481,17 +481,72 @@ writeTextureImage(JSONWriter &json, GLenum target, GLint level) } } + +static bool +getDrawableBounds(GLint *width, GLint *height) { +#if defined(_WIN32) + + HDC hDC = wglGetCurrentDC(); + if (!hDC) { + return false; + } + + HWND hWnd = WindowFromDC(hDC); + RECT rect; + + if (!GetClientRect(hWnd, &rect)) { + return false; + } + + *width = rect.right - rect.left; + *height = rect.bottom - rect.top; + +#elif 0 /* __APPLE__ */ + + CGLError CGLGetSurface(CGLContextObj, CGSConnectionID*, CGSWindowID*, CGSSurfaceID*); + CGError CGSGetWindowBounds(CGSConnectionID, CGWindowID, CGRect *ret); + +#else + + Display *display; + Drawable drawable; + Window root; + int x, y; + unsigned int w, h, bw, depth; + + display = glXGetCurrentDisplay(); + if (!display) { + return false; + } + + drawable = glXGetCurrentDrawable(); + if (drawable == None) { + return false; + } + + if (!XGetGeometry(display, drawable, &root, &x, &y, &w, &h, &bw, &depth)) { + return false; + } + + *width = w; + *height = h; + +#endif + + return true; +} + + static inline void writeDrawBufferImage(JSONWriter &json, GLenum format) { GLint channels = __gl_format_channels(format); - if (!glretrace::drawable) { + GLint width, height; + + if (!getDrawableBounds(&width, &height)) { json.writeNull(); } else { - GLint width = glretrace::drawable->width; - GLint height = glretrace::drawable->height; - json.beginObject(); // Tell the GUI this is no ordinary object, but an image @@ -509,8 +564,8 @@ writeDrawBufferImage(JSONWriter &json, GLenum format) GLubyte *pixels = new GLubyte[width*height*channels]; - GLint drawbuffer = glretrace::double_buffer ? GL_BACK : GL_FRONT; - GLint readbuffer = glretrace::double_buffer ? GL_BACK : GL_FRONT; + GLint drawbuffer = GL_NONE; + GLint readbuffer = GL_NONE; glGetIntegerv(GL_DRAW_BUFFER, &drawbuffer); glGetIntegerv(GL_READ_BUFFER, &readbuffer); glReadBuffer(drawbuffer); @@ -702,7 +757,7 @@ writeDrawBuffers(JSONWriter &json, GLboolean writeDepth, GLboolean writeStencil) print '}' print - print 'void glretrace::state_dump(std::ostream &os)' + print 'void glstate::state_dump(std::ostream &os)' print '{' print ' JSONWriter json(os);' self.dump_parameters() @@ -883,7 +938,7 @@ writeDrawBuffers(JSONWriter &json, GLboolean writeDepth, GLboolean writeStencil) print ' GLint colorRb, stencilRb, depthRb;' print ' GLint boundRb;' print ' glGetIntegerv(GL_RENDERBUFFER_BINDING, &boundRb);' - print ' GLint drawbuffer = glretrace::double_buffer ? GL_BACK : GL_FRONT;' + print ' GLint drawbuffer = GL_NONE;' print ' glGetIntegerv(GL_DRAW_BUFFER, &drawbuffer);' print print ' glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,' -- 2.43.0