]> git.cworth.org Git - apitrace/commitdiff
Start making glstate an independent module.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 18 May 2011 08:33:37 +0000 (09:33 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 18 May 2011 08:33:37 +0000 (09:33 +0100)
.gitignore
CMakeLists.txt
glretrace.hpp
glretrace_main.cpp
glstate.hpp [new file with mode: 0644]
glstate.py

index da02775279615a4e1c5d0a6e8ceb4fecebe7c598..56809775248787f381496c9dda9947e767f73c92 100644 (file)
@@ -35,7 +35,7 @@ dxsdk
 glproc.hpp
 glretrace
 glretrace_gl.cpp
-glretrace_state.cpp
+glstate.cpp
 glxtrace.cpp
 install_manifest.txt
 qapitrace
index d41e89de19169e8ddbcd21c9a01671346404e9dc..41bbd6d94c589d686c1631e55acf2ec5f1df0117 100755 (executable)
@@ -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 
index dcac8f0da70beee3a4b567d3b184bf821e7bfa06..74eb6742ede89d50b750d8c2584837f9e8e1260d 100644 (file)
@@ -26,8 +26,6 @@
 #ifndef _GLRETRACE_HPP_
 #define _GLRETRACE_HPP_
 
-#include <ostream>
-
 #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 */
 
index b9a11b1ddea9b1132b05e76a566c7fcf74a711b3..bfab151fde00f9885aab88cf5ea1c03065ef07d3 100644 (file)
@@ -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 (file)
index 0000000..1342629
--- /dev/null
@@ -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 <ostream>
+
+
+namespace glstate {
+
+
+void state_dump(std::ostream &os);
+
+
+} /* namespace glretrace */
+
+
+#endif /* _GLSTATE_HPP_ */
index 68437c18b40bf72c078e381e34742c46e5be9b05..859b3df189180f49c93fe68c8d4d0e9d01efb552 100644 (file)
@@ -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,'