goat3dgfx

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