Technique.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "GraphicsDefs.h"
  24. #include "Resource.h"
  25. namespace Urho3D
  26. {
  27. class ShaderVariation;
  28. /// Lighting mode of a pass.
  29. enum PassLightingMode
  30. {
  31. LIGHTING_UNLIT,
  32. LIGHTING_PERVERTEX,
  33. LIGHTING_PERPIXEL
  34. };
  35. /// %Material rendering pass, which defines shaders and render state.
  36. class Pass : public RefCounted
  37. {
  38. public:
  39. /// Construct.
  40. Pass(StringHash type);
  41. /// Destruct.
  42. ~Pass();
  43. /// Set blend mode.
  44. void SetBlendMode(BlendMode mode);
  45. /// Set depth compare mode.
  46. void SetDepthTestMode(CompareMode mode);
  47. /// Set pass lighting mode, affects what shader variations will be attempted to be loaded.
  48. void SetLightingMode(PassLightingMode mode);
  49. /// Set depth write on/off.
  50. void SetDepthWrite(bool enable);
  51. /// Set alpha masking hint. Completely opaque draw calls will be performed before alpha masked.
  52. void SetAlphaMask(bool enable);
  53. /// Set vertex shader name.
  54. void SetVertexShader(const String& name);
  55. /// Set pixel shader name.
  56. void SetPixelShader(const String& name);
  57. /// Reset shader pointers.
  58. void ReleaseShaders();
  59. /// Mark shaders loaded this frame.
  60. void MarkShadersLoaded(unsigned frameNumber);
  61. /// Return pass type.
  62. const StringHash& GetType() const { return type_; }
  63. /// Return blend mode.
  64. BlendMode GetBlendMode() const { return blendMode_; }
  65. /// Return depth compare mode.
  66. CompareMode GetDepthTestMode() const { return depthTestMode_; }
  67. /// Return pass lighting mode.
  68. PassLightingMode GetLightingMode() const { return lightingMode_; }
  69. /// Return last shaders loaded frame number.
  70. unsigned GetShadersLoadedFrameNumber() const { return shadersLoadedFrameNumber_; }
  71. /// Return depth write mode.
  72. bool GetDepthWrite() const { return depthWrite_; }
  73. /// Return alpha masking hint.
  74. bool GetAlphaMask() const { return alphaMask_; }
  75. /// Return vertex shader name.
  76. const String& GetVertexShader() const { return vertexShaderName_; }
  77. /// Return pixel shader name.
  78. const String& GetPixelShader() const { return pixelShaderName_; }
  79. /// Return vertex shaders.
  80. Vector<SharedPtr<ShaderVariation> >& GetVertexShaders() { return vertexShaders_; }
  81. /// Return pixel shaders.
  82. Vector<SharedPtr<ShaderVariation> >& GetPixelShaders() { return pixelShaders_; }
  83. private:
  84. /// Pass type.
  85. StringHash type_;
  86. /// Blend mode.
  87. BlendMode blendMode_;
  88. /// Depth compare mode.
  89. CompareMode depthTestMode_;
  90. /// Lighting mode.
  91. PassLightingMode lightingMode_;
  92. /// Last shaders loaded frame number.
  93. unsigned shadersLoadedFrameNumber_;
  94. /// Depth write mode.
  95. bool depthWrite_;
  96. /// Alpha masking hint.
  97. bool alphaMask_;
  98. /// Vertex shader name.
  99. String vertexShaderName_;
  100. /// Pixel shader name.
  101. String pixelShaderName_;
  102. /// Vertex shaders.
  103. Vector<SharedPtr<ShaderVariation> > vertexShaders_;
  104. /// Pixel shaders.
  105. Vector<SharedPtr<ShaderVariation> > pixelShaders_;
  106. };
  107. /// %Material technique. Consists of several passes.
  108. class Technique : public Resource
  109. {
  110. OBJECT(Technique);
  111. friend class Renderer;
  112. public:
  113. /// Construct.
  114. Technique(Context* context);
  115. /// Destruct.
  116. ~Technique();
  117. /// Register object factory.
  118. static void RegisterObject(Context* context);
  119. /// Load resource. Return true if successful.
  120. virtual bool Load(Deserializer& source);
  121. /// Set whether requires %Shader %Model 3.
  122. void SetIsSM3(bool enable);
  123. /// Create a new pass.
  124. Pass* CreatePass(StringHash type);
  125. /// Remove a pass.
  126. void RemovePass(StringHash type);
  127. /// Reset shader pointers in all passes.
  128. void ReleaseShaders();
  129. /// Return all passes.
  130. const HashMap<StringHash, SharedPtr<Pass> >& GetPasses() const { return passes_; }
  131. /// Return whether has a pass.
  132. bool HasPass(StringHash type) const { return passes_.Contains(type); }
  133. /// Return a pass, or null if not found.
  134. Pass* GetPass(StringHash type) const;
  135. /// Return whether requires %Shader %Model 3.
  136. bool IsSM3() const { return isSM3_; }
  137. private:
  138. /// Require %Shader %Model 3 flag.
  139. bool isSM3_;
  140. /// Passes.
  141. HashMap<StringHash, SharedPtr<Pass> > passes_;
  142. };
  143. }