2 * Copyright (c) 2019 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/update/manager/update-manager.h>
24 #include <dali/internal/update/rendering/scene-graph-texture-set.h>
31 TextureSetPtr TextureSet::New()
33 TextureSetPtr textureSet( new TextureSet() );
34 textureSet->Initialize();
38 void TextureSet::SetTexture( uint32_t index, TexturePtr texture )
40 uint32_t textureCount = static_cast<uint32_t>( mTextures.size() );
41 if( index >= textureCount )
43 mTextures.resize(index + 1);
45 bool samplerExist = true;
46 if( mSamplers.size() < index + 1 )
48 mSamplers.resize( index + 1 );
52 for( uint32_t i(textureCount); i<=index; ++i )
63 mTextures[index]= texture;
65 Render::Texture* renderTexture(0);
68 renderTexture = texture->GetRenderObject();
71 SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, renderTexture );
74 Texture* TextureSet::GetTexture( uint32_t index ) const
77 if( index < mTextures.size() )
79 result = mTextures[index].Get();
83 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetTexture\n");
89 void TextureSet::SetImage( uint32_t index, ImagePtr image )
91 Texture* texture( NULL );
94 uint32_t textureCount = static_cast<uint32_t>( mImages.size() );
95 if( index >= textureCount )
97 mImages.resize(index + 1);
99 mImages[index] = image;
101 texture = image->GetTexture();
104 SetTexture( index, texture );
107 Image* TextureSet::GetImage( uint32_t index ) const
109 Image* result( NULL );
110 if( index < mImages.size() )
112 result = mImages[index].Get();
116 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage\n");
122 void TextureSet::SetSampler( uint32_t index, SamplerPtr sampler )
124 uint32_t samplerCount = static_cast<uint32_t>( mSamplers.size() );
125 if( samplerCount < index + 1 )
127 mSamplers.resize( index + 1 );
128 for( uint32_t i = samplerCount; i<=index; ++i )
134 mSamplers[index] = sampler;
136 Render::Sampler* renderSampler(0);
139 renderSampler = sampler->GetSamplerRenderObject();
142 SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
145 Sampler* TextureSet::GetSampler( uint32_t index ) const
148 if( index < mSamplers.size() )
150 result = mSamplers[index].Get();
154 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler\n");
160 uint32_t TextureSet::GetTextureCount() const
162 return static_cast<uint32_t>( mTextures.size() );
165 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
170 TextureSet::TextureSet()
171 :mEventThreadServices( EventThreadServices::Get() ),
176 void TextureSet::Initialize()
178 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
180 mSceneObject = SceneGraph::TextureSet::New();
181 OwnerPointer< SceneGraph::TextureSet > transferOwnership( mSceneObject );
182 AddTextureSetMessage( updateManager, transferOwnership );
185 TextureSet::~TextureSet()
187 if( EventThreadServices::IsCoreRunning() )
189 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
190 RemoveTextureSetMessage( updateManager, *mSceneObject );
194 } // namespace Internal