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;
106 SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, texture->GetRenderObject() );
110 Image* TextureSet::GetImage( size_t index ) const
113 if( index < mImages.size() )
115 result = mImages[index].Get();
119 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage");
125 NewTexture* TextureSet::GetTexture( size_t index ) const
127 NewTexture* result(0);
128 if( index < mNewTextures.size() )
130 result = mNewTextures[index].Get();
134 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetTexture");
140 void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
142 size_t samplerCount( mSamplers.size() );
143 if( samplerCount < index + 1 )
145 mSamplers.resize( index + 1 );
146 mNewTextures.resize( index + 1 );
147 mImages.resize( index + 1 );
148 for( size_t i(samplerCount); i<=index; ++i )
152 mNewTextures[i] = NULL;
156 mSamplers[index] = sampler;
158 Render::Sampler* renderSampler(0);
161 renderSampler = sampler->GetSamplerRenderObject();
164 SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
167 Sampler* TextureSet::GetSampler( size_t index ) const
170 if( index < mSamplers.size() )
172 result = mSamplers[index].Get();
176 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler");
182 size_t TextureSet::GetTextureCount() const
184 return mImages.size();
187 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
192 bool TextureSet::OnStage() const
197 void TextureSet::Connect()
201 for( size_t i(0); i<mImages.size(); ++i )
205 mImages[i]->Connect();
206 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, mImages[i]->GetResourceId() );
210 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, Integration::InvalidResourceId );
215 void TextureSet::Disconnect()
217 for( size_t i(0); i<mImages.size(); ++i )
221 mImages[i]->Disconnect();
228 TextureSet::TextureSet()
229 :mEventThreadServices( *Stage::GetCurrent() ),
230 mSceneObject( NULL ),
235 void TextureSet::Initialize()
237 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
239 mSceneObject = SceneGraph::TextureSet::New();
240 AddTextureSetMessage( updateManager, *mSceneObject );
243 TextureSet::~TextureSet()
245 if( EventThreadServices::IsCoreRunning() )
247 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
248 RemoveTextureSetMessage( updateManager, *mSceneObject );
252 } // namespace Internal