RenderPath.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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_RENDERTARGETDIVISOR,
  53. SIZE_VIEWPORTDIVISOR
  54. };
  55. /// Rendertarget definition.
  56. struct RenderTargetInfo
  57. {
  58. /// Construct.
  59. RenderTargetInfo() :
  60. size_(IntVector2::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. /// Size.
  77. IntVector2 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. useScissor_(false),
  100. vertexLights_(false)
  101. {
  102. }
  103. /// Read from an XML element.
  104. void Load(const XMLElement& element);
  105. /// Set a texture resource name. Can also refer to a rendertarget defined in the rendering path.
  106. void SetTextureName(TextureUnit unit, const String& name);
  107. /// Set a shader parameter.
  108. void SetShaderParameter(const String& name, const Variant& value);
  109. /// Remove a shader parameter.
  110. void RemoveShaderParameter(const String& name);
  111. /// Set number of output rendertargets.
  112. void SetNumOutputs(unsigned num);
  113. /// Set output rendertarget name.
  114. void SetOutputName(unsigned index, const String& name);
  115. /// Return texture resource name.
  116. const String& GetTextureName(TextureUnit unit) const;
  117. /// Return shader parameter.
  118. const Variant& GetShaderParameter(const String& name) const;
  119. /// Return number of output rendertargets.
  120. unsigned GetNumOutputs() const { return outputNames_.Size(); }
  121. /// Return output rendertarget name.
  122. const String& GetOutputName(unsigned index) const;
  123. /// Tag name.
  124. String tag_;
  125. /// Command type.
  126. RenderCommandType type_;
  127. /// Sorting mode.
  128. RenderCommandSortMode sortMode_;
  129. /// Scene pass name.
  130. String pass_;
  131. /// Command/pass metadata.
  132. String metadata_;
  133. /// Vertex shader name.
  134. String vertexShaderName_;
  135. /// Pixel shader name.
  136. String pixelShaderName_;
  137. /// Vertex shader defines.
  138. String vertexShaderDefines_;
  139. /// Pixel shader defines.
  140. String pixelShaderDefines_;
  141. /// Textures.
  142. String textureNames_[MAX_TEXTURE_UNITS];
  143. /// %Shader parameters.
  144. HashMap<StringHash, Variant> shaderParameters_;
  145. /// Output rendertarget names.
  146. Vector<String> outputNames_;
  147. /// Clear flags.
  148. unsigned clearFlags_;
  149. /// Clear color.
  150. Color clearColor_;
  151. /// Clear depth.
  152. float clearDepth_;
  153. /// Clear stencil value.
  154. unsigned clearStencil_;
  155. /// Enabled flag.
  156. bool enabled_;
  157. /// Use fog color for clearing.
  158. bool useFogColor_;
  159. /// Mark to stencil flag.
  160. bool markToStencil_;
  161. /// Use lit base pass optimization for forward per-pixel lights.
  162. bool useLitBase_;
  163. /// Scissor optimization flag.
  164. bool useScissor_;
  165. /// Vertex lights flag.
  166. bool vertexLights_;
  167. };
  168. /// Rendering path definition.
  169. class URHO3D_API RenderPath : public RefCounted
  170. {
  171. public:
  172. /// Construct.
  173. RenderPath();
  174. /// Destruct.
  175. ~RenderPath();
  176. /// Clone the rendering path.
  177. SharedPtr<RenderPath> Clone();
  178. /// Clear existing data and load from an XML file. Return true if successful.
  179. bool Load(XMLFile* file);
  180. /// Append data from an XML file. Return true if successful.
  181. bool Append(XMLFile* file);
  182. /// Enable/disable commands and rendertargets by tag.
  183. void SetEnabled(const String& tag, bool active);
  184. /// Toggle enabled state of commands and rendertargets by tag.
  185. void ToggleEnabled(const String& tag);
  186. /// Assign rendertarget at index.
  187. void SetRenderTarget(unsigned index, const RenderTargetInfo& info);
  188. /// Add a rendertarget.
  189. void AddRenderTarget(const RenderTargetInfo& info);
  190. /// Remove a rendertarget by index.
  191. void RemoveRenderTarget(unsigned index);
  192. /// Remove a rendertarget by name.
  193. void RemoveRenderTarget(const String& name);
  194. /// Remove rendertargets by tag name.
  195. void RemoveRenderTargets(const String& tag);
  196. /// Assign command at index.
  197. void SetCommand(unsigned index, const RenderPathCommand& command);
  198. /// Add a command to the end of the list.
  199. void AddCommand(const RenderPathCommand& command);
  200. /// Insert a command at a position.
  201. void InsertCommand(unsigned index, const RenderPathCommand& command);
  202. /// Remove a command by index.
  203. void RemoveCommand(unsigned index);
  204. /// Remove commands by tag name.
  205. void RemoveCommands(const String& tag);
  206. /// Set a shader parameter in all commands that define it.
  207. void SetShaderParameter(const String& name, const Variant& value);
  208. /// Return number of rendertargets.
  209. unsigned GetNumRenderTargets() const { return renderTargets_.Size(); }
  210. /// Return number of commands.
  211. unsigned GetNumCommands() const { return commands_.Size(); }
  212. /// Return a shader parameter (first appearance in any command.)
  213. const Variant& GetShaderParameter(const String& name) const;
  214. /// Rendertargets.
  215. Vector<RenderTargetInfo> renderTargets_;
  216. /// Rendering commands.
  217. Vector<RenderPathCommand> commands_;
  218. };
  219. }