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::SetTexture( size_t index, TexturePtr texture )
41 size_t textureCount( mTextures.size() );
42 if( index >= textureCount )
44 mTextures.resize(index + 1);
46 bool samplerExist = true;
47 if( mSamplers.size() < index + 1 )
49 mSamplers.resize( index + 1 );
53 for( size_t i(textureCount); i<=index; ++i )
64 mTextures[index]= texture;
66 Render::Texture* renderTexture(0);
69 renderTexture = texture->GetRenderObject();
72 SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, renderTexture );
75 Texture* TextureSet::GetTexture( size_t index ) const
78 if( index < mTextures.size() )
80 result = mTextures[index].Get();
84 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetTexture\n");
90 void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
92 size_t samplerCount( mSamplers.size() );
93 if( samplerCount < index + 1 )
95 mSamplers.resize( index + 1 );
96 for( size_t i(samplerCount); i<=index; ++i )
102 mSamplers[index] = sampler;
104 Render::Sampler* renderSampler(0);
107 renderSampler = sampler->GetSamplerRenderObject();
110 SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
113 Sampler* TextureSet::GetSampler( size_t index ) const
116 if( index < mSamplers.size() )
118 result = mSamplers[index].Get();
122 DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler\n");
128 size_t TextureSet::GetTextureCount() const
130 return mTextures.size();
133 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
138 TextureSet::TextureSet()
139 :mEventThreadServices( *Stage::GetCurrent() ),
144 void TextureSet::Initialize()
146 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
148 mSceneObject = SceneGraph::TextureSet::New();
149 AddTextureSetMessage( updateManager, *mSceneObject );
152 TextureSet::~TextureSet()
154 if( EventThreadServices::IsCoreRunning() )
156 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
157 RemoveTextureSetMessage( updateManager, *mSceneObject );
161 } // namespace Internal