3966d1563c53dd23832c2abe38a97e44f9da01bc
[platform/core/uifw/dali-core.git] / dali / internal / render / shaders / scene-graph-shader.cpp
1 /*
2  * Copyright (c) 2015 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/render/shaders/scene-graph-shader.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/render/queue/render-queue.h>
24 #include <dali/internal/render/common/render-debug.h>
25 #include <dali/internal/render/shaders/program.h>
26 #include <dali/internal/common/image-sampler.h>
27
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace SceneGraph
36 {
37
38 Shader::Shader( Dali::Shader::ShaderHints& hints )
39 : mHints( hints ),
40   mProgram( NULL ),
41   mConnectionObservers()
42 {
43   AddUniformMapObserver( *this );
44 }
45
46 Shader::~Shader()
47 {
48   mConnectionObservers.Destroy( *this );
49 }
50
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52 // The following methods are called during RenderManager::Render()
53 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54 void Shader::SetProgram( Internal::ShaderDataPtr shaderData,
55                          ProgramCache* programCache,
56                          bool modifiesGeometry )
57 {
58   DALI_LOG_TRACE_METHOD_FMT( Debug::Filter::gShader, "%d\n", shaderData->GetHashValue() );
59
60   mProgram = Program::New( *programCache, shaderData, modifiesGeometry );
61   // The program cache owns the Program object so we don't need to worry about this raw allocation here.
62
63   mConnectionObservers.ConnectionsChanged(*this);
64 }
65
66 Program* Shader::GetProgram()
67 {
68   return mProgram;
69 }
70
71 void Shader::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
72 {
73 }
74
75 void Shader::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
76 {
77 }
78
79 void Shader::AddConnectionObserver( ConnectionChangePropagator::Observer& observer )
80 {
81   mConnectionObservers.Add(observer);
82 }
83
84 void Shader::RemoveConnectionObserver( ConnectionChangePropagator::Observer& observer )
85 {
86   mConnectionObservers.Remove(observer);
87 }
88
89 void Shader::UniformMappingsChanged( const UniformMap& mappings )
90 {
91   // Our uniform map, or that of one of the watched children has changed.
92   // Inform connected observers.
93   mConnectionObservers.ConnectedUniformMapChanged();
94 }
95
96 } // namespace SceneGraph
97
98 } // namespace Internal
99
100 } // namespace Dali