2
0

Technique.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 "GraphicsDefs.h"
  25. #include "Resource.h"
  26. class ShaderVariation;
  27. /// %Material rendering pass, which defines shaders and render state.
  28. class Pass : public RefCounted
  29. {
  30. public:
  31. /// Construct.
  32. Pass(PassType type);
  33. /// Destruct.
  34. ~Pass();
  35. /// %Set alpha test on/off.
  36. void SetAlphaTest(bool enable);
  37. /// %Set blend mode.
  38. void SetBlendMode(BlendMode mode);
  39. /// %Set depth compare mode.
  40. void SetDepthTestMode(CompareMode mode);
  41. /// %Set depth write on/off.
  42. void SetDepthWrite(bool enable);
  43. /// %Set vertex shader name.
  44. void SetVertexShader(const String& name);
  45. /// %Set pixel shader name.
  46. void SetPixelShader(const String& name);
  47. /// Reset shader pointers.
  48. void ReleaseShaders();
  49. /// Return pass type.
  50. PassType GetType() const { return type_; }
  51. /// Return alpha test mode.
  52. bool GetAlphaTest() const { return alphaTest_; }
  53. /// Return blend mode.
  54. BlendMode GetBlendMode() const { return blendMode_; }
  55. /// Return depth compare mode.
  56. CompareMode GetDepthTestMode() const { return depthTestMode_; }
  57. /// Return depth write mode.
  58. bool GetDepthWrite() const { return depthWrite_; }
  59. /// Return vertex shader name.
  60. const String& GetVertexShaderName() const { return vertexShaderName_; }
  61. /// Return pixel shader name.
  62. const String& GetPixelShaderName() const { return pixelShaderName_; }
  63. /// Return vertex shaders.
  64. Vector<SharedPtr<ShaderVariation> >& GetVertexShaders() { return vertexShaders_; }
  65. /// Return pixel shaders.
  66. Vector<SharedPtr<ShaderVariation> >& GetPixelShaders() { return pixelShaders_; }
  67. private:
  68. /// Pass type.
  69. PassType type_;
  70. /// Alpha test mode.
  71. bool alphaTest_;
  72. /// Blend mode.
  73. BlendMode blendMode_;
  74. /// Depth compare mode.
  75. CompareMode depthTestMode_;
  76. /// Depth write mode.
  77. bool depthWrite_;
  78. /// Vertex shader name.
  79. String vertexShaderName_;
  80. /// Pixel shader name.
  81. String pixelShaderName_;
  82. /// Vertex shaders.
  83. Vector<SharedPtr<ShaderVariation> > vertexShaders_;
  84. /// Pixel shaders.
  85. Vector<SharedPtr<ShaderVariation> > pixelShaders_;
  86. };
  87. /// %Material technique. Consists of several passes.
  88. class Technique : public Resource
  89. {
  90. OBJECT(Technique);
  91. friend class Renderer;
  92. public:
  93. /// Construct.
  94. Technique(Context* context);
  95. /// Destruct.
  96. ~Technique();
  97. /// Register object factory.
  98. static void RegisterObject(Context* context);
  99. /// Load resource. Return true if successful.
  100. virtual bool Load(Deserializer& source);
  101. /// %Set whether requires Shader Model 3.
  102. void SetIsSM3(bool enable);
  103. /// Create a new pass.
  104. Pass* CreatePass(PassType pass);
  105. /// Remove a pass.
  106. void RemovePass(PassType pass);
  107. /// Reset shader pointers in all passes.
  108. void ReleaseShaders();
  109. /// Mark shaders loaded this frame
  110. void MarkShadersLoaded(unsigned frameNumber);
  111. /// Return whether has a pass.
  112. bool HasPass(PassType pass) const { return passes_[pass] != 0; }
  113. /// Return a pass.
  114. Pass* GetPass(PassType pass) const { return passes_[pass]; }
  115. /// Return whether requires Shader Model 3.
  116. bool IsSM3() const { return isSM3_; }
  117. /// Return last shaders loaded frame number.
  118. unsigned GetShadersLoadedFrameNumber() const { return shadersLoadedFrameNumber_; }
  119. /// Return name for pass.
  120. static const String& GetPassName(PassType pass);
  121. private:
  122. /// Require Shader Model 3 flag.
  123. bool isSM3_;
  124. /// Last shaders loaded frame number.
  125. unsigned shadersLoadedFrameNumber_;
  126. /// Passes.
  127. SharedPtr<Pass> passes_[MAX_PASSES];
  128. };