From: Richard Huang Date: Mon, 9 Mar 2015 16:19:03 +0000 (+0000) Subject: Allow to create shader effect which is type-registered by its type name in JavaScript X-Git-Tag: accepted/tizen/mobile/20150419.232751~2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=be530b01f4a127a90f4af6346fc618769b5bd022 Allow to create shader effect which is type-registered by its type name in JavaScript Change-Id: I27145106837a36133b6a994cd869c3b03adea5d9 --- diff --git a/plugins/dali-script-v8/docs/content/shader-effect.js b/plugins/dali-script-v8/docs/content/shader-effect.js index a83df51..98e9c17 100644 --- a/plugins/dali-script-v8/docs/content/shader-effect.js +++ b/plugins/dali-script-v8/docs/content/shader-effect.js @@ -5,7 +5,13 @@ 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: ``` diff --git a/plugins/dali-script-v8/src/actors/actor-wrapper.h b/plugins/dali-script-v8/src/actors/actor-wrapper.h index 79381ba..76eee47 100644 --- a/plugins/dali-script-v8/src/actors/actor-wrapper.h +++ b/plugins/dali-script-v8/src/actors/actor-wrapper.h @@ -52,8 +52,7 @@ public: MESH_ACTOR =3, LAYER_ACTOR =4, CAMERA_ACTOR =5, - LIGHT_ACTOR =6, - TEXT_VIEW =7 + TEXT_VIEW =6 }; /** diff --git a/plugins/dali-script-v8/src/shader-effects/shader-effect-api.cpp b/plugins/dali-script-v8/src/shader-effects/shader-effect-api.cpp index 74762f2..d7bd2a5 100644 --- a/plugins/dali-script-v8/src/shader-effects/shader-effect-api.cpp +++ b/plugins/dali-script-v8/src/shader-effects/shader-effect-api.cpp @@ -19,6 +19,9 @@ // CLASS HEADER #include "shader-effect-api.h" +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include #include @@ -187,14 +190,12 @@ ShaderEffect GetShaderEffect( v8::Isolate* isolate, const v8::FunctionCallbackIn */ ShaderEffect ShaderEffectApi::New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args ) { - - v8::HandleScope handleScope( isolate ); - ShaderParameters shaderParams; - if( args[0]->IsObject() ) { + ShaderParameters shaderParams; + v8::Local obj = args[0]->ToObject(); v8::Local geometryTypeValue = obj->Get(v8::String::NewFromUtf8( isolate, "geometryType")); @@ -245,9 +246,39 @@ ShaderEffect ShaderEffectApi::New( v8::Isolate* isolate, const v8::FunctionCall } 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, diff --git a/plugins/dali-script-v8/src/shader-effects/shader-effect-wrapper.cpp b/plugins/dali-script-v8/src/shader-effects/shader-effect-wrapper.cpp index 04ae5fa..89f4ebe 100644 --- a/plugins/dali-script-v8/src/shader-effects/shader-effect-wrapper.cpp +++ b/plugins/dali-script-v8/src/shader-effects/shader-effect-wrapper.cpp @@ -126,8 +126,11 @@ void ShaderEffectWrapper::NewShaderEffect( const v8::FunctionCallbackInfo< v8::V } Dali::ShaderEffect shaderEffect = ShaderEffectApi::New( isolate, args ); - v8::Local localObject = WrapShaderEffect( isolate, shaderEffect ); - args.GetReturnValue().Set( localObject ); + if(shaderEffect) + { + v8::Local localObject = WrapShaderEffect( isolate, shaderEffect ); + args.GetReturnValue().Set( localObject ); + } }