Browse Source

Additions to the PostProcess API.
Exposed PostProcess to script.
Code cleanup.

Lasse Öörni 14 years ago
parent
commit
d449b946bd

+ 29 - 1
Docs/ScriptAPI.dox

@@ -1625,13 +1625,41 @@ Properties:<br>
 - uint useTimer (readonly)
 - uint useTimer (readonly)
 - uint numTechniques
 - uint numTechniques
 - Technique@[] technique (readonly)
 - Technique@[] technique (readonly)
-- Vector4[] shaderParameter
+- Vector4&[] shaderParameters
 - Texture@[] textures
 - Texture@[] textures
 - bool occlusion (readonly)
 - bool occlusion (readonly)
 - CullMode cullMode
 - CullMode cullMode
 - CullMode shadowCullMode
 - CullMode shadowCullMode
 
 
 
 
+PostProcessPass
+
+Methods:<br>
+- void RemoveShaderParameter(const String&)
+
+Properties:<br>
+- String& vertexShader
+- String& pixelShader
+- String& output
+- String&[] textures
+- Vector4[] shaderParameters
+
+
+PostProcess
+
+Methods:<br>
+- bool LoadParameters(XMLFile@)
+- bool CreateRenderTarget(const String&, uint, uint, uint, bool)
+- void RemoveRenderTarget(const String&)
+
+Properties:<br>
+- ShortStringHash type (readonly)
+- String& typeName (readonly)
+- uint numPasses
+- PostProcessPass@[] passes (readonly)
+- Texture2D@[] renderTargets (readonly)
+
+
 Model
 Model
 
 
 Methods:<br>
 Methods:<br>

+ 1 - 1
Engine/Audio/Sound.cpp

@@ -386,7 +386,7 @@ void Sound::LoadParameters()
         return;
         return;
     
     
     XMLElement rootElem = file->GetRoot();
     XMLElement rootElem = file->GetRoot();
-    XMLElement paramElem = rootElem.GetChild("");
+    XMLElement paramElem = rootElem.GetChild();
     
     
     while (paramElem)
     while (paramElem)
     {
     {

+ 30 - 12
Engine/Engine/GraphicsAPI.cpp

@@ -34,6 +34,7 @@
 #include "Material.h"
 #include "Material.h"
 #include "Octree.h"
 #include "Octree.h"
 #include "ParticleEmitter.h"
 #include "ParticleEmitter.h"
+#include "PostProcess.h"
 #include "Scene.h"
 #include "Scene.h"
 #include "Technique.h"
 #include "Technique.h"
 #include "Texture2D.h"
 #include "Texture2D.h"
@@ -262,16 +263,6 @@ static void RegisterTextures(asIScriptEngine* engine)
     engine->RegisterGlobalFunction("uint GetDepthStencilFormat()", asFUNCTION(Graphics::GetDepthStencilFormat), asCALL_CDECL);
     engine->RegisterGlobalFunction("uint GetDepthStencilFormat()", asFUNCTION(Graphics::GetDepthStencilFormat), asCALL_CDECL);
 }
 }
 
 
