Browse Source

Added scripting interface for RenderPath.

Lasse Öörni 13 years ago
parent
commit
09b716f0b8

+ 1 - 1
Bin/CoreData/RenderPaths/Forward.xml

@@ -2,7 +2,7 @@
     <command type="clear" color="fog" depth="1.0" stencil="0" />
     <command type="scenepass" pass="base" vertexlights="true" />
     <command type="forwardlights" />
-    <command type="scenepass" pass="prealpha" sort="state" />
+    <command type="scenepass" pass="prealpha" />
     <command type="scenepass" pass="alpha" usescissor="true" vertexlights="true" sort="backtofront" />
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 1 - 1
Bin/CoreData/RenderPaths/ForwardDepth.xml

@@ -5,7 +5,7 @@
     <command type="clear" color="fog" depth="1.0" stencil="0" />
     <command type="scenepass" pass="base" vertexlights="true" />
     <command type="forwardlights" />
-    <command type="scenepass" pass="prealpha" sort="state" />
+    <command type="scenepass" pass="prealpha" />
     <command type="scenepass" pass="alpha" usescissor="true" vertexlights="true" sort="backtofront" />
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 73 - 42
Docs/ScriptAPI.dox

@@ -76,6 +76,7 @@ namespace Urho3D
 - uint GetFloat32Format()
 - uint GetDepthStencilFormat()
 - uint GetFormat(const String&)
+- void MarkNetworkUpdate()
 - void DelayedExecute(float, bool, const String&, const Variant[]@)
 - void DelayedExecute(float, bool, const String&)
 - void ClearDelayedExecute(const String& arg0 = String ( ))
@@ -1633,6 +1634,72 @@ Properties:<br>
 - Vector3 upVector (readonly)
 
 
+RenderTargetInfo
+
+Properties:<br>
+- String name
+- String tag
+- uint format
+- IntVector2 size
+- RenderTargetSizeMode sizeMode
+- bool active
+- bool filtered
+
+
+RenderPathCommand
+
+Methods:<br>
+- void RemoveShaderParameter(const String&)
+
+Properties:<br>
+- String[] textureNames
+- Vector4[] shaderParameters
+- uint numOutputs
+- String[] outputNames
+- String tag
+- RenderCommandType type
+- RenderCommandSortMode sortMode
+- StringHash pass
+- uint clearFlags
+- Color clearColor
+- float clearDepth
+- uint clearStencil
+- bool active
+- bool useFogColor
+- bool markToStencil
+- bool vertexLights
+- bool useScissor
+- String vertexShaderName
+- String pixelShaderName
+
+
+RenderPath
+
+Methods:<br>
+- RenderPath@ Clone()
+- bool LoadParameters(XMLFile@)
+- bool Append(XMLFile@)
+- void SetActive(const String&, bool)
+- void ToggleActive(const String&)
+- void AddRenderTarget(const RenderTargetInfo&)
+- void RemoveRenderTarget(uint)
+- void RemoveRenderTarget(const String&)
+- void RemoveRenderTargts(const String&)
+- void AddCommand(const RenderPathCommand&)
+- void InsertCommand(uint, const RenderPathCommand&)
+- void RemoveCommand(uint)
+- void RemoveCommands(const String&)
+
+Properties:<br>
+- int refs (readonly)
+- int weakRefs (readonly)
+- uint numRenderTargets (readonly)
+- RenderTargetInfo[] renderTargets
+- uint numCommands (readonly)
+- RenderPathCommand[] commands
+- Vector4[] shaderParameters
+
+
 Texture
 
 Methods:<br>
@@ -1665,44 +1732,21 @@ Properties:<br>
 - bool dataLost (readonly)
 
 
-PostProcess
+Viewport
 
 Methods:<br>
 - void SendEvent(const String&, VariantMap& arg1 = VariantMap ( ))
-- bool CreateRenderTarget(const String&, uint, uint, uint, bool, bool)
-- void RemoveRenderTarget(const String&)
-- void RemoveShaderParameter(const String&)
-- PostProcess@ Clone() const
-- bool HasRenderTarget(const String&) const
+- void SetRenderPath(XMLFile@)
 
 Properties:<br>
 - ShortStringHash type (readonly)
 - String typeName (readonly)
 - int refs (readonly)
 - int weakRefs (readonly)
-- XMLFile@ parameters
-- uint numPasses
-- Vector4[] shaderParameters
-- bool active
-- PostProcessPass@[] passes (readonly)
-
-
-Viewport
-
-Methods:<br>
-- void AddPostProcess(PostProcess@)
-- void InsertPostProcess(uint, PostProcess@)
-- void RemovePostProcess(PostProcess@)
-- void RemovePostProcess(uint)
-- void RemoveAllPostProcesses()
-
-Properties:<br>
-- int refs (readonly)
-- int weakRefs (readonly)
 - Scene@ scene
 - Camera@ camera
+- RenderPath@ renderPath
 - IntRect rect
