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( ImagePtr& image )
66 // Keep a reference to the image object
67 mImageConnector.Set( image, OnStage() );
69 // sceneObject is being used in a separate thread; queue a message to set
70 unsigned int resourceId = image->GetResourceId();
71 SetTextureMessage( GetEventThreadServices(), *mSceneObject, resourceId );
75 void Sampler::SetFilterMode( Dali::Sampler::FilterMode minFilter, Dali::Sampler::FilterMode magFilter )
79 void Sampler::SetWrapMode( Dali::Sampler::WrapMode uWrap, Dali::Sampler::WrapMode vWrap )
82 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
85 void Sampler::SetAffectsTransparency( bool affectsTransparency )
88 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
91 const SceneGraph::Sampler* Sampler::GetSamplerSceneObject() const
96 unsigned int Sampler::GetDefaultPropertyCount() const
98 return SAMPLER_IMPL.GetDefaultPropertyCount();
101 void Sampler::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
103 SAMPLER_IMPL.GetDefaultPropertyIndices( indices );
106 const char* Sampler::GetDefaultPropertyName(Property::Index index) const
108 return SAMPLER_IMPL.GetDefaultPropertyName( index );
111 Property::Index Sampler::GetDefaultPropertyIndex( const std::string& name ) const
113 return SAMPLER_IMPL.GetDefaultPropertyIndex( name );
116 bool Sampler::IsDefaultPropertyWritable( Property::Index index ) const
118 return SAMPLER_IMPL.IsDefaultPropertyWritable( index );
121 bool Sampler::IsDefaultPropertyAnimatable( Property::Index index ) const
123 return SAMPLER_IMPL.IsDefaultPropertyAnimatable( index );
126 bool Sampler::IsDefaultPropertyAConstraintInput( Property::Index index ) const
128 return SAMPLER_IMPL.IsDefaultPropertyAConstraintInput( index );
131 Property::Type Sampler::GetDefaultPropertyType( Property::Index index ) const
133 return SAMPLER_IMPL.GetDefaultPropertyType( index );
136 void Sampler::SetDefaultProperty( Property::Index index,
137 const Property::Value& propertyValue )
141 case Dali::Sampler::Property::MINIFICATION_FILTER:
143 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
146 case Dali::Sampler::Property::MAGNIGICATION_FILTER:
148 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
151 case Dali::Sampler::Property::U_WRAP:
153 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
156 case Dali::Sampler::Property::V_WRAP:
158 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
161 case Dali::Sampler::Property::AFFECTS_TRANSPARENCY:
163 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
169 void Sampler::SetSceneGraphProperty( Property::Index index,
170 const PropertyMetadata& entry,
171 const Property::Value& value )
173 SAMPLER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
174 OnPropertySet(index, value);
177 Property::Value Sampler::GetDefaultProperty( Property::Index index ) const
179 Property::Value value;
183 case Dali::Sampler::Property::MINIFICATION_FILTER:
185 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
188 case Dali::Sampler::Property::MAGNIGICATION_FILTER:
190 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
193 case Dali::Sampler::Property::U_WRAP:
195 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
198 case Dali::Sampler::Property::V_WRAP:
200 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
203 case Dali::Sampler::Property::AFFECTS_TRANSPARENCY:
205 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
212 const SceneGraph::PropertyOwner* Sampler::GetPropertyOwner() const
217 const SceneGraph::PropertyOwner* Sampler::GetSceneObject() const
222 const SceneGraph::PropertyBase* Sampler::GetSceneObjectAnimatableProperty( Property::Index index ) const
224 DALI_ASSERT_ALWAYS( IsPropertyAnimatable( index ) && "Property is not animatable" );
226 const SceneGraph::PropertyBase* property = NULL;
230 property = SAMPLER_IMPL.GetRegisteredSceneGraphProperty( this,
231 &Sampler::FindAnimatableProperty,
232 &Sampler::FindCustomProperty,
235 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
237 // No animatable default props
238 DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
245 const PropertyInputImpl* Sampler::GetSceneObjectInputProperty( Property::Index index ) const
247 const PropertyInputImpl* property = NULL;
251 const SceneGraph::PropertyBase* baseProperty =
252 SAMPLER_IMPL.GetRegisteredSceneGraphProperty( this,
253 &Sampler::FindAnimatableProperty,
254 &Sampler::FindCustomProperty,
256 property = static_cast<const PropertyInputImpl*>( baseProperty );
258 if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
262 case Dali::Sampler::Property::MINIFICATION_FILTER:
264 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
267 case Dali::Sampler::Property::MAGNIGICATION_FILTER:
269 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
272 case Dali::Sampler::Property::U_WRAP:
274 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
277 case Dali::Sampler::Property::V_WRAP:
279 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
282 case Dali::Sampler::Property::AFFECTS_TRANSPARENCY:
284 DALI_ASSERT_ALWAYS( 0 && "MESH_REWORK" );
294 int Sampler::GetPropertyComponentIndex( Property::Index index ) const
296 return Property::INVALID_COMPONENT_INDEX;
299 bool Sampler::OnStage() const
304 void Sampler::Connect()
308 mImageConnector.OnStageConnect();
311 void Sampler::Disconnect()
315 mImageConnector.OnStageDisconnect();
319 : mSceneObject( NULL ),
324 void Sampler::Initialize( const std::string& textureUnitUniformName )
326 EventThreadServices& eventThreadServices = GetEventThreadServices();
327 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
329 DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() && "Core is not running" );
331 mSceneObject = new SceneGraph::Sampler( textureUnitUniformName );
332 AddMessage( updateManager, updateManager.GetSamplerOwner(), *mSceneObject );
337 if( EventThreadServices::IsCoreRunning() )
339 EventThreadServices& eventThreadServices = GetEventThreadServices();
340 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
341 RemoveMessage( updateManager, updateManager.GetSamplerOwner(), *mSceneObject );
345 } // namespace Internal