/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// INTERNAL INCLUDES
#include <dali/public-api/object/type-registry.h>
-#include <dali/public-api/shader-effects/shader-effect.h> // Dali::ShaderEffect::GeometryHints // TODO: MESH_REWORK REMOVE
-#include <dali/devel-api/rendering/shader.h> // Dali::Shader
#include <dali/devel-api/scripting/scripting.h>
-
-#include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
#include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
#include <dali/internal/event/common/thread-local-storage.h>
#include <dali/internal/event/effects/shader-factory.h>
-#include <dali/internal/event/resources/resource-ticket.h>
#include <dali/internal/update/manager/update-manager.h>
namespace Dali
*/
DALI_PROPERTY_TABLE_BEGIN
DALI_PROPERTY( "program", MAP, true, false, false, Dali::Shader::Property::PROGRAM )
-DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
-
-const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> SHADER_IMPL = { DEFAULT_PROPERTY_DETAILS };
+DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX, ShaderDefaultProperties )
Dali::Scripting::StringEnum ShaderHintsTable[] =
- { { "HINT_NONE", Dali::Shader::HINT_NONE},
- { "HINT_REQUIRES_SELF_DEPTH_TEST", Dali::Shader::HINT_REQUIRES_SELF_DEPTH_TEST},
- { "HINT_OUTPUT_IS_TRANSPARENT", Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT},
- { "HINT_OUTPUT_IS_OPAQUE", Dali::Shader::HINT_OUTPUT_IS_OPAQUE},
- { "HINT_MODIFIES_GEOMETRY", Dali::Shader::HINT_MODIFIES_GEOMETRY}
+ { { "NONE", Dali::Shader::Hint::NONE},
+ { "OUTPUT_IS_TRANSPARENT", Dali::Shader::Hint::OUTPUT_IS_TRANSPARENT},
+ { "MODIFIES_GEOMETRY", Dali::Shader::Hint::MODIFIES_GEOMETRY}
};
-const unsigned int ShaderHintsTableSize = sizeof( ShaderHintsTable ) / sizeof( ShaderHintsTable[0] );
+const uint32_t ShaderHintsTableSize = static_cast<uint32_t>( sizeof( ShaderHintsTable ) / sizeof( ShaderHintsTable[0] ) );
BaseHandle Create()
{
return Dali::BaseHandle();
}
-TypeRegistration mType( typeid( Dali::Shader ), typeid( Dali::Handle ), Create );
+TypeRegistration mType( typeid( Dali::Shader ), typeid( Dali::Handle ), Create, ShaderDefaultProperties );
#define TOKEN_STRING(x) (#x)
to += append;
}
-Property::Value HintString(const Dali::Shader::ShaderHints& hints)
+Property::Value HintString(const Dali::Shader::Hint::Value& hints)
{
std::string s;
- if(hints == Dali::Shader::HINT_NONE)
- {
- s = "HINT_NONE";
- }
-
- if(hints & Dali::Shader::HINT_REQUIRES_SELF_DEPTH_TEST)
+ if(hints == Dali::Shader::Hint::NONE)
{
- AppendString(s, "HINT_REQUIRES_SELF_DEPTH_TEST");
+ s = "NONE";
}
- if(hints & Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT)
+ if(hints & Dali::Shader::Hint::OUTPUT_IS_TRANSPARENT)
{
- AppendString(s, "HINT_OUTPUT_IS_TRANSPARENT");
+ AppendString(s, "OUTPUT_IS_TRANSPARENT");
}
- if(hints & Dali::Shader::HINT_OUTPUT_IS_OPAQUE)
+ if(hints & Dali::Shader::Hint::MODIFIES_GEOMETRY)
{
- AppendString(s, "HINT_OUTPUT_IS_OPAQUE");
- }
-
- if(hints & Dali::Shader::HINT_MODIFIES_GEOMETRY)
- {
- AppendString(s, "HINT_MODIFIES_GEOMETRY");
+ AppendString(s, "MODIFIES_GEOMETRY");
}
return Property::Value(s);
}
-
} // unnamed namespace
ShaderPtr Shader::New( const std::string& vertexShader,
const std::string& fragmentShader,
- Dali::Shader::ShaderHints hints )
-{
- //TODO: MESH_REWORK
- ShaderPtr shader( new Shader() );
- shader->Initialize( vertexShader, fragmentShader, hints );
- return shader;
-}
-
-const SceneGraph::Shader* Shader::GetShaderSceneObject() const
-{
- return mSceneObject;
-}
-
-SceneGraph::Shader* Shader::GetShaderSceneObject()
+ Dali::Shader::Hint::Value hints )
{
- return mSceneObject;
-}
+ // create scene object first so it's guaranteed to exist for the event side
+ auto sceneObject = new SceneGraph::Shader( hints );
+ OwnerPointer< SceneGraph::Shader > transferOwnership( sceneObject );
+ // pass the pointer to base for message passing
+ ShaderPtr shader( new Shader( sceneObject ) );
+ // transfer scene object ownership to update manager
+ auto&& services = shader->GetEventThreadServices();
+ SceneGraph::UpdateManager& updateManager = services.GetUpdateManager();
+ AddShaderMessage( updateManager, transferOwnership );
-unsigned int Shader::GetDefaultPropertyCount() const
-{
- return SHADER_IMPL.GetDefaultPropertyCount();
-}
-
-void Shader::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
-{
- SHADER_IMPL.GetDefaultPropertyIndices( indices );
-}
+ services.RegisterObject( shader.Get() );
+ shader->SetShader( vertexShader, fragmentShader, hints );
-const char* Shader::GetDefaultPropertyName(Property::Index index) const
-{
- return SHADER_IMPL.GetDefaultPropertyName( index );
-}
-
-Property::Index Shader::GetDefaultPropertyIndex( const std::string& name ) const
-{
- return SHADER_IMPL.GetDefaultPropertyIndex( name );
-}
-
-bool Shader::IsDefaultPropertyWritable( Property::Index index ) const
-{
- return SHADER_IMPL.IsDefaultPropertyWritable( index );
-}
-
-bool Shader::IsDefaultPropertyAnimatable( Property::Index index ) const
-{
- return SHADER_IMPL.IsDefaultPropertyAnimatable( index );
-}
-
-bool Shader::IsDefaultPropertyAConstraintInput( Property::Index index ) const
-{
- return SHADER_IMPL.IsDefaultPropertyAConstraintInput( index );
+ return shader;
}
-Property::Type Shader::GetDefaultPropertyType( Property::Index index ) const
+const SceneGraph::Shader& Shader::GetShaderSceneObject() const
{
- return SHADER_IMPL.GetDefaultPropertyType( index );
+ return static_cast<const SceneGraph::Shader&>( GetSceneObject() );
}
-void Shader::SetDefaultProperty( Property::Index index,
- const Property::Value& propertyValue )
+void Shader::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
{
switch(index)
{
{
if( propertyValue.GetType() == Property::MAP )
{
- Dali::Property::Map* map = propertyValue.GetMap();
- std::string vertex;
- std::string fragment;
- Dali::Shader::ShaderHints hints(Dali::Shader::HINT_NONE);
-
- if( Property::Value* value = map->Find("vertex") )
- {
- vertex = value->Get<std::string>();
- }
-
- if( Property::Value* value = map->Find("fragment") )
- {
- fragment = value->Get<std::string>();
- }
-
- if( Property::Value* value = map->Find("hints") )
+ const Dali::Property::Map* map = propertyValue.GetMap();
+ if( map )
{
- static_cast<void>( // ignore return
- Scripting::GetEnumeration< Dali::Shader::ShaderHints >(value->Get<std::string>().c_str(),
- ShaderHintsTable, ShaderHintsTableSize, hints)
- );
+ std::string vertex;
+ std::string fragment;
+ Dali::Shader::Hint::Value hints(Dali::Shader::Hint::NONE);
+
+ if( Property::Value* value = map->Find("vertex") )
+ {
+ vertex = value->Get<std::string>();
+ }
+
+ if( Property::Value* value = map->Find("fragment") )
+ {
+ fragment = value->Get<std::string>();
+ }
+
+ if( Property::Value* value = map->Find("hints") )
+ {
+ static_cast<void>( // ignore return
+ Scripting::GetEnumeration< Dali::Shader::Hint::Value >(value->Get<std::string>().c_str(),
+ ShaderHintsTable, ShaderHintsTableSize, hints)
+ );
+ }
+
+ SetShader( vertex, fragment, hints );
}
-
- Initialize(vertex, fragment, hints );
}
else
{
}
}
-void Shader::SetSceneGraphProperty( Property::Index index,
- const PropertyMetadata& entry,
- const Property::Value& value )
-{
- SHADER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
- OnPropertySet(index, value);
-}
-
Property::Value Shader::GetDefaultProperty( Property::Index index ) const
{
Property::Value value;
return value;
}
-const SceneGraph::PropertyOwner* Shader::GetPropertyOwner() const
+Property::Value Shader::GetDefaultPropertyCurrentValue( Property::Index index ) const
{
- return mSceneObject;
-}
-
-const SceneGraph::PropertyOwner* Shader::GetSceneObject() const
-{
- return mSceneObject;
-}
-
-const SceneGraph::PropertyBase* Shader::GetSceneObjectAnimatableProperty( Property::Index index ) const
-{
- DALI_ASSERT_ALWAYS( IsPropertyAnimatable( index ) && "Property is not animatable" );
- const SceneGraph::PropertyBase* property = NULL;
-
- property = SHADER_IMPL.GetRegisteredSceneGraphProperty( this,
- &Shader::FindAnimatableProperty,
- &Shader::FindCustomProperty,
- index );
-
- if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
- {
- DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
- }
-
- return property;
+ return GetDefaultProperty( index ); // Event-side only properties
}
-const PropertyInputImpl* Shader::GetSceneObjectInputProperty( Property::Index index ) const
+Shader::Shader( const SceneGraph::Shader* sceneObject )
+: Object( sceneObject ),
+ mShaderData( nullptr )
{
- PropertyMetadata* property = NULL;
-
- if(index >= PROPERTY_CUSTOM_START_INDEX )
- {
- property = FindCustomProperty( index );
- }
- else
- {
- property = FindAnimatableProperty( index );
- }
-
- DALI_ASSERT_ALWAYS( property && "property index is invalid" );
- return property->GetSceneGraphProperty();
}
-int Shader::GetPropertyComponentIndex( Property::Index index ) const
+void Shader::SetShader( const std::string& vertexSource,
+ const std::string& fragmentSource,
+ Dali::Shader::Hint::Value hints )
{
- return Property::INVALID_COMPONENT_INDEX;
-}
-
-Shader::Shader()
- : mSceneObject( NULL ),
- mShaderData( NULL )
-{
-}
-
-void Shader::Initialize(
- const std::string& vertexSource,
- const std::string& fragmentSource,
- Dali::Shader::ShaderHints hints )
-{
- EventThreadServices& eventThreadServices = GetEventThreadServices();
- SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
-
- // @todo MESH_REWORK - Pass hints directly to a new scene graph shader
- int effectHint = Dali::ShaderEffect::HINT_NONE;
- if( hints & Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT )
- {
- effectHint |= Dali::ShaderEffect::HINT_BLENDING;
- }
-
- if( hints & Dali::Shader::HINT_REQUIRES_SELF_DEPTH_TEST )
- {
- effectHint |= Dali::ShaderEffect::HINT_DEPTH_BUFFER;
- }
-
- if( (hints & Dali::Shader::HINT_MODIFIES_GEOMETRY) == 0x0 )
- {
- effectHint |= Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY;
- }
- Dali::ShaderEffect::GeometryHints shaderEffectHint = static_cast<Dali::ShaderEffect::GeometryHints>( effectHint );
-
- mSceneObject = new SceneGraph::Shader( shaderEffectHint );
-
- // Add to update manager
- AddShaderMessage( updateManager, *mSceneObject );
-
- // Try to load a precompiled shader binary for the source pair:
+ // Try to load a pre-compiled shader binary for the source pair:
ThreadLocalStorage& tls = ThreadLocalStorage::Get();
ShaderFactory& shaderFactory = tls.GetShaderFactory();
size_t shaderHash;
mShaderData = shaderFactory.Load( vertexSource, fragmentSource, hints, shaderHash );
// Add shader program to scene-object using a message to the UpdateManager
- SetShaderProgramMessage( updateManager, *mSceneObject, mShaderData, (hints & Dali::Shader::HINT_MODIFIES_GEOMETRY) != 0x0 );
- eventThreadServices.RegisterObject( this );
+ EventThreadServices& eventThreadServices = GetEventThreadServices();
+ SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
+ SetShaderProgramMessage( updateManager, GetShaderSceneObject(), mShaderData, (hints & Dali::Shader::Hint::MODIFIES_GEOMETRY) != 0x0 );
}
Shader::~Shader()
{
EventThreadServices& eventThreadServices = GetEventThreadServices();
SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
- RemoveShaderMessage( updateManager, *mSceneObject);
+ RemoveShaderMessage( updateManager, &GetShaderSceneObject() );
eventThreadServices.UnregisterObject( this );
}