2 * Copyright (c) 2018 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/update/rendering/scene-graph-shader.h>
22 #define DEBUG_OVERRIDE_VULKAN_SHADER
23 #ifdef DEBUG_OVERRIDE_VULKAN_SHADER
24 #include <dali/graphics/vulkan/generated/spv-shaders-gen.h>
36 Shader::Shader( Dali::Shader::Hint::Value& hints )
37 : mGraphics( nullptr ),
38 mGraphicsShader( nullptr ),
39 mShaderCache( nullptr ),
41 mConnectionObservers()
43 AddUniformMapObserver( *this );
48 mConnectionObservers.Destroy( *this );
51 void Shader::Initialize( Integration::Graphics::Graphics& graphics, ShaderCache& shaderCache )
53 mGraphics = &graphics;
54 mShaderCache = &shaderCache;
57 Graphics::API::Accessor<Graphics::API::Shader>& Shader::GetGfxObject()
59 return mGraphicsShader;
62 void Shader::AddConnectionObserver( ConnectionChangePropagator::Observer& observer )
64 mConnectionObservers.Add(observer);
67 void Shader::RemoveConnectionObserver( ConnectionChangePropagator::Observer& observer )
69 mConnectionObservers.Remove(observer);
72 void Shader::UniformMappingsChanged( const UniformMap& mappings )
74 // Our uniform map, or that of one of the watched children has changed.
75 // Inform connected observers.
76 mConnectionObservers.ConnectedUniformMapChanged();
79 void Shader::SetShaderProgram( Internal::ShaderDataPtr shaderData, bool modifiesGeometry )
81 // TODO: for now we will use hardcoded binary SPIRV shaders which will replace anything
82 // that is passed by the caller
83 #ifdef DEBUG_OVERRIDE_VULKAN_SHADER
85 mGraphicsShader = mShaderCache->GetShader( Graphics::API::ShaderDetails::ShaderSource( VSH_IMAGE_VISUAL_CODE ),
86 Graphics::API::ShaderDetails::ShaderSource( FSH_IMAGE_VISUAL_CODE ));
89 auto& controller = mGraphics->GetController();
91 mGraphicsShader = controller.CreateShader(
92 controller.GetShaderFactory()
93 .SetShaderModule( Graphics::API::ShaderDetails::PipelineStage::VERTEX,
94 Graphics::API::ShaderDetails::Language::SPIRV_1_0,
95 Graphics::API::ShaderDetails::ShaderSource( shaderData->GetVertexShader() ))
96 .SetShaderModule( Graphics::API::ShaderDetails::PipelineStage::FRAGMENT,
97 Graphics::API::ShaderDetails::Language::SPIRV_1_0,
98 Graphics::API::ShaderDetails::ShaderSource( shaderData->GetFragmentShader() )) );
103 } // namespace SceneGraph
105 } // namespace Internal