X-Git-Url: http://git.tdb.fi/?p=gldbg.git;a=blobdiff_plain;f=source%2Fglstate.cpp;h=1459324232f36d3b6af583bfe1def2a3e0ffb22a;hp=90b0ac03ff34aaf14fe44761928cad16011aede5;hb=9cdca19aa017ea1711436977855e885d91e78ab0;hpb=64592975a49e2bd26a561f36425071427f37d5fb diff --git a/source/glstate.cpp b/source/glstate.cpp index 90b0ac0..1459324 100644 --- a/source/glstate.cpp +++ b/source/glstate.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of gldbg -Copyright © 2009 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions Distributed under the GPL */ @@ -72,9 +72,19 @@ Vector4::Vector4(): 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; decoder->glColor3ubv = wrap_array >; decoder->glColor4ub = wrap_normalized; @@ -93,6 +103,7 @@ GlState::GlState(): decoder->glTexCoord4fv = wrap_array; decoder->glNormal3f = glNormal3f; decoder->glNormal3fv = wrap_array; + decoder->glActiveTexture = glActiveTexture; decoder->glActiveTextureARB = glActiveTexture; decoder->glBindTexture = glBindTexture; @@ -100,12 +111,22 @@ GlState::GlState(): 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() @@ -139,6 +160,21 @@ const BufferState *GlState::get_current_buffer(GLenum target) const return const_cast(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); @@ -153,6 +189,35 @@ 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 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::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]; @@ -187,6 +252,28 @@ void GlState::set_current_buffer(GLenum target, unsigned id) element_buffer = buf; } +// Boolean state + +void GlState::glEnableClientState(void *user_data, GLenum state) +{ + reinterpret_cast(user_data)->get_boolean_state(state) = true; +} + +void GlState::glDisableClientState(void *user_data, GLenum state) +{ + reinterpret_cast(user_data)->get_boolean_state(state) = false; +} + +void GlState::glEnableVertexAttribArray(void *user_data, unsigned index) +{ + reinterpret_cast(user_data)->attrib_arrays[index].enabled = true; +} + +void GlState::glDisableVertexAttribArray(void *user_data, unsigned index) +{ + reinterpret_cast(user_data)->attrib_arrays[index].enabled = false; +} + // Vertex attributes void GlState::glColor3f(void *user_data, float r, float g, float b) @@ -241,7 +328,9 @@ void GlState::glActiveTexture(void *user_data, unsigned index) } void GlState::glBindTexture(void *user_data, GLenum target, unsigned id) -{ reinterpret_cast(user_data)->set_current_texture(target, id); } +{ + reinterpret_cast(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 *) { @@ -264,6 +353,43 @@ void GlState::glDeleteTextures(void *user_data, int count, const unsigned *ids) reinterpret_cast(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(user_data); + self->vertex_array.set(size, type, false, stride, self->array_buffer, reinterpret_cast(data)); +} + +void GlState::glNormalPointer(void *user_data, GLenum type, int stride, const void *data) +{ + GlState *self = reinterpret_cast(user_data); + self->normal_array.set(3, type, true, stride, self->array_buffer, reinterpret_cast(data)); +} + +void GlState::glColorPointer(void *user_data, int size, GLenum type, int stride, const void *data) +{ + GlState *self = reinterpret_cast(user_data); + self->color_array.set(size, type, true, stride, self->array_buffer, reinterpret_cast(data)); +} + +void GlState::glClientActiveTexture(void *user_data, unsigned index) +{ + reinterpret_cast(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(user_data); + self->texcoord_arrays[self->client_active_tex].set(size, type, false, stride, self->array_buffer, reinterpret_cast(data)); +} + +void GlState::glVertexAttribPointer(void *user_data, unsigned index, int size, GLenum type, int norm, int stride, const void *data) +{ + GlState *self = reinterpret_cast(user_data); + self->attrib_arrays[index].set(size, type, norm, stride, self->array_buffer, reinterpret_cast(data)); +} + // Buffer objects void GlState::glBindBuffer(void *user_data, GLenum target, unsigned id) @@ -280,3 +406,9 @@ void GlState::glBufferSubData(void *user_data, GLenum target, int offset, int si if(BufferState *buf = reinterpret_cast(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(user_data)->buffers.erase(ids[i]); +}