added shader class and unistate. not using shader class yet
[laserbrain_demo] / src / unistate.h
diff --git a/src/unistate.h b/src/unistate.h
new file mode 100644 (file)
index 0000000..b7e66ad
--- /dev/null
@@ -0,0 +1,104 @@
+#ifndef UNISTATE_H_
+#define UNISTATE_H_
+
+#include <gmath/gmath.h>
+
+class ShaderProg;
+
+enum StType {
+       ST_UNKNOWN,
+       ST_INT, ST_INT2, ST_INT3, ST_INT4,
+       ST_FLOAT, ST_FLOAT2, ST_FLOAT3, ST_FLOAT4,
+       ST_MATRIX3, ST_MATRIX4
+};
+
+int add_unistate(const char *name, StType type);
+int get_unistate_index(const char *name);
+
+/** set the uniform state identified by \param sidx by copying
+ * a number of elements from \param val. If \param count is 0
+ * then it's automatically set based on the type of this state item.
+ * @{ */
+void set_unistate(int sidx, const int *val, int count = 0);
+void set_unistate(int sidx, const float *val, int count = 0);
+/// @}
+
+/** get the uniform state identified by \param sidx by copying
+ * a number of elements into \param val. If \param count is 0
+ * then it's automatically set based on the type of this state item.
+ * @{ */
+void get_unistate(int sidx, int *val, int count = 0);
+void get_unistate(int sidx, float *val, int count = 0);
+/// @}
+
+/// convenience versions of set_unistate @{
+void set_unistate(int sidx, int val);
+void set_unistate(int sidx, float val);
+void set_unistate(int sidx, const Vec2 &vec);
+void set_unistate(int sidx, const Vec3 &vec);
+void set_unistate(int sidx, const Vec4 &vec);
+void set_unistate(int sidx, const Mat3 &mat);
+void set_unistate(int sidx, const Mat4 &mat);
+/// @}
+
+/** convenience functions for setting the uniform state by name.
+ * if the name cannot be found in the current set of uniform state
+ * items, a new one is created with a type derived from the variant
+ * of the function that was called (which might not be what you want).
+ * The index of the state item is returned.
+ * @{ */
+int set_unistate(const char *name, int *val, int count = 0);
+int set_unistate(const char *name, float *val, int count = 0);
+int set_unistate(const char *name, int val);
+int set_unistate(const char *name, float val);
+int set_unistate(const char *name, const Vec2 &vec);
+int set_unistate(const char *name, const Vec3 &vec);
+int set_unistate(const char *name, const Vec4 &vec);
+int set_unistate(const char *name, const Mat3 &mat);
+int set_unistate(const char *name, const Mat4 &mat);
+/// @}
+
+/// convenience versions of get_unistate @{
+int get_unistate_int(int sidx);
+float get_unistate_float(int sidx);
+Vec2 get_unistate_vec2(int sidx);
+Vec3 get_unistate_vec3(int sidx);
+Vec4 get_unistate_vec4(int sidx);
+Mat3 get_unistate_mat3(int sidx);
+Mat4 get_unistate_mat4(int sidx);
+/// @}
+
+/// convenience versions of get_unistate for getting the uniform state by name @{
+int get_unistate_int(const char *name);
+float get_unistate_float(const char *name);
+Vec2 get_unistate_vec2(const char *name);
+Vec3 get_unistate_vec3(const char *name);
+Vec4 get_unistate_vec4(const char *name);
+Mat3 get_unistate_mat3(const char *name);
+Mat4 get_unistate_mat4(const char *name);
+/// @}
+
+/** Prepare for rendering by setting up all the state uniforms in the shader sdr.
+ * If sdr is null, then use the "current" shader as per ShaderProg::current
+ */
+void setup_unistate(const ShaderProg *sdr = 0);
+
+bool setup_unistate(int sidx, const ShaderProg *sdr, int loc);
+bool setup_unistate(const char *name, const ShaderProg *sdr);
+
+// special functions for setting the rendering pipeline matrices
+void set_world_matrix(const Mat4 &mat);
+void set_view_matrix(const Mat4 &mat);
+void set_projection_matrix(const Mat4 &mat);
+void set_texture_matrix(const Mat4 &mat);
+
+Mat4 get_world_matrix();
+Mat4 get_view_matrix();
+Mat4 get_projection_matrix();
+Mat4 get_texture_matrix();
+
+void setup_gl_matrices();      // this shouldn't be needed in the final code
+
+// TODO should do a matrix stack at some point ...
+
+#endif // UNISTATE_H_