e103ca04c65e43b73cc9dd7cc5e8a8f71cdcf928
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / api / vulkan-api-shader-factory.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
18 #include <dali/graphics/vulkan/api/vulkan-api-shader-factory.h>
19 #include <dali/graphics/vulkan/api/vulkan-api-shader.h>
20 #include <dali/graphics/vulkan/vulkan-graphics.h>
21 #include <dali/graphics/vulkan/vulkan-shader.h>
22
23 namespace Dali
24 {
25 namespace Graphics
26 {
27 namespace VulkanAPI
28 {
29
30 ShaderFactory::ShaderFactory( Vulkan::Graphics& graphics ) :
31 mGraphics( graphics )
32 {
33 }
34
35 ShaderFactory::~ShaderFactory() = default;
36
37 ShaderFactory& ShaderFactory::SetShaderModule( Graphics::API::ShaderDetails::PipelineStage       pipelineStage,
38                                          Graphics::API::ShaderDetails::Language            language,
39                                          const Graphics::API::ShaderDetails::ShaderSource& source )
40 {
41   using PipelineStage = Graphics::API::ShaderDetails::PipelineStage;
42   if( pipelineStage == PipelineStage::VERTEX )
43   {
44     mVertexShader = ShaderModuleInfo( pipelineStage, language, source );
45   }
46   else if( pipelineStage == PipelineStage::FRAGMENT )
47   {
48     mFragmentShader = ShaderModuleInfo( pipelineStage, language, source );
49   }
50   return *this;
51 }
52
53 #pragma GCC diagnostic push
54 #pragma GCC diagnostic ignored "-Wframe-larger-than="
55 std::unique_ptr<Graphics::API::Shader> ShaderFactory::Create() const
56 {
57   if( !(mVertexShader.source.IsSet() && mFragmentShader.source.IsSet()) )
58   {
59     return nullptr;
60   }
61
62   auto retval = std::make_unique<VulkanAPI::Shader>( mGraphics );
63
64   // add vertex shader
65   retval->AddShaderModule( mVertexShader.pipelineStage, mVertexShader.language, mVertexShader.source );
66
67   // add fragment shader
68   retval->AddShaderModule( mFragmentShader.pipelineStage, mFragmentShader.language, mFragmentShader.source );
69
70   return std::move(retval);
71 }
72 #pragma GCC diagnostic pop
73 } // namespace VulkanAPI
74 } // namespace Graphics
75 } // namespace Dali