]> git.tdb.fi Git - gldbg.git/blob - source/glstate.h
b21034d8b037be51cecb7e2ab45bf545025aa19c
[gldbg.git] / source / glstate.h
1 /* $Id$
2
3 This file is part of gldbg
4 Copyright © 2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
6 */
7
8 #ifndef GLSTATE_H_
9 #define GLSTATE_H_
10
11 #include <map>
12 #include <vector>
13 #include "bufferstate.h"
14 #include "gldecoder.h"
15 #include "texturestate.h"
16
17 struct Vector3
18 {
19         float x, y, z;
20
21         Vector3();
22 };
23
24 struct Vector4
25 {
26         union { float x, r, s; };
27         union { float y, g, t; };
28         union { float z, b, p; };
29         union { float w, a, q; };
30
31         Vector4();
32 };
33
34 /**
35 Tracks OpenGL state based on the command stream.  This class is essentially a
36 (partial) OpenGL implementation in itself.
37
38 XXX Should determine the number of texture units the target implementation
39 actually supports.
40 */
41 class GlState
42 {
43 public:
44         typedef std::map<unsigned, TextureState> TextureMap;
45         typedef std::map<unsigned, BufferState> BufferMap;
46
47 private:
48         GlDecoder *decoder;
49         Vector4 color;
50         Vector4 texcoord[8];
51         Vector3 normal;
52         unsigned active_tex;
53         TextureMap textures;
54         TexUnitState texunits[8];
55         BufferMap buffers;
56         BufferState *array_buffer;
57         BufferState *element_buffer;
58
59 public:
60         GlState();
61         ~GlState();
62
63         int decode(const char *, unsigned);
64         const Vector4 &get_color() const { return color; }
65         const Vector4 &get_texcoord(unsigned i) const { return texcoord[i]; }
66         const Vector3 &get_normal() const { return normal; }
67         const TextureMap &get_textures() const { return textures; }
68         const TextureState &get_texture(unsigned) const;
69         const TexUnitState &get_texture_unit(unsigned i) const { return texunits[i]; }
70         const BufferMap &get_buffers() const { return buffers; }
71         const BufferState &get_buffer(unsigned) const;
72         const BufferState *get_current_buffer(GLenum) const;
73 private:
74         TextureState *get_current_texture(GLenum);
75         BufferState *get_current_buffer(GLenum);
76         void set_current_texture(GLenum, unsigned);
77         void set_current_buffer(GLenum, unsigned);
78
79         static void glColor3f(void *, float, float, float);
80         static void glColor4f(void *, float, float, float, float);
81         static void glNormal3f(void *, float, float, float);
82         static void glTexCoord1f(void *, float);
83         static void glTexCoord2f(void *, float, float);
84         static void glTexCoord3f(void *, float, float, float);
85         static void glTexCoord4f(void *, float, float, float, float);
86         static void glMultiTexCoord4f(void *, unsigned, float, float, float, float);
87
88         static void glActiveTexture(void *, unsigned);
89         static void glBindTexture(void *, GLenum, unsigned);
90         static void glTexImage2D(void *, GLenum, int, int, int, int, int, GLenum, GLenum, const void *);
91         static void glTexParameteri(void *, GLenum, GLenum, int);
92         static void glTexParameteriv(void *, GLenum, GLenum, const int *);
93         static void glDeleteTextures(void *, int, const unsigned *);
94
95         static void glBindBuffer(void *, GLenum, unsigned);
96         static void glBufferData(void *, GLenum, int, const void *, GLenum);
97         static void glBufferSubData(void *, GLenum, int, int, const void *);
98 };
99
100 #endif