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/material-impl.h> // Dali::Internal::Material
22 #include <dali/public-api/shader-effects/material.h> // Dali::Internal::Material
23 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
24 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
25 #include <dali/internal/update/effects/scene-graph-material.h>
26 #include <dali/internal/update/effects/scene-graph-sampler.h>
27 #include <dali/internal/update/manager/update-manager.h>
38 * |name |type |writable|animatable|constraint-input|enum for index-checking|
40 DALI_PROPERTY_TABLE_BEGIN
41 DALI_PROPERTY( "color", VECTOR4, true, true, true, Dali::Material::Property::COLOR )
42 DALI_PROPERTY( "face-culling-mode", STRING, true, false, true, Dali::Material::Property::FACE_CULLING_MODE )
43 DALI_PROPERTY( "blending-mode", STRING, true, false, true, Dali::Material::Property::BLENDING_MODE )
44 DALI_PROPERTY( "blend-equation", STRING, true, false, true, Dali::Material::Property::BLEND_EQUATION )
45 DALI_PROPERTY( "source-blend-factor-rgb", STRING, true, false, true, Dali::Material::Property::BLENDING_SRC_FACTOR_RGB )
46 DALI_PROPERTY( "destination-blend-factor-rgb", STRING, true, false, true, Dali::Material::Property::BLENDING_DEST_FACTOR_RGB )
47 DALI_PROPERTY( "source-blend-factor-alpha", STRING, true, false, true, Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA )
48 DALI_PROPERTY( "destination-blend-factor-alpha", STRING, true, false, true, Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA )
49 DALI_PROPERTY( "blend-color", VECTOR4, true, true, true, Dali::Material::Property::BLEND_COLOR )
50 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
52 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> MATERIAL_IMPL = { DEFAULT_PROPERTY_DETAILS };
54 } // unnamed namespace
56 MaterialPtr Material::New()
58 MaterialPtr material( new Material() );
59 material->Initialize();
63 void Material::SetShader( Shader& shader )
65 DALI_ASSERT_DEBUG( mSceneObject )
66 mShaderConnector.Set( shader, OnStage() );
68 const SceneGraph::Shader& sceneGraphShader = dynamic_cast<const SceneGraph::Shader&>( *shader.GetSceneObject() );
69 SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
72 void Material::AddSampler( Sampler& sampler )
74 SamplerConnector connector;
75 connector.Set( sampler, OnStage() );
76 mSamplerConnectors.push_back( connector );
78 const SceneGraph::Sampler& sceneGraphSampler = dynamic_cast<const SceneGraph::Sampler&>( *sampler.GetSceneObject() );
79 SceneGraph::AddSamplerMessage( GetEventThreadServices(), *mSceneObject, sceneGraphSampler );
82 std::size_t Material::GetNumberOfSamplers() const
84 return mSamplerConnectors.size();
87 void Material::RemoveSampler( std::size_t index )
89 mSamplerConnectors.erase( mSamplerConnectors.begin() + index );
92 void Material::SetFaceCullingMode( Dali::Material::FaceCullingMode cullingMode )
95 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
98 void Material::SetBlendMode( BlendingMode::Type mode )
101 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
104 BlendingMode::Type Material::GetBlendMode() const
107 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
108 return BlendingMode::AUTO;
111 void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
114 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
117 void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
118 BlendingFactor::Type destFactorRgb,
119 BlendingFactor::Type srcFactorAlpha,
120 BlendingFactor::Type destFactorAlpha )
123 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
126 void Material::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
127 BlendingFactor::Type& destFactorRgb,
128 BlendingFactor::Type& srcFactorAlpha,
129 BlendingFactor::Type& destFactorAlpha ) const
132 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
135 void Material::SetBlendEquation( BlendingEquation::Type equationRgba )
138 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
141 void Material::SetBlendEquation( BlendingEquation::Type equationRgb,
142 BlendingEquation::Type equationAlpha )
145 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
148 void Material::GetBlendEquation( BlendingEquation::Type& equationRgb,
149 BlendingEquation::Type& equationAlpha ) const
152 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
155 void Material::SetBlendColor( const Vector4& color )
158 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
161 const Vector4& Material::GetBlendColor() const
164 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
168 const SceneGraph::Material* Material::GetMaterialSceneObject() const
173 unsigned int Material::GetDefaultPropertyCount() const
175 return MATERIAL_IMPL.GetDefaultPropertyCount();
178 void Material::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
180 MATERIAL_IMPL.GetDefaultPropertyIndices( indices );
183 const char* Material::GetDefaultPropertyName(Property::Index index) const
185 return MATERIAL_IMPL.GetDefaultPropertyName( index );
188 Property::Index Material::GetDefaultPropertyIndex( const std::string& name ) const
190 return MATERIAL_IMPL.GetDefaultPropertyIndex( name );
193 bool Material::IsDefaultPropertyWritable( Property::Index index ) const
195 return MATERIAL_IMPL.IsDefaultPropertyWritable( index );
198 bool Material::IsDefaultPropertyAnimatable( Property::Index index ) const
200 return MATERIAL_IMPL.IsDefaultPropertyAnimatable( index );
203 bool Material::IsDefaultPropertyAConstraintInput( Property::Index index ) const
205 return MATERIAL_IMPL.IsDefaultPropertyAConstraintInput( index );
208 Property::Type Material::GetDefaultPropertyType( Property::Index index ) const
210 return MATERIAL_IMPL.GetDefaultPropertyType( index );
213 void Material::SetDefaultProperty( Property::Index index,
214 const Property::Value& propertyValue )
218 case Dali::Material::Property::COLOR:
220 SceneGraph::PropertyMessage<Vector4>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mColor, &SceneGraph::AnimatableProperty<Vector4>::Bake, propertyValue.Get<Vector4>() );
223 case Dali::Material::Property::FACE_CULLING_MODE:
225 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
228 case Dali::Material::Property::BLENDING_MODE:
230 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
233 case Dali::Material::Property::BLEND_EQUATION:
235 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
238 case Dali::Material::Property::BLENDING_SRC_FACTOR_RGB:
240 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
243 case Dali::Material::Property::BLENDING_DEST_FACTOR_RGB:
245 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
248 case Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA:
250 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
253 case Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA:
255 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
258 case Dali::Material::Property::BLEND_COLOR:
260 SceneGraph::PropertyMessage<Vector4>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mBlendColor, &SceneGraph::AnimatableProperty<Vector4>::Bake, propertyValue.Get<Vector4>() );
266 void Material::SetSceneGraphProperty( Property::Index index,
267 const PropertyMetadata& entry,
268 const Property::Value& value )
270 MATERIAL_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
271 OnPropertySet(index, value);
274 Property::Value Material::GetDefaultProperty( Property::Index index ) const
276 BufferIndex bufferIndex = GetEventThreadServices().GetEventBufferIndex();
277 Property::Value value;
281 case Dali::Material::Property::COLOR:
285 value = mSceneObject->mColor[bufferIndex];
289 case Dali::Material::Property::FACE_CULLING_MODE:
291 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
294 case Dali::Material::Property::BLENDING_MODE:
296 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
299 case Dali::Material::Property::BLEND_EQUATION:
301 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
304 case Dali::Material::Property::BLENDING_SRC_FACTOR_RGB:
306 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
309 case Dali::Material::Property::BLENDING_DEST_FACTOR_RGB:
311 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
314 case Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA:
316 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
319 case Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA:
321 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
324 case Dali::Material::Property::BLEND_COLOR:
328 value = mSceneObject->mBlendColor[bufferIndex];
337 const SceneGraph::PropertyOwner* Material::GetPropertyOwner() const
342 const SceneGraph::PropertyOwner* Material::GetSceneObject() const
347 const SceneGraph::PropertyBase* Material::GetSceneObjectAnimatableProperty( Property::Index index ) const
349 DALI_ASSERT_ALWAYS( IsPropertyAnimatable( index ) && "Property is not animatable" );
351 const SceneGraph::PropertyBase* property = NULL;
355 property = MATERIAL_IMPL.GetRegisteredSceneGraphProperty( this,
356 &Material::FindAnimatableProperty,
357 &Material::FindCustomProperty,
360 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
364 case Dali::Material::Property::COLOR:
366 property = &mSceneObject->mColor;
369 case Dali::Material::Property::BLEND_COLOR:
371 property = &mSceneObject->mBlendColor;
376 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable");
386 const PropertyInputImpl* Material::GetSceneObjectInputProperty( Property::Index index ) const
388 const PropertyInputImpl* property = NULL;
392 const SceneGraph::PropertyBase* baseProperty =
393 MATERIAL_IMPL.GetRegisteredSceneGraphProperty( this,
394 &Material::FindAnimatableProperty,
395 &Material::FindCustomProperty,
397 property = static_cast<const PropertyInputImpl*>( baseProperty );
399 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
403 case Dali::Material::Property::COLOR:
405 property = &mSceneObject->mColor;
408 case Dali::Material::Property::FACE_CULLING_MODE:
410 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
413 case Dali::Material::Property::BLENDING_MODE:
415 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
418 case Dali::Material::Property::BLEND_EQUATION:
420 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
423 case Dali::Material::Property::BLENDING_SRC_FACTOR_RGB:
425 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
428 case Dali::Material::Property::BLENDING_DEST_FACTOR_RGB:
430 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
433 case Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA:
435 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
438 case Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA:
440 DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
443 case Dali::Material::Property::BLEND_COLOR:
445 property = &mSceneObject->mBlendColor;
450 DALI_ASSERT_ALWAYS( 0 && "Property cannot be a constraint input");
460 int Material::GetPropertyComponentIndex( Property::Index index ) const
462 return Property::INVALID_COMPONENT_INDEX;
465 bool Material::OnStage() const
470 void Material::Connect()
474 SamplerConnectorContainer::const_iterator end = mSamplerConnectors.end();
475 for( SamplerConnectorContainer::iterator it = mSamplerConnectors.begin();
479 it->OnStageConnect();
483 void Material::Disconnect()
487 SamplerConnectorContainer::const_iterator end = mSamplerConnectors.end();
488 for( SamplerConnectorContainer::iterator it = mSamplerConnectors.begin();
492 it->OnStageDisconnect();
497 : mSceneObject( NULL ),
502 void Material::Initialize()
504 EventThreadServices& eventThreadServices = GetEventThreadServices();
505 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
507 DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" );
509 mSceneObject = new SceneGraph::Material();
510 AddMessage( updateManager, updateManager.GetMaterialOwner(), *mSceneObject );
513 Material::~Material()
515 if( EventThreadServices::IsCoreRunning() )
517 EventThreadServices& eventThreadServices = GetEventThreadServices();
518 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
519 RemoveMessage( updateManager, updateManager.GetMaterialOwner(), *mSceneObject );
523 } // namespace Internal