RenderPath.h 7.2 KB

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