/*
- * Copyright (c) 2016 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/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[] =
{ { "NONE", Dali::Shader::Hint::NONE},
{ "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)
return Property::Value(s);
}
-
} // unnamed namespace
ShaderPtr Shader::New( const std::string& vertexShader,
const std::string& fragmentShader,
Dali::Shader::Hint::Value hints )
{
- ShaderPtr shader( new Shader() );
- shader->Initialize( vertexShader, fragmentShader, hints );
- return shader;
-}
-
-const SceneGraph::Shader* Shader::GetShaderSceneObject() const
-{
- return mSceneObject;
-}
-
-SceneGraph::Shader* Shader::GetShaderSceneObject()
-{
- return mSceneObject;
-}
-
-unsigned int Shader::GetDefaultPropertyCount() const
-{
- return SHADER_IMPL.GetDefaultPropertyCount();
-}
+ // 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 );
-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();
+ const Dali::Property::Map* map = propertyValue.GetMap();
if( map )
{
std::string vertex;
);
}
- Initialize(vertex, fragment, hints );
+ SetShader( 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
-{
- 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;
-}
-
-const PropertyInputImpl* Shader::GetSceneObjectInputProperty( Property::Index index ) const
+Property::Value Shader::GetDefaultPropertyCurrentValue( Property::Index index ) const
{
- PropertyMetadata* property = NULL;
-
- if( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && // Child properties are also stored as custom properties
- ( index <= PROPERTY_CUSTOM_MAX_INDEX ) )
- {
- property = FindCustomProperty( index );
- }
- else if( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
- {
- property = FindAnimatableProperty( index );
- }
-
- DALI_ASSERT_ALWAYS( property && "property index is invalid" );
- return property->GetSceneGraphProperty();
+ return GetDefaultProperty( index ); // Event-side only properties
}
-int Shader::GetPropertyComponentIndex( Property::Index index ) const
+Shader::Shader( const SceneGraph::Shader* sceneObject )
+: Object( sceneObject ),
+ mShaderData( nullptr )
{
- return Property::INVALID_COMPONENT_INDEX;
}
-Shader::Shader()
- : mSceneObject( NULL ),
- mShaderData( NULL )
+void Shader::SetShader( const std::string& vertexSource,
+ const std::string& fragmentSource,
+ Dali::Shader::Hint::Value hints )
{
-}
-
-void Shader::Initialize(
- const std::string& vertexSource,
- const std::string& fragmentSource,
- Dali::Shader::Hint::Value hints )
-{
- EventThreadServices& eventThreadServices = GetEventThreadServices();
- SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
- mSceneObject = new SceneGraph::Shader( hints );
-
- // 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 );
}