PostProcess.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "Viewport.h"
  25. namespace Urho3D
  26. {
  27. class Texture2D;
  28. class XMLFile;
  29. /// Post-processing effect pass.
  30. class PostProcessPass : public RefCounted
  31. {
  32. public:
  33. /// Construct.
  34. PostProcessPass();
  35. /// Destruct.
  36. ~PostProcessPass();
  37. /// Set vertex shader name.
  38. void SetVertexShader(const String& name);
  39. /// Set pixel shader name.
  40. void SetPixelShader(const String& name);
  41. /// Set texture name. This can be a named rendertarget, or a texture resource name.
  42. void SetTexture(TextureUnit unit, const String& name);
  43. /// Set shader parameter.
  44. void SetShaderParameter(const String& name, const Vector4& value);
  45. /// Remove shader parameter.
  46. void RemoveShaderParameter(const String& name);
  47. /// Set output rendertarget name.
  48. void SetOutput(const String& name);
  49. /// Clone the post-process pass.
  50. SharedPtr<PostProcessPass> Clone();
  51. /// Return vertex shader name.
  52. const String& GetVertexShader() const { return vertexShaderName_; }
  53. /// Return pixel shader name.
  54. const String& GetPixelShader() const { return pixelShaderName_; }
  55. /// Return texture name.
  56. const String& GetTexture(TextureUnit unit) const;
  57. /// Return all texture names.
  58. const String* GetTextures() const { return &textureNames_[0]; }
  59. /// Return shader parameter.
  60. const Vector4& GetShaderParameter(const String& name) const;
  61. /// Return all shader parameters.
  62. const HashMap<StringHash, Vector4>& GetShaderParameters() const { return shaderParameters_; }
  63. /// Return output rendertarget name.
  64. const String& GetOutput() const { return outputName_; }
  65. private:
  66. /// Vertex shader name.
  67. String vertexShaderName_;
  68. /// Pixel shader name.
  69. String pixelShaderName_;
  70. /// Textures.
  71. String textureNames_[MAX_TEXTURE_UNITS];
  72. /// %Shader parameters.
  73. HashMap<StringHash, Vector4> shaderParameters_;
  74. /// Output rendertarget name.
  75. String outputName_;
  76. };
  77. /// Post-processing effect.
  78. class PostProcess : public Object
  79. {
  80. OBJECT(PostProcess);
  81. public:
  82. /// Construct.
  83. PostProcess(Context* context);
  84. /// Destruct.
  85. ~PostProcess();
  86. /// Load parameters from an XML file. Return true if successful.
  87. bool LoadParameters(XMLFile* file);
  88. /// Set number of passes.
  89. void SetNumPasses(unsigned passes);
  90. /// Create a rendertarget. Width and height are either absolute pixels or viewport size divisors. Return true if successful.
  91. bool CreateRenderTarget(const String& name, unsigned width, unsigned height, unsigned format, bool sizeDivisor, bool filtered);
  92. /// Remove a rendertarget.
  93. void RemoveRenderTarget(const String& name);
  94. /// Set global shader parameter.
  95. void SetShaderParameter(const String& name, const Vector4& value);
  96. /// Remove global shader parameter.
  97. void RemoveShaderParameter(const String& name);
  98. /// Set active flag.
  99. void SetActive(bool active);
  100. /// Clone the post-process.
  101. SharedPtr<PostProcess> Clone();
  102. /// Return parameter XML file.
  103. XMLFile* GetParameters() const { return parameterSource_; }
  104. /// Return number of passes.
  105. unsigned GetNumPasses() const { return passes_.Size(); }
  106. /// Return pass by index.
  107. PostProcessPass* GetPass(unsigned index) const;
  108. /// Return if has a specific rendertarget.
  109. bool HasRenderTarget(const String& name) const;
  110. /// Return all rendertargets.
  111. const HashMap<StringHash, RenderTargetInfo>& GetRenderTargets() const { return renderTargets_; }
  112. /// Return shader parameter.
  113. const Vector4& GetShaderParameter(const String& name) const;
  114. /// Return all global shader parameters.
  115. const HashMap<StringHash, Vector4>& GetShaderParameters() const { return shaderParameters_; }
  116. /// Return active flag.
  117. bool IsActive() const { return active_; }
  118. private:
  119. /// Parameter XML file.
  120. SharedPtr<XMLFile> parameterSource_;
  121. /// Rendertargets.
  122. HashMap<StringHash, RenderTargetInfo> renderTargets_;
  123. /// Global shader parameters.
  124. HashMap<StringHash, Vector4> shaderParameters_;
  125. /// Effect passes.
  126. Vector<SharedPtr<PostProcessPass> > passes_;
  127. /// Active flag.
  128. bool active_;
  129. };
  130. }