Merge branch 'devel/new_mesh' into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / shaders / program-controller.h
1 #ifndef __DALI_INTERNAL_PROGRAM_CONTROLLER_H__
2 #define __DALI_INTERNAL_PROGRAM_CONTROLLER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/common/owner-container.h>
23 #include <dali/internal/render/shaders/program.h>
24 #include <dali/internal/render/shaders/program-cache.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 namespace SceneGraph
33 {
34 class PostProcessResourceDispatcher;
35 }
36
37 /**
38  * This class is the owner of GL shader programs
39  */
40 class ProgramController : public ProgramCache
41 {
42 public:
43
44   /**
45    * Wrapper for a program and its hash code
46    */
47   class ProgramPair
48   {
49   public: // API
50
51     /**
52      * Constructor
53      * @param program
54      * @param shaderHash
55      */
56     ProgramPair( Program* program, size_t shaderHash )
57     : mProgram( program ), mShaderHash( shaderHash )
58     { }
59
60     /**
61      * Destructor, non-virtual as not a base
62      */
63     ~ProgramPair()
64     {
65       delete mProgram;
66     }
67
68     /**
69      * Inline getter for the program
70      * @return the program
71      */
72     inline Program* GetProgram()
73     {
74       return mProgram;
75     }
76
77     /**
78      * Inline getter for the hash
79      * @return the hash
80      */
81     inline size_t GetHash()
82     {
83       return mShaderHash;
84     }
85
86   private: // Not implemented
87     ProgramPair( const ProgramPair& );
88     ProgramPair& operator=( const ProgramPair& );
89
90   private: // Data
91     Program* mProgram;
92     size_t mShaderHash;
93   };
94
95   /**
96    * Constructor
97    * @param postProcessDispatcher to send save binary message back to update
98    */
99   ProgramController( SceneGraph::PostProcessResourceDispatcher& postProcessDispatcher, Integration::GlAbstraction& glAbstraction );
100
101   /**
102    * Destructor, non virtual as not a base class
103    */
104   ~ProgramController();
105
106 public: // API
107
108   /**
109    * Resets the program matrices. Must be called at the beginning of every frame
110    */
111   void ResetProgramMatrices();
112
113   /**
114    * Notifies the cache that context is (re)created
115    */
116   void GlContextCreated();
117
118   /**
119    * Notifies cache that context is lost
120    */
121   void GlContextDestroyed();
122
123 private: // From ProgramCache
124
125   /**
126    * @copydoc ProgramCache::GetGlAbstraction
127    */
128   virtual Integration::GlAbstraction& GetGlAbstraction();
129
130   /**
131    * @copydoc ProgramCache::GetProgram
132    */
133   virtual Program* GetProgram( size_t shaderHash );
134
135   /**
136    * @copydoc ProgramCache::AddProgram
137    */
138   virtual void AddProgram( size_t shaderHash, Program* program );
139
140   /**
141    * @copydoc ProgramCache::GetCurrentProgram
142    */
143   virtual Program* GetCurrentProgram();
144
145   /**
146    * @copydoc ProgramCache::SetCurrentProgram
147    */
148   virtual void SetCurrentProgram( Program* program );
149
150   /**
151    * @copydoc ProgramCache::IsBinarySupported
152    */
153   virtual bool IsBinarySupported();
154
155   /**
156    * @copydoc ProgramCache::ProgramBinaryFormat
157    */
158   virtual GLenum ProgramBinaryFormat();
159
160   /**
161    * @copydoc ProgramCache::StoreBinary
162    */
163   virtual void StoreBinary( Integration::ShaderDataPtr programData );
164
165 private: // not implemented as non-copyable
166
167   ProgramController( const ProgramController& rhs );
168   ProgramController& operator=( const ProgramController& rhs );
169
170 private: // Data
171
172   SceneGraph::PostProcessResourceDispatcher& mPostProcessDispatcher;
173   Integration::GlAbstraction& mGlAbstraction;
174   Program* mCurrentProgram;
175
176   typedef OwnerContainer< ProgramPair* > ProgramContainer;
177   typedef ProgramContainer::Iterator ProgramIterator;
178   ProgramContainer mProgramCache;
179
180   GLint mProgramBinaryFormat;
181   GLint mNumberOfProgramBinaryFormats;
182
183 };
184
185 } // namespace Internal
186
187 } // namespace Dali
188
189 #endif // __DALI_INTERNAL_PROGRAM_CONTROLLER_H__
190