]> git.cworth.org Git - apitrace/commitdiff
Dump stencil buffer too.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 12 Apr 2011 07:28:45 +0000 (08:28 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 12 Apr 2011 08:24:38 +0000 (09:24 +0100)
dispatch.py
glsize.hpp
glstate.py
gui/apisurface.cpp
gui/apisurface.h
gui/apitracecall.cpp

index bfd332bd5dfd029d54f98dcc43ff6b6ba94e338b..292b69f189cd317c5b4a840909af97418cb0f02e 100644 (file)
@@ -62,7 +62,9 @@ class Dispatcher:
         # functions
         print '#ifdef RETRACE'
         for function in api.functions:
-            if not self.is_public_function(function):
+            if self.is_public_function(function):
+                print '#define __%s %s' % (function.name, function.name)
+            else:
                 print '#define %s __%s' % (function.name, function.name)
         print '#endif /* RETRACE */'
         print
index 90e1c39fe439585aaab40f75bea9fefc2a41d337..64b96af25ee61c24728fe6bbec129b0ac513896f 100644 (file)
@@ -1401,8 +1401,7 @@ __glGetFramebufferAttachmentParameterivEXT_size(GLenum pname)
 #define __glGetFramebufferAttachmentParameteriv_size __glGetFramebufferAttachmentParameterivEXT_size
 
 static inline size_t
-__glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLint border) {
-    size_t num_channels;
+__gl_format_channels(GLenum format) {
     switch (format) {
     case GL_COLOR_INDEX:
     case GL_RED:
@@ -1413,24 +1412,29 @@ __glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, G
     case GL_LUMINANCE:
     case GL_DEPTH_COMPONENT:
     case GL_STENCIL_INDEX:
-        num_channels = 1;
+        return 1;
         break;
     case GL_LUMINANCE_ALPHA:
-        num_channels = 2;
+        return 2;
         break;
     case GL_RGB:
     case GL_BGR:
-        num_channels = 3;
+        return 3;
         break;
     case GL_RGBA:
     case GL_BGRA:
-        num_channels = 4;
+        return 4;
         break;
     default:
         OS::DebugMessage("warning: %s: unexpected format GLenum 0x%04X\n", __FUNCTION__, format);
-        num_channels = 0;
+        return 0;
         break;
     }
+}
+
+static inline size_t
+__glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLint border) {
+    size_t num_channels = __gl_format_channels(format);
 
     size_t bits_per_pixel;
     switch (type) {
index cf136656c0f17a424b7643a7ac68fd0a61b1340f..8179a2587c3cd7a82c4811398d73d4b6bc743758 100644 (file)
@@ -2958,6 +2958,7 @@ class StateDumper:
         print '#include "json.hpp"'
         print '#include "glimports.hpp"'
         print '#include "glproc.hpp"'
+        print '#include "glsize.hpp"'
         print '#include "glretrace.hpp"'
         print
 
@@ -3084,11 +3085,13 @@ writeTextureImage(JSONWriter &json, GLenum target, GLint level)
 }
 
 static inline void
-writeDrawBufferImage(JSONWriter &json)
+writeDrawBufferImage(JSONWriter &json, GLenum format)
 {
     GLint width  = glretrace::window_width;
     GLint height = glretrace::window_height;
 
+    GLint channels = __gl_format_channels(format);
+
     if (!width || !height) {
         json.writeNull();
     } else {
@@ -3105,21 +3108,21 @@ writeDrawBufferImage(JSONWriter &json)
         // texture internal format
         json.writeStringMember("__type__", "uint8");
         json.writeBoolMember("__normalized__", true);
-        json.writeNumberMember("__channels__", 4);
-        
-        GLubyte *pixels = new GLubyte[width*height*4];
+        json.writeNumberMember("__channels__", channels);
+
+        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;
         glGetIntegerv(GL_DRAW_BUFFER, &drawbuffer);
         glGetIntegerv(GL_READ_BUFFER, &readbuffer);
         glReadBuffer(drawbuffer);
-        glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+        glReadPixels(0, 0, width, height, format, GL_UNSIGNED_BYTE, pixels);
         glReadBuffer(readbuffer);
 
         json.writeStringMember("__encoding__", "base64");
         json.beginMember("__data__");
-        json.writeBase64(pixels, width * height * 4 * sizeof *pixels);
+        json.writeBase64(pixels, width * height * channels * sizeof *pixels);
         json.endMember(); // __data__
 
         delete [] pixels;
@@ -3295,10 +3298,28 @@ writeDrawBufferImage(JSONWriter &json)
     def dump_framebuffer(self):
         print '    json.beginMember("framebuffer");'
         print '    json.beginObject();'
-        print '    json.beginMember("GL_DRAW_BUFFER");'
-        # TODO: Handle FBOs
-        print '    writeDrawBufferImage(json);'
+        # TODO: Handle real FBOs
+        print
+        print '    json.beginMember("GL_RGBA");'
+        print '    writeDrawBufferImage(json, GL_RGBA);'
         print '    json.endMember();'
+        print
+        print '    GLint depth_bits = 0;'
+        print '    glGetIntegerv(GL_DEPTH_BITS, &depth_bits);'
+        print '    if (depth_bits) {'
+        print '        json.beginMember("GL_DEPTH_COMPONENT");'
+        print '        writeDrawBufferImage(json, GL_DEPTH_COMPONENT);'
+        print '        json.endMember();'
+        print '    }'
+        print
+        print '    GLint stencil_bits = 0;'
+        print '    glGetIntegerv(GL_STENCIL_BITS, &stencil_bits);'
+        print '    if (stencil_bits) {'
+        print '        json.beginMember("GL_STENCIL_INDEX");'
+        print '        writeDrawBufferImage(json, GL_STENCIL_INDEX);'
+        print '        json.endMember();'
+        print '    }'
+        print
         print '    json.endObject();'
         print '    json.endMember(); // framebuffer'
         pass
index 8c985ae282a0b2321484705c8c054bdfa40ef5f6..c875c6ff432662fcbedc267ae41f8451034abfda 100644 (file)
@@ -17,6 +17,16 @@ void ApiSurface::setSize(const QSize &size)
     m_size = size;
 }
 
+int ApiSurface::numChannels() const
+{
+    return m_numChannels;
+}
+
+void ApiSurface::setNumChannels(int numChannels)
+{
+    m_numChannels = numChannels;
+}
+
 static inline int
 rgba8_to_argb(quint8 r, quint8 g, quint8 b, quint8 a)
 {
@@ -49,14 +59,28 @@ void ApiSurface::contentsFromBase64(const QByteArray &base64)
     //XXX not sure if this will work when
     //    QSysInfo::ByteOrder == QSysInfo::BigEndian
 
-    for (int y = 0; y < height; ++y) {
-        for (int x = 0; x < width; ++x) {
-            int pixel = rgba8_to_argb(data[(y * width + x) * 4 + 0],
-                                      data[(y * width + x) * 4 + 1],
-                                      data[(y * width + x) * 4 + 2],
-                                      data[(y * width + x) * 4 + 3]);
-            pixelData[y * width + x] = pixel;
+    if (m_numChannels == 4) {
+        for (int y = 0; y < height; ++y) {
+            for (int x = 0; x < width; ++x) {
+                int pixel = rgba8_to_argb(data[(y * width + x) * 4 + 0],
+                                          data[(y * width + x) * 4 + 1],
+                                          data[(y * width + x) * 4 + 2],
+                                          data[(y * width + x) * 4 + 3]);
+                pixelData[y * width + x] = pixel;
+            }
+        }
+    } else if (m_numChannels == 1) {
+        for (int y = 0; y < height; ++y) {
+            for (int x = 0; x < width; ++x) {
+                int pixel = rgba8_to_argb(data[y * width + x],
+                                          data[y * width + x],
+                                          data[y * width + x],
+                                          255);
+                pixelData[y * width + x] = pixel;
+            }
         }
+    } else {
+        Q_ASSERT(0);
     }
 
     m_image = QImage((uchar*)pixelData,
index 9cf2a96c34aa813697c9477beda893992586d6e4..3dd0ea58fb54b2434cc94cb549fe22fe5ea1395f 100644 (file)
@@ -13,6 +13,9 @@ public:
     QSize size() const;
     void setSize(const QSize &size);
 
+    int numChannels() const;
+    void setNumChannels(int numChannels);
+
     void contentsFromBase64(const QByteArray &base64);
 
     QImage image() const;
@@ -20,6 +23,7 @@ public:
 
 private:
     QSize  m_size;
+    int m_numChannels;
     QImage m_image;
     QImage m_thumb;
 };
index 4664102e48eb1d22de154ff7de437f8185a49d2c..76d50caf93f3e97064d7c381926b34fdc19becef 100644 (file)
@@ -462,7 +462,6 @@ ApiTraceState::ApiTraceState(const QVariantMap &parsedJson)
                     int numChannels =
                         image[QLatin1String("__channels__")].toInt();
 
-                    Q_ASSERT(numChannels == 4);
                     Q_ASSERT(type == QLatin1String("uint8"));
                     Q_ASSERT(normalized == true);
 
@@ -471,6 +470,7 @@ ApiTraceState::ApiTraceState(const QVariantMap &parsedJson)
 
                     ApiTexture tex;
                     tex.setSize(size);
+                    tex.setNumChannels(numChannels);
                     tex.setLevel(j);
                     tex.setUnit(i);
                     tex.setTarget(itr.key());
@@ -494,7 +494,6 @@ ApiTraceState::ApiTraceState(const QVariantMap &parsedJson)
         bool normalized = buffer[QLatin1String("__normalized__")].toBool();
         int numChannels = buffer[QLatin1String("__channels__")].toInt();
 
-        Q_ASSERT(numChannels == 4);
         Q_ASSERT(type == QLatin1String("uint8"));
         Q_ASSERT(normalized == true);
 
@@ -503,6 +502,7 @@ ApiTraceState::ApiTraceState(const QVariantMap &parsedJson)
 
         ApiFramebuffer fbo;
         fbo.setSize(size);
+        fbo.setNumChannels(numChannels);
         fbo.setType(itr.key());
         fbo.contentsFromBase64(dataArray);
         m_framebuffers.append(fbo);