2 * Copyright (c) 2016 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/rendering/texture-set-impl.h> // Dali::Internal::TextureSet
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/devel-api/rendering/texture-set.h> // Dali::Internal::Render::TextureSet
24 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
25 #include <dali/internal/update/manager/update-manager.h>
26 #include <dali/internal/update/rendering/scene-graph-texture-set.h>
33 TextureSetPtr TextureSet::New()
35 TextureSetPtr textureSet( new TextureSet() );
36 textureSet->Initialize();
40 void TextureSet::SetImage( size_t index, ImagePtr image )
42 size_t textureCount( mTextures.size() );
43 if( index < textureCount )
45 if( mTextures[index].image && mOnStage )
47 mTextures[index].image->Disconnect();
52 mTextures.resize(index + 1);
53 for( size_t i(textureCount); i<=index; ++i )
55 mTextures[i].image = NULL;
56 mTextures[i].sampler = NULL;
59 mTextures[index].image = image;
68 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, image->GetResourceId() );
72 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, Integration::InvalidResourceId );
76 Image* TextureSet::GetImage( size_t index ) const
79 if( index < mTextures.size() )
81 result = mTextures[index].image.Get();
85 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage");
91 void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
93 size_t textureCount( mTextures.size() );
94 if( textureCount < index + 1 )
96 mTextures.resize(index + 1);
97 for( size_t i(textureCount); i<=index; ++i )
99 mTextures[i].image = NULL;
100 mTextures[i].sampler = NULL;
104 mTextures[index].sampler = sampler;
106 Render::Sampler* renderSampler(0);
109 renderSampler = sampler->GetSamplerRenderObject();
112 SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
115 Sampler* TextureSet::GetSampler( size_t index ) const
118 if( index < mTextures.size() )
120 result = mTextures[index].sampler.Get();
124 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler");
130 size_t TextureSet::GetTextureCount() const
132 return mTextures.size();
135 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
140 bool TextureSet::OnStage() const
145 void TextureSet::Connect()
149 for( size_t i(0); i<mTextures.size(); ++i )
151 if( mTextures[i].image )
153 mTextures[i].image->Connect();
154 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, mTextures[i].image->GetResourceId() );
158 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, Integration::InvalidResourceId );
163 void TextureSet::Disconnect()
165 for( size_t i(0); i<mTextures.size(); ++i )
167 if( mTextures[i].image )
169 mTextures[i].image->Disconnect();
176 TextureSet::TextureSet()
177 :mEventThreadServices( *Stage::GetCurrent() ),
178 mSceneObject( NULL ),
184 void TextureSet::Initialize()
186 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
188 mSceneObject = SceneGraph::TextureSet::New();
189 AddTextureSetMessage( updateManager, *mSceneObject );
192 TextureSet::~TextureSet()
194 if( EventThreadServices::IsCoreRunning() )
196 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
197 RemoveTextureSetMessage( updateManager, *mSceneObject );
201 } // namespace Internal