RenderPath.h 7.9 KB

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