CmGpuParams.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmGpuParam.h"
  4. #include "CmBindableGpuParams.h"
  5. namespace CamelotFramework
  6. {
  7. class CM_EXPORT GpuParams
  8. {
  9. public:
  10. GpuParams(GpuParamDesc& paramDesc, bool transposeMatrices);
  11. ~GpuParams();
  12. void setParamBlockBuffer(UINT32 slot, const GpuParamBlockBufferPtr& paramBlockBuffer);
  13. void setParamBlockBuffer(const String& name, const GpuParamBlockBufferPtr& paramBlockBuffer);
  14. const GpuParamDesc& getParamDesc() const { return mParamDesc; }
  15. UINT32 getDataParamSize(const String& name) const;
  16. bool hasParam(const String& name) const;
  17. bool hasTexture(const String& name) const;
  18. bool hasSamplerState(const String& name) const;
  19. bool hasParamBlock(const String& name) const;
  20. template<class T> void getParam(const String& name, GpuDataParamBase<T>& output) const
  21. {
  22. CM_EXCEPT(InvalidParametersException, "Unsupported parameter type");
  23. }
  24. template<>
  25. void getParam<float>(const String& name, GpuDataParamBase<float>& output) const
  26. {
  27. auto iterFind = mFloatParams.find(name);
  28. if(iterFind == mFloatParams.end())
  29. CM_EXCEPT(InvalidParametersException, "Cannot find float parameter with the name '" + name + "'");
  30. output = iterFind->second;
  31. }
  32. template<>
  33. void getParam<Vector2>(const String& name, GpuDataParamBase<Vector2>& output) const
  34. {
  35. auto iterFind = mVec2Params.find(name);
  36. if(iterFind == mVec2Params.end())
  37. CM_EXCEPT(InvalidParametersException, "Cannot find vector(2) parameter with the name '" + name + "'");
  38. output = iterFind->second;
  39. }
  40. template<>
  41. void getParam<Vector3>(const String& name, GpuDataParamBase<Vector3>& output) const
  42. {
  43. auto iterFind = mVec3Params.find(name);
  44. if(iterFind == mVec3Params.end())
  45. CM_EXCEPT(InvalidParametersException, "Cannot find vector(3) parameter with the name '" + name + "'");
  46. output = iterFind->second;
  47. }
  48. template<>
  49. void getParam<Vector4>(const String& name, GpuDataParamBase<Vector4>& output) const
  50. {
  51. auto iterFind = mVec4Params.find(name);
  52. if(iterFind == mVec4Params.end())
  53. CM_EXCEPT(InvalidParametersException, "Cannot find vector(4) parameter with the name '" + name + "'");
  54. output = iterFind->second;
  55. }
  56. template<>
  57. void getParam<Matrix3>(const String& name, GpuDataParamBase<Matrix3>& output) const
  58. {
  59. auto iterFind = mMat3Params.find(name);
  60. if(iterFind == mMat3Params.end())
  61. CM_EXCEPT(InvalidParametersException, "Cannot find matrix(3x3) parameter with the name '" + name + "'");
  62. output = iterFind->second;
  63. }
  64. template<>
  65. void getParam<Matrix4>(const String& name, GpuDataParamBase<Matrix4>& output) const
  66. {
  67. auto iterFind = mMat4Params.find(name);
  68. if(iterFind == mMat4Params.end())
  69. CM_EXCEPT(InvalidParametersException, "Cannot find matrix(4x4) parameter with the name '" + name + "'");
  70. output = iterFind->second;
  71. }
  72. void getStructParam(const String& name, GpuParamStruct& output) const;
  73. void getTextureParam(const String& name, GpuParamTexture& output) const;
  74. void getSamplerStateParam(const String& name, GpuParamSampState& output) const;
  75. private:
  76. friend class BindableGpuParams;
  77. GpuParamDesc& mParamDesc;
  78. bool mTransposeMatrices;
  79. GpuParamDataDesc* getParamDesc(const String& name) const;
  80. UINT8* mData;
  81. UINT32 mNumParamBlocks;
  82. UINT32 mNumTextures;
  83. UINT32 mNumSamplerStates;
  84. GpuParamBlock** mParamBlocks;
  85. GpuParamBlockBufferPtr* mParamBlockBuffers;
  86. HTexture* mTextures;
  87. HSamplerState* mSamplerStates;
  88. mutable Map<String, GpuParamFloat>::type mFloatParams;
  89. mutable Map<String, GpuParamVec2>::type mVec2Params;
  90. mutable Map<String, GpuParamVec3>::type mVec3Params;
  91. mutable Map<String, GpuParamVec4>::type mVec4Params;
  92. mutable Map<String, GpuParamMat3>::type mMat3Params;
  93. mutable Map<String, GpuParamMat4>::type mMat4Params;
  94. mutable Map<String, GpuParamStruct>::type mStructParams;
  95. mutable Map<String, GpuParamTexture>::type mTextureParams;
  96. mutable Map<String, GpuParamSampState>::type mSampStateParams;
  97. };
  98. }