shaderMaterialParameters.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SHADERMATERIALPARAMETERS_H_
  23. #define _SHADERMATERIALPARAMETERS_H_
  24. #ifndef _MATERIALPARAMETERS_H_
  25. #include "materials/materialParameters.h"
  26. #endif
  27. #ifndef _GFXSHADER_H_
  28. #include "gfx/gfxShader.h"
  29. #endif
  30. class ShaderMaterialParameterHandle : public MaterialParameterHandle
  31. {
  32. friend class ShaderMaterialParameters;
  33. public:
  34. virtual ~ShaderMaterialParameterHandle();
  35. ShaderMaterialParameterHandle(const String& name);
  36. ShaderMaterialParameterHandle(const String& name, Vector<GFXShader*>& shaders);
  37. virtual const String& getName() const { return mName; }
  38. virtual S32 getSamplerRegister( U32 pass ) const;
  39. // NOTE: We always return true here instead of querying the
  40. // children... often there is only one element, so lets just
  41. // hit the loop once on the set.
  42. virtual bool isValid() const { return true; };
  43. protected:
  44. Vector< GFXShaderConstHandle* > mHandles;
  45. String mName;
  46. };
  47. // This is the union of all of the shaders contained in a material
  48. class ShaderMaterialParameters : public MaterialParameters
  49. {
  50. public:
  51. ShaderMaterialParameters();
  52. virtual ~ShaderMaterialParameters();
  53. void setBuffers(Vector<GFXShaderConstDesc>& constDesc, Vector<GFXShaderConstBufferRef>& buffers);
  54. GFXShaderConstBuffer* getBuffer(U32 i) { return mBuffers[i]; }
  55. ///
  56. /// MaterialParameter interface
  57. ///
  58. /// Returns the material parameter handle for name.
  59. virtual void set(MaterialParameterHandle* handle, const F32 f);
  60. virtual void set(MaterialParameterHandle* handle, const Point2F& fv);
  61. virtual void set(MaterialParameterHandle* handle, const Point3F& fv);
  62. virtual void set(MaterialParameterHandle* handle, const Point4F& fv);
  63. virtual void set(MaterialParameterHandle* handle, const PlaneF& fv);
  64. virtual void set(MaterialParameterHandle* handle, const LinearColorF& fv);
  65. virtual void set(MaterialParameterHandle* handle, const S32 f);
  66. virtual void set(MaterialParameterHandle* handle, const Point2I& fv);
  67. virtual void set(MaterialParameterHandle* handle, const Point3I& fv);
  68. virtual void set(MaterialParameterHandle* handle, const Point4I& fv);
  69. virtual void set(MaterialParameterHandle* handle, const AlignedArray<F32>& fv);
  70. virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point2F>& fv);
  71. virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point3F>& fv);
  72. virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point4F>& fv);
  73. virtual void set(MaterialParameterHandle* handle, const AlignedArray<S32>& fv);
  74. virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point2I>& fv);
  75. virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point3I>& fv);
  76. virtual void set(MaterialParameterHandle* handle, const AlignedArray<Point4I>& fv);
  77. virtual void set(MaterialParameterHandle* handle, const MatrixF& mat, const GFXShaderConstType matrixType = GFXSCT_Float4x4);
  78. virtual void set(MaterialParameterHandle* handle, const MatrixF* mat, const U32 arraySize, const GFXShaderConstType matrixType = GFXSCT_Float4x4);
  79. virtual U32 getAlignmentValue(const GFXShaderConstType constType);
  80. private:
  81. Vector<GFXShaderConstBufferRef> mBuffers;
  82. void releaseBuffers();
  83. };
  84. #endif