ShaderProgram.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "GPUObject.h"
  25. #include "GraphicsDefs.h"
  26. #include "Resource.h"
  27. //
  28. // Urho3D Engine
  29. // Copyright (c) 2008-2011 Lasse Öörni
  30. //
  31. // Permission is hereby granted, free of charge, to any person obtaining a copy
  32. // of this software and associated documentation files (the "Software"), to deal
  33. // in the Software without restriction, including without limitation the rights
  34. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  35. // copies of the Software, and to permit persons to whom the Software is
  36. // furnished to do so, subject to the following conditions:
  37. //
  38. // The above copyright notice and this permission notice shall be included in
  39. // all copies or substantial portions of the Software.
  40. //
  41. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  42. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  43. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  44. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  45. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  46. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  47. // THE SOFTWARE.
  48. //
  49. #pragma once
  50. #include "GPUObject.h"
  51. #include "GraphicsDefs.h"
  52. #include "RefCounted.h"
  53. #include "SharedArrayPtr.h"
  54. class Shader;
  55. /// Shader program on the GPU
  56. class ShaderProgram : public RefCounted, public GPUObject
  57. {
  58. OBJECT(ShaderProgram);
  59. public:
  60. /// Construct
  61. ShaderProgram(Shader* shader, ShaderType type, bool isSM3);
  62. /// Destruct
  63. virtual ~ShaderProgram();
  64. /// Create the shader program. Return true if successful
  65. bool Create();
  66. /// Release shader
  67. virtual void Release();
  68. /// Set name
  69. void SetName(const String& name);
  70. /// Set bytecode
  71. void SetByteCode(const SharedArrayPtr<unsigned char>& byteCode);
  72. /// Set to use a parameter
  73. void SetUseParameter(ShaderParameter param, bool enable);
  74. /// Set to use a texture unit
  75. void SetUseTextureUnit(TextureUnit unit, bool enable);
  76. /// Clear parameter and texture unit use flags
  77. void ClearParameters();
  78. /// Return parent shader
  79. Shader* GetShader() const;
  80. /// Return shader type
  81. ShaderType GetShaderType() const { return shaderType_; }
  82. /// Return variation name
  83. const String& GetName() const { return name_; }
  84. /// Return whether requires Shader Model 3
  85. bool IsSM3() const { return isSM3_; }
  86. /// Return whether uses a specific shader parameter
  87. bool HasParameter(ShaderParameter parameter) const { return useParameter_[parameter]; }
  88. /// Return whether uses a texture unit (only for pixel shaders)
  89. bool HasTextureUnit(TextureUnit unit) const { return useTextureUnit_[unit]; }
  90. /// Check whether a shader parameter needs update
  91. bool NeedParameterUpdate(ShaderParameter parameter, const void* source);
  92. private:
  93. /// Parent shader
  94. WeakPtr<Shader> shader_;
  95. /// Shader bytecode
  96. SharedArrayPtr<unsigned char> byteCode_;
  97. /// Shader type
  98. ShaderType shaderType_;
  99. /// Variation name
  100. String name_;
  101. /// Shader Model 3 flag
  102. bool isSM3_;
  103. /// Parameter use flags
  104. bool useParameter_[MAX_SHADER_PARAMETERS];
  105. /// Texture unit use flags
  106. bool useTextureUnit_[MAX_TEXTURE_UNITS];
  107. };