BuildinMaterialVariable.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "BuildinMaterialVariable.h"
  2. #include "Util/Exception.h"
  3. #include <cstring>
  4. #include <boost/lexical_cast.hpp>
  5. //==============================================================================
  6. // Statics =
  7. //==============================================================================
  8. boost::array<BuildinMaterialVariable::BuildinVarInfo,
  9. BuildinMaterialVariable::BV_NUM> BuildinMaterialVariable::infos =
  10. {{
  11. {"position", GL_FLOAT_VEC3},
  12. {"tangent", GL_FLOAT_VEC4},
  13. {"normal", GL_FLOAT_VEC3},
  14. {"texCoords", GL_FLOAT_VEC2},
  15. {"modelMat", GL_FLOAT_MAT4},
  16. {"viewMat", GL_FLOAT_MAT4},
  17. {"projectionMat", GL_FLOAT_MAT4},
  18. {"modelViewMat", GL_FLOAT_MAT4},
  19. {"viewProjectionMat", GL_FLOAT_MAT4},
  20. {"normalMat", GL_FLOAT_MAT3},
  21. {"modelViewProjectionMat", GL_FLOAT_MAT4},
  22. {"msNormalFai", GL_SAMPLER_2D},
  23. {"msDiffuseFai", GL_SAMPLER_2D},
  24. {"msSpecularFai", GL_SAMPLER_2D},
  25. {"msDepthFai", GL_SAMPLER_2D},
  26. {"isFai", GL_SAMPLER_2D},
  27. {"ppsPrePassFai", GL_SAMPLER_2D},
  28. {"ppsPostPassFai", GL_SAMPLER_2D},
  29. {"rendererSize", GL_FLOAT_VEC2},
  30. {"sceneAmbientColor", GL_FLOAT_VEC3},
  31. {"blurring", GL_FLOAT},
  32. }};
  33. //==============================================================================
  34. // Constructor =
  35. //==============================================================================
  36. BuildinMaterialVariable::BuildinMaterialVariable(
  37. const SProgVar* cpSProgVar, const SProgVar* dpSProgVar,
  38. const char* name)
  39. : MaterialVariable(T_BUILDIN, cpSProgVar, dpSProgVar),
  40. var(BV_NUM)
  41. {
  42. GLenum dataType;
  43. // Sanity checks
  44. if(!isBuildin(name, &var, &dataType))
  45. {
  46. throw EXCEPTION("The variable is not buildin: " + name);
  47. }
  48. if(dataType != getGlDataType())
  49. {
  50. throw EXCEPTION("The buildin variable \"" + name +
  51. "\" sould be of type: " +
  52. boost::lexical_cast<std::string>(dataType));
  53. }
  54. }
  55. //==============================================================================
  56. // isBuildin =
  57. //==============================================================================
  58. bool BuildinMaterialVariable::isBuildin(const char* name,
  59. BuildinVariable* var, GLenum* dataType)
  60. {
  61. for(uint i = 0; i < BV_NUM; i++)
  62. {
  63. if(!strcmp(infos[i].name, name))
  64. {
  65. if(var)
  66. {
  67. *var = static_cast<BuildinVariable>(i);
  68. }
  69. if(dataType)
  70. {
  71. *dataType = infos[i].dataType;
  72. }
  73. return true;
  74. }
  75. }
  76. return false;
  77. }