-- uint numPostProcesses (readonly)
 
 
 RenderSurface
@@ -1801,6 +1845,7 @@ Properties:<br>
 - int weakRefs (readonly)
 - BlendMode blendMode
 - CompareMode depthTestMode
+- PassLightingMode lightingMode
 - bool depthWrite
 - bool alphaMask
 - String vertexShader
@@ -1858,21 +1903,6 @@ Properties:<br>
 - BiasParameters depthBias
 
 
-PostProcessPass
-
-Methods:<br>
-- void RemoveShaderParameter(const String&)
-
-Properties:<br>
-- int refs (readonly)
-- int weakRefs (readonly)
-- String vertexShader
-- String pixelShader
-- String output
-- String[] textures
-- Vector4[] shaderParameters
-
-
 Model
 
 Methods:<br>
@@ -2720,6 +2750,7 @@ Methods:<br>
 - void SendEvent(const String&, VariantMap& arg1 = VariantMap ( ))
 - void DrawDebugGeometry(bool) const
 - void ReloadShaders() const
+- void SetDefaultRenderPath(XMLFile@)
 
 Properties:<br>
 - ShortStringHash type (readonly)
@@ -2728,7 +2759,7 @@ Properties:<br>
 - int weakRefs (readonly)
 - uint numViewports
 - Viewport@[] viewports
-- RenderMode renderMode
+- RenderPath@ defaultRenderPath
 - bool specularLighting
 - int textureAnisotropy
 - TextureFilterMode textureFilterMode

+ 164 - 26
Engine/Engine/GraphicsAPI.cpp

@@ -170,6 +170,38 @@ static bool TextureCubeLoad(CubeMapFace face, Image* image, bool useAlpha, Textu
     return ptr->Load(face, SharedPtr<Image>(image), useAlpha);
 }
 
+static void ConstructRenderTargetInfo(RenderTargetInfo* ptr)
+{
+    // Init to zero because performance is not critical
+    new(ptr) RenderTargetInfo();
+}
+
+static void ConstructRenderTargetInfoCopy(const RenderTargetInfo& info, RenderTargetInfo* ptr)
+{
+    new(ptr) RenderTargetInfo(info);
+}
+
+static void DestructRenderTargetInfo(RenderTargetInfo* ptr)
+{
+    ptr->~RenderTargetInfo();
+}
+
+static void ConstructRenderPathCommand(RenderPathCommand* ptr)
+{
+    // Init to zero because performance is not critical
+    new(ptr) RenderPathCommand();
+}
+
+static void ConstructRenderPathCommandCopy(const RenderPathCommand& command, RenderPathCommand* ptr)
+{
+    new(ptr) RenderPathCommand(command);
+}
+
+static void DestructRenderPathCommand(RenderPathCommand* ptr)
+{
+    ptr->~RenderPathCommand();
+}
+
 static RenderPath* ConstructRenderPath()
 {
     return new RenderPath();
@@ -184,6 +216,137 @@ static RenderPath* RenderPathClone(RenderPath* ptr)
     return clone.Get();
 }
 