-static Vector4 MaterialGetShaderParameter(const String& name, Material* ptr)
-{
-    const HashMap<StringHash, MaterialShaderParameter>& parameters = ptr->GetShaderParameters();
-    HashMap<StringHash, MaterialShaderParameter>::ConstIterator i = parameters.Find(StringHash(name));
-    if (i == parameters.End())
-        return Vector4::ZERO;
-    else
-        return i->second_.value_;
-}
-
 static Material* MaterialClone(const String& cloneName, Material* ptr)
 static Material* MaterialClone(const String& cloneName, Material* ptr)
 {
 {
     SharedPtr<Material> clonedMaterial = ptr->Clone(cloneName);
     SharedPtr<Material> clonedMaterial = ptr->Clone(cloneName);
@@ -354,8 +345,8 @@ static void RegisterMaterial(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Material", "void set_numTechniques(uint)", asMETHOD(Material, SetNumTechniques), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "void set_numTechniques(uint)", asMETHOD(Material, SetNumTechniques), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "uint get_numTechniques() const", asMETHOD(Material, GetNumTechniques), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "uint get_numTechniques() const", asMETHOD(Material, GetNumTechniques), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Technique@+ get_technique(uint)", asMETHOD(Material, GetTechnique), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Technique@+ get_technique(uint)", asMETHOD(Material, GetTechnique), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Material", "void set_shaderParameter(const String&in, const Vector4&in)", asMETHOD(Material, SetShaderParameter), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Material", "Vector4 get_shaderParameter(const String&in) const", asFUNCTION(MaterialGetShaderParameter), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Material", "void set_shaderParameters(const String&in, const Vector4&in)", asMETHOD(Material, SetShaderParameter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Material", "const Vector4& get_shaderParameters(const String&in) const", asMETHOD(Material, GetShaderParameter), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "void set_textures(uint, Texture@+)", asMETHOD(Material, SetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "void set_textures(uint, Texture@+)", asMETHOD(Material, SetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Texture@+ get_textures(uint) const", asMETHOD(Material, GetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Texture@+ get_textures(uint) const", asMETHOD(Material, GetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "bool get_occlusion()", asMETHOD(Material, GetOcclusion), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "bool get_occlusion()", asMETHOD(Material, GetOcclusion), asCALL_THISCALL);
@@ -365,6 +356,32 @@ static void RegisterMaterial(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Material", "CullMode get_shadowCullMode() const", asMETHOD(Material, GetShadowCullMode), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "CullMode get_shadowCullMode() const", asMETHOD(Material, GetShadowCullMode), asCALL_THISCALL);
 }
 }
 
 
+static void RegisterPostProcess(asIScriptEngine* engine)
+{
+    RegisterRefCounted<PostProcessPass>(engine, "PostProcessPass");
+    engine->RegisterObjectMethod("PostProcessPass", "void RemoveShaderParameter(const String&in)", asMETHOD(PostProcessPass, RemoveShaderParameter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "void set_vertexShader(const String&in)", asMETHOD(PostProcessPass, SetVertexShader), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "const String& get_vertexShader() const", asMETHOD(PostProcessPass, GetVertexShader), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "void set_pixelShader(const String&in)", asMETHOD(PostProcessPass, SetPixelShader), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "const String& get_pixelShader() const", asMETHOD(PostProcessPass, GetPixelShader), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "void set_output(const String&in)", asMETHOD(PostProcessPass, SetOutput), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "const String& get_output() const", asMETHOD(PostProcessPass, GetOutput), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "void set_textures(uint, const String&in)", asMETHOD(PostProcessPass, SetTexture), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "const String& get_textures(uint) const", asMETHOD(PostProcessPass, GetTexture), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "void set_shaderParameters(const String&in, const Vector4&in)", asMETHOD(PostProcessPass, SetShaderParameter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("PostProcessPass", "Vector4 get_shaderParameters(const String&in) const", asMETHOD(PostProcessPass, GetShaderParameter), asCALL_THISCALL);
+    
+    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", "void RemoveRenderTarget(const String&in)", asMETHOD(PostProcess, RemoveRenderTarget), 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)
 static void RegisterModel(asIScriptEngine* engine)
 {
 {
     RegisterResource<Model>(engine, "Model");
     RegisterResource<Model>(engine, "Model");
@@ -1002,6 +1019,7 @@ void RegisterGraphicsAPI(asIScriptEngine* engine)
     RegisterSkeleton(engine);
     RegisterSkeleton(engine);
     RegisterTextures(engine);
     RegisterTextures(engine);
     RegisterMaterial(engine);
     RegisterMaterial(engine);
+    RegisterPostProcess(engine);
     RegisterModel(engine);
     RegisterModel(engine);
     RegisterAnimation(engine);
     RegisterAnimation(engine);
     RegisterDebugRenderer(engine);
     RegisterDebugRenderer(engine);

+ 6 - 2
Engine/Graphics/Direct3D9/D3D9Texture.cpp

@@ -218,8 +218,12 @@ void Texture::LoadParameters(XMLFile* file)
         return;
         return;
     
     
     XMLElement rootElem = file->GetRoot();
     XMLElement rootElem = file->GetRoot();
-    XMLElement paramElem = rootElem.GetChild("");
-    
+    LoadParameters(rootElem);
+}
+
+void Texture::LoadParameters(const XMLElement& elem)
+{
+    XMLElement paramElem = elem.GetChild();
     while (paramElem)
     while (paramElem)
     {
     {
         String name = paramElem.GetName();
         String name = paramElem.GetName();

+ 5 - 1
Engine/Graphics/Direct3D9/D3D9Texture.h

@@ -31,6 +31,7 @@
 
 
 static const int MAX_TEXTURE_QUALITY_LEVELS = 3;
 static const int MAX_TEXTURE_QUALITY_LEVELS = 3;
 
 
+class XMLElement;
 class XMLFile;
 class XMLFile;
 
 
 /// Base class for texture resources.
 /// Base class for texture resources.
@@ -86,11 +87,14 @@ public:
     /// Return API-specific DXT compressed texture format.
     /// Return API-specific DXT compressed texture format.
     static unsigned GetDXTFormat(CompressedFormat format);
     static unsigned GetDXTFormat(CompressedFormat format);
     
     
-protected:
     /// Load parameters.
     /// Load parameters.
     void LoadParameters();
     void LoadParameters();
     /// Load parameters from an XML file.
     /// Load parameters from an XML file.
     void LoadParameters(XMLFile* xml);
     void LoadParameters(XMLFile* xml);
+    /// Load parameters from an XML element.
+    void LoadParameters(const XMLElement& elem);
+    
+protected:
     /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
     /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
     void CheckTextureBudget(ShortStringHash type);
     void CheckTextureBudget(ShortStringHash type);
     
     

+ 6 - 0
Engine/Graphics/Material.cpp

@@ -394,6 +394,12 @@ Texture* Material::GetTexture(TextureUnit unit) const
     return (unsigned)unit < textures_.Size() ? textures_[unit] : (Texture*)0;
     return (unsigned)unit < textures_.Size() ? textures_[unit] : (Texture*)0;
 }
 }
 
 
+const Vector4& Material::GetShaderParameter(const String& name) const
+{
+    HashMap<StringHash, MaterialShaderParameter>::ConstIterator i = shaderParameters_.Find(StringHash(name));
+    return i != shaderParameters_.End() ? i->second_.value_ : Vector4::ZERO;
+}
+
 const String& Material::GetTextureUnitName(TextureUnit unit)
 const String& Material::GetTextureUnitName(TextureUnit unit)
 {
 {
     return textureUnitNames[unit];
     return textureUnitNames[unit];

+ 3 - 1
Engine/Graphics/Material.h

@@ -95,7 +95,7 @@ public:
     void SetCullMode(CullMode mode);
     void SetCullMode(CullMode mode);
     /// %Set culling mode for shadows.
     /// %Set culling mode for shadows.
     void SetShadowCullMode(CullMode mode);
     void SetShadowCullMode(CullMode mode);
-    /// Remove a shader parameter.
+    /// Remove shader parameter.
     void RemoveShaderParameter(const String& name);
     void RemoveShaderParameter(const String& name);
     /// Reset all shader pointers.
     /// Reset all shader pointers.
     void ReleaseShaders();
     void ReleaseShaders();
@@ -118,6 +118,8 @@ public:
     const Vector<SharedPtr<Texture> >& GetTextures() const { return textures_; }
     const Vector<SharedPtr<Texture> >& GetTextures() const { return textures_; }
     /// Return texture by unit.
     /// Return texture by unit.
     Texture* GetTexture(TextureUnit unit) const;
     Texture* GetTexture(TextureUnit unit) const;
+    /// Return shader parameter.
+    const Vector4& GetShaderParameter(const String& name) const;
     /// Return all shader parameters.
     /// Return all shader parameters.
     const HashMap<StringHash, MaterialShaderParameter>& GetShaderParameters() const { return shaderParameters_; }
     const HashMap<StringHash, MaterialShaderParameter>& GetShaderParameters() const { return shaderParameters_; }
     /// Return normal culling mode.
     /// Return normal culling mode.

+ 6 - 2
Engine/Graphics/OpenGL/OGLTexture.cpp

@@ -306,8 +306,12 @@ void Texture::LoadParameters(XMLFile* file)
         return;
         return;
     
     
     XMLElement rootElem = file->GetRoot();
     XMLElement rootElem = file->GetRoot();
-    XMLElement paramElem = rootElem.GetChild("");
-    
+    LoadParameters(rootElem);
+}
+
+void Texture::LoadParameters(const XMLElement& elem)
+{
+    XMLElement paramElem = elem.GetChild();
     while (paramElem)
     while (paramElem)
     {
     {
         String name = paramElem.GetName();
         String name = paramElem.GetName();

+ 4 - 1
Engine/Graphics/OpenGL/OGLTexture.h

@@ -105,11 +105,14 @@ public:
     /// Return the data type corresponding to an OpenGL internal format.
     /// Return the data type corresponding to an OpenGL internal format.
     static unsigned GetDataType(unsigned format);
     static unsigned GetDataType(unsigned format);
     
     
-protected:
     /// Load parameters.
     /// Load parameters.
     void LoadParameters();
     void LoadParameters();
     /// Load parameters from an XML file.
     /// Load parameters from an XML file.
     void LoadParameters(XMLFile* xml);
     void LoadParameters(XMLFile* xml);
+    /// Load parameters from an XML element.
+    void LoadParameters(const XMLElement& elem);
+    
+protected:
     /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
     /// Check whether texture memory budget has been exceeded. Free unused materials in that case to release the texture references.
     void CheckTextureBudget(ShortStringHash type);
     void CheckTextureBudget(ShortStringHash type);
     
     

+ 17 - 9
Engine/Graphics/PostProcess.cpp

@@ -29,6 +29,8 @@
 #include "Texture2D.h"
 #include "Texture2D.h"
 #include "XMLFile.h"
 #include "XMLFile.h"
 
 
+static const String emptyName;
+
 TextureUnit ParseTextureUnitName(const String& name);
 TextureUnit ParseTextureUnitName(const String& name);
 
 
 PostProcessPass::PostProcessPass()
 PostProcessPass::PostProcessPass()
@@ -51,7 +53,8 @@ void PostProcessPass::SetPixelShader(const String& name)
 
 
 void PostProcessPass::SetTexture(TextureUnit unit, const String& name)
 void PostProcessPass::SetTexture(TextureUnit unit, const String& name)
 {
 {
-    textureNames_[unit] = name;
+    if (unit < MAX_TEXTURE_UNITS)
+        textureNames_[unit] = name;
 }
 }
 
 
 void PostProcessPass::SetShaderParameter(const String& name, const Vector4& value)
 void PostProcessPass::SetShaderParameter(const String& name, const Vector4& value)
@@ -71,22 +74,21 @@ void PostProcessPass::SetOutput(const String& name)
 
 
 const String& PostProcessPass::GetTexture(TextureUnit unit) const
 const String& PostProcessPass::GetTexture(TextureUnit unit) const
 {
 {
-    return textureNames_[unit];
+    return unit < MAX_TEXTURE_UNITS ? textureNames_[unit] : emptyName;
 }
 }
 
 
 const Vector4& PostProcessPass::GetShaderParameter(const String& name) const
 const Vector4& PostProcessPass::GetShaderParameter(const String& name) const
 {
 {
     HashMap<StringHash, Vector4>::ConstIterator i = shaderParameters_.Find(StringHash(name));
     HashMap<StringHash, Vector4>::ConstIterator i = shaderParameters_.Find(StringHash(name));
-    if (i != shaderParameters_.End())
-        return i->second_;
-    else
-        return Vector4::ZERO;
+    return i != shaderParameters_.End() ? i->second_ : Vector4::ZERO;
 }
 }
 
 
 PostProcessRenderTarget::~PostProcessRenderTarget()
 PostProcessRenderTarget::~PostProcessRenderTarget()
 {
 {
 }
 }
 
 
+OBJECTTYPESTATIC(PostProcess);
+
 PostProcess::PostProcess(Context* context) :
 PostProcess::PostProcess(Context* context) :
     Object(context)
     Object(context)
 {
 {
@@ -117,12 +119,18 @@ bool PostProcess::LoadParameters(XMLFile* file)
         unsigned height = rtElem.GetInt("height");
         unsigned height = rtElem.GetInt("height");
         unsigned format = Graphics::GetRGBFormat();
         unsigned format = Graphics::GetRGBFormat();
         bool relativeSize = rtElem.GetBool("relativesize");
         bool relativeSize = rtElem.GetBool("relativesize");
+        
         String formatName = rtElem.GetString("format").ToLower();
         String formatName = rtElem.GetString("format").ToLower();
         if (formatName == "rgba")
         if (formatName == "rgba")
             format = Graphics::GetRGBAFormat();
             format = Graphics::GetRGBAFormat();
         else if (formatName == "float")
         else if (formatName == "float")
             format = Graphics::GetFloatFormat();
             format = Graphics::GetFloatFormat();
-        CreateRenderTarget(name, width, height, format, relativeSize);
+        
+        if (CreateRenderTarget(name, width, height, format, relativeSize))
+        {
+            // Process additional texture parameters (for example filtering)
+            renderTargets_[StringHash(name)].texture_->LoadParameters(rtElem);
+        }
         
         
         rtElem = rtElem.GetNext("rendertarget");
         rtElem = rtElem.GetNext("rendertarget");
     }
     }
@@ -218,11 +226,11 @@ PostProcessPass* PostProcess::GetPass(unsigned index) const
         return 0;
         return 0;
 }
 }
 
 
-const PostProcessRenderTarget* PostProcess::GetRenderTarget(const String& name) const
+Texture2D* PostProcess::GetRenderTarget(const String& name) const
 {
 {
     HashMap<StringHash, PostProcessRenderTarget>::ConstIterator i = renderTargets_.Find(StringHash(name));
     HashMap<StringHash, PostProcessRenderTarget>::ConstIterator i = renderTargets_.Find(StringHash(name));
     if (i != renderTargets_.End())
     if (i != renderTargets_.End())
-        return &i->second_;
+        return i->second_.texture_;
     else
     else
         return 0;
         return 0;
 }
 }

+ 5 - 1
Engine/Graphics/PostProcess.h

@@ -95,6 +95,8 @@ struct PostProcessRenderTarget
 /// Post-processing effect.
 /// Post-processing effect.
 class PostProcess : public Object
 class PostProcess : public Object
 {
 {
+    OBJECT(PostProcess);
+    
 public:
 public:
     /// Construct.
     /// Construct.
     PostProcess(Context* context);
     PostProcess(Context* context);
@@ -112,10 +114,12 @@ public:
     
     
     /// Return parameter XML file.
     /// Return parameter XML file.
     XMLFile* GetParameters() const { return parameterSource_; }
     XMLFile* GetParameters() const { return parameterSource_; }
+    /// Return number of passes.
+    unsigned GetNumPasses() const { return passes_.Size(); }
     /// Return pass by index.
     /// Return pass by index.
     PostProcessPass* GetPass(unsigned index) const;
     PostProcessPass* GetPass(unsigned index) const;
     /// Return rendertarget by name.
     /// Return rendertarget by name.
-    const PostProcessRenderTarget* GetRenderTarget(const String& name) const;
+    Texture2D* GetRenderTarget(const String& name) const;
     
     
 private:
 private:
     /// Parameter XML file.
     /// Parameter XML file.

+ 1 - 1
Tools/ShaderCompiler/ShaderCompiler.cpp

@@ -301,7 +301,7 @@ void Run(const Vector<String>& arguments)
         
         
         Shader baseShader(source, compileType);
         Shader baseShader(source, compileType);
         
         
-        XMLElement variation = shader.GetChild("");
+        XMLElement variation = shader.GetChild();
         while (variation)
         while (variation)
         {
         {
             String value = variation.GetName();
             String value = variation.GetName();