RenderPath.h 7.4 KB

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