--- /dev/null
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2009 Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#ifndef GLSTATE_H_
+#define GLSTATE_H_
+
+#include <map>
+#include <vector>
+#include "bufferstate.h"
+#include "gldecoder.h"
+#include "texturestate.h"
+
+struct Vector3
+{
+ float x, y, z;
+
+ Vector3();
+};
+
+struct Vector4
+{
+ union { float x, r, s; };
+ union { float y, g, t; };
+ union { float z, b, p; };
+ union { float w, a, q; };
+
+ Vector4();
+};
+
+/**
+Tracks OpenGL state based on the command stream. This class is essentially a
+(partial) OpenGL implementation in itself.
+
+XXX Should determine the number of texture units the target implementation
+actually supports.
+*/
+class GlState
+{
+public:
+ typedef std::map<unsigned, TextureState> TextureMap;
+ typedef std::map<unsigned, BufferState> BufferMap;
+
+private:
+ GlDecoder *decoder;
+ Vector4 color;
+ Vector4 texcoord[8];
+ Vector3 normal;
+ unsigned active_tex;
+ TextureMap textures;
+ TexUnitState texunits[8];
+ BufferMap buffers;
+ BufferState *array_buffer;
+ BufferState *element_buffer;
+
+public:
+ GlState();
+ ~GlState();
+
+ int decode(const char *, unsigned);
+ const Vector4 &get_color() const { return color; }
+ const Vector4 &get_texcoord(unsigned i) const { return texcoord[i]; }
+ const Vector3 &get_normal() const { return normal; }
+ const TextureMap &get_textures() const { return textures; }
+ const TextureState &get_texture(unsigned) const;
+ const TexUnitState &get_texture_unit(unsigned i) const { return texunits[i]; }
+ const BufferMap &get_buffers() const { return buffers; }
+ const BufferState &get_buffer(unsigned) const;
+ const BufferState *get_current_buffer(GLenum) const;
+private:
+ TextureState *get_current_texture(GLenum);
+ BufferState *get_current_buffer(GLenum);
+ void set_current_texture(GLenum, unsigned);
+ void set_current_buffer(GLenum, unsigned);
+
+ static void glColor3f(void *, float, float, float);
+ static void glColor4f(void *, float, float, float, float);
+ static void glNormal3f(void *, float, float, float);
+ static void glTexCoord1f(void *, float);
+ static void glTexCoord2f(void *, float, float);
+ static void glTexCoord3f(void *, float, float, float);
+ static void glTexCoord4f(void *, float, float, float, float);
+ static void glMultiTexCoord4f(void *, unsigned, float, float, float, float);
+
+ static void glActiveTexture(void *, unsigned);
+ static void glBindTexture(void *, GLenum, unsigned);
+ static void glTexImage2D(void *, GLenum, int, int, int, int, int, GLenum, GLenum, const void *);
+ static void glTexParameteri(void *, GLenum, GLenum, int);
+ static void glTexParameteriv(void *, GLenum, GLenum, const int *);
+ static void glDeleteTextures(void *, int, const unsigned *);
+
+ static void glBindBuffer(void *, GLenum, unsigned);
+ static void glBufferData(void *, GLenum, int, const void *, GLenum);
+ static void glBufferSubData(void *, GLenum, int, int, const void *);
+};
+
+#endif