X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=flavors%2Fgl%2Fsource%2Fglstate.cpp;h=e3c9871c34c5ca5772a229f55c6c6107e288325d;hb=fffbad8853e5849c64227635db70e5ce980d2f26;hp=e33e49019bc6f660272a20b6cedd06fccef41354;hpb=76324b7394d25ba654e938eb33ee985532df7cc6;p=gldbg.git diff --git a/flavors/gl/source/glstate.cpp b/flavors/gl/source/glstate.cpp index e33e490..e3c9871 100644 --- a/flavors/gl/source/glstate.cpp +++ b/flavors/gl/source/glstate.cpp @@ -1,15 +1,14 @@ /* $Id$ This file is part of gldbg -Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2011 Mikko Rasa, Mikkosoft Productions Distributed under the GPL */ -#include +#include #include "glstate.h" using namespace std; -using namespace Msp; namespace { @@ -85,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; decoder->glColor3ubv = wrap_array >; decoder->glColor4ub = wrap_normalized; @@ -118,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; @@ -147,7 +155,7 @@ const TextureState &GlState::get_texture(unsigned id) const { TextureMap::const_iterator i = textures.find(id); if(i==textures.end()) - throw KeyError("Unknown texture"); + throw runtime_error("Unknown texture"); return i->second; } @@ -155,10 +163,39 @@ const BufferState &GlState::get_buffer(unsigned id) const { BufferMap::const_iterator i = buffers.find(id); if(i==buffers.end()) - throw KeyError("Unknown buffer"); + throw runtime_error("Unknown buffer"); 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::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(this)->get_current_buffer(target); @@ -193,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 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]; @@ -256,6 +264,18 @@ void GlState::set_current_buffer(GLenum target, unsigned id) element_buffer = buf; } +ArrayState &GlState::get_attrib_array(unsigned index) +{ + map::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) @@ -388,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(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(user_data); - self->attrib_arrays[index].set(size, type, norm, stride, self->array_buffer, reinterpret_cast(data)); + self->get_attrib_array(index).set(size, type, norm, stride, self->array_buffer, reinterpret_cast(data)); } // Buffer objects