2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/effects/shader-impl.h> // Dali::Internal::Shader
22 #include <dali/public-api/shader-effects/shader.h> // Dali::Shader
23 #include <dali/public-api/shader-effects/shader-effect.h> // Dali::ShaderEffect::GeometryHints // TODO: MESH_REWORK REMOVE
25 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
26 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
28 #include <dali/internal/event/common/thread-local-storage.h>
29 #include <dali/internal/event/effects/shader-factory.h>
30 #include <dali/internal/event/resources/resource-ticket.h>
31 #include <dali/internal/update/manager/update-manager.h>
42 * |name |type |writable|animatable|constraint-input|enum for index-checking|
44 DALI_PROPERTY_TABLE_BEGIN
45 DALI_PROPERTY( "program", MAP, true, false, false, Dali::Shader::Property::PROGRAM )
46 DALI_PROPERTY( "shader-hints", UNSIGNED_INTEGER, true, false, true, Dali::Shader::Property::SHADER_HINTS )
47 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
49 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> SHADER_IMPL = { DEFAULT_PROPERTY_DETAILS };
51 } // unnamed namespace
53 ShaderPtr Shader::New( const std::string& vertexShader,
54 const std::string& fragmentShader,
55 Dali::Shader::ShaderHints hints )
58 ShaderPtr shader( new Shader() );
59 shader->Initialize( vertexShader, fragmentShader, hints );
63 const SceneGraph::Shader* Shader::GetShaderSceneObject() const
68 unsigned int Shader::GetDefaultPropertyCount() const
70 return SHADER_IMPL.GetDefaultPropertyCount();
73 void Shader::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
75 SHADER_IMPL.GetDefaultPropertyIndices( indices );
78 const char* Shader::GetDefaultPropertyName(Property::Index index) const
80 return SHADER_IMPL.GetDefaultPropertyName( index );
83 Property::Index Shader::GetDefaultPropertyIndex( const std::string& name ) const
85 return SHADER_IMPL.GetDefaultPropertyIndex( name );
88 bool Shader::IsDefaultPropertyWritable( Property::Index index ) const
90 return SHADER_IMPL.IsDefaultPropertyWritable( index );
93 bool Shader::IsDefaultPropertyAnimatable( Property::Index index ) const
95 return SHADER_IMPL.IsDefaultPropertyAnimatable( index );
98 bool Shader::IsDefaultPropertyAConstraintInput( Property::Index index ) const
100 return SHADER_IMPL.IsDefaultPropertyAConstraintInput( index );
103 Property::Type Shader::GetDefaultPropertyType( Property::Index index ) const
105 return SHADER_IMPL.GetDefaultPropertyType( index );
108 void Shader::SetDefaultProperty( Property::Index index,
109 const Property::Value& propertyValue )
113 case Dali::Shader::Property::PROGRAM:
115 // @todo MESH_REWORK Set program again?
116 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
119 case Dali::Shader::Property::SHADER_HINTS:
121 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
127 void Shader::SetSceneGraphProperty( Property::Index index,
128 const PropertyMetadata& entry,
129 const Property::Value& value )
131 SHADER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
132 OnPropertySet(index, value);
135 Property::Value Shader::GetDefaultProperty( Property::Index index ) const
137 Property::Value value;
141 case Dali::Shader::Property::PROGRAM:
143 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
146 case Dali::Shader::Property::SHADER_HINTS:
148 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
156 const SceneGraph::PropertyOwner* Shader::GetPropertyOwner() const
161 const SceneGraph::PropertyOwner* Shader::GetSceneObject() const
166 const SceneGraph::PropertyBase* Shader::GetSceneObjectAnimatableProperty( Property::Index index ) const
168 DALI_ASSERT_ALWAYS( IsPropertyAnimatable( index ) && "Property is not animatable" );
169 const SceneGraph::PropertyBase* property = NULL;
173 property = SHADER_IMPL.GetRegisteredSceneGraphProperty( this,
174 &Shader::FindAnimatableProperty,
175 &Shader::FindCustomProperty,
178 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
180 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
187 const PropertyInputImpl* Shader::GetSceneObjectInputProperty( Property::Index index ) const
189 const PropertyInputImpl* property = NULL;
193 const SceneGraph::PropertyBase* baseProperty =
194 SHADER_IMPL.GetRegisteredSceneGraphProperty( this,
195 &Shader::FindAnimatableProperty,
196 &Shader::FindCustomProperty,
198 property = static_cast<const PropertyInputImpl*>( baseProperty );
200 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
202 if( index == Dali::Shader::Property::SHADER_HINTS )
204 // @todo MESH_REWORK - return the property
208 DALI_ASSERT_ALWAYS( 0 && "Property is not a valid constraint input" );
216 int Shader::GetPropertyComponentIndex( Property::Index index ) const
218 return Property::INVALID_COMPONENT_INDEX;
221 bool Shader::OnStage() const
226 void Shader::Connect()
231 void Shader::Disconnect()
237 : mSceneObject( NULL ),
242 void Shader::Initialize(
243 const std::string& vertexSource,
244 const std::string& fragmentSource,
245 Dali::Shader::ShaderHints hints )
247 DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" );
248 EventThreadServices& eventThreadServices = GetEventThreadServices();
249 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
251 // @todo MESH_REWORK - Pass hints directly to a new scene graph shader
252 int effectHint = Dali::ShaderEffect::HINT_NONE;
253 if( hints & Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT )
255 effectHint |= Dali::ShaderEffect::HINT_BLENDING;
258 if( hints & Dali::Shader::HINT_REQUIRES_SELF_DEPTH_TEST )
260 effectHint |= Dali::ShaderEffect::HINT_DEPTH_BUFFER;
263 if( (hints & Dali::Shader::HINT_MODIFIES_GEOMETRY) == 0x0 )
265 effectHint |= Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY;
267 Dali::ShaderEffect::GeometryHints shaderEffectHint = static_cast<Dali::ShaderEffect::GeometryHints>( effectHint );
269 mSceneObject = new SceneGraph::Shader(shaderEffectHint);
271 // Add to update manager
272 AddShaderMessage( updateManager, *mSceneObject );
274 ThreadLocalStorage& tls = ThreadLocalStorage::Get();
275 ShaderFactory& shaderFactory = tls.GetShaderFactory();
278 mTicket = ResourceTicketPtr( shaderFactory.Load(vertexSource, fragmentSource, shaderHash) );
280 // Add shader program to scene-object using a message to the UpdateManager
281 SetShaderProgramMessage( updateManager, *mSceneObject, mTicket->GetId(), shaderHash, false );
286 if( EventThreadServices::IsCoreRunning() )
288 EventThreadServices& eventThreadServices = GetEventThreadServices();
289 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
290 RemoveShaderMessage( updateManager, *mSceneObject);
295 } // namespace Internal