Browse Source

Merge pull request #1530 from AtomicGameEngine/JME-ATOMIC-SCRIPTSHADERPARMS

Script shader parameter setters for RenderPath and RenderPathCommand
JoshEngebretson 8 years ago
parent
commit
1a201173b9

+ 3 - 1
Script/Packages/Atomic/Graphics.json

@@ -53,8 +53,10 @@
 		],
 		],
 		"CustomGeometry" : [
 		"CustomGeometry" : [
 			"setMaterialIndex(index:number, material:Material);"
 			"setMaterialIndex(index:number, material:Material);"
+		],
+		"RenderPath" : [
+			"setShaderParameter(name:string, value:Object);"
 		]
 		]
-
 	},
 	},
 
 
 	"haxe_decl" : {
 	"haxe_decl" : {

+ 10 - 1
Script/Packages/Atomic/Script.json

@@ -1,5 +1,14 @@
 {
 {
 	"name" : "Script",
 	"name" : "Script",
 	"sources" : ["Source/Atomic/Script"],
 	"sources" : ["Source/Atomic/Script"],
-	"classes" : ["ScriptVariant", "ScriptVariantMap", "ScriptVector", "ScriptComponent", "ScriptComponentFile", "PhysicsContact", "PhysicsNodeCollision"]
+	"classes_rename" : {
+		"ScriptRenderPathCommand" : "RenderPathCommand"
+	},
+	"classes" : ["ScriptVariant", "ScriptVariantMap", "ScriptVector", "ScriptComponent", "ScriptComponentFile", "PhysicsContact", "PhysicsNodeCollision", "ScriptRenderPathCommand"],
+	"typescript_decl" : {
+		"ScriptRenderPathCommand" : [
+			"setShaderParameter(name:string, value:Object);"
+		]
+	}
+	
 }
 }

+ 28 - 0
Source/Atomic/Graphics/RenderPath.cpp

@@ -28,6 +28,10 @@
 #include "../IO/Log.h"
 #include "../IO/Log.h"
 #include "../Resource/XMLFile.h"
 #include "../Resource/XMLFile.h"
 
 
+// ATOMIC BEGIN
+#include "../Script/ScriptRenderPathCommand.h"
+// ATOMIC END
+
 #include "../DebugNew.h"
 #include "../DebugNew.h"
 
 
 #ifdef _MSC_VER
 #ifdef _MSC_VER
@@ -491,4 +495,28 @@ const Variant& RenderPath::GetShaderParameter(const String& name) const
     return Variant::EMPTY;
     return Variant::EMPTY;
 }
 }
 
 
+// ATOMIC BEGIN
+
+bool RenderPath::GetCommand(unsigned index, ScriptRenderPathCommand* dst)
+{
+    if (!dst || index >= commands_.Size())
+        return false;    
+
+    dst->renderPathCommand_ = commands_[index];
+
+    return true;
+}
+/// Sets the render command at specified index
+bool RenderPath::SetCommand(unsigned index, ScriptRenderPathCommand* src)
+{
+    if (!src || index >= commands_.Size())
+        return false;
+
+    SetCommand(index, src->renderPathCommand_);
+
+    return true;
+}
+
+// ATOMIC END
+
 }
 }

+ 11 - 0
Source/Atomic/Graphics/RenderPath.h

@@ -34,6 +34,10 @@ namespace Atomic
 class XMLElement;
 class XMLElement;
 class XMLFile;
 class XMLFile;
 
 
+// ATOMIC BEGIN
+class ScriptRenderPathCommand;
+// ATOMIC END
+
 /// Rendering path command types.
 /// Rendering path command types.
 enum RenderCommandType
 enum RenderCommandType
 {
 {
@@ -270,6 +274,13 @@ public:
     Vector<RenderTargetInfo> renderTargets_;
     Vector<RenderTargetInfo> renderTargets_;
     /// Rendering commands.
     /// Rendering commands.
     Vector<RenderPathCommand> commands_;
     Vector<RenderPathCommand> commands_;
+
+    // ATOMIC BEGIN
+    /// Gets the render command at specified index, note SetCommand must be called to update the RenderPath with any changes
+    bool GetCommand(unsigned index, ScriptRenderPathCommand* dst);
+    /// Sets the render command at specified index
+    bool SetCommand(unsigned index, ScriptRenderPathCommand* src);
+    // ATOMIC END
 };
 };
 
 
 }
 }

+ 29 - 0
Source/Atomic/Script/ScriptRenderPathCommand.cpp

