7c2a6ebb8b24c0a268599fd937175f38d7f42d99
[platform/core/uifw/dali-adaptor.git] / adaptors / common / gl / gl-proxy-implementation.h
1 #ifndef __DALI_INTERNAL_GL_PROXY_IMPLEMENTATION_H__
2 #define __DALI_INTERNAL_GL_PROXY_IMPLEMENTATION_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 <gl/gl-implementation.h>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace Adaptor
29 {
30 class EnvironmentOptions;
31
32 /**
33  * Helper class to calculate the statistics for Open GLES calls
34  */
35 class Sampler
36 {
37 public:
38
39   /**
40    * Constructor
41    * @param description to write to the log
42    */
43   Sampler( const char* description );
44
45   /**
46    * Increment the counter for this frame
47    */
48   void  Increment();
49
50   /**
51    * Reset the counter
52    */
53   void  Reset();
54
55   /**
56    * Accumulate the count onto statistics
57    */
58   void  Accumulate();
59
60   /**
61    * @return the description of the sampler
62    */
63   const char* GetDescription() const;
64
65   /**
66    * @return the mean value
67    */
68   float GetMeanValue() const;
69
70   /**
71    * @return the standard deviation
72    */
73   float GetStandardDeviation() const;
74
75   /**
76    * @return the minimum value
77    */
78   float GetMin() const;
79
80   /**
81    * @return the maximum value
82    */
83   float GetMax() const;
84
85 private: // Data
86
87   const char* mDescription;
88   float mAccumulated;
89   float mAccumulatedSquare;
90   float mMin;
91   float mMax;
92   unsigned int mNumSamples;
93   unsigned int mCurrentFrameCount;
94 };
95
96 /**
97  * Helper class to calculate number of OpenGL objects
98  */
99 class ObjectCounter
100 {
101 public:
102   ObjectCounter( const char* description );
103
104   /**
105    * Increment the counter
106    */
107   void  Increment();
108
109   /**
110    * Decrement the counter
111    */
112   void Decrement();
113
114   /**
115    * @return The current number of objects
116    */
117   unsigned int GetCount() const;
118
119   /**
120    * @return The maximum number of objects created
121    */
122   unsigned int GetPeak() const;
123
124   /**
125    * @return the description of the sampler
126    */
127   const char* GetDescription() const;
128
129 private:
130   const char* mDescription;
131   unsigned int mCount;
132   unsigned int mPeak;
133 };
134
135 /**
136  * GlProxyImplementation is a wrapper for the concrete implementation
137  * of GlAbstraction that also gathers statistical information.
138  */
139 class GlProxyImplementation : public GlImplementation
140 {
141 public:
142
143   /**
144    * Constructor
145    * @param environmentOptions to check how often to log results
146    */
147   GlProxyImplementation(EnvironmentOptions& environmentOptions);
148
149   /**
150    * Virtual destructor
151    */
152   virtual ~GlProxyImplementation();
153
154   /**
155    * @copydoc GlAbstraction::PreRender();
156    */
157   virtual void PreRender();
158
159   /**
160    * @copydoc GlAbstraction::PostRender();
161    */
162   virtual void PostRender();
163
164   /* OpenGL ES 2.0 API */
165   virtual void Clear( GLbitfield mask );
166
167   virtual void GenBuffers (GLsizei n, GLuint* buffers);
168   virtual void DeleteBuffers (GLsizei n, const GLuint* buffers);
169   virtual void BindBuffer( GLenum target, GLuint buffer );
170
171   virtual void GenTextures (GLsizei n, GLuint* textures);
172   virtual void DeleteTextures (GLsizei n, const GLuint* textures);
173   virtual void ActiveTexture(GLenum texture);
174   virtual void BindTexture( GLenum target, GLuint texture );
175
176   virtual void DrawArrays( GLenum mode, GLint first, GLsizei count );
177   virtual void DrawElements( GLenum mode, GLsizei count, GLenum type, const void* indices );
178
179   virtual void Uniform1f ( GLint location, GLfloat x );
180   virtual void Uniform1fv( GLint location, GLsizei count, const GLfloat* v );
181   virtual void Uniform1i ( GLint location, GLint x );
182   virtual void Uniform1iv( GLint location, GLsizei count, const GLint* v );
183   virtual void Uniform2f ( GLint location, GLfloat x, GLfloat y );
184   virtual void Uniform2fv( GLint location, GLsizei count, const GLfloat* v );
185   virtual void Uniform2i ( GLint location, GLint x, GLint y );
186   virtual void Uniform2iv( GLint location, GLsizei count, const GLint* v );
187   virtual void Uniform3f ( GLint location, GLfloat x, GLfloat y, GLfloat z );
188   virtual void Uniform3fv( GLint location, GLsizei count, const GLfloat* v );
189   virtual void Uniform3i ( GLint location, GLint x, GLint y, GLint z );
190   virtual void Uniform3iv( GLint location, GLsizei count, const GLint* v );
191   virtual void Uniform4f ( GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w );
192   virtual void Uniform4fv( GLint location, GLsizei count, const GLfloat* v );
193   virtual void Uniform4i ( GLint location, GLint x, GLint y, GLint z, GLint w );
194   virtual void Uniform4iv( GLint location, GLsizei count, const GLint* v );
195   virtual void UniformMatrix2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
196   virtual void UniformMatrix3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
197   virtual void UniformMatrix4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
198
199   virtual GLuint CreateProgram (void);
200   virtual void DeleteProgram (GLuint program);
201   virtual void UseProgram( GLuint program );
202
203 private: // Helpers
204
205   void AccumulateSamples();
206   void LogResults();
207   void LogCalls( const Sampler& sampler );
208   void LogObjectCounter( const ObjectCounter& sampler );
209   void ResetSamplers();
210
211 private: // Data
212
213   EnvironmentOptions& mEnvironmentOptions;
214   Sampler mActiveTextureSampler;
215   Sampler mClearSampler;
216   Sampler mBindBufferSampler;
217   Sampler mBindTextureSampler;
218   Sampler mDrawSampler;
219   Sampler mUniformSampler;
220   Sampler mUseProgramSampler;
221   ObjectCounter mBufferCount;
222   ObjectCounter mTextureCount;
223   ObjectCounter mProgramCount;
224
225   int mFrameCount;
226
227 };
228
229 } // namespace Adaptor
230
231 } // namespace Internal
232
233 } // namespace Dali
234
235 #endif // __DALI_INTERNAL_GL_PROXY_IMPLEMENTATION_H__