[Vulkan] Builtin shaders and shaders offline compilation script
[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 std::unique_ptr<Graphics::API::Shader> ShaderFactory::Create() const
54 {
55   if( !mVertexShader.source.IsSet() || !mFragmentShader.source.IsSet() )
56   {
57     return nullptr;
58   }
59
60   auto retval = std::make_unique<VulkanAPI::Shader>( mGraphics );
61
62   // add vertex shader
63   retval->AddShaderModule( mVertexShader.pipelineStage, mVertexShader.language, mVertexShader.source );
64
65   // add fragment shader
66   retval->AddShaderModule( mFragmentShader.pipelineStage, mFragmentShader.language, mFragmentShader.source );
67
68   return std::move(retval);
69 }
70
71 } // namespace VulkanAPI
72 } // namespace Graphics
73 } // namespace Dali