CmGpuParams.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. namespace CamelotFramework
  4. {
  5. class CM_EXPORT GpuParams
  6. {
  7. public:
  8. GpuParams(GpuParamDesc& paramDesc);
  9. ~GpuParams();
  10. GpuParamBlockBufferPtr getParamBlockBuffer(UINT32 slot) const;
  11. GpuParamBlockBufferPtr getParamBlockBuffer(const String& name) const;
  12. void setParamBlockBuffer(UINT32 slot, GpuParamBlockBufferPtr paramBlockBuffer);
  13. void setParamBlockBuffer(const String& name, 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. void setParam(const String& name, float value, UINT32 arrayIndex = 0);
  21. void setParam(const String& name, int value, UINT32 arrayIndex = 0);
  22. void setParam(const String& name, bool value, UINT32 arrayIndex = 0);
  23. void setParam(const String& name, const Vector4& vec, UINT32 arrayIndex = 0);
  24. void setParam(const String& name, const Vector3& vec, UINT32 arrayIndex = 0);
  25. void setParam(const String& name, const Vector2& vec, UINT32 arrayIndex = 0);
  26. void setParam(const String& name, const Matrix4& mat, UINT32 arrayIndex = 0);
  27. void setParam(const String& name, const Matrix3& mat, UINT32 arrayIndex = 0);
  28. void setParam(const String& name, const Color& color, UINT32 arrayIndex = 0);
  29. /**
  30. * @brief Sets a parameter.
  31. *
  32. * @param name Name of the parameter.
  33. * @param value Parameter data.
  34. * @param size Size of the provided data. It can be exact size or lower than the exact size of the wanted field.
  35. * If it's lower unused bytes will be set to 0.
  36. * @param arrayIndex (optional) zero-based index of the array.
  37. */
  38. void setParam(const String& name, const void* value, UINT32 sizeBytes, UINT32 arrayIndex = 0);
  39. void setTexture(const String& name, const HTexture& val);
  40. HTexture getTexture(UINT32 slot);
  41. void setSamplerState(const String& name, const HSamplerState& val);
  42. HSamplerState getSamplerState(UINT32 slot);
  43. void setTransposeMatrices(bool transpose) { mTransposeMatrices = transpose; }
  44. /**
  45. * @brief Updates all used hardware parameter buffers. Should ONLY be called from core thread.
  46. */
  47. void updateHardwareBuffers();
  48. /**
  49. * @brief Creates the copy of this object in a special way. Should only be called
  50. * internally by core thread accessor when passing gpu params to the core thread.
  51. */
  52. static BindableGpuParams createBindableCopy(GpuParamsPtr params);
  53. /**
  54. * @brief Needs to be called on any copy created with "createBindableCopy" before the object is deleted.
  55. */
  56. static void releaseBindableCopy(BindableGpuParams& bindableParams);
  57. private:
  58. GpuParamDesc& mParamDesc;
  59. bool mTransposeMatrices;
  60. GpuParamDataDesc* getParamDesc(const String& name) const;
  61. Vector<GpuParamBlock*>::type mParamBlocks;
  62. Vector<GpuParamBlockBufferPtr>::type mParamBlockBuffers;
  63. Vector<HTexture>::type mTextures;
  64. Vector<HSamplerState>::type mSamplerStates;
  65. };
  66. /**
  67. * @brief Specialized class for binding GPU parameters to the render system. You should not
  68. * handle this class manually.
  69. *
  70. * @note Upon assignment this class transfers ownership of its data. Internal data
  71. * is destroyed when last assigned instance goes out of scope.
  72. * (In short, you should never have more than one active copy of an instance of this class)
  73. */
  74. class CM_EXPORT BindableGpuParams
  75. {
  76. public:
  77. BindableGpuParams(const BindableGpuParams& source);
  78. ~BindableGpuParams();
  79. GpuParams& getParams() const { return *mParams; }
  80. private:
  81. friend class GpuParams;
  82. BindableGpuParams(GpuParams* params);
  83. GpuParams *mParams;
  84. mutable bool mIsDataOwner;
  85. };
  86. }