+static RenderTargetInfo* RenderPathGetRenderTarget(unsigned index, RenderPath* ptr)
+{
+    if (index >= ptr->renderTargets_.Size())
+    {
+        asIScriptContext* context = asGetActiveContext();
+        if (context)
+            context->SetException("Index out of bounds");
+        return 0;
+    }
+    else
+        return &ptr->renderTargets_[index];
+}
+
+static RenderPathCommand* RenderPathGetCommand(unsigned index, RenderPath* ptr)
+{
+    if (index >= ptr->commands_.Size())
+    {
+        asIScriptContext* context = asGetActiveContext();
+        if (context)
+            context->SetException("Index out of bounds");
+        return 0;
+    }
+    else
+        return &ptr->commands_[index];
+}
+
+static void RegisterRenderPath(asIScriptEngine* engine)
+{
+    engine->RegisterEnum("RenderCommandType");
+    engine->RegisterEnumValue("RenderCommandType", "CMD_NONE", CMD_NONE);
+    engine->RegisterEnumValue("RenderCommandType", "CMD_CLEAR", CMD_CLEAR);
+    engine->RegisterEnumValue("RenderCommandType", "CMD_SCENEPASS", CMD_SCENEPASS);
+    engine->RegisterEnumValue("RenderCommandType", "CMD_QUAD", CMD_QUAD);
+    engine->RegisterEnumValue("RenderCommandType", "CMD_FORWARDLIGHTS", CMD_FORWARDLIGHTS);
+    engine->RegisterEnumValue("RenderCommandType", "CMD_LIGHTVOLUMES", CMD_LIGHTVOLUMES);
+    
+    engine->RegisterEnum("RenderCommandSortMode");
+    engine->RegisterEnumValue("RenderCommandType", "SORT_FRONTTOBACK", SORT_FRONTTOBACK);
+    engine->RegisterEnumValue("RenderCommandType", "SORT_BACKTOFRONT", SORT_BACKTOFRONT);
+    
+    engine->RegisterEnum("RenderTargetSizeMode");
+    engine->RegisterEnumValue("RenderTargetSizeMode", "SIZE_ABSOLUTE", SIZE_ABSOLUTE);
+    engine->RegisterEnumValue("RenderTargetSizeMode", "SIZE_RENDERTARGETDIVISOR", SIZE_RENDERTARGETDIVISOR);
+    engine->RegisterEnumValue("RenderTargetSizeMode", "SIZE_VIEWPORTDIVISOR", SIZE_VIEWPORTDIVISOR);
+    
+    engine->RegisterEnum("TextureUnit");
+    engine->RegisterEnumValue("TextureUnit", "TU_DIFFUSE", TU_DIFFUSE);
+    engine->RegisterEnumValue("TextureUnit", "TU_NORMAL", TU_NORMAL);
+    engine->RegisterEnumValue("TextureUnit", "TU_SPECULAR", TU_SPECULAR);
+    engine->RegisterEnumValue("TextureUnit", "TU_EMISSIVE", TU_EMISSIVE);
+    engine->RegisterEnumValue("TextureUnit", "TU_ENVIRONMENT", TU_ENVIRONMENT);
+    engine->RegisterEnumValue("TextureUnit", "TU_LIGHTRAMP", TU_LIGHTRAMP);
+    engine->RegisterEnumValue("TextureUnit", "TU_LIGHTSHAPE", TU_LIGHTSHAPE);
+    engine->RegisterEnumValue("TextureUnit", "TU_SHADOWMAP", TU_SHADOWMAP);
+    engine->RegisterEnumValue("TextureUnit", "TU_FACESELECT", TU_FACESELECT);
+    engine->RegisterEnumValue("TextureUnit", "TU_INDIRECTION", TU_INDIRECTION);
+    engine->RegisterEnumValue("TextureUnit", "TU_ALBEDOBUFFER", TU_ALBEDOBUFFER);
+    engine->RegisterEnumValue("TextureUnit", "TU_NORMALBUFFER", TU_NORMALBUFFER);
+    engine->RegisterEnumValue("TextureUnit", "TU_DEPTHBUFFER", TU_DEPTHBUFFER);
+    engine->RegisterEnumValue("TextureUnit", "TU_LIGHTBUFFER", TU_LIGHTBUFFER);
+    engine->RegisterEnumValue("TextureUnit", "MAX_MATERIAL_TEXTURE_UNITS", MAX_MATERIAL_TEXTURE_UNITS);
+    engine->RegisterEnumValue("TextureUnit", "MAX_TEXTURE_UNITS", MAX_TEXTURE_UNITS);
+    
+    engine->RegisterObjectType("RenderTargetInfo", sizeof(RenderTargetInfo), asOBJ_VALUE | asOBJ_APP_CLASS_C);
+    engine->RegisterObjectBehaviour("RenderTargetInfo", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructRenderTargetInfo), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectBehaviour("RenderTargetInfo", asBEHAVE_CONSTRUCT, "void f(const RenderTargetInfo&in)", asFUNCTION(ConstructRenderTargetInfoCopy), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectBehaviour("RenderTargetInfo", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructRenderTargetInfo), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("RenderTargetInfo", "RenderTargetInfo& opAssign(const RenderTargetInfo&in)", asMETHOD(RenderTargetInfo, operator =), asCALL_THISCALL);
+    engine->RegisterObjectProperty("RenderTargetInfo", "String name", offsetof(RenderTargetInfo, name_));
+    engine->RegisterObjectProperty("RenderTargetInfo", "String tag", offsetof(RenderTargetInfo, tag_));
+    engine->RegisterObjectProperty("RenderTargetInfo", "uint format", offsetof(RenderTargetInfo, format_));
+    engine->RegisterObjectProperty("RenderTargetInfo", "IntVector2 size", offsetof(RenderTargetInfo, size_));
+    engine->RegisterObjectProperty("RenderTargetInfo", "RenderTargetSizeMode sizeMode", offsetof(RenderTargetInfo, sizeMode_));
+    engine->RegisterObjectProperty("RenderTargetInfo", "bool active", offsetof(RenderTargetInfo, active_));
+    engine->RegisterObjectProperty("RenderTargetInfo", "bool filtered", offsetof(RenderTargetInfo, filtered_));
+    
+    engine->RegisterObjectType("RenderPathCommand", sizeof(RenderPathCommand), asOBJ_VALUE | asOBJ_APP_CLASS_C);
+    engine->RegisterObjectBehaviour("RenderPathCommand", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructRenderPathCommand), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectBehaviour("RenderPathCommand", asBEHAVE_CONSTRUCT, "void f(const RenderPathCommand&in)", asFUNCTION(ConstructRenderPathCommandCopy), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectBehaviour("RenderPathCommand", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructRenderPathCommand), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("RenderPathCommand", "void RemoveShaderParameter(const String&in)", asMETHOD(RenderPathCommand, RemoveShaderParameter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPathCommand", "RenderPathCommand& opAssign(const RenderPathCommand&in)", asMETHOD(RenderPathCommand, operator =), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPathCommand", "void set_textureNames(TextureUnit, const String&in)", asMETHOD(RenderPathCommand, SetTextureName), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPathCommand", "const String& get_textureNames(TextureUnit) const", asMETHOD(RenderPathCommand, GetTextureName), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPathCommand", "void set_shaderParameters(const String&in, const Vector4&in)", asMETHOD(RenderPathCommand, SetShaderParameter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPathCommand", "const Vector4& get_shaderParameters(const String&in) const", asMETHOD(RenderPathCommand, GetShaderParameter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPathCommand", "void set_numOutputs(uint)", asMETHOD(RenderPathCommand, SetNumOutputs), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPathCommand", "uint get_numOutputs() const", asMETHOD(RenderPathCommand, GetNumOutputs), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPathCommand", "void set_outputNames(uint, const String&in)", asMETHOD(RenderPathCommand, SetOutputName), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPathCommand", "const String& get_outputNames(uint) const", asMETHOD(RenderPathCommand, GetOutputName), asCALL_THISCALL);
+    engine->RegisterObjectProperty("RenderPathCommand", "String tag", offsetof(RenderPathCommand, tag_));
+    engine->RegisterObjectProperty("RenderPathCommand", "RenderCommandType type", offsetof(RenderPathCommand, type_));
+    engine->RegisterObjectProperty("RenderPathCommand", "RenderCommandSortMode sortMode", offsetof(RenderPathCommand, sortMode_));
+    engine->RegisterObjectProperty("RenderPathCommand", "StringHash pass", offsetof(RenderPathCommand, pass_));
+    engine->RegisterObjectProperty("RenderPathCommand", "uint clearFlags", offsetof(RenderPathCommand, clearFlags_));
+    engine->RegisterObjectProperty("RenderPathCommand", "Color clearColor", offsetof(RenderPathCommand, clearColor_));
+    engine->RegisterObjectProperty("RenderPathCommand", "float clearDepth", offsetof(RenderPathCommand, clearDepth_));
+    engine->RegisterObjectProperty("RenderPathCommand", "uint clearStencil", offsetof(RenderPathCommand, clearStencil_));
+    engine->RegisterObjectProperty("RenderPathCommand", "bool active", offsetof(RenderPathCommand, active_));
+    engine->RegisterObjectProperty("RenderPathCommand", "bool useFogColor", offsetof(RenderPathCommand, useFogColor_));
+    engine->RegisterObjectProperty("RenderPathCommand", "bool markToStencil", offsetof(RenderPathCommand, markToStencil_));
+    engine->RegisterObjectProperty("RenderPathCommand", "bool vertexLights", offsetof(RenderPathCommand, vertexLights_));
+    engine->RegisterObjectProperty("RenderPathCommand", "bool useScissor", offsetof(RenderPathCommand, useScissor_));
+    engine->RegisterObjectProperty("RenderPathCommand", "String vertexShaderName", offsetof(RenderPathCommand, vertexShaderName_));
+    engine->RegisterObjectProperty("RenderPathCommand", "String pixelShaderName", offsetof(RenderPathCommand, pixelShaderName_));
+    
+    RegisterRefCounted<RenderPath>(engine, "RenderPath");
+    engine->RegisterObjectBehaviour("RenderPath", asBEHAVE_FACTORY, "RenderPath@+ f()", asFUNCTION(ConstructRenderPath), asCALL_CDECL);
+    engine->RegisterObjectMethod("RenderPath", "RenderPath@ Clone()", asFUNCTION(RenderPathClone), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("RenderPath", "bool LoadParameters(XMLFile@+)", asMETHOD(RenderPath, LoadParameters), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "bool Append(XMLFile@+)", asMETHOD(RenderPath, Append), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void SetActive(const String&in, bool)", asMETHOD(RenderPath, SetActive), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void ToggleActive(const String&in)", asMETHOD(RenderPath, ToggleActive), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void AddRenderTarget(const RenderTargetInfo&in)", asMETHOD(RenderPath, AddRenderTarget), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void RemoveRenderTarget(uint)", asMETHODPR(RenderPath, RemoveRenderTarget, (unsigned), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void RemoveRenderTarget(const String&in)", asMETHODPR(RenderPath, RemoveRenderTarget, (const String&), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void RemoveRenderTargts(const String&in)", asMETHOD(RenderPath, RemoveRenderTargets), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void AddCommand(const RenderPathCommand&in)", asMETHOD(RenderPath, AddCommand), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void InsertCommand(uint, const RenderPathCommand&in)", asMETHOD(RenderPath, InsertCommand), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void RemoveCommand(uint)", asMETHOD(RenderPath, RemoveCommand), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void RemoveCommands(const String&in)", asMETHOD(RenderPath, RemoveCommands), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "uint get_numRenderTargets() const", asMETHOD(RenderPath, GetNumRenderTargets), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void set_renderTargets(uint, const RenderTargetInfo&in)", asMETHOD(RenderPath, SetRenderTarget), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "const RenderTargetInfo& get_renderTargets(uint) const", asFUNCTION(RenderPathGetRenderTarget), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("RenderPath", "uint get_numCommands() const", asMETHOD(RenderPath, GetNumCommands), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "void set_commands(uint, const RenderPathCommand&in)", asMETHOD(RenderPath, SetCommand), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "const RenderPathCommand& get_commands(uint) const", asFUNCTION(RenderPathGetCommand), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("RenderPath", "void set_shaderParameters(const String&in, const Vector4&in)", asMETHOD(RenderPath, SetShaderParameter), asCALL_THISCALL);
+    engine->RegisterObjectMethod("RenderPath", "const Vector4& get_shaderParameters(const String&in) const", asMETHOD(RenderPath, GetShaderParameter), asCALL_THISCALL);
+}
+
 static void RegisterTextures(asIScriptEngine* engine)
 {
     /// \todo Expose getting/setting raw texture data
@@ -222,14 +385,6 @@ static void RegisterTextures(asIScriptEngine* engine)
     
     RegisterTexture<Texture>(engine, "Texture");
     
-    RegisterRefCounted<RenderPath>(engine, "RenderPath");
-    engine->RegisterObjectBehaviour("RenderPath", asBEHAVE_FACTORY, "RenderPath@+ f()", asFUNCTION(ConstructRenderPath), asCALL_CDECL);
-    engine->RegisterObjectMethod("RenderPath", "RenderPath@ Clone()", asFUNCTION(RenderPathClone), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("RenderPath", "bool LoadParameters(XMLFile@+)", asMETHOD(RenderPath, LoadParameters), asCALL_THISCALL);
-    engine->RegisterObjectMethod("RenderPath", "bool Append(XMLFile@+)", asMETHOD(RenderPath, Append), asCALL_THISCALL);
-    engine->RegisterObjectMethod("RenderPath", "void SetActive(const String&in, bool)", asMETHOD(RenderPath, SetActive), asCALL_THISCALL);
-    engine->RegisterObjectMethod("RenderPath", "void ToggleActive(const String&in)", asMETHOD(RenderPath, ToggleActive), asCALL_THISCALL);
-    
     RegisterObject<Viewport>(engine, "Viewport");
     engine->RegisterObjectBehaviour("Viewport", asBEHAVE_FACTORY, "Viewport@+ f()", asFUNCTION(ConstructViewport), asCALL_CDECL);
     engine->RegisterObjectBehaviour("Viewport", asBEHAVE_FACTORY, "Viewport@+ f(Scene@+, Camera@+, RenderPath@+ renderPath = null)", asFUNCTION(ConstructViewportSceneCamera), asCALL_CDECL);
@@ -318,24 +473,6 @@ static void RegisterMaterial(asIScriptEngine* engine)
     engine->RegisterObjectProperty("BiasParameters", "float constantBias", offsetof(BiasParameters, constantBias_));
     engine->RegisterObjectProperty("BiasParameters", "float slopeScaledBias", offsetof(BiasParameters, slopeScaledBias_));
     
-    engine->RegisterEnum("TextureUnit");
-    engine->RegisterEnumValue("TextureUnit", "TU_DIFFUSE", TU_DIFFUSE);
-    engine->RegisterEnumValue("TextureUnit", "TU_NORMAL", TU_NORMAL);
-    engine->RegisterEnumValue("TextureUnit", "TU_SPECULAR", TU_SPECULAR);
-    engine->RegisterEnumValue("TextureUnit", "TU_EMISSIVE", TU_EMISSIVE);
-    engine->RegisterEnumValue("TextureUnit", "TU_ENVIRONMENT", TU_ENVIRONMENT);
-    engine->RegisterEnumValue("TextureUnit", "TU_LIGHTRAMP", TU_LIGHTRAMP);
-    engine->RegisterEnumValue("TextureUnit", "TU_LIGHTSHAPE", TU_LIGHTSHAPE);
-    engine->RegisterEnumValue("TextureUnit", "TU_SHADOWMAP", TU_SHADOWMAP);
-    engine->RegisterEnumValue("TextureUnit", "TU_FACESELECT", TU_FACESELECT);
-    engine->RegisterEnumValue("TextureUnit", "TU_INDIRECTION", TU_INDIRECTION);
-    engine->RegisterEnumValue("TextureUnit", "TU_ALBEDOBUFFER", TU_ALBEDOBUFFER);
-    engine->RegisterEnumValue("TextureUnit", "TU_NORMALBUFFER", TU_NORMALBUFFER);
-    engine->RegisterEnumValue("TextureUnit", "TU_DEPTHBUFFER", TU_DEPTHBUFFER);
-    engine->RegisterEnumValue("TextureUnit", "TU_LIGHTBUFFER", TU_LIGHTBUFFER);
-    engine->RegisterEnumValue("TextureUnit", "MAX_MATERIAL_TEXTURE_UNITS", MAX_MATERIAL_TEXTURE_UNITS);
-    engine->RegisterEnumValue("TextureUnit", "MAX_TEXTURE_UNITS", MAX_TEXTURE_UNITS);
-    
     engine->RegisterEnum("BlendMode");
     engine->RegisterEnumValue("BlendMode", "BLEND_REPLACE", BLEND_REPLACE);
     engine->RegisterEnumValue("BlendMode", "BLEND_ADD", BLEND_ADD);
@@ -1098,6 +1235,7 @@ void RegisterGraphicsAPI(asIScriptEngine* engine)
     RegisterSkeleton(engine);
     RegisterDebugRenderer(engine);
     RegisterCamera(engine);
+    RegisterRenderPath(engine);
     RegisterTextures(engine);
     RegisterMaterial(engine);
     RegisterModel(engine);

+ 9 - 1
Engine/Engine/ScriptAPI.cpp

@@ -182,6 +182,13 @@ static void SelfDelayedExecute(float delay, bool repeat, const String& declarati
     ptr->DelayedExecute(delay, repeat, declaration, destParams);
 }
 
+static void SelfMarkNetworkUpdate()
+{
+    ScriptInstance* ptr = GetScriptContextInstance();
+    if (ptr)
+        ptr->MarkNetworkUpdate();
+}
+
 static void SelfDelayedExecuteNoParams(float delay, bool repeat, const String& declaration)
 {
     ScriptInstance* ptr = GetScriptContextInstance();
@@ -230,7 +237,8 @@ static void RegisterScriptInstance(asIScriptEngine* engine)
     engine->RegisterObjectMethod("ScriptInstance", "const String& get_className() const", asMETHOD(ScriptInstance, GetClassName), asCALL_THISCALL);
     engine->RegisterGlobalFunction("ScriptInstance@+ get_self()", asFUNCTION(GetSelf), asCALL_CDECL);
     
-    // Register convenience functions for controlling delayed execution on self, similar to event sending
+    // Register convenience functions for controlling self, similar to event sending
+    engine->RegisterGlobalFunction("void MarkNetworkUpdate()", asFUNCTION(SelfMarkNetworkUpdate), asCALL_CDECL);
     engine->RegisterGlobalFunction("void DelayedExecute(float, bool, const String&in, const Array<Variant>@+)", asFUNCTION(SelfDelayedExecute), asCALL_CDECL);
     engine->RegisterGlobalFunction("void DelayedExecute(float, bool, const String&in)", asFUNCTION(SelfDelayedExecuteNoParams), asCALL_CDECL);
     engine->RegisterGlobalFunction("void ClearDelayedExecute(const String&in declaration = String())", asFUNCTION(SelfClearDelayedExecute), asCALL_CDECL);

+ 148 - 5
Engine/Graphics/RenderPath.cpp

@@ -145,9 +145,9 @@ void RenderPathCommand::LoadParameters(const XMLElement& element)
     }
     
     // By default use 1 output, which is the viewport
-    outputs_.Push("viewport");
+    outputNames_.Push("viewport");
     if (element.HasAttribute("output"))
-        outputs_[0] = element.GetAttribute("output");
+        outputNames_[0] = element.GetAttribute("output");
     // Check for defining multiple outputs
     XMLElement outputElem = element.GetChild("output");
     while (outputElem)
@@ -155,9 +155,9 @@ void RenderPathCommand::LoadParameters(const XMLElement& element)
         unsigned index = outputElem.GetInt("index");
         if (index < MAX_RENDERTARGETS)
         {
-            if (index >= outputs_.Size())
-                outputs_.Resize(index + 1);
-            outputs_[index] = outputElem.GetAttribute("name");
+            if (index >= outputNames_.Size())
+                outputNames_.Resize(index + 1);
+            outputNames_[index] = outputElem.GetAttribute("name");
         }
         outputElem = outputElem.GetNext("output");
     }
@@ -184,6 +184,52 @@ void RenderPathCommand::LoadParameters(const XMLElement& element)
     }
 }
 
+void RenderPathCommand::SetTextureName(TextureUnit unit, const String& name)
+{
+    if (unit < MAX_TEXTURE_UNITS)
+        textureNames_[unit] = name;
+}
+
+void RenderPathCommand::SetShaderParameter(const String& name, const Vector4& value)
+{
+    shaderParameters_[StringHash(name)] = value;
+}
+
+void RenderPathCommand::RemoveShaderParameter(const String& name)
+{
+    shaderParameters_.Erase(StringHash(name));
+}
+
+void RenderPathCommand::SetNumOutputs(unsigned num)
+{
+    num = Clamp((int)num, 1, MAX_RENDERTARGETS);
+    outputNames_.Resize(num);
+}
+
+void RenderPathCommand::SetOutputName(unsigned index, const String& name)
+{
+    if (index < outputNames_.Size())
+        outputNames_[index] = name;
+    else if (index == outputNames_.Size() && index < MAX_RENDERTARGETS)
+        outputNames_.Push(name);
+}
+
+const String& RenderPathCommand::GetTextureName(TextureUnit unit) const
+{
+    return unit < MAX_TEXTURE_UNITS ? textureNames_[unit] : String::EMPTY;
+}
+
+const Vector4& RenderPathCommand::GetShaderParameter(const String& name) const
+{
+    HashMap<StringHash, Vector4>::ConstIterator i = shaderParameters_.Find(StringHash(name));
+    return i != shaderParameters_.End() ? i->second_ : Vector4::ZERO;
+}
+
+const String& RenderPathCommand::GetOutputName(unsigned index) const
+{
+    return index < outputNames_.Size() ? outputNames_[index] : String::EMPTY;
+}
+
 RenderPath::RenderPath()
 {
 }
@@ -272,4 +318,101 @@ void RenderPath::ToggleActive(const String& tag)
     }
 }
 
+void RenderPath::SetRenderTarget(unsigned index, const RenderTargetInfo& info)
+{
+    if (index < renderTargets_.Size())
+        renderTargets_[index] = info;
+    else if (index == renderTargets_.Size())
+        AddRenderTarget(info);
+}
+
+void RenderPath::AddRenderTarget(const RenderTargetInfo& info)
+{
+    renderTargets_.Push(info);
+}
+
+void RenderPath::RemoveRenderTarget(unsigned index)
+{
+    renderTargets_.Erase(index);
+}
+
+void RenderPath::RemoveRenderTarget(const String& name)
+{
+    for (unsigned i = 0; i < renderTargets_.Size(); ++i)
+    {
+        if (!renderTargets_[i].name_.Compare(name, false))
+        {
+            renderTargets_.Erase(i);
+            return;
+        }
+    }
+}
+
+void RenderPath::RemoveRenderTargets(const String& tag)
+{
+    for (unsigned i = renderTargets_.Size() - 1; i < renderTargets_.Size(); --i)
+    {
+        if (!renderTargets_[i].tag_.Compare(tag, false))
+            renderTargets_.Erase(i);
+    }
+}
+
+void RenderPath::SetCommand(unsigned index, const RenderPathCommand& command)
+{
+    if (index < commands_.Size())
+        commands_[index] = command;
+    else if (index == commands_.Size())
+        AddCommand(command);
+}
+
+void RenderPath::AddCommand(const RenderPathCommand& command)
+{
+    commands_.Push(command);
+}
+
+void RenderPath::InsertCommand(unsigned index, const RenderPathCommand& command)
+{
+    commands_.Insert(index, command);
+}
+
+void RenderPath::RemoveCommand(unsigned index)
+{
+    commands_.Erase(index);
+}
+
+void RenderPath::RemoveCommands(const String& tag)
+{
+    for (unsigned i = commands_.Size() - 1; i < commands_.Size(); --i)
+    {
+        if (!commands_[i].tag_.Compare(tag, false))
+            commands_.Erase(i);
+    }
+}
+
+void RenderPath::SetShaderParameter(const String& name, const Vector4& value)
+{
+    StringHash nameHash(name);
+    
+    for (unsigned i = 0; i < commands_.Size(); ++i)
+    {
+        HashMap<StringHash, Vector4>::Iterator j = commands_[i].shaderParameters_.Find(nameHash);
+        if (j != commands_[i].shaderParameters_.End())
+            j->second_ = value;
+    }
+}
+
+const Vector4& RenderPath::GetShaderParameter(const String& name) const
+{
+    StringHash nameHash(name);
+    
+    for (unsigned i = 0; i < commands_.Size(); ++i)
+    {
+        HashMap<StringHash, Vector4>::ConstIterator j = commands_[i].shaderParameters_.Find(nameHash);
+        if (j != commands_[i].shaderParameters_.End())
+            return j->second_;
+    }
+    
+    return Vector4::ZERO;
+}
+
 }

+ 50 - 3
Engine/Graphics/RenderPath.h

@@ -39,8 +39,7 @@ enum RenderCommandType
     CMD_SCENEPASS,
     CMD_QUAD,
     CMD_FORWARDLIGHTS,
-    CMD_LIGHTVOLUMES,
-    CMD_UNKNOWN
+    CMD_LIGHTVOLUMES
 };
 
 /// Rendering path sorting modes.
@@ -105,6 +104,25 @@ struct RenderPathCommand
     
     /// Read from an XML element.
     void LoadParameters(const XMLElement& element);
+    /// Set a texture resource name. Can also refer to a rendertarget defined in the rendering path.
+    void SetTextureName(TextureUnit unit, const String& name);
+    /// Set a shader parameter.
+    void SetShaderParameter(const String& name, const Vector4& value);
+    /// Remove a shader parameter.
+    void RemoveShaderParameter(const String& name);
+    /// Set number of output rendertargets.
+    void SetNumOutputs(unsigned num);
+    /// Set output rendertarget name.
+    void SetOutputName(unsigned index, const String& name);
+    
+    /// Return texture resource name.
+    const String& GetTextureName(TextureUnit unit) const;
+    /// Return shader paramter.
+    const Vector4& GetShaderParameter(const String& name) const;
+    /// Return number of output rendertargets.
+    unsigned GetNumOutputs() const { return outputNames_.Size(); }
+    /// Return output rendertarget name.
+    const String& GetOutputName(unsigned index) const;
     
     /// Tag name.
     String tag_;
@@ -141,7 +159,7 @@ struct RenderPathCommand
     /// %Shader parameters.
     HashMap<StringHash, Vector4> shaderParameters_;
     /// Output rendertarget names.
-    Vector<String> outputs_;
+    Vector<String> outputNames_;
 };
 
 /// Rendering path definition.
@@ -163,6 +181,35 @@ public:
     void SetActive(const String& tag, bool active);
     /// Toggle activation of commands and rendertargets by tag.
     void ToggleActive(const String& tag);
+    /// Assign rendertarget at index.
+    void SetRenderTarget(unsigned index, const RenderTargetInfo& info);
+    /// Add a rendertarget.
+    void AddRenderTarget(const RenderTargetInfo& info);
+    /// Remove a rendertarget by index.
+    void RemoveRenderTarget(unsigned index);
+    /// Remove a rendertarget by name.
+    void RemoveRenderTarget(const String& name);
+    /// Remove rendertargets by tag name.
+    void RemoveRenderTargets(const String& tag);
+    /// Assign command at index.
+    void SetCommand(unsigned index, const RenderPathCommand& command);
+    /// Add a command to the end of the list.
+    void AddCommand(const RenderPathCommand& command);
+    /// Insert a command at a position.
+    void InsertCommand(unsigned index, const RenderPathCommand& command);
+    /// Remove a command by index.
+    void RemoveCommand(unsigned index);
+    /// Remove commands by tag name.
+    void RemoveCommands(const String& tag);
+    /// Set a shader parameter in all commands that define it.
+    void SetShaderParameter(const String& name, const Vector4& value);
+    
+    /// Return number of rendertargets.
+    unsigned GetNumRenderTargets() const { return renderTargets_.Size(); }
+    /// Return number of commands.
+    unsigned GetNumCommands() const { return commands_.Size(); }
+    /// Return a shader parameter (first appearance in any command.)
+    const Vector4& GetShaderParameter(const String& name) const;
     
     /// Rendertargets.
     Vector<RenderTargetInfo> renderTargets_;

+ 7 - 7
Engine/Graphics/View.cpp

@@ -1167,7 +1167,7 @@ void View::ExecuteRenderPathCommands()
             if (CheckViewportRead(command))
             {
                 readBuffer_ = writeBuffer_;
-                if (!command.outputs_[0].Compare("viewport", false))
+                if (!command.outputNames_[0].Compare("viewport", false))
                 {
                     ++writeBuffer_;
                     if (writeBuffer_ >= screenBuffers_.Size())
@@ -1198,8 +1198,8 @@ void View::ExecuteRenderPathCommands()
             
             // Optimization: if the last command is a quad with output to the viewport, do not use the screenbuffers,
             // but the viewport directly. This saves the extra copy
-            if (screenBuffers_.Size() && i == lastCommandIndex && command.type_ == CMD_QUAD && command.outputs_.Size() == 1 &&
-                !command.outputs_[0].Compare("viewport", false))
+            if (screenBuffers_.Size() && i == lastCommandIndex && command.type_ == CMD_QUAD && command.outputNames_.Size() == 1 &&
+                !command.outputNames_[0].Compare("viewport", false))
                 currentRenderTarget_ = renderTarget_;
             
             switch (command.type_)
@@ -1313,13 +1313,13 @@ void View::SetRenderTargets(const RenderPathCommand& command)
 {
     unsigned index = 0;
     
-    while (index < command.outputs_.Size())
+    while (index < command.outputNames_.Size())
     {
-        if (!command.outputs_[index].Compare("viewport", false))
+        if (!command.outputNames_[index].Compare("viewport", false))
             graphics_->SetRenderTarget(index, currentRenderTarget_);
         else
         {
-            StringHash nameHash(command.outputs_[index]);
+            StringHash nameHash(command.outputNames_[index]);
             if (renderTargets_.Contains(nameHash))
                 graphics_->SetRenderTarget(index, renderTargets_[nameHash]);
             else
@@ -1483,7 +1483,7 @@ void View::AllocateScreenBuffers()
         if (CheckViewportRead(command))
         {
             hasViewportRead = true;
-            if (!command.outputs_[0].Compare("viewport", false))
+            if (!command.outputNames_[0].Compare("viewport", false))
                 hasViewportReadWrite = true;
         }
     }