1 #ifndef DALI_INTERNAL_PROGRAM_CONTROLLER_H
2 #define DALI_INTERNAL_PROGRAM_CONTROLLER_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/devel-api/common/owner-container.h>
23 #include <dali/internal/common/shader-data.h>
24 #include <dali/internal/render/shaders/program.h>
25 #include <dali/internal/render/shaders/program-cache.h>
36 * This class is the owner of GL shader programs
38 class ProgramController : public ProgramCache
43 * Wrapper for a program and its hash code
54 ProgramPair( Program* program, size_t shaderHash )
55 : mProgram( program ), mShaderHash( shaderHash )
59 * Destructor, non-virtual as not a base
67 * Inline getter for the program
70 inline Program* GetProgram()
76 * Inline getter for the hash
79 inline size_t GetHash()
84 private: // Not implemented
85 ProgramPair( const ProgramPair& );
86 ProgramPair& operator=( const ProgramPair& );
95 * @param postProcessDispatcher to send save binary message back to update
97 ProgramController( Integration::GlAbstraction& glAbstraction );
100 * Destructor, non virtual as not a base class
102 ~ProgramController();
107 * Resets the program matrices. Must be called at the beginning of every frame
109 void ResetProgramMatrices();
112 * Notifies the cache that context is (re)created
114 void GlContextCreated();
117 * Notifies cache that context is lost
119 void GlContextDestroyed();
122 * Set the destination for compiler shader binaries so they can be saved.
123 * @note Must be called during initialisation.
125 void SetShaderSaver( ShaderSaver& shaderSaver );
128 * Clear current cached program
130 void ClearCurrentProgram();
132 private: // From ProgramCache
135 * @copydoc ProgramCache::GetGlAbstraction
137 virtual Integration::GlAbstraction& GetGlAbstraction();
140 * @copydoc ProgramCache::GetProgram
142 virtual Program* GetProgram( size_t shaderHash );
145 * @copydoc ProgramCache::AddProgram
147 virtual void AddProgram( size_t shaderHash, Program* program );
150 * @copydoc ProgramCache::GetCurrentProgram
152 virtual Program* GetCurrentProgram();
155 * @copydoc ProgramCache::SetCurrentProgram
157 virtual void SetCurrentProgram( Program* program );
160 * @copydoc ProgramCache::IsBinarySupported
162 virtual bool IsBinarySupported();
165 * @copydoc ProgramCache::ProgramBinaryFormat
167 virtual GLenum ProgramBinaryFormat();
170 * @copydoc ProgramCache::StoreBinary
172 virtual void StoreBinary( Internal::ShaderDataPtr programData );
174 private: // not implemented as non-copyable
176 ProgramController( const ProgramController& rhs );
177 ProgramController& operator=( const ProgramController& rhs );
181 ShaderSaver* mShaderSaver;
182 Integration::GlAbstraction& mGlAbstraction;
183 Program* mCurrentProgram;
185 using ProgramContainer = OwnerContainer<ProgramPair*>;
186 using ProgramIterator = ProgramContainer::Iterator;
187 ProgramContainer mProgramCache;
189 GLint mProgramBinaryFormat;
190 GLint mNumberOfProgramBinaryFormats;
194 } // namespace Internal
198 #endif // DALI_INTERNAL_PROGRAM_CONTROLLER_H