Wrapped ShaderHints enum inside a struct
[platform/core/uifw/dali-core.git] / dali / internal / event / effects / shader-factory.h
1 #ifndef __DALI_INTERNAL_SHADER_FACTORY_H__
2 #define __DALI_INTERNAL_SHADER_FACTORY_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/public-api/common/dali-vector.h>
23 #include <dali/internal/event/effects/shader-declarations.h>
24 #include <dali/internal/common/message.h>
25 #include <dali/internal/common/shader-data.h>
26 #include <dali/internal/common/shader-saver.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 class ShaderData;
35 typedef IntrusivePtr<ShaderData> ShaderDataPtr;
36
37 /**
38  * ShaderFactory is an object which manages shader binary resource load requests,
39  * It triggers the load requests during core initialization and sends a message to the
40  * render manager with information about all the requested shader binaries.
41  */
42 class ShaderFactory : public ShaderSaver
43 {
44 public:
45
46   /**
47    * Default constructor
48    */
49   ShaderFactory();
50
51   /**
52    * Destructor
53    */
54   virtual ~ShaderFactory();
55
56   /**
57    * @brief Looks for precompiled binary version of shader program in memory and file caches.
58    *
59    * Tries to load a binary version of a shader program identified by a hash over the two source
60    * files, checking an in-memory cache first.
61    * If the cache hits or the load succeeds, the buffer member of the returned ShaderData will
62    * contain a precompiled shader binary program which can be uploaded directly to GLES.
63    *
64    * @param [in] vertexSource   The vertex shader source code
65    * @param [in] fragmentSource The fragment shader source code
66    * @param [out] shaderHash    Hash key created from vertex and fragment shader code
67    * @return                    ShaderData containing the source and hash value, and additionally,
68    *                            a compiled shader program binary if one could be found, else an
69    *                            empty binary buffer cleared to size zero.
70    */
71   Internal::ShaderDataPtr Load( const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::Hint::Value hints, size_t& shaderHash );
72
73   /**
74    * @brief Saves shader to memory cache and filesystem.
75    * This is called when a shader binary is ready to be saved to the memory cache file system.
76    * Shaders that pass through here become available to subsequent invocations of Load.
77    * @param[in] shader The data to be saved.
78    * @sa Load
79    */
80   virtual void SaveBinary( Internal::ShaderDataPtr shader );
81
82   /**
83    * Called during Core initialization to load the default shader.
84    */
85   void LoadDefaultShaders();
86
87 private:
88
89   void MemoryCacheInsert( Internal::ShaderData& shaderData );
90
91   // Undefined
92   ShaderFactory( const ShaderFactory& );
93
94   // Undefined
95   ShaderFactory& operator=( const ShaderFactory& rhs );
96
97 private:
98   ShaderEffectPtr                           mDefaultShader;
99   Dali::Vector< Internal::ShaderData* > mShaderBinaryCache; ///< Cache of pre-compiled shaders.
100
101 }; // class ShaderFactory
102
103 inline MessageBase* ShaderCompiledMessage( ShaderSaver& factory, Internal::ShaderDataPtr shaderData )
104 {
105   return new MessageValue1< ShaderSaver, Internal::ShaderDataPtr >( &factory,
106                                                             &ShaderSaver::SaveBinary,
107                                                             shaderData );
108 }
109
110 } // namespace Internal
111
112 } // namespace Dali
113
114 #endif // __DALI_INTERNAL_SHADER_FACTORY_H__