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 if( !mNewTextures.empty() )
44 DALI_LOG_ERROR( "Error: Cannot mix images and textures in the same TextureSet");
48 size_t textureCount( mImages.size() );
49 if( index < textureCount )
51 if( mImages[index] && mOnStage )
53 mImages[index]->Disconnect();
58 mImages.resize(index + 1);
59 mSamplers.resize(index + 1);
60 for( size_t i(textureCount); i<=index; ++i )
66 mImages[index] = image;
75 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, image->GetResourceId() );
79 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, Integration::InvalidResourceId );
83 void TextureSet::SetTexture( size_t index, NewTexturePtr texture )
85 if( !mImages.empty() )
87 DALI_LOG_ERROR( "Error: Cannot mix images and textures in the same texture set");
91 size_t textureCount( mNewTextures.size() );
92 if( index >= textureCount )
94 mNewTextures.resize(index + 1);
95 mSamplers.resize(index + 1);
96 for( size_t i(textureCount); i<=index; ++i )
98 mNewTextures[i] = NULL;
103 mNewTextures[index]= texture;
105 Render::NewTexture* renderTexture(0);
108 renderTexture = texture->GetRenderObject();
111 SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, renderTexture );
114 Image* TextureSet::GetImage( size_t index ) const
117 if( index < mImages.size() )
119 result = mImages[index].Get();
123 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage");
129 NewTexture* TextureSet::GetTexture( size_t index ) const
131 NewTexture* result(0);
132 if( index < mNewTextures.size() )
134 result = mNewTextures[index].Get();
138 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetTexture");
144 void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
146 size_t samplerCount( mSamplers.size() );
147 if( samplerCount < index + 1 )
149 mSamplers.resize( index + 1 );
150 mNewTextures.resize( index + 1 );
151 mImages.resize( index + 1 );
152 for( size_t i(samplerCount); i<=index; ++i )
156 mNewTextures[i] = NULL;
160 mSamplers[index] = sampler;
162 Render::Sampler* renderSampler(0);
165 renderSampler = sampler->GetSamplerRenderObject();
168 SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
171 Sampler* TextureSet::GetSampler( size_t index ) const
174 if( index < mSamplers.size() )
176 result = mSamplers[index].Get();
180 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler");
186 size_t TextureSet::GetTextureCount() const
188 return mImages.size();
191 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
196 bool TextureSet::OnStage() const
201 void TextureSet::Connect()
205 for( size_t i(0); i<mImages.size(); ++i )
209 mImages[i]->Connect();
210 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, mImages[i]->GetResourceId() );
214 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, Integration::InvalidResourceId );
219 void TextureSet::Disconnect()
221 for( size_t i(0); i<mImages.size(); ++i )
225 mImages[i]->Disconnect();
232 TextureSet::TextureSet()
233 :mEventThreadServices( *Stage::GetCurrent() ),
234 mSceneObject( NULL ),
239 void TextureSet::Initialize()
241 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
243 mSceneObject = SceneGraph::TextureSet::New();
244 AddTextureSetMessage( updateManager, *mSceneObject );
247 TextureSet::~TextureSet()
249 if( EventThreadServices::IsCoreRunning() )
251 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
252 RemoveTextureSetMessage( updateManager, *mSceneObject );
256 } // namespace Internal