goat3dgfx

diff src/unistate.h @ 0:1873dfd13f2d

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 14 Nov 2013 05:27:09 +0200
parents
children 7d6b667821cf
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/unistate.h	Thu Nov 14 05:27:09 2013 +0200
     1.3 @@ -0,0 +1,104 @@
     1.4 +#ifndef UNISTATE_H_
     1.5 +#define UNISTATE_H_
     1.6 +
     1.7 +#include "vmath/vmath.h"
     1.8 +
     1.9 +class ShaderProg;
    1.10 +
    1.11 +enum StType {
    1.12 +	ST_UNKNOWN,
    1.13 +	ST_INT,	ST_INT2, ST_INT3, ST_INT4,
    1.14 +	ST_FLOAT, ST_FLOAT2, ST_FLOAT3, ST_FLOAT4,
    1.15 +	ST_MATRIX3, ST_MATRIX4
    1.16 +};
    1.17 +
    1.18 +int add_unistate(const char *name, StType type);
    1.19 +int get_unistate_index(const char *name);
    1.20 +
    1.21 +/** set the uniform state identified by \param sidx by copying
    1.22 + * a number of elements from \param val. If \param count is 0
    1.23 + * then it's automatically set based on the type of this state item.
    1.24 + * @{ */
    1.25 +void set_unistate(int sidx, const int *val, int count = 0);
    1.26 +void set_unistate(int sidx, const float *val, int count = 0);
    1.27 +/// @}
    1.28 +
    1.29 +/** get the uniform state identified by \param sidx by copying
    1.30 + * a number of elements into \param val. If \param count is 0
    1.31 + * then it's automatically set based on the type of this state item.
    1.32 + * @{ */
    1.33 +void get_unistate(int sidx, int *val, int count = 0);
    1.34 +void get_unistate(int sidx, float *val, int count = 0);
    1.35 +/// @}
    1.36 +
    1.37 +/// convenience versions of set_unistate @{
    1.38 +void set_unistate(int sidx, int val);
    1.39 +void set_unistate(int sidx, float val);
    1.40 +void set_unistate(int sidx, const Vector2 &vec);
    1.41 +void set_unistate(int sidx, const Vector3 &vec);
    1.42 +void set_unistate(int sidx, const Vector4 &vec);
    1.43 +void set_unistate(int sidx, const Matrix3x3 &mat);
    1.44 +void set_unistate(int sidx, const Matrix4x4 &mat);
    1.45 +/// @}
    1.46 +
    1.47 +/** convenience functions for setting the uniform state by name.
    1.48 + * if the name cannot be found in the current set of uniform state
    1.49 + * items, a new one is created with a type derived from the variant
    1.50 + * of the function that was called (which might not be what you want).
    1.51 + * The index of the state item is returned.
    1.52 + * @{ */
    1.53 +int set_unistate(const char *name, int *val, int count = 0);
    1.54 +int set_unistate(const char *name, float *val, int count = 0);
    1.55 +int set_unistate(const char *name, int val);
    1.56 +int set_unistate(const char *name, float val);
    1.57 +int set_unistate(const char *name, const Vector2 &vec);
    1.58 +int set_unistate(const char *name, const Vector3 &vec);
    1.59 +int set_unistate(const char *name, const Vector4 &vec);
    1.60 +int set_unistate(const char *name, const Matrix3x3 &mat);
    1.61 +int set_unistate(const char *name, const Matrix4x4 &mat);
    1.62 +/// @}
    1.63 +
    1.64 +/// convenience versions of get_unistate @{
    1.65 +int get_unistate_int(int sidx);
    1.66 +float get_unistate_float(int sidx);
    1.67 +Vector2 get_unistate_vec2(int sidx);
    1.68 +Vector3 get_unistate_vec3(int sidx);
    1.69 +Vector4 get_unistate_vec4(int sidx);
    1.70 +Matrix3x3 get_unistate_mat3(int sidx);
    1.71 +Matrix4x4 get_unistate_mat4(int sidx);
    1.72 +/// @}
    1.73 +
    1.74 +/// convenience versions of get_unistate for getting the uniform state by name @{
    1.75 +int get_unistate_int(const char *name);
    1.76 +float get_unistate_float(const char *name);
    1.77 +Vector2 get_unistate_vec2(const char *name);
    1.78 +Vector3 get_unistate_vec3(const char *name);
    1.79 +Vector4 get_unistate_vec4(const char *name);
    1.80 +Matrix3x3 get_unistate_mat3(const char *name);
    1.81 +Matrix4x4 get_unistate_mat4(const char *name);
    1.82 +/// @}
    1.83 +
    1.84 +/** Prepare for rendering by setting up all the state uniforms in the shader sdr.
    1.85 + * If sdr is null, then use the "current" shader as per ShaderProg::current
    1.86 + */
    1.87 +void setup_unistate(const ShaderProg *sdr = 0);
    1.88 +
    1.89 +bool setup_unistate(int sidx, const ShaderProg *sdr, int loc);
    1.90 +bool setup_unistate(const char *name, const ShaderProg *sdr);
    1.91 +
    1.92 +// special functions for setting the rendering pipeline matrices
    1.93 +void set_world_matrix(const Matrix4x4 &mat);
    1.94 +void set_view_matrix(const Matrix4x4 &mat);
    1.95 +void set_projection_matrix(const Matrix4x4 &mat);
    1.96 +void set_texture_matrix(const Matrix4x4 &mat);
    1.97 +
    1.98 +Matrix4x4 get_world_matrix();
    1.99 +Matrix4x4 get_view_matrix();
   1.100 +Matrix4x4 get_projection_matrix();
   1.101 +Matrix4x4 get_texture_matrix();
   1.102 +
   1.103 +void setup_gl_matrices();	// this shouldn't be needed in the final code
   1.104 +
   1.105 +// TODO should do a matrix stack at some point ...
   1.106 +
   1.107 +#endif	// UNISTATE_H_