]> git.tdb.fi Git - gldbg.git/commitdiff
Fix generic attribute arrays and array enabledness tracking
authorMikko Rasa <tdb@tdb.fi>
Tue, 18 Jan 2011 07:10:14 +0000 (07:10 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 18 Jan 2011 07:10:14 +0000 (07:10 +0000)
flavors/gl/source/glstate.cpp
flavors/gl/source/glstate.h

index f910b49cc041bd87ef2072f61837be3e41b2cfc6..e3c9871c34c5ca5772a229f55c6c6107e288325d 100644 (file)
@@ -84,6 +84,13 @@ GlState::GlState():
                texcoord_arrays[i].index = i;
        }
 
+       decoder->glEnableClientState = glEnableClientState;
+       decoder->glDisableClientState = glDisableClientState;
+       decoder->glEnableVertexAttribArray = glEnableVertexAttribArray;
+       decoder->glEnableVertexAttribArrayARB = glEnableVertexAttribArray;
+       decoder->glDisableVertexAttribArray = glDisableVertexAttribArray;
+       decoder->glDisableVertexAttribArrayARB = glDisableVertexAttribArray;
+
        decoder->glColor3ub = wrap_normalized<GLubyte, glColor3f>;
        decoder->glColor3ubv = wrap_array<GLubyte, wrap_normalized<GLubyte, glColor3f> >;
        decoder->glColor4ub = wrap_normalized<GLubyte, glColor4f>;
@@ -117,6 +124,8 @@ GlState::GlState():
        decoder->glClientActiveTexture = glClientActiveTexture;
        decoder->glClientActiveTextureARB = glClientActiveTexture;
        decoder->glTexCoordPointer = glTexCoordPointer;
+       decoder->glVertexAttribPointer = glVertexAttribPointer;
+       decoder->glVertexAttribPointerARB = glVertexAttribPointer;
 
        decoder->glBindBuffer = glBindBuffer;
        decoder->glBindBufferARB = glBindBuffer;
@@ -158,6 +167,35 @@ const BufferState &GlState::get_buffer(unsigned id) const
        return i->second;
 }
 
+const ArrayState &GlState::get_array(GLenum array) const
+{
+       if(array==GL_VERTEX_ARRAY)
+               return vertex_array;
+       else if(array==GL_NORMAL_ARRAY)
+               return normal_array;
+       else if(array==GL_COLOR_ARRAY)
+               return color_array;
+       else if(array==GL_TEXTURE_COORD_ARRAY)
+               return texcoord_arrays[client_active_tex];
+       else
+               throw logic_error("Invalid array");
+}
+
+const ArrayState &GlState::get_texture_coord_array(unsigned index) const
+{
+       return texcoord_arrays[index];
+}
+
+const ArrayState &GlState::get_attrib_array(unsigned index) const
+{
+       map<unsigned, ArrayState>::const_iterator i = attrib_arrays.find(index);
+       if(i!=attrib_arrays.end())
+               return i->second;
+
+       // XXX Return a dummy?
+       throw runtime_error("Unknown attribute array");
+}
+
 const BufferState *GlState::get_current_buffer(GLenum target) const
 {
        return const_cast<GlState *>(this)->get_current_buffer(target);
@@ -192,35 +230,6 @@ BufferState *GlState::get_current_buffer(GLenum target)
        return 0;
 }
 
-const ArrayState &GlState::get_array(GLenum array) const
-{
-       if(array==GL_VERTEX_ARRAY)
-               return vertex_array;
-       else if(array==GL_NORMAL_ARRAY)
-               return normal_array;
-       else if(array==GL_COLOR_ARRAY)
-               return color_array;
-       else if(array==GL_TEXTURE_COORD_ARRAY)
-               return texcoord_arrays[client_active_tex];
-       else
-               throw logic_error("Invalid array");
-}
-
-const ArrayState &GlState::get_texture_coord_array(unsigned index) const
-{
-       return texcoord_arrays[index];
-}
-
-const ArrayState &GlState::get_attrib_array(unsigned index) const
-{
-       map<unsigned, ArrayState>::const_iterator i = attrib_arrays.find(index);
-       if(i!=attrib_arrays.end())
-               return i->second;
-
-       // XXX Return a dummy?
-       throw runtime_error("Unknown attribute array");
-}
-
 void GlState::set_current_texture(GLenum target, unsigned id)
 {
        TexUnitState &unit = texunits[active_tex];
@@ -255,6 +264,18 @@ void GlState::set_current_buffer(GLenum target, unsigned id)
                element_buffer = buf;
 }
 
+ArrayState &GlState::get_attrib_array(unsigned index)
+{
+       map<unsigned, ArrayState>::iterator i = attrib_arrays.find(index);
+       if(i!=attrib_arrays.end())
+               return i->second;
+
+       ArrayState &array = attrib_arrays[index];
+       array.index = index;
+
+       return array;
+}
+
 // Boolean state
 
 void GlState::glEnableClientState(void *user_data, GLenum state)
@@ -387,10 +408,10 @@ void GlState::glTexCoordPointer(void *user_data, int size, GLenum type, int stri
        self->texcoord_arrays[self->client_active_tex].set(size, type, false, stride, self->array_buffer, reinterpret_cast<long>(data));
 }
 
-void GlState::glVertexAttribPointer(void *user_data, unsigned index, int size, GLenum type, int norm, int stride, const void *data)
+void GlState::glVertexAttribPointer(void *user_data, unsigned index, int size, GLenum type, unsigned char norm, int stride, const void *data)
 {
        GlState *self = reinterpret_cast<GlState *>(user_data);
-       self->attrib_arrays[index].set(size, type, norm, stride, self->array_buffer, reinterpret_cast<long>(data));
+       self->get_attrib_array(index).set(size, type, norm, stride, self->array_buffer, reinterpret_cast<long>(data));
 }
 
 // Buffer objects
index 43e8f39f094f90c17745f2832d82a3c088b94982..ab70c676bdc1f7017e021438bc7498dd4dc4e443 100644 (file)
@@ -86,6 +86,7 @@ private:
        BufferState *get_current_buffer(GLenum);
        void set_current_texture(GLenum, unsigned);
        void set_current_buffer(GLenum, unsigned);
+       ArrayState &get_attrib_array(unsigned);
 
        static void glEnableClientState(void *, GLenum);
        static void glDisableClientState(void *, GLenum);
@@ -113,7 +114,7 @@ private:
        static void glColorPointer(void *, int, GLenum, int, const void *);
        static void glClientActiveTexture(void *, unsigned);
        static void glTexCoordPointer(void *, int, GLenum, int, const void *);
-       static void glVertexAttribPointer(void *, unsigned, int, GLenum, int, int, const void *);
+       static void glVertexAttribPointer(void *, unsigned, int, GLenum, unsigned char, int, const void *);
 
        static void glBindBuffer(void *, GLenum, unsigned);
        static void glBufferData(void *, GLenum, int, const void *, GLenum);