Removing rendering backend
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / shader-cache.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <dali/internal/update/rendering/shader-cache.h>
18 #include <dali/graphics-api/graphics-api-controller.h>
19
20 namespace Dali
21 {
22 namespace Internal
23 {
24 namespace SceneGraph
25 {
26
27 ShaderCache::ShaderCache( Dali::Graphics::API::Controller& controller )
28 : mController( controller )
29 {
30 }
31
32 Dali::Graphics::API::Accessor<Dali::Graphics::API::Shader> ShaderCache::GetShader(
33   const Dali::Graphics::API::ShaderDetails::ShaderSource& vsh,
34   const Dali::Graphics::API::ShaderDetails::ShaderSource& fsh )
35 {
36   for( auto&& item : mItems )
37   {
38     if( item.vertexSource == vsh && item.fragmentSource == fsh )
39     {
40       return item.shader;
41     }
42   }
43   auto shaderRef =
44     mController.CreateShader( mController.GetShaderFactory()
45                               .SetShaderModule( Graphics::API::ShaderDetails::PipelineStage::VERTEX,
46                                                 Graphics::API::ShaderDetails::Language::SPIRV_1_0,
47                                                 vsh )
48                               .SetShaderModule( Graphics::API::ShaderDetails::PipelineStage::FRAGMENT,
49                                                 Graphics::API::ShaderDetails::Language::SPIRV_1_0,
50                                                 fsh ) );
51   mItems.emplace_back( Item() = { shaderRef, vsh, fsh } );
52   return shaderRef;
53 }
54
55 } // namespace SceneGraph
56 } // namespace Internal
57 } // namespace Dali