RenderPath.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 "RefCounted.h"
  25. namespace Urho3D
  26. {
  27. class XMLElement;
  28. class XMLFile;
  29. /// Rendering path command types.
  30. enum RenderCommandType
  31. {
  32. CMD_NONE = 0,
  33. CMD_CLEAR,
  34. CMD_SCENEPASS,
  35. CMD_QUAD,
  36. CMD_FORWARDLIGHTS,
  37. CMD_LIGHTVOLUMES
  38. };
  39. /// Rendering path sorting modes.
  40. enum RenderCommandSortMode
  41. {
  42. SORT_FRONTTOBACK = 0,
  43. SORT_BACKTOFRONT
  44. };
  45. /// Rendertarget size mode.
  46. enum RenderTargetSizeMode
  47. {
  48. SIZE_ABSOLUTE = 0,
  49. SIZE_RENDERTARGETDIVISOR,
  50. SIZE_VIEWPORTDIVISOR
  51. };
  52. /// Rendertarget definition.
  53. struct RenderTargetInfo
  54. {
  55. /// Construct.
  56. RenderTargetInfo() :
  57. size_(IntVector2::ZERO),
  58. sizeMode_(SIZE_ABSOLUTE),
  59. active_(true),
  60. filtered_(false)
  61. {
  62. }
  63. /// Read from an XML element.
  64. void LoadParameters(const XMLElement& element);
  65. /// Name.
  66. String name_;
  67. /// Tag name.
  68. String tag_;
  69. /// Texture format.
  70. unsigned format_;
  71. /// Size.
  72. IntVector2 size_;
  73. /// Size mode.
  74. RenderTargetSizeMode sizeMode_;
  75. /// Active flag.
  76. bool active_;
  77. /// Filtering flag.
  78. bool filtered_;
  79. };
  80. /// Rendering path command.
  81. struct RenderPathCommand
  82. {
  83. /// Construct.
  84. RenderPathCommand() :
  85. clearFlags_(0),
  86. active_(true),
  87. useFogColor_(false),
  88. markToStencil_(false),
  89. useLitBase_(true),
  90. useScissor_(false),
  91. vertexLights_(false)
  92. {
  93. }
  94. /// Read from an XML element.
  95. void LoadParameters(const XMLElement& element);
  96. /// Set a texture resource name. Can also refer to a rendertarget defined in the rendering path.
  97. void SetTextureName(TextureUnit unit, const String& name);
  98. /// Set a shader parameter.
  99. void SetShaderParameter(const String& name, const Vector4& value);
  100. /// Remove a shader parameter.
  101. void RemoveShaderParameter(const String& name);
  102. /// Set number of output rendertargets.
  103. void SetNumOutputs(unsigned num);
  104. /// Set output rendertarget name.
  105. void SetOutputName(unsigned index, const String& name);
  106. /// Return texture resource name.
  107. const String& GetTextureName(TextureUnit unit) const;
  108. /// Return shader paramter.
  109. const Vector4& GetShaderParameter(const String& name) const;
  110. /// Return number of output rendertargets.
  111. unsigned GetNumOutputs() const { return outputNames_.Size(); }
  112. /// Return output rendertarget name.
  113. const String& GetOutputName(unsigned index) const;
  114. /// Tag name.
  115. String tag_;
  116. /// Command type.
  117. RenderCommandType type_;
  118. /// Sorting mode.
  119. RenderCommandSortMode sortMode_;
  120. /// Scene pass hash.
  121. StringHash pass_;
  122. /// Clear flags.
  123. unsigned clearFlags_;
  124. /// Clear color.
  125. Color clearColor_;
  126. /// Clear depth.
  127. float clearDepth_;
  128. /// Clear stencil value.
  129. unsigned clearStencil_;
  130. /// Active flag.
  131. bool active_;
  132. /// Use fog color for clearing.
  133. bool useFogColor_;
  134. /// Mark to stencil flag.
  135. bool markToStencil_;
  136. /// Use lit base pass optimization for forward per-pixel lights.
  137. bool useLitBase_;
  138. /// Scissor optimization flag.
  139. bool useScissor_;
  140. /// Vertex lights flag.
  141. bool vertexLights_;
  142. /// Vertex shader name.
  143. String vertexShaderName_;
  144. /// Pixel shader name.
  145. String pixelShaderName_;
  146. /// Textures.
  147. String textureNames_[MAX_TEXTURE_UNITS];
  148. /// %Shader parameters.
  149. HashMap<StringHash, Vector4> shaderParameters_;
  150. /// Output rendertarget names.
  151. Vector<String> outputNames_;
  152. };
  153. /// Rendering path definition.
  154. class RenderPath : public RefCounted
  155. {
  156. public:
  157. /// Construct.
  158. RenderPath();
  159. /// Destruct.
  160. ~RenderPath();
  161. /// Clone the rendering path.
  162. SharedPtr<RenderPath> Clone();
  163. /// Read from an XML file. Return true if successful.
  164. bool LoadParameters(XMLFile* file);
  165. /// Append data from an XML file. Return true if successful.
  166. bool Append(XMLFile* file);
  167. /// Activate/inactivate commands and rendertargets by tag.
  168. void SetActive(const String& tag, bool active);
  169. /// Toggle activation of commands and rendertargets by tag.
  170. void ToggleActive(const String& tag);
  171. /// Assign rendertarget at index.
  172. void SetRenderTarget(unsigned index, const RenderTargetInfo& info);
  173. /// Add a rendertarget.
  174. void AddRenderTarget(const RenderTargetInfo& info);
  175. /// Remove a rendertarget by index.
  176. void RemoveRenderTarget(unsigned index);
  177. /// Remove a rendertarget by name.
  178. void RemoveRenderTarget(const String& name);
  179. /// Remove rendertargets by tag name.
  180. void RemoveRenderTargets(const String& tag);
  181. /// Assign command at index.
  182. void SetCommand(unsigned index, const RenderPathCommand& command);
  183. /// Add a command to the end of the list.
  184. void AddCommand(const RenderPathCommand& command);
  185. /// Insert a command at a position.
  186. void InsertCommand(unsigned index, const RenderPathCommand& command);
  187. /// Remove a command by index.
  188. void RemoveCommand(unsigned index);
  189. /// Remove commands by tag name.
  190. void RemoveCommands(const String& tag);
  191. /// Set a shader parameter in all commands that define it.
  192. void SetShaderParameter(const String& name, const Vector4& value);
  193. /// Return number of rendertargets.
  194. unsigned GetNumRenderTargets() const { return renderTargets_.Size(); }
  195. /// Return number of commands.
  196. unsigned GetNumCommands() const { return commands_.Size(); }
  197. /// Return a shader parameter (first appearance in any command.)
  198. const Vector4& GetShaderParameter(const String& name) const;
  199. /// Rendertargets.
  200. Vector<RenderTargetInfo> renderTargets_;
  201. /// Rendering commands.
  202. Vector<RenderPathCommand> commands_;
  203. };
  204. }