Browse Source

Changed PostProcess class to not allocate rendertargets beforehand.

Lasse Öörni 14 years ago
parent
commit
86608f6ba5
4 changed files with 43 additions and 45 deletions
  1. 2 2
      Docs/ScriptAPI.dox
  2. 2 2
      Engine/Engine/GraphicsAPI.cpp
  3. 30 29
      Engine/Graphics/PostProcess.cpp
  4. 9 12
      Engine/Graphics/PostProcess.h

+ 2 - 2
Docs/ScriptAPI.dox

@@ -1649,15 +1649,15 @@ PostProcess
 
 Methods:<br>
 - bool LoadParameters(XMLFile@)
-- bool CreateRenderTarget(const String&, uint, uint, uint, bool)
+- bool CreateRenderTarget(const String&, uint, uint, uint, bool, bool)
 - void RemoveRenderTarget(const String&)
+- bool HasRenderTarget(const String&) const
 
 Properties:<br>
 - ShortStringHash type (readonly)
 - String& typeName (readonly)
 - uint numPasses
 - PostProcessPass@[] passes (readonly)
-- Texture2D@[] renderTargets (readonly)
 
 
 Model

+ 2 - 2
Engine/Engine/GraphicsAPI.cpp

@@ -374,12 +374,12 @@ static void RegisterPostProcess(asIScriptEngine* engine)
     RegisterObject<PostProcess>(engine, "PostProcess");
     RegisterObjectConstructor<PostProcess>(engine, "PostProcess");
     engine->RegisterObjectMethod("PostProcess", "bool LoadParameters(XMLFile@+)", asMETHOD(PostProcess, LoadParameters), asCALL_THISCALL);
-    engine->RegisterObjectMethod("PostProcess", "bool CreateRenderTarget(const String&in, uint, uint, uint, bool)", asMETHOD(PostProcess, CreateRenderTarget), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcess", "bool CreateRenderTarget(const String&in, uint, uint, uint, bool, bool)", asMETHOD(PostProcess, CreateRenderTarget), asCALL_THISCALL);
     engine->RegisterObjectMethod("PostProcess", "void RemoveRenderTarget(const String&in)", asMETHOD(PostProcess, RemoveRenderTarget), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcess", "bool HasRenderTarget(const String&in) const", asMETHOD(PostProcess, HasRenderTarget), asCALL_THISCALL);
     engine->RegisterObjectMethod("PostProcess", "void set_numPasses(uint)", asMETHOD(PostProcess, SetNumPasses), asCALL_THISCALL);
     engine->RegisterObjectMethod("PostProcess", "uint get_numPasses() const", asMETHOD(PostProcess, GetNumPasses), asCALL_THISCALL);
     engine->RegisterObjectMethod("PostProcess", "PostProcessPass@+ get_passes(uint) const", asMETHOD(PostProcess, GetPass), asCALL_THISCALL);
-    engine->RegisterObjectMethod("PostProcess", "Texture2D@+ get_renderTargets(const String&in) const", asMETHOD(PostProcess, GetPass), asCALL_THISCALL);
 }
 
 static void RegisterModel(asIScriptEngine* engine)

+ 30 - 29
Engine/Graphics/PostProcess.cpp

@@ -83,10 +83,6 @@ const Vector4& PostProcessPass::GetShaderParameter(const String& name) const
     return i != shaderParameters_.End() ? i->second_ : Vector4::ZERO;
 }
 
-PostProcessRenderTarget::~PostProcessRenderTarget()
-{
-}
-
 OBJECTTYPESTATIC(PostProcess);
 
 PostProcess::PostProcess(Context* context) :
