RenderPath.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 "GraphicsDefs.h"
  24. #include "RefCounted.h"
  25. namespace Urho3D
  26. {
  27. class XMLElement;
  28. class XMLFile;
  29. /// Rendering path command types.
  30. enum RenderCommandType
  31. {
  32. CMD_NONE = 0,
  33. CMD_CLEAR,
  34. CMD_SCENEPASS,
  35. CMD_QUAD,
  36. CMD_FORWARDLIGHTS,
  37. CMD_LIGHTVOLUMES,
  38. CMD_UNKNOWN
  39. };
  40. /// Rendering path sorting modes.
  41. enum RenderCommandSortMode
  42. {
  43. SORT_FRONTTOBACK = 0,
  44. SORT_BACKTOFRONT
  45. };
  46. /// Rendertarget size mode.
  47. enum RenderTargetSizeMode
  48. {
  49. SIZE_ABSOLUTE = 0,
  50. SIZE_RENDERTARGETDIVISOR,
  51. SIZE_VIEWPORTDIVISOR
  52. };
  53. /// Rendertarget definition.
  54. struct RenderTargetInfo
  55. {
  56. /// Construct.
  57. RenderTargetInfo() :
  58. size_(IntVector2::ZERO),
  59. sizeMode_(SIZE_ABSOLUTE),
  60. active_(true),
  61. filtered_(false)
  62. {
  63. }
  64. /// Read from an XML element.
  65. void LoadParameters(const XMLElement& element);
  66. /// Name.
  67. String name_;
  68. /// Tag name.
  69. String tag_;
  70. /// Texture format.
  71. unsigned format_;
  72. /// Size.
  73. IntVector2 size_;
  74. /// Size mode.
  75. RenderTargetSizeMode sizeMode_;
  76. /// Active flag.
  77. bool active_;
  78. /// Filtering flag.
  79. bool filtered_;
  80. };
  81. /// Rendering path command.
  82. struct RenderPathCommand
  83. {
  84. /// Construct.
  85. RenderPathCommand() :
  86. clearFlags_(0),
  87. active_(true),
  88. useFogColor_(false),
  89. markToStencil_(false),
  90. useScissor_(false),
  91. vertexLights_(false)
  92. {
  93. }
  94. /// Read from an XML element.
  95. void LoadParameters(const XMLElement& element);
  96. /// Tag name.
  97. String tag_;
  98. /// Command type.
  99. RenderCommandType type_;
  100. /// Sorting mode.
  101. RenderCommandSortMode sortMode_;
  102. /// Scene pass hash.
  103. StringHash pass_;
  104. /// Clear flags.
  105. unsigned clearFlags_;
  106. /// Clear color.
  107. Color clearColor_;
  108. /// Clear depth.
  109. float clearDepth_;
  110. /// Clear stencil value.
  111. unsigned clearStencil_;
  112. /// Active flag.
  113. bool active_;
  114. /// Use fog color for clearing.
  115. bool useFogColor_;
  116. /// Mark to stencil flag.
  117. bool markToStencil_;
  118. /// Vertex lights flag.
  119. bool vertexLights_;
  120. /// Scissor optimization flag.
  121. bool useScissor_;
  122. /// Vertex shader name.
  123. String vertexShaderName_;
  124. /// Pixel shader name.
  125. String pixelShaderName_;
  126. /// Textures.
  127. String textureNames_[MAX_TEXTURE_UNITS];
  128. /// %Shader parameters.
  129. HashMap<StringHash, Vector4> shaderParameters_;
  130. /// Output rendertarget names.
  131. Vector<String> outputs_;
  132. };
  133. /// Rendering path definition.
  134. class RenderPath : public RefCounted
  135. {
  136. public:
  137. /// Construct.
  138. RenderPath();
  139. /// Destruct.
  140. ~RenderPath();
  141. /// Clone the rendering path.
  142. SharedPtr<RenderPath> Clone();
  143. /// Read from an XML file. Return true if successful.
  144. bool LoadParameters(XMLFile* file);
  145. /// Append data from an XML file. Return true if successful.
  146. bool Append(XMLFile* file);
  147. /// Activate/inactivate commands and rendertargets by tag.
  148. void SetActive(const String& tag, bool active);
  149. /// Toggle activation of commands and rendertargets by tag.
  150. void ToggleActive(const String& tag);
  151. /// Rendertargets.
  152. Vector<RenderTargetInfo> renderTargets_;
  153. /// Rendering commands.
  154. Vector<RenderPathCommand> commands_;
  155. };
  156. }