]> git.tdb.fi Git - gldbg.git/commitdiff
Track uniform buffer bindings
authorMikko Rasa <tdb@tdb.fi>
Sat, 25 Aug 2012 10:54:48 +0000 (13:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 25 Aug 2012 10:54:48 +0000 (13:54 +0300)
flavors/gl/source/bufferstate.cpp
flavors/gl/source/bufferstate.h
flavors/gl/source/glstate.cpp
flavors/gl/source/glstate.h
flavors/gl/source/inspector.cpp

index a8d5c4d86ba206f7bb26b81e8a3ebb4375dd1e3a..e48d221df6458375335dd7a29e9c2f81d1e72550 100644 (file)
@@ -168,3 +168,10 @@ string BufferState::describe() const
        else
                return strformat("%d bytes, %s", size, describe_enum(usage, ""));
 }
+
+
+BufferBindingState::BufferBindingState():
+       buffer(0),
+       offset(0),
+       size(0)
+{ }
index bf0e1ec1050b9eb77bb396323537b8e3ef0eae3d..18013a77dfb29445ee20271ada9543eaa6ca42f0 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <string>
 #include <vector>
+#include "autoconstptr.h"
 #include "opengl.h"
 
 struct ArrayState;
@@ -46,4 +47,13 @@ struct BufferState
        std::string describe() const;
 };
 
+struct BufferBindingState
+{
+       AutoConstPtr<BufferState> buffer;
+       unsigned offset;
+       unsigned size;
+
+       BufferBindingState();
+};
+
 #endif
index 9fc2993aa6b1e2d5ea5ca82e1c5357f9771331a6..0163c2f884605603170f60303ad9d856e611ea28 100644 (file)
@@ -66,7 +66,9 @@ GlState::GlState():
        active_tex(0),
        client_active_tex(0),
        array_buffer(0),
-       element_buffer(0)
+       element_buffer(0),
+       uniform_buffer(0),
+       uniform_bind_points(64)
 {
        vertex_array.kind = GL_VERTEX_ARRAY;
        normal_array.kind = GL_NORMAL_ARRAY;
@@ -122,6 +124,8 @@ GlState::GlState():
 
        decoder->glBindBuffer = glBindBuffer;
        decoder->glBindBufferARB = glBindBuffer;
+       decoder->glBindBufferBase = glBindBufferBase;
+       decoder->glBindBufferRange = glBindBufferRange;
        decoder->glBufferData = glBufferData;
        decoder->glBufferDataARB = glBufferData;
        decoder->glBufferSubData = glBufferSubData;
@@ -160,6 +164,13 @@ const BufferState &GlState::get_buffer(unsigned id) const
        return i->second;
 }
 
+const BufferBindingState &GlState::get_buffer_binding(GLenum target, unsigned index) const
+{
+       if(target==GL_UNIFORM_BUFFER)
+               return uniform_bind_points[index];
+       throw runtime_error("This buffer target does not have indexed binding points");
+}
+
 const ArrayState &GlState::get_array(GLenum array) const
 {
        if(array==GL_VERTEX_ARRAY)
@@ -214,12 +225,27 @@ TextureState *GlState::get_current_texture(GLenum target)
        return texunits[active_tex].get_current_texture(target);
 }
 
+BufferState *GlState::get_buffer_object(unsigned id)
+{
+       BufferMap::iterator i = buffers.find(id);
+       return (i==buffers.end() ? 0 : &i->second);
+}
+
 BufferState *GlState::get_current_buffer(GLenum target)
 {
        if(target==GL_ARRAY_BUFFER)
                return array_buffer;
        else if(target==GL_ELEMENT_ARRAY_BUFFER)
                return element_buffer;
+       else if(target==GL_UNIFORM_BUFFER)
+               return uniform_buffer;
+       return 0;
+}
+
+BufferBindingState *GlState::get_buffer_binding(GLenum target, unsigned index)
+{
+       if(target==GL_UNIFORM_BUFFER)
+               return &uniform_bind_points[index];
        return 0;
 }
 
@@ -255,6 +281,8 @@ void GlState::set_current_buffer(GLenum target, unsigned id)
                array_buffer = buf;
        else if(target==GL_ELEMENT_ARRAY_BUFFER)
                element_buffer = buf;
+       else if(target==GL_UNIFORM_BUFFER)
+               uniform_buffer = buf;
 }
 
 ArrayState &GlState::get_attrib_array(unsigned index)
