// 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>
typedef std::vector< std::string > HintsArray;
-
-struct GeometryTypePair
-{
- const char* name;
- GeometryType type;
-};
-
-const GeometryTypePair GeometryTypeTable[]=
-{
- {"image", GEOMETRY_TYPE_IMAGE },
- {"mesh", GEOMETRY_TYPE_UNTEXTURED_MESH },
- {"textured-mesh", GEOMETRY_TYPE_TEXTURED_MESH },
-};
-
-const unsigned int GeometryTypeTableCount = sizeof(GeometryTypeTable)/sizeof(GeometryTypeTable[0]);
-
struct GeometryHintPair
{
const char* name;
struct ShaderParameters
{
ShaderParameters()
- : mType( GEOMETRY_TYPE_IMAGE),
- mHints( ShaderEffect::HINT_NONE )
+ : mHints( ShaderEffect::HINT_NONE )
{
}
- void SetGeometryType( v8::Isolate* isolate, const std::string& typeName )
- {
- for( unsigned int i = 0; i < GeometryTypeTableCount; ++i )
- {
- if( typeName == GeometryTypeTable[i].name )
- {
- mType = GeometryTypeTable[i].type;
- return;
- }
- }
- DALI_SCRIPT_EXCEPTION( isolate, "Geometry type not found\n");
- }
-
ShaderEffect::GeometryHints GetGeometryHint( const std::string& hint )
{
for( unsigned int i = 0 ; i < GeometryHintTableCount; ++i )
}
}
-
-
ShaderEffect NewShader()
{
return ShaderEffect::NewWithPrefix( mVertexPrefix ,
mVertex,
mFragmentPrefix,
mFragment,
- mType,
mHints);
}
std::string mVertexPrefix;
std::string mVertex;
std::string mFragmentPrefix;
std::string mFragment;
- GeometryType mType;
ShaderEffect::GeometryHints mHints;
};
* @for ShaderEffect
* @method ShaderEffect
* @param {Object} shaderOptions
- * @param {String} [shaderOptions.geometryType] Type of geometry to be rendered with the effect. "image", "text", "mesh", "textured-mesh", default is image.
+ * @param {String} [shaderOptions.geometryType] Type of geometry to be rendered with the effect. "image", "text", "mesh", "texturedMesh", default is image.
* @param {String} [shaderOptions.vertexShaderPrefix] This string will be inserted before the default uniforms for the vertex shader(ideal for #defines)
* @param {String} [shaderOptions.vertexShader] VertexShader code for the effect. If not defined, the default version will be used
* @param {String} [shaderOptions.fragmentShaderPrefix] This string will be inserted before the default uniforms for the fragment shader(ideal for #defines)
*/
ShaderEffect ShaderEffectApi::New( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
{
-
-
v8::HandleScope handleScope( isolate );
- ShaderParameters shaderParams;
-
if( args[0]->IsObject() )
{
- v8::Local<v8::Object > obj = args[0]->ToObject();
+ ShaderParameters shaderParams;
- v8::Local<v8::Value> geometryTypeValue = obj->Get(v8::String::NewFromUtf8( isolate, "geometryType"));
- if( geometryTypeValue->IsString() )
- {
- std::string geometryTypeName = V8Utils::v8StringToStdString( geometryTypeValue );
- // printf(" geometry type found %s \n", geometryTypeName.c_str() );
- shaderParams.SetGeometryType( isolate, geometryTypeName );
- }
+ v8::Local<v8::Object > obj = args[0]->ToObject();
v8::Local<v8::Value> vertexPrefixValue = obj->Get(v8::String::NewFromUtf8( isolate, "vertexShaderPrefix"));
if( vertexPrefixValue->IsString() )
}
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,