@@ -0,0 +1,29 @@
+//
+// Copyright (c) 2014-2017, THUNDERBEAST GAMES LLC All rights reserved
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+
+#include "ScriptRenderPathCommand.h"
+
+namespace Atomic
+{
+
+}

+ 59 - 0
Source/Atomic/Script/ScriptRenderPathCommand.h

@@ -0,0 +1,59 @@
+//
+// Copyright (c) 2014-2017, THUNDERBEAST GAMES LLC All rights reserved
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#pragma once
+
+#include "../Core/Variant.h"
+#include "../Graphics/RenderPath.h"
+
+namespace Atomic
+{
+
+    /// Wrapper around RenderPathCommand as that is setup as a struct and usage a significant delta in order to change to RefCounted
+    class ATOMIC_API ScriptRenderPathCommand : public RefCounted
+    {
+        ATOMIC_REFCOUNTED(ScriptRenderPathCommand)
+
+    public:
+
+        /// Construct.
+        ScriptRenderPathCommand()
+        {
+
+        }
+
+        virtual ~ScriptRenderPathCommand()
+        {
+
+        }
+
+        /// Set a shader parameter.
+        void SetShaderParameter(const String& name, const Variant& value) { renderPathCommand_.SetShaderParameter(name, value); }
+
+        /// Gets tag associated with command
+        const String& GetTag() const { return renderPathCommand_.tag_; }
+
+        RenderPathCommand renderPathCommand_;
+
+    };
+
+}

+ 43 - 0
Source/AtomicJS/Javascript/JSGraphics.cpp

@@ -28,6 +28,7 @@
 #include <Atomic/Graphics/Octree.h>
 #include <Atomic/Graphics/Octree.h>
 #include <Atomic/Graphics/Camera.h>
 #include <Atomic/Graphics/Camera.h>
 #include <Atomic/Scene/Node.h>
 #include <Atomic/Scene/Node.h>
+#include <Atomic/Script/ScriptRenderPathCommand.h>
 
 
 namespace Atomic
 namespace Atomic
 {
 {
@@ -337,6 +338,37 @@ static int Octree_Raycast(duk_context* ctx)
     return 1;
     return 1;
 }
 }
 
 
+static int RenderPath_SetShaderParameter(duk_context* ctx)
+{
+    const char* name = duk_require_string(ctx, 0);
+
+    Variant value;
+    js_to_variant(ctx, 1, value);
+
+    duk_push_this(ctx);
+    RenderPath* renderPath = js_to_class_instance<RenderPath>(ctx, -1, 0);
+
+    renderPath->SetShaderParameter(name, value);
+
+    return 0;
+}
+
+
+static int RenderPathCommand_SetShaderParameter(duk_context* ctx)
+{
+    const char* name = duk_require_string(ctx, 0);
+
+    Variant value;
+    js_to_variant(ctx, 1, value);
+
+    duk_push_this(ctx);
+    ScriptRenderPathCommand* scriptRenderPathCommand = js_to_class_instance<ScriptRenderPathCommand>(ctx, -1, 0);
+
+    scriptRenderPathCommand->renderPathCommand_.SetShaderParameter(name, value);
+
+    return 0;
+}
+
 void jsapi_init_graphics(JSVM* vm)
 void jsapi_init_graphics(JSVM* vm)
 {
 {
     duk_context* ctx = vm->GetJSContext();
     duk_context* ctx = vm->GetJSContext();
@@ -373,6 +405,17 @@ void jsapi_init_graphics(JSVM* vm)
     duk_put_prop_string(ctx, -2, "getScreenRay");
     duk_put_prop_string(ctx, -2, "getScreenRay");
     duk_pop(ctx);
     duk_pop(ctx);
 
 
+
+    js_class_get_prototype(ctx, "Atomic", "RenderPath");
+    duk_push_c_function(ctx, RenderPath_SetShaderParameter, 2);
+    duk_put_prop_string(ctx, -2, "setShaderParameter");
+    duk_pop(ctx);
+
+    js_class_get_prototype(ctx, "Atomic", "RenderPathCommand");
+    duk_push_c_function(ctx, RenderPathCommand_SetShaderParameter, 2);
+    duk_put_prop_string(ctx, -2, "setShaderParameter");
+    duk_pop(ctx);
+
     // static methods
     // static methods
     js_class_get_constructor(ctx, "Atomic", "Material");
     js_class_get_constructor(ctx, "Atomic", "Material");
     duk_push_c_function(ctx, Material_GetTextureUnitName, 1);
     duk_push_c_function(ctx, Material_GetTextureUnitName, 1);