@@ -412,6 +440,23 @@ void GlState::glVertexAttribPointer(void *user_data, unsigned index, int size, G
 void GlState::glBindBuffer(void *user_data, GLenum target, unsigned id)
 { reinterpret_cast<GlState *>(user_data)->set_current_buffer(target, id); }
 
+void GlState::glBindBufferBase(void *user_data, GLenum target, unsigned index, unsigned id)
+{
+       if(BufferState *buffer = reinterpret_cast<GlState *>(user_data)->get_buffer_object(id))
+               glBindBufferRange(user_data, target, index, id, 0, buffer->size);
+}
+
+void GlState::glBindBufferRange(void *user_data, GLenum target, unsigned index, unsigned id, int offset, int size)
+{
+       GlState *self = reinterpret_cast<GlState *>(user_data);
+       if(BufferBindingState *binding = self->get_buffer_binding(target, index))
+       {
+               binding->buffer = self->get_buffer_object(id);
+               binding->offset = offset;
+               binding->size = size;
+       }
+}
+
 void GlState::glBufferData(void *user_data, GLenum target, int size, const void *data, GLenum usage)
 {
        if(BufferState *buf = reinterpret_cast<GlState *>(user_data)->get_current_buffer(target))
index 7f15b0157489986f87f0b1213c642d5096b713d9..e6a3d9812f556f6b351799da28625e8978620402 100644 (file)
@@ -50,6 +50,8 @@ private:
        BufferMap buffers;
        BufferState *array_buffer;
        BufferState *element_buffer;
+       BufferState *uniform_buffer;
+       std::vector<BufferBindingState> uniform_bind_points;
        ArrayState vertex_array;
        ArrayState normal_array;
        ArrayState color_array;
@@ -70,13 +72,16 @@ public:
        const BufferMap &get_buffers() const { return buffers; }
        const BufferState &get_buffer(unsigned) const;
        const BufferState *get_current_buffer(GLenum) const;
+       const BufferBindingState &get_buffer_binding(GLenum, unsigned) const;
        const ArrayState &get_array(GLenum) const;
        const ArrayState &get_texture_coord_array(unsigned) const;
        const ArrayState &get_attrib_array(unsigned) const;
 private:
        bool &get_boolean_state(GLenum);
        TextureState *get_current_texture(GLenum);
+       BufferState *get_buffer_object(unsigned);
        BufferState *get_current_buffer(GLenum);
+       BufferBindingState *get_buffer_binding(GLenum, unsigned);
        void set_current_texture(GLenum, unsigned);
        void set_current_buffer(GLenum, unsigned);
        ArrayState &get_attrib_array(unsigned);
@@ -110,6 +115,8 @@ private:
        static void glVertexAttribPointer(void *, unsigned, int, GLenum, unsigned char, int, const void *);
 
        static void glBindBuffer(void *, GLenum, unsigned);
+       static void glBindBufferBase(void *, GLenum, unsigned, unsigned);
+       static void glBindBufferRange(void *, GLenum, unsigned, unsigned, int, int);
        static void glBufferData(void *, GLenum, int, const void *, GLenum);
        static void glBufferSubData(void *, GLenum, int, int, const void *);
        static void glDeleteBuffers(void *, int, const unsigned *);
index 936f7e824f0828149db56de10933e52ae62dd713..150457eb8a87ff4750d1f3be6243242c3ac4ec35 100644 (file)
@@ -72,6 +72,14 @@ void Inspector::cmd_state(const string &args)
                printf("    GL_ARRAY_BUFFER:         %d\n", (buf ? buf->id : 0));
                buf = glstate.get_current_buffer(GL_ELEMENT_ARRAY_BUFFER);
                printf("    GL_ELEMENT_ARRAY_BUFFER: %d\n", (buf ? buf->id : 0));
+               buf = glstate.get_current_buffer(GL_UNIFORM_BUFFER);
+               printf("    GL_UNIFORM_BUFFER:       %d\n", (buf ? buf->id : 0));
+               for(unsigned i=0; i<64; ++i)
+               {
+                       const BufferBindingState &binding = glstate.get_buffer_binding(GL_UNIFORM_BUFFER, i);
+                       if(binding.buffer)
+                               printf("      %d: %d (%d bytes at %d)\n", i, binding.buffer->id, binding.size, binding.offset);
+               }
        }
        else
                throw runtime_error("Invalid or missing argument");