Allow to create shader effect which is type-registered by its type name in JavaScript 36/36536/6
authorRichard Huang <r.huang@samsung.com>
Mon, 9 Mar 2015 16:19:03 +0000 (16:19 +0000)
committerRichard Huang <r.huang@samsung.com>
Mon, 23 Mar 2015 14:40:44 +0000 (14:40 +0000)
Change-Id: I27145106837a36133b6a994cd869c3b03adea5d9

plugins/dali-script-v8/docs/content/shader-effect.js
plugins/dali-script-v8/src/actors/actor-wrapper.h
plugins/dali-script-v8/src/shader-effects/shader-effect-api.cpp
plugins/dali-script-v8/src/shader-effects/shader-effect-wrapper.cpp

index a83df51..98e9c17 100644 (file)
@@ -5,7 +5,13 @@
 
 Shader effects provide a visual effect for actors.
 
 
 Shader effects provide a visual effect for actors.
 
-For a Custom shader you can provide the vertex and fragment shader code as strings.
+You can create a type-registered shader effect by its type name.
+```
+// create a new shader effect
+var shader = new dali.ShaderEffect("BlindEffect");
+```
+
+Alternatively you can create a Custom shader by providing the vertex and fragment shader code as strings.
 Each shader is provided with default uniforms and attributes.
 For a vertex shader this part contains the following code:
 ```
 Each shader is provided with default uniforms and attributes.
 For a vertex shader this part contains the following code:
 ```
index 79381ba..76eee47 100644 (file)
@@ -52,8 +52,7 @@ public:
     MESH_ACTOR   =3,
     LAYER_ACTOR  =4,
     CAMERA_ACTOR =5,
     MESH_ACTOR   =3,
     LAYER_ACTOR  =4,
     CAMERA_ACTOR =5,
-    LIGHT_ACTOR  =6,
-    TEXT_VIEW    =7
+    TEXT_VIEW    =6
   };
 
   /**
   };
 
   /**
index 74762f2..d7bd2a5 100644 (file)
@@ -19,6 +19,9 @@
 // CLASS HEADER
 #include "shader-effect-api.h"
 
 // CLASS HEADER
 #include "shader-effect-api.h"
 
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry.h>
+
 // INTERNAL INCLUDES
 #include <v8-utils.h>
 #include <shader-effects/shader-effect-wrapper.h>
 // INTERNAL INCLUDES
 #include <v8-utils.h>
 #include <shader-effects/shader-effect-wrapper.h>
@@ -187,14 +190,12 @@ ShaderEffect GetShaderEffect( v8::Isolate* isolate, const v8::FunctionCallbackIn
  */
 ShaderEffect ShaderEffectApi::New(  v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
 {
  */
 ShaderEffect ShaderEffectApi::New(  v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
 {
-
-
   v8::HandleScope handleScope( isolate );
 
   v8::HandleScope handleScope( isolate );
 
-  ShaderParameters shaderParams;
-
   if( args[0]->IsObject() )
   {
   if( args[0]->IsObject() )
   {
+    ShaderParameters shaderParams;
+
     v8::Local<v8::Object > obj = args[0]->ToObject();
 
     v8::Local<v8::Value> geometryTypeValue = obj->Get(v8::String::NewFromUtf8( isolate, "geometryType"));
     v8::Local<v8::Object > obj = args[0]->ToObject();
 
     v8::Local<v8::Value> geometryTypeValue = obj->Get(v8::String::NewFromUtf8( isolate, "geometryType"));
@@ -245,9 +246,39 @@ ShaderEffect ShaderEffectApi::New(  v8::Isolate* isolate, const v8::FunctionCall
       }
       shaderParams.ProcessHintsArray( hintsArray );
     }
       }
       shaderParams.ProcessHintsArray( hintsArray );
     }
+
+    return shaderParams.NewShader();
   }
   }
-  return shaderParams.NewShader();
+  else
+  {
+    ShaderEffect effect;
+
+    bool found( false );
+    std::string typeName = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+    if( !found )
+    {
+      DALI_SCRIPT_EXCEPTION( isolate, "string parameter missing" );
+    }
+    else
+    {
+      // create a new shader effect based on type, using the type registry.
+      Dali::TypeInfo typeInfo = Dali::TypeRegistry::Get().GetTypeInfo( typeName );
+      if( typeInfo ) // handle, check if it has a value
+      {
+        Dali::BaseHandle handle = typeInfo.CreateInstance();
+        if( handle )
+        {
+          effect = ShaderEffect::DownCast( handle );
+        }
+      }
+      else
+      {
+        DALI_SCRIPT_EXCEPTION(isolate,"Unknown shader effect type");
+      }
+    }
 
 
+    return effect;
+  }
 }
 
 ShaderEffect ShaderEffectApi::GetShaderEffectFromParams( int paramIndex,
 }
 
 ShaderEffect ShaderEffectApi::GetShaderEffectFromParams( int paramIndex,
index 04ae5fa..89f4ebe 100644 (file)
@@ -126,8 +126,11 @@ void ShaderEffectWrapper::NewShaderEffect( const v8::FunctionCallbackInfo< v8::V
   }
   Dali::ShaderEffect shaderEffect = ShaderEffectApi::New( isolate, args );
 
   }
   Dali::ShaderEffect shaderEffect = ShaderEffectApi::New( isolate, args );
 
-  v8::Local<v8::Object> localObject = WrapShaderEffect( isolate, shaderEffect );
-  args.GetReturnValue().Set( localObject );
+  if(shaderEffect)
+  {
+    v8::Local<v8::Object> localObject = WrapShaderEffect( isolate, shaderEffect );
+    args.GetReturnValue().Set( localObject );
+  }
 }
 
 
 }