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