Fix code to not include std set directly
[platform/core/uifw/dali-core.git] / dali / internal / render / gl-resources / context.h
1 #ifndef __DALI_INTERNAL_CONTEXT_H__
2 #define __DALI_INTERNAL_CONTEXT_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/common/map-wrapper.h>
22 #include <dali/public-api/common/set-wrapper.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/actors/renderable-actor.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/gl-abstraction.h>
27 #include <dali/internal/render/common/performance-monitor.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/math/rect.h>
30 #include <dali/public-api/math/vector4.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 class ContextObserver;
39 class Program; // to be able to cache programs
40
41 // wrap gl calls with CHECK_GL eg "CHECK_GL( *this, glBindTexture(textureId) );"
42 // will LOG any glErrors eg "glError (0x0501) GL_INVALID_VALUE - glBindTexture(textureId)"
43 // only enable if specifically enabled as it slows down GL a lot!
44 #ifdef DALI_GL_ERROR_CHECK
45 #define CHECK_GL(c,a)  (a); (c).CheckGlError(#a)
46 #else
47 #define CHECK_GL(c,a)  (a)
48 #endif
49
50 // Don't put guards around here (LOG_INFO has it's own guards)
51 #define LOG_GL(format, args...) \
52   DALI_LOG_INFO(Context::gGlLogFilter, Debug::General, format, ## args)
53
54 /**
55  * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
56  * Observers will be notified when the GL context is created/destroyed.
57  * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
58  */
59 class Context
60 {
61 public:
62
63   /**
64    * Size of the VertexAttributeArray enables
65    * GLES specification states that there's minimum of 8
66    */
67   static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
68
69   /**
70    * Creates the Dali Context object.
71    * This method does not create an OpenGL context i.e. that is done from outside dali-core.
72    * @pre Context has not been created.
73    * @exception Context already created.
74    * @param glAbstraction the gl abstraction.
75    */
76   Context( Integration::GlAbstraction& glAbstraction );
77
78   /**
79    * Destructor
80    */
81   ~Context();
82
83   /**
84    * Called when the GL context has been created.
85    * @post Context observers will be notified.
86    */
87   void GlContextCreated();
88
89   /**
90    * Called when the GL context is about to be destroyed.
91    * @post Context observers will be notified, and should free any GL resources held.
92    */
93   void GlContextToBeDestroyed();
94
95   /**
96    * Query whether the OpenGL context has been created.
97    * @return True if the OpenGL context has been created.
98    */
99   bool IsGlContextCreated() { return mGlContextCreated; }
100
101   /**
102    * Adds an observer to the Context object.
103    * The observer is responsible for calling RemoveObserver() before destruction.
104    * @param[in] observer The observer to add.
105    */
106   void AddObserver(ContextObserver& observer);
107
108   /**
109    * Removes an observer from the Context object.
110    * The observer must call this method before it is destroyed.
111    * @param[in] observer The observer to remove.
112    */
113   void RemoveObserver(ContextObserver& observer);
114
115   /**
116    * @return the GLAbstraction
117    */
118   Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
119
120 #ifdef DALI_CONTEXT_LOGGING
121
122   /**
123    * Debug helper which prints the currently cached GL state.
124    */
125   void PrintCurrentState();
126
127 #endif
128
129   /**
130    * Helper to convert GL error code to string
131    * @param errorCode to convert
132    * @return C string
133    */
134   const char* ErrorToString( GLenum errorCode );
135
136   /**
137    * Helper to check GL error during an operation
138    * @param operation that was performed
139    */
140   void CheckGlError( const char* operation )
141   {
142     for( GLint error = GetError(); error; error = GetError() )
143     {
144       DALI_LOG_ERROR( "glError (0x%x) %s - after %s\n",  error, ErrorToString(error), operation );
145       DALI_ASSERT_ALWAYS( error && "GL ERROR"); // if errors are being checked we should assert
146     }
147   }
148
149   /**
150    * Helper to print GL string to debug log
151    */
152   void PrintGlString(const char* stringName, GLenum stringId)
153   {
154     DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, (const char *)GetString( stringId ) );
155   }
156
157   /****************************************************************************************
158    * The following methods are forwarded to Dali::Integration::GlAbstraction.
159    * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
160    * All Shader, Program, Uniform and Attribute related calls are not here, Program class
161    * handles them and optimizes any program related state changes
162    ****************************************************************************************/
163
164   /**
165    * Wrapper for OpenGL ES 2.0 glActiveTexture()
166    */
167   void ActiveTexture(GLenum textureUnit)
168   {
169     // GL texture units are #defines in growing order to converting that to index
170     unsigned int unit = textureUnit - GL_TEXTURE0;
171
172     if ( unit != mActiveTextureUnit )
173     {
174       mActiveTextureUnit = unit;
175       LOG_GL("ActiveTexture %x\n", textureUnit);
176       CHECK_GL( *this, mGlAbstraction.ActiveTexture(textureUnit) );
177     }
178   }
179
180   /**
181    * Wrapper for OpenGL ES 3.0 glBeginQuery()
182    */
183   void BeginQuery(GLenum target, GLuint id)
184   {
185     LOG_GL("BeginQuery %d %d\n", target, id);
186     CHECK_GL( *this, mGlAbstraction.BeginQuery(target, id) );
187   }
188
189   /**
190    * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
191    */
192   void BeginTransformFeedback(GLenum primitiveMode)
193   {
194     LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
195     CHECK_GL( *this, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
196   }
197
198   /**
199    * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
200    */
201
202   /**
203    * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
204    */
205   void BindArrayBuffer(GLuint buffer)
206   {
207     // Avoid unecessary calls to BindBuffer
208     if (mBoundArrayBufferId != buffer)
209     {
210       mBoundArrayBufferId = buffer;
211
212       LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
213       CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
214     }
215   }
216
217   /**
218    * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
219    */
220   void BindElementArrayBuffer(GLuint buffer)
221   {
222     // Avoid unecessary calls to BindBuffer
223     if (mBoundElementArrayBufferId!= buffer)
224     {
225       mBoundElementArrayBufferId = buffer;
226
227       LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
228       CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
229     }
230   }
231
232   /**
233    * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
234    */
235   void BindTransformFeedbackBuffer(GLuint buffer)
236   {
237     // Avoid unecessary calls to BindBuffer
238     if (mBoundTransformFeedbackBufferId != buffer)
239     {
240       mBoundTransformFeedbackBufferId = buffer;
241
242       LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
243       CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
244     }
245   }
246
247   /**
248    * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
249    */
250   void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
251   {
252     // Avoid unecessary calls to BindBufferBase
253     if (mBoundTransformFeedbackBufferId != buffer)
254     {
255       mBoundTransformFeedbackBufferId = buffer;
256
257       LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
258       CHECK_GL( *this, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
259     }
260   }
261
262   /**
263    * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
264    */
265   void BindFramebuffer(GLenum target, GLuint framebuffer)
266   {
267     LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
268     CHECK_GL( *this, mGlAbstraction.BindFramebuffer(target, framebuffer) );
269   }
270
271   /**
272    * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
273    */
274   void BindRenderbuffer(GLenum target, GLuint renderbuffer)
275   {
276     LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
277     CHECK_GL( *this, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
278   }
279
280   /**
281    * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
282    */
283   void BindTransformFeedback(GLenum target, GLuint id)
284   {
285     LOG_GL("BindTransformFeedback %d %d\n", target, id);
286     CHECK_GL( *this, mGlAbstraction.BindTransformFeedback(target, id) );
287   }
288
289   /**
290    * The wrapper for OpenGL ES 2.0 glBindTexture() has been replaced by Bind2dTexture and BindCubeMapTexture.
291    */
292
293   /**
294    * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D)
295    */
296   void Bind2dTexture( GLuint texture )
297   {
298     if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
299     {
300       mBound2dTextureId[ mActiveTextureUnit ] = texture;
301
302       LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture);
303       CHECK_GL( *this, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) );
304
305       INCREASE_COUNTER(PerformanceMonitor::TEXTURE_STATE_CHANGES);
306     }
307   }
308
309   /**
310    * Wrapper for OpenGL ES 2.0 glBlendColor()
311    */
312   void SetDefaultBlendColor()
313   {
314     if( !mUsingDefaultBlendColor )
315     {
316       LOG_GL( "BlendColor %f %f %f %f\n", 0.0f, 0.0f, 0.0f, 0.0f );
317       CHECK_GL( *this, mGlAbstraction.BlendColor( 0.0f, 0.0f, 0.0f, 0.0f ) );
318       mUsingDefaultBlendColor = true;
319     }
320   }
321
322   /**
323    * Wrapper for OpenGL ES 2.0 glBlendColor()
324    */
325   void SetCustomBlendColor( const Vector4& color )
326   {
327     LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
328     CHECK_GL( *this, mGlAbstraction.BlendColor(color.r, color.g, color.b, color.a) );
329     mUsingDefaultBlendColor = false;
330   }
331
332   /**
333    * Wrapper for OpenGL ES 2.0 glBlendEquation()
334    */
335   void BlendEquation(GLenum mode)
336   {
337     // use BlendEquationSeparate to set the rgb and alpha modes the same
338     BlendEquationSeparate( mode, mode );
339   }
340
341   /**
342    * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
343    */
344   void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
345   {
346     if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
347         ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
348     {
349       mBlendEquationSeparateModeRGB = modeRGB;
350       mBlendEquationSeparateModeAlpha = modeAlpha;
351       LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
352       CHECK_GL( *this, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
353     }
354   }
355
356   /**
357    * Wrapper for OpenGL ES 2.0 glBlendFunc()
358    */
359   void BlendFunc(GLenum sfactor, GLenum dfactor)
360   {
361     // reuse the BlendFuncSeparate as thats what the DDK does anyways
362     BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
363   }
364
365   /**
366    * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
367    */
368   void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
369   {
370     if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
371         ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
372     {
373       mBlendFuncSeparateSrcRGB = srcRGB;
374       mBlendFuncSeparateDstRGB = dstRGB;
375       mBlendFuncSeparateSrcAlpha = srcAlpha;
376       mBlendFuncSeparateDstAlpha = dstAlpha;
377
378       LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
379       CHECK_GL( *this, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
380     }
381   }
382
383   /**
384    * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
385    */
386   void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
387   {
388     LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
389     CHECK_GL( *this, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
390   }
391
392   /**
393    * Wrapper for OpenGL ES 2.0 glBufferData()
394    */
395   void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
396   {
397     LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
398     CHECK_GL( *this, mGlAbstraction.BufferData(target, size, data, usage) );
399   }
400
401   /**
402    * Wrapper for OpenGL ES 2.0 glBufferSubData()
403    */
404   void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
405   {
406     LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
407     CHECK_GL( *this, mGlAbstraction.BufferSubData(target, offset, size, data) );
408   }
409
410   /**
411    * Wrapper for OpenGL ES 2.0  glCheckFramebufferStatus()
412    */
413   GLenum CheckFramebufferStatus(GLenum target)
414   {
415     LOG_GL("CheckFramebufferStatus %d\n", target);
416     GLenum value = CHECK_GL( *this, mGlAbstraction.CheckFramebufferStatus(target) );
417     return value;
418   }
419
420   /**
421    * Wrapper for OpenGL ES 2.0 glClear()
422    */
423   void Clear(GLbitfield mask)
424   {
425     LOG_GL("Clear %d\n", mask);
426     CHECK_GL( *this, mGlAbstraction.Clear(mask) );
427   }
428
429   /**
430    * Wrapper for OpenGL ES 2.0 glClearColor()
431    */
432   void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
433   {
434     Vector4 newCol(red,green,blue,alpha);
435
436     if (!mClearColorSet || mClearColor !=newCol )
437     {
438       LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
439       CHECK_GL( *this, mGlAbstraction.ClearColor(red, green, blue, alpha) );
440
441       mClearColorSet = true;
442       mClearColor = newCol;
443     }
444   }
445
446   /**
447    * Wrapper for OpenGL ES 2.0 glClearDepthf()
448    */
449   void ClearDepthf(GLclampf depth)
450   {
451     LOG_GL("ClearDepthf %f\n", depth);
452     CHECK_GL( *this, mGlAbstraction.ClearDepthf(depth) );
453   }
454
455   /**
456    * Wrapper for OpenGL ES 2.0 glClearStencil()
457    */
458   void ClearStencil(GLint s)
459   {
460     LOG_GL("ClearStencil %d\n", s);
461     CHECK_GL( *this, mGlAbstraction.ClearStencil(s) );
462   }
463
464   /**
465    * Wrapper for OpenGL ES 2.0 glColorMask()
466    * @note This has been optimized to a single boolean value (masking individual channels is not required)
467    */
468   void ColorMask( bool flag )
469   {
470     // only change state if needed
471     if( flag != mColorMask )
472     {
473       mColorMask = flag;
474       LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
475       CHECK_GL( *this, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
476     }
477   }
478
479   /**
480    * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
481    */
482   void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
483                             GLint border, GLsizei imageSize, const void* data)
484   {
485     LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
486     CHECK_GL( *this, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
487   }
488
489   /**
490    * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
491    */
492   void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
493                             GLint border, GLsizei imageSize, const void* data)
494   {
495     LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
496     CHECK_GL( *this, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
497   }
498
499   /**
500    * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
501    */
502   void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
503                                GLenum format, GLsizei imageSize, const void* data)
504   {
505     LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
506     CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
507   }
508
509   /**
510    * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
511    */
512   void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
513                                GLsizei width, GLsizei height, GLsizei depth,
514                                GLenum format, GLsizei imageSize, const void* data)
515   {
516     LOG_GL("CompressedTexSubImage3D %x %d %d %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, xoffset, width, height, depth, format, imageSize, data);
517     CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
518   }
519
520   /**
521    * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
522    */
523   void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
524   {
525     LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
526     CHECK_GL( *this, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
527   }
528
529   /**
530    * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
531    */
532   void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
533   {
534     LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
535     CHECK_GL( *this, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
536   }
537
538   /**
539    * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
540    */
541   void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
542   {
543     LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
544     CHECK_GL( *this, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
545   }
546
547   /**
548    * Wrapper for OpenGL ES 2.0 glCullFace()
549    * enables GL_CULL_FACE if in any of the face culling modes
550    * otherwise disables GL_CULL_FACE
551    */
552   void CullFace(CullFaceMode mode)
553   {
554     // Avoid unnecessary calls to gl
555     if(mCullFaceMode != mode)
556     {
557       mCullFaceMode = mode;
558       switch(mode)
559       {
560         case CullNone:
561         {
562           LOG_GL("Disable GL_CULL_FACE\n");
563           CHECK_GL( *this, mGlAbstraction.Disable(GL_CULL_FACE) );
564           break;
565         }
566
567         case CullFront:
568         {
569           LOG_GL("Enable GL_CULL_FACE\n");
570           CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
571           LOG_GL("Enable GL_FRONT\n");
572           CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT) );
573           break;
574         }
575
576         case CullBack:
577         {
578           LOG_GL("Enable GL_CULL_FACE\n");
579           CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
580           LOG_GL("Enable GL_BACK\n");
581           CHECK_GL( *this, mGlAbstraction.CullFace(GL_BACK) );
582           break;
583         }
584
585         case CullFrontAndBack:
586         {
587           LOG_GL("Enable GL_CULL_FACE\n");
588           CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
589           LOG_GL("Enable GL_FRONT_AND_BACK\n");
590           CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
591           break;
592         }
593
594         default:
595           break;
596       }
597     }
598   }
599
600   /**
601    * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
602    */
603   void DeleteBuffers(GLsizei n, const GLuint* buffers)
604   {
605     LOG_GL("DeleteBuffers %d %p\n", n, buffers);
606     CHECK_GL( *this, mGlAbstraction.DeleteBuffers(n, buffers) );
607
608     // reset the cached buffer id's
609     // fixes problem where some drivers will a generate a buffer with the
610     // same id, as the last deleted buffer id.
611     mBoundArrayBufferId = 0;
612     mBoundElementArrayBufferId = 0;
613     mBoundTransformFeedbackBufferId = 0;
614   }
615
616   /**
617    * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
618    */
619   void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
620   {
621     LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
622     CHECK_GL( *this, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
623   }
624
625   /**
626    * Wrapper for OpenGL ES 3.0 glDeleteQueries()
627    */
628   void DeleteQueries(GLsizei n, GLuint* ids)
629   {
630     LOG_GL("DeleteQueries %d %p\n", n, ids);
631     CHECK_GL( *this, mGlAbstraction.DeleteQueries(n, ids) );
632   }
633
634   /**
635    * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
636    */
637   void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
638   {
639     LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
640     CHECK_GL( *this, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
641   }
642
643   /**
644    * Wrapper for OpenGL ES 2.0 glDeleteTextures()
645    */
646   void DeleteTextures(GLsizei n, const GLuint* textures)
647   {
648     LOG_GL("DeleteTextures %d %p\n", n, textures);
649     CHECK_GL( *this, mGlAbstraction.DeleteTextures(n, textures) );
650
651     // reset the cached texture id's incase the driver re-uses them
652     // when creating new textures
653     for( int i=0; i < mMaxTextureUnits; ++i )
654     {
655        mBound2dTextureId[ i ] = 0;
656     }
657   }
658
659   /**
660    * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
661    */
662   void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
663   {
664     LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
665     CHECK_GL( *this, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
666   }
667
668   /**
669    * Wrapper for OpenGL ES 2.0 glDepthFunc()
670    */
671   void DepthFunc(GLenum func)
672   {
673     LOG_GL("DepthFunc %x\n", func);
674     CHECK_GL( *this, mGlAbstraction.DepthFunc(func) );
675   }
676
677   /**
678    * Wrapper for OpenGL ES 2.0 glDepthMask()
679    */
680   void DepthMask(GLboolean flag)
681   {
682     // only change state if needed
683     if( flag != mDepthMaskEnabled )
684     {
685       mDepthMaskEnabled = flag;
686       LOG_GL("DepthMask %s\n", flag ? "True" : "False");
687       CHECK_GL( *this, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
688     }
689   }
690
691   /**
692    * Wrapper for OpenGL ES 2.0 glDepthRangef()
693    */
694   void DepthRangef(GLclampf zNear, GLclampf zFar)
695   {
696     LOG_GL("DepthRangef %f %f\n", zNear, zFar);
697     CHECK_GL( *this, mGlAbstraction.DepthRangef(zNear, zFar) );
698   }
699
700   /**
701    * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
702    * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
703    */
704
705   /**
706    * Wrapper for OpenGL ES 2.0 glDrawArrays()
707    */
708   void DrawArrays(GLenum mode, GLint first, GLsizei count)
709   {
710     FlushVertexAttributeLocations();
711
712     LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
713     CHECK_GL( *this, mGlAbstraction.DrawArrays(mode, first, count) );
714   }
715
716   /**
717    * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
718    */
719   void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
720   {
721     FlushVertexAttributeLocations();
722
723     LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
724     CHECK_GL( *this, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
725   }
726
727   /**
728    * Wrapper for OpenGL ES 3.0 glDrawBuffers()
729    */
730   void DrawBuffers(GLsizei n, const GLenum* bufs)
731   {
732     LOG_GL("DrawBuffers %d %p\n", n, bufs);
733     CHECK_GL( *this, mGlAbstraction.DrawBuffers(n, bufs) );
734   }
735
736   /**
737    * Wrapper for OpenGL ES 2.0 glDrawElements()
738    */
739   void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
740   {
741     FlushVertexAttributeLocations();
742
743     LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
744     CHECK_GL( *this, mGlAbstraction.DrawElements(mode, count, type, indices) );
745   }
746
747   /**
748    * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
749    */
750   void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
751   {
752     FlushVertexAttributeLocations();
753
754     LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
755     CHECK_GL( *this, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
756   }
757
758   /**
759    * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
760    */
761   void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
762   {
763     FlushVertexAttributeLocations();
764
765     LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
766     CHECK_GL( *this, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
767   }
768
769   /**
770    * Wrapper for OpenGL ES 3.0 glGenQuerieS()
771    */
772   void GenQueries(GLsizei n, GLuint* ids)
773   {
774     LOG_GL("GenQueries %d %p\n", n, ids);
775     CHECK_GL( *this, mGlAbstraction.GenQueries(n, ids) );
776   }
777
778   /**
779    * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
780    */
781   void GenTransformFeedbacks(GLsizei n, GLuint* ids)
782   {
783     LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
784     CHECK_GL( *this, mGlAbstraction.GenTransformFeedbacks(n, ids) );
785   }
786
787   /**
788    * @return the current buffer bound for a given target
789    */
790   GLuint GetCurrentBoundArrayBuffer(GLenum target)
791   {
792     GLuint result(0);
793     switch(target)
794     {
795       case GL_ARRAY_BUFFER:
796       {
797         result = mBoundArrayBufferId;
798         break;
799       }
800       case GL_ELEMENT_ARRAY_BUFFER:
801       {
802         result = mBoundElementArrayBufferId;
803         break;
804       }
805       case GL_TRANSFORM_FEEDBACK_BUFFER:
806       {
807         result = mBoundTransformFeedbackBufferId;
808         break;
809       }
810       default:
811       {
812         DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
813       }
814     }
815     return result;
816   }
817
818   void EnableVertexAttributeArray( GLuint location )
819   {
820     SetVertexAttributeLocation( location, true);
821   }
822
823   void DisableVertexAttributeArray( GLuint location )
824   {
825     SetVertexAttributeLocation( location, false);
826   }
827
828   /**
829    * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
830    */
831   void VertexAttribDivisor ( GLuint index, GLuint divisor )
832   {
833     LOG_GL("VertexAttribPointer(%d, %d)\n", index, divisor );
834     CHECK_GL( *this, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
835   }
836
837   /**
838    * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
839    */
840   void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
841   {
842     LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
843     CHECK_GL( *this, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
844   }
845
846   /**
847    * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
848    */
849   void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
850   {
851     LOG_GL("InvalidateFramebuffer\n");
852     CHECK_GL( *this, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
853   }
854
855   /**
856    * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
857    * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
858    */
859
860   /**
861    * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
862    * @param[in] enable True if GL_BLEND should be enabled.
863    */
864   void SetBlend(bool enable)
865   {
866     // Avoid unecessary calls to glEnable/glDisable
867     if (enable != mBlendEnabled)
868     {
869       mBlendEnabled = enable;
870
871       if (enable)
872       {
873         LOG_GL("Enable GL_BLEND\n");
874         CHECK_GL( *this, mGlAbstraction.Enable(GL_BLEND) );
875       }
876       else
877       {
878         LOG_GL("Disable GL_BLEND\n");
879         CHECK_GL( *this, mGlAbstraction.Disable(GL_BLEND) );
880       }
881     }
882   }
883
884   /**
885    * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
886    * @param[in] enable True if GL_DEPTH_TEST should be enabled.
887    */
888   void SetDepthTest(bool enable)
889   {
890     // Avoid unecessary calls to glEnable/glDisable
891     if (enable != mDepthTestEnabled)
892     {
893       mDepthTestEnabled = enable;
894
895       if (enable)
896       {
897         LOG_GL("Enable GL_DEPTH_TEST\n");
898         CHECK_GL( *this, mGlAbstraction.Enable(GL_DEPTH_TEST) );
899       }
900       else
901       {
902         LOG_GL("Disable GL_DEPTH_TEST\n");
903         CHECK_GL( *this, mGlAbstraction.Disable(GL_DEPTH_TEST) );
904       }
905     }
906   }
907
908   /**
909    * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
910    * @param[in] enable True if GL_DITHER should be enabled.
911    */
912   void SetDither(bool enable)
913   {
914     // Avoid unecessary calls to glEnable/glDisable
915     if (enable != mDitherEnabled)
916     {
917       mDitherEnabled = enable;
918
919       if (enable)
920       {
921         LOG_GL("Enable GL_DITHER\n");
922         CHECK_GL( *this, mGlAbstraction.Enable(GL_DITHER) );
923       }
924       else
925       {
926         LOG_GL("Disable GL_DITHER\n");
927         CHECK_GL( *this, mGlAbstraction.Disable(GL_DITHER) );
928       }
929     }
930   }
931
932   /**
933    * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
934    * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
935    */
936   void SetPolygonOffsetFill(bool enable)
937   {
938     // Avoid unecessary calls to glEnable/glDisable
939     if (enable != mPolygonOffsetFillEnabled)
940     {
941       mPolygonOffsetFillEnabled = enable;
942
943       if (enable)
944       {
945         LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
946         CHECK_GL( *this, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
947       }
948       else
949       {
950         LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
951         CHECK_GL( *this, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
952       }
953     }
954   }
955
956   /**
957    * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
958    * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
959    */
960   void SetSampleAlphaToCoverage(bool enable)
961   {
962     // Avoid unecessary calls to glEnable/glDisable
963     if (enable != mSampleAlphaToCoverageEnabled)
964     {
965       mSampleAlphaToCoverageEnabled = enable;
966
967       if (enable)
968       {
969         LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
970         CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
971       }
972       else
973       {
974         LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
975         CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
976       }
977     }
978   }
979
980   /**
981    * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
982    * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
983    */
984   void SetSampleCoverage(bool enable)
985   {
986     // Avoid unecessary calls to glEnable/glDisable
987     if (enable != mSampleCoverageEnabled)
988     {
989       mSampleCoverageEnabled = enable;
990
991       if (enable)
992       {
993         LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
994         CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
995       }
996       else
997       {
998         LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
999         CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
1000       }
1001     }
1002   }
1003
1004   /**
1005    * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
1006    * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
1007    */
1008   void SetScissorTest(bool enable)
1009   {
1010     // Avoid unecessary calls to glEnable/glDisable
1011     if (enable != mScissorTestEnabled)
1012     {
1013       mScissorTestEnabled = enable;
1014
1015       if (enable)
1016       {
1017         LOG_GL("Enable GL_SCISSOR_TEST\n");
1018         CHECK_GL( *this, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1019       }
1020       else
1021       {
1022         LOG_GL("Disable GL_SCISSOR_TEST\n");
1023         CHECK_GL( *this, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1024       }
1025     }
1026   }
1027
1028   /**
1029    * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1030    * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1031    */
1032   void SetStencilTest(bool enable)
1033   {
1034     // Avoid unecessary calls to glEnable/glDisable
1035     if (enable != mStencilTestEnabled)
1036     {
1037       mStencilTestEnabled = enable;
1038
1039       if (enable)
1040       {
1041         LOG_GL("Enable GL_STENCIL_TEST\n");
1042         CHECK_GL( *this, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1043       }
1044       else
1045       {
1046         LOG_GL("Disable GL_STENCIL_TEST\n");
1047         CHECK_GL( *this, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1048       }
1049     }
1050   }
1051
1052   /**
1053    * Wrapper for OpenGL ES 3.0 glEndQuery()
1054    */
1055   void EndQuery(GLenum target)
1056   {
1057     LOG_GL("EndQuery %d\n", target);
1058     CHECK_GL( *this, mGlAbstraction.EndQuery(target) );
1059   }
1060
1061   /**
1062    * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1063    */
1064   void EndTransformFeedback()
1065   {
1066     LOG_GL("EndTransformFeedback\n");
1067     CHECK_GL( *this, mGlAbstraction.EndTransformFeedback() );
1068   }
1069
1070   /**
1071    * Wrapper for OpenGL ES 2.0 glFinish()
1072    */
1073   void Finish(void)
1074   {
1075     LOG_GL("Finish\n");
1076     CHECK_GL( *this, mGlAbstraction.Finish() );
1077   }
1078
1079   /**
1080    * Wrapper for OpenGL ES 2.0 glFlush()
1081    */
1082   void Flush(void)
1083   {
1084     LOG_GL("Flush\n");
1085     CHECK_GL( *this, mGlAbstraction.Flush() );
1086   }
1087
1088   /**
1089    * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1090    */
1091   void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1092   {
1093     LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1094     CHECK_GL( *this, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1095   }
1096
1097   /**
1098    * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1099    */
1100   void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1101   {
1102     LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1103     CHECK_GL( *this, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1104   }
1105
1106   /**
1107    * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1108    */
1109   void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1110   {
1111     LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1112     CHECK_GL( *this, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1113   }
1114
1115   /**
1116    * Wrapper for OpenGL ES 2.0 glFrontFace()
1117    */
1118   void FrontFace(GLenum mode)
1119   {
1120     LOG_GL("FrontFace %x\n", mode);
1121     CHECK_GL( *this, mGlAbstraction.FrontFace(mode) );
1122   }
1123
1124   /**
1125    * Wrapper for OpenGL ES 2.0 glGenBuffers()
1126    */
1127   void GenBuffers(GLsizei n, GLuint* buffers)
1128   {
1129     LOG_GL("GenBuffers %d\n", n, buffers);
1130     CHECK_GL( *this, mGlAbstraction.GenBuffers(n, buffers) );
1131   }
1132
1133   /**
1134    * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1135    */
1136   void GenerateMipmap(GLenum target)
1137   {
1138     LOG_GL("GenerateMipmap %x\n", target);
1139     CHECK_GL( *this, mGlAbstraction.GenerateMipmap(target) );
1140   }
1141
1142   /**
1143    * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1144    */
1145   void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1146   {
1147     LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1148     CHECK_GL( *this, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1149   }
1150
1151   /**
1152    * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1153    */
1154   void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1155   {
1156     LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1157     CHECK_GL( *this, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1158   }
1159
1160   /**
1161    * Wrapper for OpenGL ES 2.0 glGenTextures()
1162    */
1163   void GenTextures(GLsizei n, GLuint* textures)
1164   {
1165     LOG_GL("GenTextures %d %p\n", n, textures);
1166     CHECK_GL( *this, mGlAbstraction.GenTextures(n, textures) );
1167   }
1168
1169   /**
1170    * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1171    */
1172   void GetBooleanv(GLenum pname, GLboolean* params)
1173   {
1174     LOG_GL("GetBooleanv %x\n", pname);
1175     CHECK_GL( *this, mGlAbstraction.GetBooleanv(pname, params) );
1176   }
1177
1178   /**
1179    * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1180    */
1181   void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1182   {
1183     LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1184     CHECK_GL( *this, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1185   }
1186
1187   /**
1188    * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1189    */
1190   void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1191   {
1192     LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1193     CHECK_GL( *this, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1194   }
1195
1196   /**
1197    * Wrapper for OpenGL ES 2.0 glGetError()
1198    */
1199   GLenum GetError(void)
1200   {
1201     // Not worth logging here
1202     return mGlAbstraction.GetError();
1203   }
1204
1205   /**
1206    * Wrapper for OpenGL ES 2.0 glGetFloatv()
1207    */
1208   void GetFloatv(GLenum pname, GLfloat* params)
1209   {
1210     LOG_GL("GetFloatv %x\n", pname);
1211     CHECK_GL( *this, mGlAbstraction.GetFloatv(pname, params) );
1212   }
1213
1214   /**
1215    * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1216    */
1217   void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1218   {
1219     LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1220     CHECK_GL( *this, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1221   }
1222
1223   /**
1224    * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1225    */
1226   void GetIntegerv(GLenum pname, GLint* params)
1227   {
1228     LOG_GL("GetIntegerv %x\n", pname);
1229     CHECK_GL( *this, mGlAbstraction.GetIntegerv(pname, params) );
1230   }
1231
1232   /**
1233    * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1234    */
1235   void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1236   {
1237     LOG_GL("GetQueryiv %x %x\n", target, pname);
1238     CHECK_GL( *this, mGlAbstraction.GetQueryiv(target, pname, params) );
1239   }
1240
1241   /**
1242    * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1243    */
1244   void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1245   {
1246     LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1247     CHECK_GL( *this, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1248   }
1249
1250   /**
1251    * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1252    */
1253   void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1254   {
1255     LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1256     CHECK_GL( *this, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1257   }
1258
1259   /**
1260    * Wrapper for OpenGL ES 2.0 glGetString()
1261    */
1262   const GLubyte* GetString(GLenum name)
1263   {
1264     LOG_GL("GetString %x\n", name);
1265     const GLubyte* str = CHECK_GL( *this, mGlAbstraction.GetString(name) );
1266     return str;
1267   }
1268
1269   /**
1270    * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1271    */
1272   void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1273   {
1274     LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1275     CHECK_GL( *this, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1276   }
1277
1278   /**
1279    * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1280    */
1281   void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1282   {
1283     LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1284     CHECK_GL( *this, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1285   }
1286
1287   /**
1288    * Wrapper for OpenGL ES 2.0 glHint()
1289    */
1290   void Hint(GLenum target, GLenum mode)
1291   {
1292     LOG_GL("Hint %x %x\n", target, mode);
1293     CHECK_GL( *this, mGlAbstraction.Hint(target, mode) );
1294   }
1295
1296   /**
1297    * Wrapper for OpenGL ES 2.0 glIsBuffer()
1298    */
1299   GLboolean IsBuffer(GLuint buffer)
1300   {
1301     LOG_GL("IsBuffer %d\n", buffer);
1302     GLboolean val = CHECK_GL( *this, mGlAbstraction.IsBuffer(buffer) );
1303     return val;
1304   }
1305
1306   /**
1307    * Wrapper for OpenGL ES 2.0 glIsEnabled()
1308    */
1309   GLboolean IsEnabled(GLenum cap)
1310   {
1311     LOG_GL("IsEnabled %x\n", cap);
1312     GLboolean val = CHECK_GL( *this, mGlAbstraction.IsEnabled(cap) );
1313     return val;
1314   }
1315
1316   /**
1317    * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1318    */
1319   GLboolean IsFramebuffer(GLuint framebuffer)
1320   {
1321     LOG_GL("IsFramebuffer %d\n", framebuffer);
1322     GLboolean val = CHECK_GL( *this, mGlAbstraction.IsFramebuffer(framebuffer) );
1323     return val;
1324   }
1325
1326   /**
1327    * Wrapper for OpenGL ES 3.0 glIsQuery()
1328    */
1329   GLboolean IsQuery(GLuint id)
1330   {
1331     LOG_GL("IsQuery %u\n", id);
1332     GLboolean val = CHECK_GL( *this, mGlAbstraction.IsQuery(id) );
1333     return val;
1334   }
1335
1336   /**
1337    * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1338    */
1339   GLboolean IsRenderbuffer(GLuint renderbuffer)
1340   {
1341     LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1342     GLboolean val = CHECK_GL( *this, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1343     return val;
1344   }
1345
1346   /**
1347    * Wrapper for OpenGL ES 2.0 glIsTexture()
1348    */
1349   GLboolean IsTexture(GLuint texture)
1350   {
1351     LOG_GL("IsTexture %d\n", texture);
1352     GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTexture(texture) );
1353     return val;
1354   }
1355
1356   /**
1357    * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1358    */
1359   GLboolean IsTransformFeedback(GLuint id)
1360   {
1361     LOG_GL("IsTransformFeedback %u\n", id);
1362     GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTransformFeedback(id) );
1363     return val;
1364   }
1365
1366   /**
1367    * Wrapper for OpenGL ES 2.0 glLineWidth()
1368    */
1369   void LineWidth(GLfloat width)
1370   {
1371     LOG_GL("LineWidth %f\n", width);
1372     CHECK_GL( *this, mGlAbstraction.LineWidth(width) );
1373   }
1374
1375   /**
1376    * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1377    */
1378   void PauseTransformFeedback()
1379   {
1380     LOG_GL("PauseTransformFeedback\n");
1381     CHECK_GL( *this, mGlAbstraction.PauseTransformFeedback() );
1382   }
1383
1384   /**
1385    * Wrapper for OpenGL ES 2.0 glPixelStorei()
1386    */
1387   void PixelStorei(GLenum pname, GLint param)
1388   {
1389     LOG_GL("PixelStorei %x %d\n", pname, param);
1390     CHECK_GL( *this, mGlAbstraction.PixelStorei(pname, param) );
1391   }
1392
1393   /**
1394    * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1395    */
1396   void PolygonOffset(GLfloat factor, GLfloat units)
1397   {
1398     LOG_GL("PolygonOffset %f %f\n", factor, units);
1399     CHECK_GL( *this, mGlAbstraction.PolygonOffset(factor, units) );
1400   }
1401
1402   /**
1403    * Wrapper for OpenGL ES 2.0 glReadPixels()
1404    */
1405   void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1406   {
1407     LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1408     CHECK_GL( *this, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1409   }
1410
1411   /**
1412    * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1413    */
1414   void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1415   {
1416     LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1417     CHECK_GL( *this, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1418   }
1419
1420   /**
1421    * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1422    */
1423   void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1424   {
1425     LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1426     CHECK_GL( *this, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1427   }
1428
1429   /**
1430    * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1431    */
1432   void ResumeTransformFeedback()
1433   {
1434     LOG_GL("ResumeTransformFeedback\n");
1435     CHECK_GL( *this, mGlAbstraction.ResumeTransformFeedback() );
1436   }
1437
1438   /**
1439    * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1440    */
1441   void SampleCoverage(GLclampf value, GLboolean invert)
1442   {
1443     LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1444     CHECK_GL( *this, mGlAbstraction.SampleCoverage(value, invert) );
1445   }
1446
1447   /**
1448    * Wrapper for OpenGL ES 2.0 glScissor()
1449    */
1450   void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1451   {
1452     LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1453     CHECK_GL( *this, mGlAbstraction.Scissor(x, y, width, height) );
1454   }
1455
1456   /**
1457    * Wrapper for OpenGL ES 2.0 glStencilFunc()
1458    */
1459   void StencilFunc(GLenum func, GLint ref, GLuint mask)
1460   {
1461     LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1462     CHECK_GL( *this, mGlAbstraction.StencilFunc(func, ref, mask) );
1463   }
1464
1465   /**
1466    * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1467    */
1468   void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1469   {
1470     LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1471     CHECK_GL( *this, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1472   }
1473
1474   /**
1475    * Wrapper for OpenGL ES 2.0 glStencilMask()
1476    */
1477   void StencilMask(GLuint mask)
1478   {
1479     if( mask != mStencilMask )
1480     {
1481       mStencilMask = mask;
1482
1483       LOG_GL("StencilMask %d\n", mask);
1484       CHECK_GL( *this, mGlAbstraction.StencilMask(mask) );
1485     }
1486   }
1487
1488   /**
1489    * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1490    */
1491   void StencilMaskSeparate(GLenum face, GLuint mask)
1492   {
1493     LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1494     CHECK_GL( *this, mGlAbstraction.StencilMaskSeparate(face, mask) );
1495   }
1496
1497   /**
1498    * Wrapper for OpenGL ES 2.0 glStencilOp()
1499    */
1500   void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1501   {
1502     LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1503     CHECK_GL( *this, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1504   }
1505
1506   /**
1507    * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1508    */
1509   void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1510   {
1511     LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1512     CHECK_GL( *this, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1513   }
1514
1515   /**
1516    * Wrapper for OpenGL ES 2.0 glTexImage2D()
1517    */
1518   void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1519                   GLint border, GLenum format, GLenum type, const void* pixels)
1520   {
1521     LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1522     CHECK_GL( *this, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1523   }
1524
1525   /**
1526    * Wrapper for OpenGL ES 3.0 glTexImage3D()
1527    */
1528   void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1529                   GLint border, GLenum format, GLenum type, const void* pixels)
1530   {
1531     LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1532     CHECK_GL( *this, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1533   }
1534
1535   /**
1536    * Wrapper for OpenGL ES 2.0 glTexParameterf()
1537    */
1538   void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1539   {
1540     LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1541     CHECK_GL( *this, mGlAbstraction.TexParameterf(target, pname, param) );
1542   }
1543
1544   /**
1545    * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1546    */
1547   void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1548   {
1549     LOG_GL("TexParameterfv %x %x\n", target, pname);
1550     CHECK_GL( *this, mGlAbstraction.TexParameterfv(target, pname, params) );
1551   }
1552
1553   /**
1554    * Wrapper for OpenGL ES 2.0 glTexParameteri()
1555    */
1556   void TexParameteri(GLenum target, GLenum pname, GLint param)
1557   {
1558     LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1559     CHECK_GL( *this, mGlAbstraction.TexParameteri(target, pname, param) );
1560   }
1561
1562   /**
1563    * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1564    */
1565   void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1566   {
1567     LOG_GL("TexParameteriv %x %x\n", target, pname);
1568     CHECK_GL( *this, mGlAbstraction.TexParameteriv(target, pname, params) );
1569   }
1570
1571   /**
1572    * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1573    */
1574   void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1575                      GLenum format, GLenum type, const void* pixels)
1576   {
1577     LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1578     CHECK_GL( *this, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1579   }
1580
1581   /**
1582    * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1583    */
1584   void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1585                      GLsizei width, GLsizei height, GLsizei depth,
1586                      GLenum format, GLenum type, const void* pixels)
1587   {
1588     LOG_GL("TexSubImage3D %x %d %d %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
1589     CHECK_GL( *this, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1590   }
1591
1592   /**
1593    * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1594    */
1595   GLboolean UnmapBuffer(GLenum target)
1596   {
1597     LOG_GL("UnmapBuffer %x \n", target);
1598     GLboolean val = CHECK_GL( *this, mGlAbstraction.UnmapBuffer(target) );
1599     return val;
1600   }
1601   /**
1602    * Wrapper for OpenGL ES 2.0 glViewport()
1603    */
1604   void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1605   {
1606     // check if its same as already set
1607     Rect<int> newViewport( x, y, width, height );
1608     if( mViewPort != newViewport )
1609     {
1610       // set new one
1611       LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1612       CHECK_GL( *this, mGlAbstraction.Viewport(x, y, width, height) );
1613       mViewPort = newViewport; // remember new one
1614     }
1615   }
1616
1617   /**
1618    * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1619    * @return The implementation defined MAX_TEXTURE_SIZE
1620    */
1621   GLint CachedMaxTextureSize() const
1622   {
1623     return mMaxTextureSize;
1624   }
1625
1626   /**
1627    * Get the number of supported program binary formats
1628    * @return The number of supported program binary formats
1629    */
1630   GLint CachedNumberOfProgramBinaryFormats() const
1631   {
1632     return mProgramBinaryFormats.size();
1633   }
1634
1635   /**
1636    * Get a supported program binary format
1637    * @param[in] formatIndex The index of the format to return (default: 0)
1638    * @return A supported program binary format
1639    */
1640   GLint CachedProgramBinaryFormat( const unsigned int formatIndex = 0 ) const
1641   {
1642     DALI_ASSERT_ALWAYS( formatIndex < mProgramBinaryFormats.size() && "formatIndex out of bounds");
1643
1644     return mProgramBinaryFormats[ formatIndex ];
1645   }
1646
1647   /**
1648    * @return current program
1649    */
1650   const Program* GetCurrentProgram() const
1651   {
1652     return mCurrentProgram;
1653   }
1654
1655   /**
1656    * Set current program
1657    * @param [in] program that is in use
1658    */
1659   void SetCurrentProgram( Program* program )
1660   {
1661     mCurrentProgram = program;
1662   }
1663
1664   /**
1665    * Get a cached program
1666    * @param [in] hash value
1667    * @return pointer to the program
1668    */
1669   Program* GetCachedProgram( std::size_t hash ) const;
1670
1671   /**
1672    * Cache a program
1673    * @param [in] hash value
1674    * @param [in] pointer to the program
1675    */
1676   void CacheProgram( std::size_t hash, Program* pointer );
1677
1678   /**
1679    * Get the current viewport.
1680    * @return Viewport rectangle.
1681    */
1682   const Rect< int >& GetViewport();
1683
1684 #ifdef DEBUG_ENABLED
1685
1686   /// Switch debug level to Concise to disable, General to enable. Note, enabling snapshot logging will do this on the fly.
1687   static Debug::Filter *gGlLogFilter;
1688
1689 #endif // DEBUG_ENABLED
1690
1691 private: // Implementation
1692
1693   /**
1694    * Flushes vertex attribute location changes to the driver
1695    */
1696   void FlushVertexAttributeLocations();
1697
1698   /**
1699    * Reset the cached internal vertex attribute state
1700    */
1701   void ResetVertexAttributeState();
1702
1703   /**
1704    * Either enables or disables a vertex attribute location in the cache
1705    * The cahnges won't take affect until FlushVertexAttributeLocations is called
1706    * @param location attribute location
1707    * @param state attribute state
1708    */
1709   void SetVertexAttributeLocation(unsigned int location, bool state);
1710
1711   /**
1712    * Sets the initial GL state.
1713    */
1714   void ResetGlState();
1715
1716 private: // Data
1717
1718   Integration::GlAbstraction& mGlAbstraction;
1719
1720   bool mGlContextCreated; ///< True if the OpenGL context has been created
1721
1722   // glEnable/glDisable states
1723   bool mColorMask;
1724   GLuint mStencilMask;
1725   bool mBlendEnabled;
1726   bool mDepthTestEnabled;
1727   bool mDepthMaskEnabled;
1728   bool mDitherEnabled;
1729   bool mPolygonOffsetFillEnabled;
1730   bool mSampleAlphaToCoverageEnabled;
1731   bool mSampleCoverageEnabled;
1732   bool mScissorTestEnabled;
1733   bool mStencilTestEnabled;
1734   bool mClearColorSet;
1735
1736   // glBindBuffer() state
1737   GLuint mBoundArrayBufferId;        ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1738   GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1739   GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1740
1741   // glBindTexture() state
1742   unsigned int mActiveTextureUnit;
1743   std::vector<GLuint> mBound2dTextureId;  ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
1744
1745   // glBlendColor() state
1746   bool mUsingDefaultBlendColor;
1747
1748   // glBlendFuncSeparate() state
1749   GLenum mBlendFuncSeparateSrcRGB;   ///< The srcRGB parameter passed to glBlendFuncSeparate()
1750   GLenum mBlendFuncSeparateDstRGB;   ///< The dstRGB parameter passed to glBlendFuncSeparate()
1751   GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1752   GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1753
1754   // glBlendEquationSeparate state
1755   GLenum mBlendEquationSeparateModeRGB;    ///< Controls RGB blend mode
1756   GLenum mBlendEquationSeparateModeAlpha;  ///< Controls Alpha blend mode
1757
1758   GLint mMaxTextureSize;      ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1759   GLint mMaxTextureUnits;     ///< return value from GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS)
1760   Vector4 mClearColor;        ///< clear color
1761
1762   std::vector<GLint>  mProgramBinaryFormats; ///< array of supported program binary formats
1763
1764   // Face culling mode
1765   CullFaceMode mCullFaceMode;
1766
1767   // cached viewport size
1768   Rect< int > mViewPort;
1769
1770   // Vertex Attribute Buffer enable caching
1771   bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ];    ///< Value cache for Enable Vertex Attribute
1772   bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ];   ///< Current state on the driver for Enable Vertex Attribute
1773
1774   std::set<ContextObserver*> mObservers;
1775
1776   Program* mCurrentProgram;
1777   std::map< std::size_t, Program* > mProgramCache; /// program cache
1778
1779 };
1780
1781 } // namespace Internal
1782
1783 } // namespace Dali
1784
1785 #endif // __DALI_INTERNAL_CONTEXT_H__