@@ -115,23 +111,40 @@ bool PostProcess::LoadParameters(XMLFile* file)
     while (rtElem)
     {
         String name = rtElem.GetString("name");
-        unsigned width = rtElem.GetInt("width");
-        unsigned height = rtElem.GetInt("height");
-        unsigned format = Graphics::GetRGBFormat();
-        bool relativeSize = rtElem.GetBool("relativesize");
         
+        unsigned format = Graphics::GetRGBFormat();
         String formatName = rtElem.GetString("format").ToLower();
         if (formatName == "rgba")
             format = Graphics::GetRGBAFormat();
         else if (formatName == "float")
             format = Graphics::GetFloatFormat();
         
-        if (CreateRenderTarget(name, width, height, format, relativeSize))
+        bool sizeDivisor = false;
+        bool filtered = false;
+        unsigned width = 0;
+        unsigned height = 0;
+        
+        if (rtElem.HasAttribute("filter"))
+            filtered = rtElem.GetBool("filter");
+        if (rtElem.HasAttribute("size"))
         {
-            // Process additional texture parameters (for example filtering)
-            renderTargets_[StringHash(name)].texture_->LoadParameters(rtElem);
+            IntVector2 size = rtElem.GetIntVector2("size");
+            width = size.x_;
+            height = size.y_;
+        }
+        if (rtElem.HasAttribute("width"))
+            width = rtElem.GetInt("width");
+        if (rtElem.HasAttribute("height"))
+            height = rtElem.GetInt("height");
+        if (rtElem.HasAttribute("sizedivisor"))
+        {
+            IntVector2 size = rtElem.GetIntVector2("sizedivisor");
+            width = size.x_;
+            height = size.y_;
+            sizeDivisor = true;
         }
         
+        CreateRenderTarget(name, width, height, format, sizeDivisor, filtered);
         rtElem = rtElem.GetNext("rendertarget");
     }
     
@@ -190,24 +203,16 @@ void PostProcess::SetNumPasses(unsigned passes)
     }
 }
 
-bool PostProcess::CreateRenderTarget(const String& name, unsigned width, unsigned height, unsigned format, bool relativeSize)
+bool PostProcess::CreateRenderTarget(const String& name, unsigned width, unsigned height, unsigned format, bool sizeDivisor, bool filtered)
 {
     if (name.Trimmed().Empty())
         return false;
     
     PostProcessRenderTarget target;
-    target.texture_ = new Texture2D(context_);
     target.format_ = format;
-    target.relativeSize_ = relativeSize;
-    // If size is absolute, can reserve the texture now. Otherwise must defer to later
-    if (!relativeSize)
-    {
-        target.sizeDivisor_ = IntVector2(1, 1);
-        if (!target.texture_->SetSize(width, height, format, TEXTURE_RENDERTARGET))
-            return false;
-    }
-    else
-        target.sizeDivisor_ = IntVector2(Max((int)width, 1), Max((int)height, 1));
+    target.size_ = IntVector2(width, height),
+    target.sizeDivisor_ = sizeDivisor;
+    target.filtered_ = filtered;
     
     renderTargets_[StringHash(name)] = target;
     return true;
@@ -226,11 +231,7 @@ PostProcessPass* PostProcess::GetPass(unsigned index) const
         return 0;
 }
 
-Texture2D* PostProcess::GetRenderTarget(const String& name) const
+bool PostProcess::HasRenderTarget(const String& name) const
 {
-    HashMap<StringHash, PostProcessRenderTarget>::ConstIterator i = renderTargets_.Find(StringHash(name));
-    if (i != renderTargets_.End())
-        return i->second_.texture_;
-    else
-        return 0;
+    return renderTargets_.Contains(StringHash(name));
 }

+ 9 - 12
Engine/Graphics/PostProcess.h

@@ -79,17 +79,14 @@ private:
 /// Post-processing rendertarget.
 struct PostProcessRenderTarget
 {
-    /// Destruct.
-    ~PostProcessRenderTarget();
-    
-    /// Rendertarget texture.
-    SharedPtr<Texture2D> texture_;
     /// Texture format.
     unsigned format_;
-    /// Size divisor.
-    IntVector2 sizeDivisor_;
-    /// Relative size (divisor mode) flag.
-    bool relativeSize_;
+    /// Size.
+    IntVector2 size_;
+    /// Divisor mode flag.
+    bool sizeDivisor_;
+    /// Filtering flag.
+    bool filtered_;
 };
 
 /// Post-processing effect.
@@ -108,7 +105,7 @@ public:
     /// Set number of passes.
     void SetNumPasses(unsigned passes);
     /// Create a rendertarget. Width and height are either absolute pixels or viewport size divisors. Return true if successful.
-    bool CreateRenderTarget(const String& name, unsigned width, unsigned height, unsigned format, bool relativeSize);
+    bool CreateRenderTarget(const String& name, unsigned width, unsigned height, unsigned format, bool sizeDivisor, bool filtered);
     /// Remove a rendertarget.
     void RemoveRenderTarget(const String& name);
     
@@ -118,8 +115,8 @@ public:
     unsigned GetNumPasses() const { return passes_.Size(); }
     /// Return pass by index.
     PostProcessPass* GetPass(unsigned index) const;
-    /// Return rendertarget by name.
-    Texture2D* GetRenderTarget(const String& name) const;
+    /// Return if has a specific rendertarget.
+    bool HasRenderTarget(const String& name) const;
     
 private:
     /// Parameter XML file.