RenderPath.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. //
  2. // Copyright (c) 2008-2017 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 "../Container/Ptr.h"
  24. #include "../Container/RefCounted.h"
  25. #include "../Graphics/GraphicsDefs.h"
  26. #include "../Math/Color.h"
  27. #include "../Math/Vector4.h"
  28. namespace Atomic
  29. {
  30. class XMLElement;
  31. class XMLFile;
  32. // ATOMIC BEGIN
  33. class ScriptRenderPathCommand;
  34. // ATOMIC END
  35. /// Rendering path command types.
  36. enum RenderCommandType
  37. {
  38. CMD_NONE = 0,
  39. CMD_CLEAR,
  40. CMD_SCENEPASS,
  41. CMD_QUAD,
  42. CMD_FORWARDLIGHTS,
  43. CMD_LIGHTVOLUMES,
  44. CMD_RENDERUI,
  45. CMD_SENDEVENT
  46. };
  47. /// Rendering path sorting modes.
  48. enum RenderCommandSortMode
  49. {
  50. SORT_FRONTTOBACK = 0,
  51. SORT_BACKTOFRONT
  52. };
  53. /// Rendertarget size mode.
  54. enum RenderTargetSizeMode
  55. {
  56. SIZE_ABSOLUTE = 0,
  57. SIZE_VIEWPORTDIVISOR,
  58. SIZE_VIEWPORTMULTIPLIER
  59. };
  60. /// Rendertarget definition.
  61. struct ATOMIC_API RenderTargetInfo
  62. {
  63. /// Construct.
  64. RenderTargetInfo() :
  65. size_(Vector2::ZERO),
  66. sizeMode_(SIZE_ABSOLUTE),
  67. multiSample_(1),
  68. autoResolve_(true),
  69. enabled_(true),
  70. cubemap_(false),
  71. filtered_(false),
  72. sRGB_(false),
  73. persistent_(false)
  74. {
  75. }
  76. /// Read from an XML element.
  77. void Load(const XMLElement& element);
  78. /// Name.
  79. String name_;
  80. /// Tag name.
  81. String tag_;
  82. /// Texture format.
  83. unsigned format_;
  84. /// Absolute size or multiplier.
  85. Vector2 size_;
  86. /// Size mode.
  87. RenderTargetSizeMode sizeMode_;
  88. /// Multisampling level (1 = no multisampling).
  89. int multiSample_;
  90. /// Multisampling autoresolve flag.
  91. bool autoResolve_;
  92. /// Enabled flag.
  93. bool enabled_;
  94. /// Cube map flag.
  95. bool cubemap_;
  96. /// Filtering flag.
  97. bool filtered_;
  98. /// sRGB sampling/writing mode flag.
  99. bool sRGB_;
  100. /// Should be persistent and not shared/reused between other buffers of same size.
  101. bool persistent_;
  102. };
  103. /// Rendering path command.
  104. struct ATOMIC_API RenderPathCommand
  105. {
  106. /// Construct.
  107. RenderPathCommand() :
  108. clearFlags_(0),
  109. blendMode_(BLEND_REPLACE),
  110. enabled_(true),
  111. useFogColor_(false),
  112. markToStencil_(false),
  113. useLitBase_(true),
  114. vertexLights_(false)
  115. {
  116. }
  117. /// Read from an XML element.
  118. void Load(const XMLElement& element);
  119. /// Set a texture resource name. Can also refer to a rendertarget defined in the rendering path.
  120. void SetTextureName(TextureUnit unit, const String& name);
  121. /// Set a shader parameter.
  122. void SetShaderParameter(const String& name, const Variant& value);
  123. /// Remove a shader parameter.
  124. void RemoveShaderParameter(const String& name);
  125. /// Set number of output rendertargets.
  126. void SetNumOutputs(unsigned num);
  127. /// Set output rendertarget name and face index for cube maps.
  128. void SetOutput(unsigned index, const String& name, CubeMapFace face = FACE_POSITIVE_X);
  129. /// Set output rendertarget name.
  130. void SetOutputName(unsigned index, const String& name);
  131. /// Set output rendertarget face index for cube maps.
  132. void SetOutputFace(unsigned index, CubeMapFace face);
  133. /// Set depth-stencil output name. When empty, will assign a depth-stencil buffer automatically.
  134. void SetDepthStencilName(const String& name);
  135. /// Return texture resource name.
  136. const String& GetTextureName(TextureUnit unit) const;
  137. /// Return shader parameter.
  138. const Variant& GetShaderParameter(const String& name) const;
  139. /// Return number of output rendertargets.
  140. unsigned GetNumOutputs() const { return outputs_.Size(); }
  141. /// Return output rendertarget name.
  142. const String& GetOutputName(unsigned index) const;
  143. /// Return output rendertarget face index.
  144. CubeMapFace GetOutputFace(unsigned index) const;
  145. /// Return depth-stencil output name.
  146. const String& GetDepthStencilName() const { return depthStencilName_; }
  147. /// Tag name.
  148. String tag_;
  149. /// Command type.
  150. RenderCommandType type_;
  151. /// Sorting mode.
  152. RenderCommandSortMode sortMode_;
  153. /// Scene pass name.
  154. String pass_;
  155. /// Scene pass index. Filled by View.
  156. unsigned passIndex_;
  157. /// Command/pass metadata.
  158. String metadata_;
  159. /// Vertex shader name.
  160. String vertexShaderName_;
  161. /// Pixel shader name.
  162. String pixelShaderName_;
  163. /// Vertex shader defines.
  164. String vertexShaderDefines_;
  165. /// Pixel shader defines.
  166. String pixelShaderDefines_;
  167. /// Textures.
  168. String textureNames_[MAX_TEXTURE_UNITS];
  169. /// %Shader parameters.
  170. HashMap<StringHash, Variant> shaderParameters_;
  171. /// Output rendertarget names and faces.
  172. Vector<Pair<String, CubeMapFace> > outputs_;
  173. /// Depth-stencil output name.
  174. String depthStencilName_;
  175. /// Clear flags. Affects clear command only.
  176. unsigned clearFlags_;
  177. /// Clear color. Affects clear command only.
  178. Color clearColor_;
  179. /// Clear depth. Affects clear command only.
  180. float clearDepth_;
  181. /// Clear stencil value. Affects clear command only.
  182. unsigned clearStencil_;
  183. /// Blend mode. Affects quad command only.
  184. BlendMode blendMode_;
  185. /// Enabled flag.
  186. bool enabled_;
  187. /// Use fog color for clearing.
  188. bool useFogColor_;
  189. /// Mark to stencil flag.
  190. bool markToStencil_;
  191. /// Use lit base pass optimization for forward per-pixel lights.
  192. bool useLitBase_;
  193. /// Vertex lights flag.
  194. bool vertexLights_;
  195. /// Event name.
  196. String eventName_;
  197. };
  198. /// Rendering path definition. A sequence of commands (e.g. clear screen, draw objects with specific pass) that yields the scene rendering result.
  199. class ATOMIC_API RenderPath : public RefCounted
  200. {
  201. ATOMIC_REFCOUNTED(RenderPath)
  202. public:
  203. /// Construct.
  204. RenderPath();
  205. /// Destruct.
  206. ~RenderPath();
  207. /// Clone the rendering path.
  208. SharedPtr<RenderPath> Clone();
  209. /// Clear existing data and load from an XML file. Return true if successful.
  210. bool Load(XMLFile* file);
  211. /// Append data from an XML file. Return true if successful.
  212. bool Append(XMLFile* file);
  213. /// Enable/disable commands and rendertargets by tag.
  214. void SetEnabled(const String& tag, bool active);
  215. /// Toggle enabled state of commands and rendertargets by tag.
  216. void ToggleEnabled(const String& tag);
  217. /// Assign rendertarget at index.
  218. void SetRenderTarget(unsigned index, const RenderTargetInfo& info);
  219. /// Add a rendertarget.
  220. void AddRenderTarget(const RenderTargetInfo& info);
  221. /// Remove a rendertarget by index.
  222. void RemoveRenderTarget(unsigned index);
  223. /// Remove a rendertarget by name.
  224. void RemoveRenderTarget(const String& name);
  225. /// Remove rendertargets by tag name.
  226. void RemoveRenderTargets(const String& tag);
  227. /// Assign command at index.
  228. void SetCommand(unsigned index, const RenderPathCommand& command);
  229. /// Add a command to the end of the list.
  230. void AddCommand(const RenderPathCommand& command);
  231. /// Insert a command at a position.
  232. void InsertCommand(unsigned index, const RenderPathCommand& command);
  233. /// Remove a command by index.
  234. void RemoveCommand(unsigned index);
  235. /// Remove commands by tag name.
  236. void RemoveCommands(const String& tag);
  237. /// Set a shader parameter in all commands that define it.
  238. void SetShaderParameter(const String& name, const Variant& value);
  239. /// Return number of rendertargets.
  240. unsigned GetNumRenderTargets() const { return renderTargets_.Size(); }
  241. /// Return number of commands.
  242. unsigned GetNumCommands() const { return commands_.Size(); }
  243. /// Return command at index, or null if does not exist.
  244. RenderPathCommand* GetCommand(unsigned index) { return index < commands_.Size() ? &commands_[index] : (RenderPathCommand*)0; }
  245. /// Return a shader parameter (first appearance in any command.)
  246. const Variant& GetShaderParameter(const String& name) const;
  247. /// Rendertargets.
  248. Vector<RenderTargetInfo> renderTargets_;
  249. /// Rendering commands.
  250. Vector<RenderPathCommand> commands_;
  251. // ATOMIC BEGIN
  252. /// Gets the render command at specified index, note SetCommand must be called to update the RenderPath with any changes
  253. bool GetCommand(unsigned index, ScriptRenderPathCommand* dst);
  254. /// Sets the render command at specified index
  255. bool SetCommand(unsigned index, ScriptRenderPathCommand* src);
  256. // ATOMIC END
  257. };
  258. }