goat3dgfx

view src/unistate.h @ 16:f61cc1df533c

added viewscn example (under dev)
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 30 Nov 2013 20:53:26 +0200
parents 1873dfd13f2d
children
line source
1 #ifndef UNISTATE_H_
2 #define UNISTATE_H_
4 #include "vmath/vmath.h"
6 namespace goatgfx {
8 class ShaderProg;
10 enum StType {
11 ST_UNKNOWN,
12 ST_INT, ST_INT2, ST_INT3, ST_INT4,
13 ST_FLOAT, ST_FLOAT2, ST_FLOAT3, ST_FLOAT4,
14 ST_MATRIX3, ST_MATRIX4
15 };
17 int add_unistate(const char *name, StType type);
18 int get_unistate_index(const char *name);
20 /** set the uniform state identified by \param sidx by copying
21 * a number of elements from \param val. If \param count is 0
22 * then it's automatically set based on the type of this state item.
23 * @{ */
24 void set_unistate(int sidx, const int *val, int count = 0);
25 void set_unistate(int sidx, const float *val, int count = 0);
26 /// @}
28 /** get the uniform state identified by \param sidx by copying
29 * a number of elements into \param val. If \param count is 0
30 * then it's automatically set based on the type of this state item.
31 * @{ */
32 void get_unistate(int sidx, int *val, int count = 0);
33 void get_unistate(int sidx, float *val, int count = 0);
34 /// @}
36 /// convenience versions of set_unistate @{
37 void set_unistate(int sidx, int val);
38 void set_unistate(int sidx, float val);
39 void set_unistate(int sidx, const Vector2 &vec);
40 void set_unistate(int sidx, const Vector3 &vec);
41 void set_unistate(int sidx, const Vector4 &vec);
42 void set_unistate(int sidx, const Matrix3x3 &mat);
43 void set_unistate(int sidx, const Matrix4x4 &mat);
44 /// @}
46 /** convenience functions for setting the uniform state by name.
47 * if the name cannot be found in the current set of uniform state
48 * items, a new one is created with a type derived from the variant
49 * of the function that was called (which might not be what you want).
50 * The index of the state item is returned.
51 * @{ */
52 int set_unistate(const char *name, int *val, int count = 0);
53 int set_unistate(const char *name, float *val, int count = 0);
54 int set_unistate(const char *name, int val);
55 int set_unistate(const char *name, float val);
56 int set_unistate(const char *name, const Vector2 &vec);
57 int set_unistate(const char *name, const Vector3 &vec);
58 int set_unistate(const char *name, const Vector4 &vec);
59 int set_unistate(const char *name, const Matrix3x3 &mat);
60 int set_unistate(const char *name, const Matrix4x4 &mat);
61 /// @}
63 /// convenience versions of get_unistate @{
64 int get_unistate_int(int sidx);
65 float get_unistate_float(int sidx);
66 Vector2 get_unistate_vec2(int sidx);
67 Vector3 get_unistate_vec3(int sidx);
68 Vector4 get_unistate_vec4(int sidx);
69 Matrix3x3 get_unistate_mat3(int sidx);
70 Matrix4x4 get_unistate_mat4(int sidx);
71 /// @}
73 /// convenience versions of get_unistate for getting the uniform state by name @{
74 int get_unistate_int(const char *name);
75 float get_unistate_float(const char *name);
76 Vector2 get_unistate_vec2(const char *name);
77 Vector3 get_unistate_vec3(const char *name);
78 Vector4 get_unistate_vec4(const char *name);
79 Matrix3x3 get_unistate_mat3(const char *name);
80 Matrix4x4 get_unistate_mat4(const char *name);
81 /// @}
83 /** Prepare for rendering by setting up all the state uniforms in the shader sdr.
84 * If sdr is null, then use the "current" shader as per ShaderProg::current
85 */
86 void setup_unistate(const ShaderProg *sdr = 0);
88 bool setup_unistate(int sidx, const ShaderProg *sdr, int loc);
89 bool setup_unistate(const char *name, const ShaderProg *sdr);
91 // special functions for setting the rendering pipeline matrices
92 void set_world_matrix(const Matrix4x4 &mat);
93 void set_view_matrix(const Matrix4x4 &mat);
94 void set_projection_matrix(const Matrix4x4 &mat);
95 void set_texture_matrix(const Matrix4x4 &mat);
97 Matrix4x4 get_world_matrix();
98 Matrix4x4 get_view_matrix();
99 Matrix4x4 get_projection_matrix();
100 Matrix4x4 get_texture_matrix();
102 void setup_gl_matrices(); // this shouldn't be needed in the final code
104 // TODO should do a matrix stack at some point ...
106 } // namespace goatgfx
108 #endif // UNISTATE_H_