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/sampler-impl.h> // Dali::Internal::Sampler
22 #include <dali/public-api/shader-effects/sampler.h> // Dali::Internal::Sampler
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-sampler.h> // Dali::Internal::SceneGraph::Sampler
26 #include <dali/internal/update/manager/update-manager.h>
37 * |name |type |writable|animatable|constraint-input|enum for index-checking|
39 DALI_PROPERTY_TABLE_BEGIN
40 DALI_PROPERTY( "minification-filter", STRING, true, false, true, Dali::Sampler::Property::MINIFICATION_FILTER )
41 DALI_PROPERTY( "magnification-filter", STRING, true, false, true, Dali::Sampler::Property::MAGNIGICATION_FILTER )
42 DALI_PROPERTY( "u-wrap", STRING, true, false, true, Dali::Sampler::Property::U_WRAP )
43 DALI_PROPERTY( "v-wrap", STRING, true, false, true, Dali::Sampler::Property::V_WRAP )
44 DALI_PROPERTY( "affects-transparency", BOOLEAN, true, false, true, Dali::Sampler::Property::AFFECTS_TRANSPARENCY )
45 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
47 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> SAMPLER_IMPL = { DEFAULT_PROPERTY_DETAILS };
49 } // unnamed namespace
51 SamplerPtr Sampler::New( const std::string& textureUnitUniformName )
53 SamplerPtr sampler( new Sampler() );
54 sampler->Initialize( textureUnitUniformName );
58 void Sampler::SetUniformName( const std::string& name )
60 // TODO: MESH_REWORK - change method to SetUnitName (or SetTextureUnitUniformName)
61 SetUnitNameMessage( GetEventThreadServices(), *mSceneObject, name);
64 void Sampler::SetImage( Image& image )
66 unsigned int resourceId = image.GetResourceId();
68 // sceneObject is being used in a separate thread; queue a message to set
69 SetTextureMessage( GetEventThreadServices(), *mSceneObject, resourceId );
72 void Sampler::SetFilterMode( Dali::Sampler::FilterMode minFilter, Dali::Sampler::FilterMode magFilter )
76 void Sampler::SetWrapMode( Dali::Sampler::WrapMode uWrap, Dali::Sampler::WrapMode vWrap )
79 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
82 void Sampler::SetAffectsTransparency( bool affectsTransparency )
85 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
88 const SceneGraph::Sampler* Sampler::GetSamplerSceneObject() const
93 unsigned int Sampler::GetDefaultPropertyCount() const
95 return SAMPLER_IMPL.GetDefaultPropertyCount();
98 void Sampler::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
100 SAMPLER_IMPL.GetDefaultPropertyIndices( indices );
103 const char* Sampler::GetDefaultPropertyName(Property::Index index) const
105 return SAMPLER_IMPL.GetDefaultPropertyName( index );
108 Property::Index Sampler::GetDefaultPropertyIndex( const std::string& name ) const
110 return SAMPLER_IMPL.GetDefaultPropertyIndex( name );
113 bool Sampler::IsDefaultPropertyWritable( Property::Index index ) const
115 return SAMPLER_IMPL.IsDefaultPropertyWritable( index );
118 bool Sampler::IsDefaultPropertyAnimatable( Property::Index index ) const
120 return SAMPLER_IMPL.IsDefaultPropertyAnimatable( index );
123 bool Sampler::IsDefaultPropertyAConstraintInput( Property::Index index ) const
125 return SAMPLER_IMPL.IsDefaultPropertyAConstraintInput( index );
128 Property::Type Sampler::GetDefaultPropertyType( Property::Index index ) const
130 return SAMPLER_IMPL.GetDefaultPropertyType( index );
133 void Sampler::SetDefaultProperty( Property::Index index,
134 const Property::Value& propertyValue )
138 case Dali::Sampler::Property::MINIFICATION_FILTER:
140 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
143 case Dali::Sampler::Property::MAGNIGICATION_FILTER:
145 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
148 case Dali::Sampler::Property::U_WRAP:
150 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
153 case Dali::Sampler::Property::V_WRAP:
155 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
158 case Dali::Sampler::Property::AFFECTS_TRANSPARENCY:
160 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
166 void Sampler::SetSceneGraphProperty( Property::Index index,
167 const PropertyMetadata& entry,
168 const Property::Value& value )
170 SAMPLER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
171 OnPropertySet(index, value);
174 Property::Value Sampler::GetDefaultProperty( Property::Index index ) const
176 Property::Value value;
180 case Dali::Sampler::Property::MINIFICATION_FILTER:
182 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
185 case Dali::Sampler::Property::MAGNIGICATION_FILTER:
187 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
190 case Dali::Sampler::Property::U_WRAP:
192 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
195 case Dali::Sampler::Property::V_WRAP:
197 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
200 case Dali::Sampler::Property::AFFECTS_TRANSPARENCY:
202 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
209 const SceneGraph::PropertyOwner* Sampler::GetPropertyOwner() const
214 const SceneGraph::PropertyOwner* Sampler::GetSceneObject() const
219 const SceneGraph::PropertyBase* Sampler::GetSceneObjectAnimatableProperty( Property::Index index ) const
221 DALI_ASSERT_ALWAYS( IsPropertyAnimatable( index ) && "Property is not animatable" );
223 const SceneGraph::PropertyBase* property = NULL;
227 property = SAMPLER_IMPL.GetRegisteredSceneGraphProperty( this,
228 &Sampler::FindAnimatableProperty,
229 &Sampler::FindCustomProperty,
232 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
234 // No animatable default props
235 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
242 const PropertyInputImpl* Sampler::GetSceneObjectInputProperty( Property::Index index ) const
244 const PropertyInputImpl* property = NULL;
248 const SceneGraph::PropertyBase* baseProperty =
249 SAMPLER_IMPL.GetRegisteredSceneGraphProperty( this,
250 &Sampler::FindAnimatableProperty,
251 &Sampler::FindCustomProperty,
253 property = static_cast<const PropertyInputImpl*>( baseProperty );
255 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
259 case Dali::Sampler::Property::MINIFICATION_FILTER:
261 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
264 case Dali::Sampler::Property::MAGNIGICATION_FILTER:
266 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
269 case Dali::Sampler::Property::U_WRAP:
271 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
274 case Dali::Sampler::Property::V_WRAP:
276 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
279 case Dali::Sampler::Property::AFFECTS_TRANSPARENCY:
281 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
291 int Sampler::GetPropertyComponentIndex( Property::Index index ) const
293 return Property::INVALID_COMPONENT_INDEX;
296 bool Sampler::OnStage() const
301 void Sampler::Connect()
305 mImageConnector.OnStageConnect();
308 void Sampler::Disconnect()
312 mImageConnector.OnStageDisconnect();
316 : mSceneObject( NULL ),
321 void Sampler::Initialize( const std::string& textureUnitUniformName )
323 EventThreadServices& eventThreadServices = GetEventThreadServices();
324 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
326 DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" );
328 mSceneObject = new SceneGraph::Sampler( textureUnitUniformName );
329 AddMessage( updateManager, updateManager.GetSamplerOwner(), *mSceneObject );
334 if( EventThreadServices::IsCoreRunning() )
336 EventThreadServices& eventThreadServices = GetEventThreadServices();
337 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
338 RemoveMessage( updateManager, updateManager.GetSamplerOwner(), *mSceneObject );
342 } // namespace Internal