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/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
24 #include <dali/internal/update/manager/update-manager.h>
25 #include <dali/internal/update/rendering/scene-graph-texture-set.h>
32 TextureSetPtr TextureSet::New()
34 TextureSetPtr textureSet( new TextureSet() );
35 textureSet->Initialize();
39 void TextureSet::SetImage( size_t index, ImagePtr image )
41 if( !mNewTextures.empty() )
43 DALI_LOG_ERROR( "Error: Cannot mix images and textures in the same TextureSet\n");
47 size_t textureCount( mImages.size() );
48 if( index < textureCount )
50 if( mImages[index] && mOnStage )
52 mImages[index]->Disconnect();
57 mImages.resize(index + 1);
59 bool samplerExist = true;
60 if( mSamplers.size() < index + 1 )
62 mSamplers.resize( index + 1 );
66 mSamplers.resize(index + 1);
67 for( size_t i(textureCount); i<=index; ++i )
77 mImages[index] = image;
86 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, image->GetResourceId() );
90 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, Integration::InvalidResourceId );
94 void TextureSet::SetTexture( size_t index, NewTexturePtr texture )
96 if( !mImages.empty() )
98 DALI_LOG_ERROR( "Error: Cannot mix images and textures in the same texture set\n");
102 size_t textureCount( mNewTextures.size() );
103 if( index >= textureCount )
105 mNewTextures.resize(index + 1);
107 bool samplerExist = true;
108 if( mSamplers.size() < index + 1 )
110 mSamplers.resize( index + 1 );
111 samplerExist = false;
114 for( size_t i(textureCount); i<=index; ++i )
116 mNewTextures[i] = NULL;
125 mNewTextures[index]= texture;
127 Render::NewTexture* renderTexture(0);
130 renderTexture = texture->GetRenderObject();
133 SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, renderTexture );
136 Image* TextureSet::GetImage( size_t index ) const
139 if( index < mImages.size() )
141 result = mImages[index].Get();
145 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage\n");
151 NewTexture* TextureSet::GetTexture( size_t index ) const
153 NewTexture* result(0);
154 if( index < mNewTextures.size() )
156 result = mNewTextures[index].Get();
160 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetTexture\n");
166 void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
168 size_t samplerCount( mSamplers.size() );
169 if( samplerCount < index + 1 )
171 mSamplers.resize( index + 1 );
172 for( size_t i(samplerCount); i<=index; ++i )
178 mSamplers[index] = sampler;
180 Render::Sampler* renderSampler(0);
183 renderSampler = sampler->GetSamplerRenderObject();
186 SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
189 Sampler* TextureSet::GetSampler( size_t index ) const
192 if( index < mSamplers.size() )
194 result = mSamplers[index].Get();
198 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler\n");
204 size_t TextureSet::GetTextureCount() const
206 return mImages.size() + mNewTextures.size();
209 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
214 bool TextureSet::OnStage() const
219 void TextureSet::Connect()
223 for( size_t i(0); i<mImages.size(); ++i )
227 mImages[i]->Connect();
228 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, mImages[i]->GetResourceId() );
232 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, Integration::InvalidResourceId );
237 void TextureSet::Disconnect()
239 for( size_t i(0); i<mImages.size(); ++i )
243 mImages[i]->Disconnect();
250 TextureSet::TextureSet()
251 :mEventThreadServices( *Stage::GetCurrent() ),
252 mSceneObject( NULL ),
257 void TextureSet::Initialize()
259 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
261 mSceneObject = SceneGraph::TextureSet::New();
262 AddTextureSetMessage( updateManager, *mSceneObject );
265 TextureSet::~TextureSet()
267 if( EventThreadServices::IsCoreRunning() )
269 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
270 RemoveTextureSetMessage( updateManager, *mSceneObject );
274 } // namespace Internal