Guest User

Untitled

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