Technique.h 4.7 KB

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