RenderPath.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 Load(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 Load(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 parameter.
  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 name.
  124. String pass_;
  125. /// Command/pass metadata.
  126. String metadata_;
  127. /// Clear flags.
  128. unsigned clearFlags_;
  129. /// Clear color.
  130. Color clearColor_;
  131. /// Clear depth.
  132. float clearDepth_;
  133. /// Clear stencil value.
  134. unsigned clearStencil_;
  135. /// Enabled flag.
  136. bool enabled_;
  137. /// Use fog color for clearing.
  138. bool useFogColor_;
  139. /// Mark to stencil flag.
  140. bool markToStencil_;
  141. /// Use lit base pass optimization for forward per-pixel lights.
  142. bool useLitBase_;
  143. /// Scissor optimization flag.
  144. bool useScissor_;
  145. /// Vertex lights flag.
  146. bool vertexLights_;
  147. /// Vertex shader name.
  148. String vertexShaderName_;
  149. /// Pixel shader name.
  150. String pixelShaderName_;
  151. /// Textures.
  152. String textureNames_[MAX_TEXTURE_UNITS];
  153. /// %Shader parameters.
  154. HashMap<StringHash, Vector4> shaderParameters_;
  155. /// Output rendertarget names.
  156. Vector<String> outputNames_;
  157. };
  158. /// Rendering path definition.
  159. class RenderPath : public RefCounted
  160. {
  161. public:
  162. /// Construct.
  163. RenderPath();
  164. /// Destruct.
  165. ~RenderPath();
  166. /// Clone the rendering path.
  167. SharedPtr<RenderPath> Clone();
  168. /// Clear existing data and load from an XML file. Return true if successful.
  169. bool Load(XMLFile* file);
  170. /// Append data from an XML file. Return true if successful.
  171. bool Append(XMLFile* file);
  172. /// Enable/disable commands and rendertargets by tag.
  173. void SetEnabled(const String& tag, bool active);
  174. /// Toggle enabled state of commands and rendertargets by tag.
  175. void ToggleEnabled(const String& tag);
  176. /// Assign rendertarget at index.
  177. void SetRenderTarget(unsigned index, const RenderTargetInfo& info);
  178. /// Add a rendertarget.
  179. void AddRenderTarget(const RenderTargetInfo& info);
  180. /// Remove a rendertarget by index.
  181. void RemoveRenderTarget(unsigned index);
  182. /// Remove a rendertarget by name.
  183. void RemoveRenderTarget(const String& name);
  184. /// Remove rendertargets by tag name.
  185. void RemoveRenderTargets(const String& tag);
  186. /// Assign command at index.
  187. void SetCommand(unsigned index, const RenderPathCommand& command);
  188. /// Add a command to the end of the list.
  189. void AddCommand(const RenderPathCommand& command);
  190. /// Insert a command at a position.
  191. void InsertCommand(unsigned index, const RenderPathCommand& command);
  192. /// Remove a command by index.
  193. void RemoveCommand(unsigned index);
  194. /// Remove commands by tag name.
  195. void RemoveCommands(const String& tag);
  196. /// Set a shader parameter in all commands that define it.
  197. void SetShaderParameter(const String& name, const Vector4& value);
  198. /// Return number of rendertargets.
  199. unsigned GetNumRenderTargets() const { return renderTargets_.Size(); }
  200. /// Return number of commands.
  201. unsigned GetNumCommands() const { return commands_.Size(); }
  202. /// Return a shader parameter (first appearance in any command.)
  203. const Vector4& GetShaderParameter(const String& name) const;
  204. /// Rendertargets.
  205. Vector<RenderTargetInfo> renderTargets_;
  206. /// Rendering commands.
  207. Vector<RenderPathCommand> commands_;
  208. };
  209. }