[Vulkan] Builtin shaders and shaders offline compilation script
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-shader.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 // CLASS HEADER
19 #include <dali/internal/update/rendering/scene-graph-shader.h>
20
21 namespace Dali
22 {
23
24 namespace Internal
25 {
26
27 namespace SceneGraph
28 {
29
30 Shader::Shader( Dali::Shader::Hint::Value& hints )
31 : mGraphics( nullptr ),
32   mGraphicsShader( nullptr ),
33   mShaderCache( nullptr ),
34   mHints( hints ),
35   mConnectionObservers()
36 {
37   AddUniformMapObserver( *this );
38 }
39
40 Shader::~Shader()
41 {
42   mConnectionObservers.Destroy( *this );
43 }
44
45 void Shader::Initialize( Integration::Graphics::Graphics& graphics, ShaderCache& shaderCache )
46 {
47   mGraphics = &graphics;
48   mShaderCache = &shaderCache;
49 }
50
51 Graphics::API::Accessor<Graphics::API::Shader>& Shader::GetGfxObject()
52 {
53   return mGraphicsShader;
54 }
55
56 void Shader::AddConnectionObserver( ConnectionChangePropagator::Observer& observer )
57 {
58   mConnectionObservers.Add(observer);
59 }
60
61 void Shader::RemoveConnectionObserver( ConnectionChangePropagator::Observer& observer )
62 {
63   mConnectionObservers.Remove(observer);
64 }
65
66 void Shader::UniformMappingsChanged( const UniformMap& mappings )
67 {
68   // Our uniform map, or that of one of the watched children has changed.
69   // Inform connected observers.
70   mConnectionObservers.ConnectedUniformMapChanged();
71 }
72
73 void Shader::SetShaderProgram( Internal::ShaderDataPtr shaderData, bool modifiesGeometry )
74 {
75   // TODO: for now we will use hardcoded binary SPIRV shaders which will replace anything
76   // that is passed by the caller
77   if (shaderData->GetType() == ShaderData::Type::BINARY)
78   {
79     mGraphicsShader = mShaderCache->GetShader(
80       Graphics::API::ShaderDetails::ShaderSource(shaderData->GetShaderForStage(ShaderData::ShaderStage::VERTEX)),
81       Graphics::API::ShaderDetails::ShaderSource(shaderData->GetShaderForStage(ShaderData::ShaderStage::FRAGMENT)));
82   }
83 }
84
85
86 } // namespace SceneGraph
87
88 } // namespace Internal
89
90 } // namespace Dali