GlState::GlState():
decoder(gldecoder_new(this, NULL)),
+ texcoord(1),
active_tex(0),
client_active_tex(0),
+ texunits(1),
array_buffer(0),
element_buffer(0),
uniform_buffer(0),
- uniform_bind_points(64)
+ texcoord_arrays(1)
{
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;
- }
+ texcoord_arrays[0].kind = GL_TEXTURE_COORD_ARRAY;
+ texcoord_arrays[0].index = 0;
+
+ decoder->glGetIntegerv = glGetIntegerv;
decoder->glEnableClientState = glEnableClientState;
decoder->glDisableClientState = glDisableClientState;
return gldecoder_decode(decoder, data, len);
}
+void GlState::glGetIntegerv(void *user_data, GLenum pname, int *param)
+{
+ GlState *self = reinterpret_cast<GlState *>(user_data);
+ if(pname==GL_MAX_TEXTURE_UNITS)
+ {
+ self->texcoord.resize(*param);
+ self->texunits.resize(*param);
+ self->texcoord_arrays.resize(*param);
+ for(unsigned i=0; i<self->texcoord_arrays.size(); ++i)
+ {
+ self->texcoord_arrays[i].kind = GL_TEXTURE_COORD_ARRAY;
+ self->texcoord_arrays[i].index = i;
+ }
+ }
+ else if(pname==GL_MAX_VERTEX_ATTRIBS)
+ {
+ self->attrib_arrays.resize(*param);
+ for(unsigned i=0; i<self->attrib_arrays.size(); ++i)
+ self->attrib_arrays[i].index = i;
+ }
+ else if(pname==GL_MAX_UNIFORM_BUFFER_BINDINGS)
+ self->uniform_bind_points.resize(*param);
+}
+
// Boolean state
bool &GlState::get_boolean_state(GLenum state)
// Vertex arrays
-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;
-}
-
void GlState::glVertexPointer(void *user_data, int size, GLenum type, int stride, const void *data)
{
GlState *self = reinterpret_cast<GlState *>(user_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->get_attrib_array(index).set(size, type, norm, stride, self->array_buffer, reinterpret_cast<long>(data));
+ self->attrib_arrays[index].set(size, type, norm, stride, self->array_buffer, reinterpret_cast<long>(data));
}
const ArrayState &GlState::get_array(GLenum array) const
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");
+ return attrib_arrays[index];
}
// Array draw commands