2 * Copyright (c) 2020 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 )
54 mTextures[i] = nullptr;
58 mSamplers[i] = nullptr;
63 mTextures[index]= texture;
65 Render::Texture* renderTexture(nullptr);
68 renderTexture = texture->GetRenderObject();
71 SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, renderTexture );
74 Texture* TextureSet::GetTexture( uint32_t index ) const
76 Texture* result(nullptr);
77 if( index < mTextures.size() )
79 result = mTextures[index].Get();
83 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetTexture\n");
89 void TextureSet::SetSampler( uint32_t index, SamplerPtr sampler )
91 uint32_t samplerCount = static_cast<uint32_t>( mSamplers.size() );
92 if( samplerCount < index + 1 )
94 mSamplers.resize( index + 1 );
95 for( uint32_t i = samplerCount; i<=index; ++i )
97 mSamplers[i] = nullptr;
101 mSamplers[index] = sampler;
103 Render::Sampler* renderSampler(nullptr);
106 renderSampler = sampler->GetSamplerRenderObject();
109 SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
112 Sampler* TextureSet::GetSampler( uint32_t index ) const
114 Sampler* result(nullptr);
115 if( index < mSamplers.size() )
117 result = mSamplers[index].Get();
121 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler\n");
127 uint32_t TextureSet::GetTextureCount() const
129 return static_cast<uint32_t>( mTextures.size() );
132 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
137 TextureSet::TextureSet()
138 :mEventThreadServices( EventThreadServices::Get() ),
139 mSceneObject( nullptr )
143 void TextureSet::Initialize()
145 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
147 mSceneObject = SceneGraph::TextureSet::New();
148 OwnerPointer< SceneGraph::TextureSet > transferOwnership( mSceneObject );
149 AddTextureSetMessage( updateManager, transferOwnership );
152 TextureSet::~TextureSet()
154 if( EventThreadServices::IsCoreRunning() )
156 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
157 RemoveTextureSetMessage( updateManager, *mSceneObject );
161 } // namespace Internal