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");
47 size_t textureCount( mImages.size() );
48 if( index < textureCount )
50 if( mImages[index] && mOnStage )
52 mImages[index]->Disconnect();
57 mImages.resize(index + 1);
58 mSamplers.resize(index + 1);
59 for( size_t i(textureCount); i<=index; ++i )
65 mImages[index] = image;
74 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, image->GetResourceId() );
78 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, Integration::InvalidResourceId );
82 void TextureSet::SetTexture( size_t index, NewTexturePtr texture )
84 if( !mImages.empty() )
86 DALI_LOG_ERROR( "Error: Cannot mix images and textures in the same texture set");
90 size_t textureCount( mNewTextures.size() );
91 if( index >= textureCount )
93 mNewTextures.resize(index + 1);
94 mSamplers.resize(index + 1);
95 for( size_t i(textureCount); i<=index; ++i )
97 mNewTextures[i] = NULL;
102 mNewTextures[index]= texture;
104 Render::NewTexture* renderTexture(0);
107 renderTexture = texture->GetRenderObject();
110 SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, renderTexture );
113 Image* TextureSet::GetImage( size_t index ) const
116 if( index < mImages.size() )
118 result = mImages[index].Get();
122 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage");
128 NewTexture* TextureSet::GetTexture( size_t index ) const
130 NewTexture* result(0);
131 if( index < mNewTextures.size() )
133 result = mNewTextures[index].Get();
137 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetTexture");
143 void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
145 size_t samplerCount( mSamplers.size() );
146 if( samplerCount < index + 1 )
148 mSamplers.resize( index + 1 );
149 mNewTextures.resize( index + 1 );
150 mImages.resize( index + 1 );
151 for( size_t i(samplerCount); i<=index; ++i )
155 mNewTextures[i] = NULL;
159 mSamplers[index] = sampler;
161 Render::Sampler* renderSampler(0);
164 renderSampler = sampler->GetSamplerRenderObject();
167 SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
170 Sampler* TextureSet::GetSampler( size_t index ) const
173 if( index < mSamplers.size() )
175 result = mSamplers[index].Get();
179 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler");
185 size_t TextureSet::GetTextureCount() const
187 return mImages.size();
190 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
195 bool TextureSet::OnStage() const
200 void TextureSet::Connect()
204 for( size_t i(0); i<mImages.size(); ++i )
208 mImages[i]->Connect();
209 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, mImages[i]->GetResourceId() );
213 SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, Integration::InvalidResourceId );
218 void TextureSet::Disconnect()
220 for( size_t i(0); i<mImages.size(); ++i )
224 mImages[i]->Disconnect();
231 TextureSet::TextureSet()
232 :mEventThreadServices( *Stage::GetCurrent() ),
233 mSceneObject( NULL ),
238 void TextureSet::Initialize()
240 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
242 mSceneObject = SceneGraph::TextureSet::New();
243 AddTextureSetMessage( updateManager, *mSceneObject );
246 TextureSet::~TextureSet()
248 if( EventThreadServices::IsCoreRunning() )
250 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
251 RemoveTextureSetMessage( updateManager, *mSceneObject );
255 } // namespace Internal