From b794df1710c5c4aa9fe859ba84ec3573b3b1600d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 12 Apr 2011 08:28:45 +0100 Subject: [PATCH] Dump stencil buffer too. --- dispatch.py | 4 +++- glsize.hpp | 18 +++++++++++------- glstate.py | 39 ++++++++++++++++++++++++++++++--------- gui/apisurface.cpp | 38 +++++++++++++++++++++++++++++++------- gui/apisurface.h | 4 ++++ gui/apitracecall.cpp | 4 ++-- 6 files changed, 81 insertions(+), 26 deletions(-) diff --git a/dispatch.py b/dispatch.py index bfd332b..292b69f 100644 --- a/dispatch.py +++ b/dispatch.py @@ -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 diff --git a/glsize.hpp b/glsize.hpp index 90e1c39..64b96af 100644 --- a/glsize.hpp +++ b/glsize.hpp @@ -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) { diff --git a/glstate.py b/glstate.py index cf13665..8179a25 100644 --- a/glstate.py +++ b/glstate.py @@ -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 diff --git a/gui/apisurface.cpp b/gui/apisurface.cpp index 8c985ae..c875c6f 100644 --- a/gui/apisurface.cpp +++ b/gui/apisurface.cpp @@ -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, diff --git a/gui/apisurface.h b/gui/apisurface.h index 9cf2a96..3dd0ea5 100644 --- a/gui/apisurface.h +++ b/gui/apisurface.h @@ -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; }; diff --git a/gui/apitracecall.cpp b/gui/apitracecall.cpp index 4664102..76d50ca 100644 --- a/gui/apitracecall.cpp +++ b/gui/apitracecall.cpp @@ -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); -- 2.43.0