/* $Id$
This file is part of gldbg
-Copyright © 2009 Mikko Rasa, Mikkosoft Productions
+Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions
Distributed under the GPL
*/
GlState::GlState():
decoder(gldecoder_new(this, NULL)),
active_tex(0),
+ client_active_tex(0),
array_buffer(0),
element_buffer(0)
{
+ vertex_array.kind = GL_VERTEX_ARRAY;
+ normal_array.kind = GL_NORMAL_ARRAY;
+ color_array.kind = GL_COLOR_ARRAY;
+ for(unsigned i=0; i<8; ++i)
+ {
+ texcoord_arrays[i].kind = GL_TEXTURE_COORD_ARRAY;
+ texcoord_arrays[i].index = i;
+ }
+
decoder->glColor3ub = wrap_normalized<GLubyte, glColor3f>;
decoder->glColor3ubv = wrap_array<GLubyte, wrap_normalized<GLubyte, glColor3f> >;
decoder->glColor4ub = wrap_normalized<GLubyte, glColor4f>;
decoder->glTexCoord4fv = wrap_array<float, glTexCoord4f>;
decoder->glNormal3f = glNormal3f;
decoder->glNormal3fv = wrap_array<float, glNormal3f>;
+
decoder->glActiveTexture = glActiveTexture;
decoder->glActiveTextureARB = glActiveTexture;
decoder->glBindTexture = glBindTexture;
decoder->glTexParameteri = glTexParameteri;
decoder->glTexParameteriv = glTexParameteriv;
decoder->glDeleteTextures = glDeleteTextures;
+
+ decoder->glVertexPointer = glVertexPointer;
+ decoder->glNormalPointer = glNormalPointer;
+ decoder->glColorPointer = glColorPointer;
+ decoder->glClientActiveTexture = glClientActiveTexture;
+ decoder->glClientActiveTextureARB = glClientActiveTexture;
+ decoder->glTexCoordPointer = glTexCoordPointer;
+
decoder->glBindBuffer = glBindBuffer;
decoder->glBindBufferARB = glBindBuffer;
decoder->glBufferData = glBufferData;
decoder->glBufferDataARB = glBufferData;
decoder->glBufferSubData = glBufferSubData;
decoder->glBufferSubDataARB = glBufferSubData;
+ decoder->glDeleteBuffers = glDeleteBuffers;
+ decoder->glDeleteBuffersARB = glDeleteBuffers;
}
GlState::~GlState()
return const_cast<GlState *>(this)->get_current_buffer(target);
}
+bool &GlState::get_boolean_state(GLenum state)
+{
+ if(state==GL_VERTEX_ARRAY)
+ return vertex_array.enabled;
+ else if(state==GL_NORMAL_ARRAY)
+ return normal_array.enabled;
+ else if(state==GL_COLOR_ARRAY)
+ return color_array.enabled;
+ else if(state==GL_TEXTURE_COORD_ARRAY)
+ return texcoord_arrays[client_active_tex].enabled;
+
+ static bool dummy;
+ return dummy;
+}
+
TextureState *GlState::get_current_texture(GLenum target)
{
return texunits[active_tex].get_current_texture(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 InvalidParameterValue("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 KeyError("Unknown attribute array");
+}
+
void GlState::set_current_texture(GLenum target, unsigned id)
{
TexUnitState &unit = texunits[active_tex];
element_buffer = buf;
}
+// Boolean state
+
+void GlState::glEnableClientState(void *user_data, GLenum state)
+{
+ reinterpret_cast<GlState *>(user_data)->get_boolean_state(state) = true;
+}
+
+void GlState::glDisableClientState(void *user_data, GLenum state)
+{
+ reinterpret_cast<GlState *>(user_data)->get_boolean_state(state) = false;
+}
+
+void GlState::glEnableVertexAttribArray(void *user_data, unsigned index)
+{
+ reinterpret_cast<GlState *>(user_data)->attrib_arrays[index].enabled = true;
+}
+
+void GlState::glDisableVertexAttribArray(void *user_data, unsigned index)
+{
+ reinterpret_cast<GlState *>(user_data)->attrib_arrays[index].enabled = false;
+}
+
// Vertex attributes
void GlState::glColor3f(void *user_data, float r, float g, float b)
void GlState::glActiveTexture(void *user_data, unsigned index)
{
- reinterpret_cast<GlState *>(user_data)->active_tex = index;
+ reinterpret_cast<GlState *>(user_data)->active_tex = index-GL_TEXTURE0;
}
void GlState::glBindTexture(void *user_data, GLenum target, unsigned id)
-{ reinterpret_cast<GlState *>(user_data)->set_current_texture(target, id); }
+{
+ reinterpret_cast<GlState *>(user_data)->set_current_texture(target, id);
+}
void GlState::glTexImage2D(void *user_data, GLenum target, int level, int ifmt, int width, int height, int, GLenum, GLenum, const void *)
{
reinterpret_cast<GlState *>(user_data)->textures.erase(ids[i]);
}
+// Vertex arrays
+
+void GlState::glVertexPointer(void *user_data, int size, GLenum type, int stride, const void *data)
+{
+ GlState *self = reinterpret_cast<GlState *>(user_data);
+ self->vertex_array.set(size, type, false, stride, self->array_buffer, reinterpret_cast<long>(data));
+}
+
+void GlState::glNormalPointer(void *user_data, GLenum type, int stride, const void *data)
+{
+ GlState *self = reinterpret_cast<GlState *>(user_data);
+ self->normal_array.set(3, type, true, stride, self->array_buffer, reinterpret_cast<long>(data));
+}
+
+void GlState::glColorPointer(void *user_data, int size, GLenum type, int stride, const void *data)
+{
+ GlState *self = reinterpret_cast<GlState *>(user_data);
+ self->color_array.set(size, type, true, stride, self->array_buffer, reinterpret_cast<long>(data));
+}
+
+void GlState::glClientActiveTexture(void *user_data, unsigned index)
+{
+ reinterpret_cast<GlState *>(user_data)->client_active_tex = index-GL_TEXTURE0;
+}
+
+void GlState::glTexCoordPointer(void *user_data, int size, GLenum type, int stride, const void *data)
+{
+ GlState *self = reinterpret_cast<GlState *>(user_data);
+ 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)
+{
+ GlState *self = reinterpret_cast<GlState *>(user_data);
+ self->attrib_arrays[index].set(size, type, norm, stride, self->array_buffer, reinterpret_cast<long>(data));
+}
+
// Buffer objects
void GlState::glBindBuffer(void *user_data, GLenum target, unsigned id)
if(BufferState *buf = reinterpret_cast<GlState *>(user_data)->get_current_buffer(target))
buf->set_sub_data(offset, size, data);
}
+
+void GlState::glDeleteBuffers(void *user_data, int count, const unsigned *ids)
+{
+ for(int i=0; i<count; ++i)
+ reinterpret_cast<GlState *>(user_data)->buffers.erase(ids[i]);
+}