RenderPath.h 7.0 KB

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