[3.0] Modify texture bind for OES_EGL_image_external
[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) 2016 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/math/vector4.h>
26 #include <dali/public-api/rendering/renderer.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 glBindTexture( target )
290    */
291   void BindTexture( int target, GLuint texture )
292   {
293     if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
294     {
295       mBound2dTextureId[ mActiveTextureUnit ] = texture;
296
297       LOG_GL("BindTexture target(%d) %d\n", target, texture);
298       CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(target, texture) );
299     }
300   }
301
302   /**
303    * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_CUBE_MAP)
304    */
305   void BindCubeMapTexture( GLuint texture )
306   {
307     LOG_GL("BindTexture GL_TEXTURE_CUBE_MAP %d\n", texture);
308     CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(GL_TEXTURE_CUBE_MAP, texture) );
309   }
310
311   /**
312    * Wrapper for OpenGL ES 2.0 glBlendColor()
313    */
314   void SetDefaultBlendColor()
315   {
316     if( ! mUsingDefaultBlendColor )
317     {
318       SetCustomBlendColor( Color::TRANSPARENT );
319       mUsingDefaultBlendColor = true;
320     }
321   }
322
323   /**
324    * Wrapper for OpenGL ES 2.0 glBlendColor()
325    */
326   void SetCustomBlendColor( const Vector4& color )
327   {
328     if( mUsingDefaultBlendColor || mBlendColor != color )
329     {
330       LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
331       CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor( color.r, color.g, color.b, color.a ) );
332       mUsingDefaultBlendColor = false;
333       mBlendColor = color;
334     }
335   }
336
337   /**
338    * Wrapper for OpenGL ES 2.0 glBlendEquation()
339    */
340   void BlendEquation(GLenum mode)
341   {
342     // use BlendEquationSeparate to set the rgb and alpha modes the same
343     BlendEquationSeparate( mode, mode );
344   }
345
346   /**
347    * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
348    */
349   void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
350   {
351     if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
352         ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
353     {
354       mBlendEquationSeparateModeRGB = modeRGB;
355       mBlendEquationSeparateModeAlpha = modeAlpha;
356       LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
357       CHECK_GL( mGlAbstraction, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
358     }
359   }
360
361   /**
362    * Wrapper for OpenGL ES 2.0 glBlendFunc()
363    */
364   void BlendFunc(GLenum sfactor, GLenum dfactor)
365   {
366     // reuse the BlendFuncSeparate as thats what the DDK does anyways
367     BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
368   }
369
370   /**
371    * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
372    */
373   void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
374   {
375     if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
376         ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
377     {
378       mBlendFuncSeparateSrcRGB = srcRGB;
379       mBlendFuncSeparateDstRGB = dstRGB;
380       mBlendFuncSeparateSrcAlpha = srcAlpha;
381       mBlendFuncSeparateDstAlpha = dstAlpha;
382
383       LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
384       CHECK_GL( mGlAbstraction, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
385     }
386   }
387
388   /**
389    * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
390    */
391   void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
392   {
393     LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
394     CHECK_GL( mGlAbstraction, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
395   }
396
397   /**
398    * Wrapper for OpenGL ES 2.0 glBufferData()
399    */
400   void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
401   {
402     LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
403     CHECK_GL( mGlAbstraction, mGlAbstraction.BufferData(target, size, data, usage) );
404   }
405
406   /**
407    * Wrapper for OpenGL ES 2.0 glBufferSubData()
408    */
409   void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
410   {
411     LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
412     CHECK_GL( mGlAbstraction, mGlAbstraction.BufferSubData(target, offset, size, data) );
413   }
414
415   /**
416    * Wrapper for OpenGL ES 2.0  glCheckFramebufferStatus()
417    */
418   GLenum CheckFramebufferStatus(GLenum target)
419   {
420     LOG_GL("CheckFramebufferStatus %d\n", target);
421     GLenum value = CHECK_GL( mGlAbstraction, mGlAbstraction.CheckFramebufferStatus(target) );
422     return value;
423   }
424
425   /**
426    * Wrapper for OpenGL ES 2.0 glClear()
427    */
428   void Clear(GLbitfield mask, ClearMode mode )
429   {
430     bool forceClear = (mode == FORCE_CLEAR );
431     mask = mFrameBufferStateCache.GetClearMask( mask, forceClear , mScissorTestEnabled );
432
433     if( mask > 0 )
434     {
435       LOG_GL("Clear %d\n", mask);
436       CHECK_GL( mGlAbstraction, mGlAbstraction.Clear( mask ) );
437     }
438   }
439
440   /**
441    * Wrapper for OpenGL ES 2.0 glClearColor()
442    */
443   void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
444   {
445     Vector4 newCol(red,green,blue,alpha);
446
447     if (!mClearColorSet || mClearColor !=newCol )
448     {
449       LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
450       CHECK_GL( mGlAbstraction, mGlAbstraction.ClearColor(red, green, blue, alpha) );
451
452       mClearColorSet = true;
453       mClearColor = newCol;
454     }
455   }
456
457   /**
458    * Wrapper for OpenGL ES 2.0 glClearDepthf()
459    */
460   void ClearDepthf(GLclampf depth)
461   {
462     LOG_GL("ClearDepthf %f\n", depth);
463     CHECK_GL( mGlAbstraction, mGlAbstraction.ClearDepthf(depth) );
464   }
465
466   /**
467    * Wrapper for OpenGL ES 2.0 glClearStencil()
468    */
469   void ClearStencil(GLint s)
470   {
471     LOG_GL("ClearStencil %d\n", s);
472     CHECK_GL( mGlAbstraction, mGlAbstraction.ClearStencil(s) );
473   }
474
475   /**
476    * Wrapper for OpenGL ES 2.0 glColorMask()
477    * @note This has been optimized to a single boolean value (masking individual channels is not required)
478    */
479   void ColorMask( bool flag )
480   {
481     // only change state if needed
482     if( flag != mColorMask )
483     {
484       mColorMask = flag;
485       LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
486       CHECK_GL( mGlAbstraction, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
487     }
488   }
489
490   /**
491    * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
492    */
493   void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
494                             GLint border, GLsizei imageSize, const void* data)
495   {
496     LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
497     CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
498   }
499
500   /**
501    * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
502    */
503   void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
504                             GLint border, GLsizei imageSize, const void* data)
505   {
506     LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
507     CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
508   }
509
510   /**
511    * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
512    */
513   void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
514                                GLenum format, GLsizei imageSize, const void* data)
515   {
516     LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
517     CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
518   }
519
520   /**
521    * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
522    */
523   void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
524                                GLsizei width, GLsizei height, GLsizei depth,
525                                GLenum format, GLsizei imageSize, const void* data)
526   {
527     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);
528     CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
529   }
530
531   /**
532    * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
533    */
534   void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
535   {
536     LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
537     CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
538   }
539
540   /**
541    * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
542    */
543   void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
544   {
545     LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
546     CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
547   }
548
549   /**
550    * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
551    */
552   void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
553   {
554     LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
555     CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
556   }
557
558   /**
559    * Wrapper for OpenGL ES 2.0 glCullFace()
560    * enables GL_CULL_FACE if in any of the face culling modes
561    * otherwise disables GL_CULL_FACE
562    */
563   void CullFace( Dali::FaceCullingMode::Type mode )
564   {
565     // Avoid unnecessary calls to gl
566     if(mCullFaceMode != mode)
567     {
568       mCullFaceMode = mode;
569       switch(mode)
570       {
571         case Dali::FaceCullingMode::NONE:
572         {
573           LOG_GL("Disable GL_CULL_FACE\n");
574           CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE) );
575           break;
576         }
577
578         case Dali::FaceCullingMode::FRONT:
579         {
580           LOG_GL("Enable GL_CULL_FACE\n");
581           CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
582           LOG_GL("Enable GL_FRONT\n");
583           CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT) );
584           break;
585         }
586
587         case Dali::FaceCullingMode::BACK:
588         {
589           LOG_GL("Enable GL_CULL_FACE\n");
590           CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
591           LOG_GL("Enable GL_BACK\n");
592           CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_BACK) );
593           break;
594         }
595
596         case Dali::FaceCullingMode::FRONT_AND_BACK:
597         {
598           LOG_GL("Enable GL_CULL_FACE\n");
599           CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
600           LOG_GL("Enable GL_FRONT_AND_BACK\n");
601           CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
602           break;
603         }
604
605         default:
606           break;
607       }
608     }
609   }
610
611   /**
612    * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
613    */
614   void DeleteBuffers(GLsizei n, const GLuint* buffers)
615   {
616     // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
617     // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
618     if( this->IsGlContextCreated() )
619     {
620       LOG_GL("DeleteBuffers %d %p\n", n, buffers);
621       CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
622     }
623     // reset the cached buffer id's
624     // fixes problem where some drivers will a generate a buffer with the
625     // same id, as the last deleted buffer id.
626     mBoundArrayBufferId = 0;
627     mBoundElementArrayBufferId = 0;
628     mBoundTransformFeedbackBufferId = 0;
629   }
630
631   /**
632    * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
633    */
634   void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
635   {
636     mFrameBufferStateCache.FrameBuffersDeleted( n, framebuffers );
637
638     LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
639     CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
640   }
641
642   /**
643    * Wrapper for OpenGL ES 3.0 glDeleteQueries()
644    */
645   void DeleteQueries(GLsizei n, GLuint* ids)
646   {
647     LOG_GL("DeleteQueries %d %p\n", n, ids);
648     CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteQueries(n, ids) );
649   }
650
651   /**
652    * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
653    */
654   void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
655   {
656     LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
657     CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
658   }
659
660   /**
661    * Wrapper for OpenGL ES 2.0 glDeleteTextures()
662    */
663   void DeleteTextures(GLsizei n, const GLuint* textures)
664   {
665     LOG_GL("DeleteTextures %d %p\n", n, textures);
666     CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
667
668     // reset the cached texture id's incase the driver re-uses them
669     // when creating new textures
670     for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
671     {
672        mBound2dTextureId[ i ] = 0;
673     }
674   }
675
676   /**
677    * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
678    */
679   void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
680   {
681     LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
682     CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
683   }
684
685   /**
686    * Wrapper for OpenGL ES 2.0 glDepthFunc()
687    */
688   void DepthFunc(GLenum func)
689   {
690     if( func != mDepthFunction )
691     {
692       mDepthFunction = func;
693       LOG_GL("DepthFunc %x\n", func);
694       CHECK_GL( mGlAbstraction, mGlAbstraction.DepthFunc(func) );
695     }
696   }
697
698   /**
699    * Wrapper for OpenGL ES 2.0 glDepthMask()
700    */
701   void DepthMask(GLboolean flag)
702   {
703     // only change state if needed
704     if( flag != mDepthMaskEnabled )
705     {
706       mDepthMaskEnabled = flag;
707       LOG_GL("DepthMask %s\n", flag ? "True" : "False");
708       CHECK_GL( mGlAbstraction, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
709     }
710   }
711
712   /**
713    * Wrapper for OpenGL ES 2.0 glDepthRangef()
714    */
715   void DepthRangef(GLclampf zNear, GLclampf zFar)
716   {
717     LOG_GL("DepthRangef %f %f\n", zNear, zFar);
718     CHECK_GL( mGlAbstraction, mGlAbstraction.DepthRangef(zNear, zFar) );
719   }
720
721   /**
722    * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
723    * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
724    */
725
726   /**
727    * Wrapper for OpenGL ES 2.0 glDrawArrays()
728    */
729   void DrawArrays(GLenum mode, GLint first, GLsizei count)
730   {
731     mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
732     FlushVertexAttributeLocations();
733
734     LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
735     CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArrays(mode, first, count) );
736   }
737
738   /**
739    * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
740    */
741   void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
742   {
743     mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
744     FlushVertexAttributeLocations();
745
746     LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
747     CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
748   }
749
750   /**
751    * Wrapper for OpenGL ES 3.0 glDrawBuffers()
752    */
753   void DrawBuffers(GLsizei n, const GLenum* bufs)
754   {
755     mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
756     LOG_GL("DrawBuffers %d %p\n", n, bufs);
757     CHECK_GL( mGlAbstraction, mGlAbstraction.DrawBuffers(n, bufs) );
758   }
759
760   /**
761    * Wrapper for OpenGL ES 2.0 glDrawElements()
762    */
763   void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
764   {
765     mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
766
767     FlushVertexAttributeLocations();
768
769     LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
770     CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElements(mode, count, type, indices) );
771   }
772
773   /**
774    * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
775    */
776   void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
777   {
778     mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
779
780     FlushVertexAttributeLocations();
781
782     LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
783     CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
784   }
785
786   /**
787    * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
788    */
789   void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
790   {
791     mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
792     FlushVertexAttributeLocations();
793
794     LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
795     CHECK_GL( mGlAbstraction, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
796   }
797
798   /**
799    * Wrapper for OpenGL ES 3.0 glGenQuerieS()
800    */
801   void GenQueries(GLsizei n, GLuint* ids)
802   {
803     LOG_GL("GenQueries %d %p\n", n, ids);
804     CHECK_GL( mGlAbstraction, mGlAbstraction.GenQueries(n, ids) );
805   }
806
807   /**
808    * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
809    */
810   void GenTransformFeedbacks(GLsizei n, GLuint* ids)
811   {
812     LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
813     CHECK_GL( mGlAbstraction, mGlAbstraction.GenTransformFeedbacks(n, ids) );
814   }
815
816   /**
817    * @return the current buffer bound for a given target
818    */
819   GLuint GetCurrentBoundArrayBuffer(GLenum target)
820   {
821     GLuint result(0);
822     switch(target)
823     {
824       case GL_ARRAY_BUFFER:
825       {
826         result = mBoundArrayBufferId;
827         break;
828       }
829       case GL_ELEMENT_ARRAY_BUFFER:
830       {
831         result = mBoundElementArrayBufferId;
832         break;
833       }
834       case GL_TRANSFORM_FEEDBACK_BUFFER:
835       {
836         result = mBoundTransformFeedbackBufferId;
837         break;
838       }
839       default:
840       {
841         DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
842       }
843     }
844     return result;
845   }
846
847   void EnableVertexAttributeArray( GLuint location )
848   {
849     SetVertexAttributeLocation( location, true);
850   }
851
852   void DisableVertexAttributeArray( GLuint location )
853   {
854     SetVertexAttributeLocation( location, false);
855   }
856
857   /**
858    * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
859    */
860   void VertexAttribDivisor ( GLuint index, GLuint divisor )
861   {
862     LOG_GL("VertexAttribDivisor(%d, %d)\n", index, divisor );
863     CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
864   }
865
866   /**
867    * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
868    */
869   void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
870   {
871     LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
872     CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
873   }
874
875   /**
876    * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
877    */
878   void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
879   {
880     LOG_GL("InvalidateFramebuffer\n");
881     CHECK_GL( mGlAbstraction, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
882   }
883
884   /**
885    * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
886    * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
887    */
888
889   /**
890    * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
891    * @param[in] enable True if GL_BLEND should be enabled.
892    */
893   void SetBlend(bool enable)
894   {
895     // Avoid unecessary calls to glEnable/glDisable
896     if (enable != mBlendEnabled)
897     {
898       mBlendEnabled = enable;
899
900       if (enable)
901       {
902         LOG_GL("Enable GL_BLEND\n");
903         CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_BLEND) );
904       }
905       else
906       {
907         LOG_GL("Disable GL_BLEND\n");
908         CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_BLEND) );
909       }
910     }
911   }
912
913   /**
914    * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
915    * Note GL_DEPTH_TEST means enable the depth buffer for writing and or testing.
916    * glDepthMask is used to enable / disable writing to depth buffer.
917    * glDepthFunc us used to control if testing is enabled and how it is performed ( default GL_LESS)
918    *
919    * @param[in] enable True if GL_DEPTH_TEST should be enabled.
920    */
921   void EnableDepthBuffer( bool enable )
922   {
923     // Avoid unecessary calls to glEnable/glDisable
924     if( enable != mDepthBufferEnabled )
925     {
926       mDepthBufferEnabled = enable;
927
928       if (enable)
929       {
930         LOG_GL("Enable GL_DEPTH_TEST\n");
931         CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DEPTH_TEST) );
932       }
933       else
934       {
935         LOG_GL("Disable GL_DEPTH_TEST\n");
936         CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DEPTH_TEST) );
937       }
938     }
939   }
940
941   /**
942    * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
943    * @param[in] enable True if GL_DITHER should be enabled.
944    */
945   void SetDither(bool enable)
946   {
947     // Avoid unecessary calls to glEnable/glDisable
948     if (enable != mDitherEnabled)
949     {
950       mDitherEnabled = enable;
951
952       if (enable)
953       {
954         LOG_GL("Enable GL_DITHER\n");
955         CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DITHER) );
956       }
957       else
958       {
959         LOG_GL("Disable GL_DITHER\n");
960         CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DITHER) );
961       }
962     }
963   }
964
965   /**
966    * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
967    * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
968    */
969   void SetPolygonOffsetFill(bool enable)
970   {
971     // Avoid unecessary calls to glEnable/glDisable
972     if (enable != mPolygonOffsetFillEnabled)
973     {
974       mPolygonOffsetFillEnabled = enable;
975
976       if (enable)
977       {
978         LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
979         CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
980       }
981       else
982       {
983         LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
984         CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
985       }
986     }
987   }
988
989   /**
990    * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
991    * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
992    */
993   void SetSampleAlphaToCoverage(bool enable)
994   {
995     // Avoid unecessary calls to glEnable/glDisable
996     if (enable != mSampleAlphaToCoverageEnabled)
997     {
998       mSampleAlphaToCoverageEnabled = enable;
999
1000       if (enable)
1001       {
1002         LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1003         CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1004       }
1005       else
1006       {
1007         LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1008         CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1009       }
1010     }
1011   }
1012
1013   /**
1014    * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
1015    * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
1016    */
1017   void SetSampleCoverage(bool enable)
1018   {
1019     // Avoid unecessary calls to glEnable/glDisable
1020     if (enable != mSampleCoverageEnabled)
1021     {
1022       mSampleCoverageEnabled = enable;
1023
1024       if (enable)
1025       {
1026         LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
1027         CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
1028       }
1029       else
1030       {
1031         LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
1032         CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
1033       }
1034     }
1035   }
1036
1037   /**
1038    * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
1039    * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
1040    */
1041   void SetScissorTest(bool enable)
1042   {
1043     // Avoid unecessary calls to glEnable/glDisable
1044     if (enable != mScissorTestEnabled)
1045     {
1046       mScissorTestEnabled = enable;
1047
1048       if (enable)
1049       {
1050         LOG_GL("Enable GL_SCISSOR_TEST\n");
1051         CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1052       }
1053       else
1054       {
1055         LOG_GL("Disable GL_SCISSOR_TEST\n");
1056         CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1057       }
1058     }
1059   }
1060
1061   /**
1062    * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1063    * Note GL_STENCIL_TEST means enable the stencil buffer for writing and or testing.
1064    * glStencilMask is used to control how bits are written to the stencil buffer.
1065    * glStencilFunc is used to control if testing is enabled and how it is performed ( default GL_ALWAYS )
1066    * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1067    */
1068   void EnableStencilBuffer(bool enable)
1069   {
1070     // Avoid unecessary calls to glEnable/glDisable
1071     if( enable != mStencilBufferEnabled )
1072     {
1073       mStencilBufferEnabled = enable;
1074
1075       if (enable)
1076       {
1077         LOG_GL("Enable GL_STENCIL_TEST\n");
1078         CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1079       }
1080       else
1081       {
1082         LOG_GL("Disable GL_STENCIL_TEST\n");
1083         CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1084       }
1085     }
1086   }
1087
1088   /**
1089    * Wrapper for OpenGL ES 3.0 glEndQuery()
1090    */
1091   void EndQuery(GLenum target)
1092   {
1093     LOG_GL("EndQuery %d\n", target);
1094     CHECK_GL( mGlAbstraction, mGlAbstraction.EndQuery(target) );
1095   }
1096
1097   /**
1098    * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1099    */
1100   void EndTransformFeedback()
1101   {
1102     LOG_GL("EndTransformFeedback\n");
1103     CHECK_GL( mGlAbstraction, mGlAbstraction.EndTransformFeedback() );
1104   }
1105
1106   /**
1107    * Wrapper for OpenGL ES 2.0 glFinish()
1108    */
1109   void Finish(void)
1110   {
1111     LOG_GL("Finish\n");
1112     CHECK_GL( mGlAbstraction, mGlAbstraction.Finish() );
1113   }
1114
1115   /**
1116    * Wrapper for OpenGL ES 2.0 glFlush()
1117    */
1118   void Flush(void)
1119   {
1120     LOG_GL("Flush\n");
1121     CHECK_GL( mGlAbstraction, mGlAbstraction.Flush() );
1122   }
1123
1124   /**
1125    * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1126    */
1127   void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1128   {
1129     LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1130     CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1131   }
1132
1133   /**
1134    * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1135    */
1136   void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1137   {
1138     LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1139     CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1140   }
1141
1142   /**
1143    * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1144    */
1145   void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1146   {
1147     LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1148     CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1149   }
1150
1151   /**
1152    * Wrapper for OpenGL ES 2.0 glFrontFace()
1153    */
1154   void FrontFace(GLenum mode)
1155   {
1156     LOG_GL("FrontFace %x\n", mode);
1157     CHECK_GL( mGlAbstraction, mGlAbstraction.FrontFace(mode) );
1158   }
1159
1160   /**
1161    * Wrapper for OpenGL ES 2.0 glGenBuffers()
1162    */
1163   void GenBuffers(GLsizei n, GLuint* buffers)
1164   {
1165     LOG_GL("GenBuffers %d\n", n, buffers);
1166     CHECK_GL( mGlAbstraction, mGlAbstraction.GenBuffers(n, buffers) );
1167   }
1168
1169   /**
1170    * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1171    */
1172   void GenerateMipmap(GLenum target)
1173   {
1174     LOG_GL("GenerateMipmap %x\n", target);
1175     CHECK_GL( mGlAbstraction, mGlAbstraction.GenerateMipmap(target) );
1176   }
1177
1178   /**
1179    * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1180    */
1181   void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1182   {
1183     LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1184     CHECK_GL( mGlAbstraction, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1185
1186     mFrameBufferStateCache.FrameBuffersCreated( n, framebuffers );
1187   }
1188
1189   /**
1190    * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1191    */
1192   void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1193   {
1194     LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1195     CHECK_GL( mGlAbstraction, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1196   }
1197
1198   /**
1199    * Wrapper for OpenGL ES 2.0 glGenTextures()
1200    */
1201   void GenTextures(GLsizei n, GLuint* textures)
1202   {
1203     LOG_GL("GenTextures %d %p\n", n, textures);
1204     CHECK_GL( mGlAbstraction, mGlAbstraction.GenTextures(n, textures) );
1205   }
1206
1207   /**
1208    * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1209    */
1210   void GetBooleanv(GLenum pname, GLboolean* params)
1211   {
1212     LOG_GL("GetBooleanv %x\n", pname);
1213     CHECK_GL( mGlAbstraction, mGlAbstraction.GetBooleanv(pname, params) );
1214   }
1215
1216   /**
1217    * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1218    */
1219   void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1220   {
1221     LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1222     CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1223   }
1224
1225   /**
1226    * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1227    */
1228   void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1229   {
1230     LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1231     CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1232   }
1233
1234   /**
1235    * Wrapper for OpenGL ES 2.0 glGetError()
1236    */
1237   GLenum GetError(void)
1238   {
1239     // Not worth logging here
1240     return mGlAbstraction.GetError();
1241   }
1242
1243   /**
1244    * Wrapper for OpenGL ES 2.0 glGetFloatv()
1245    */
1246   void GetFloatv(GLenum pname, GLfloat* params)
1247   {
1248     LOG_GL("GetFloatv %x\n", pname);
1249     CHECK_GL( mGlAbstraction, mGlAbstraction.GetFloatv(pname, params) );
1250   }
1251
1252   /**
1253    * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1254    */
1255   void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1256   {
1257     LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1258     CHECK_GL( mGlAbstraction, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1259   }
1260
1261   /**
1262    * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1263    */
1264   void GetIntegerv(GLenum pname, GLint* params)
1265   {
1266     LOG_GL("GetIntegerv %x\n", pname);
1267     CHECK_GL( mGlAbstraction, mGlAbstraction.GetIntegerv(pname, params) );
1268   }
1269
1270   /**
1271    * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1272    */
1273   void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1274   {
1275     LOG_GL("GetQueryiv %x %x\n", target, pname);
1276     CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryiv(target, pname, params) );
1277   }
1278
1279   /**
1280    * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1281    */
1282   void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1283   {
1284     LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1285     CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1286   }
1287
1288   /**
1289    * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1290    */
1291   void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1292   {
1293     LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1294     CHECK_GL( mGlAbstraction, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1295   }
1296
1297   /**
1298    * Wrapper for OpenGL ES 2.0 glGetString()
1299    */
1300   const GLubyte* GetString(GLenum name)
1301   {
1302     LOG_GL("GetString %x\n", name);
1303     const GLubyte* str = CHECK_GL( mGlAbstraction, mGlAbstraction.GetString(name) );
1304     return str;
1305   }
1306
1307   /**
1308    * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1309    */
1310   void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1311   {
1312     LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1313     CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1314   }
1315
1316   /**
1317    * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1318    */
1319   void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1320   {
1321     LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1322     CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1323   }
1324
1325   /**
1326    * Wrapper for OpenGL ES 2.0 glHint()
1327    */
1328   void Hint(GLenum target, GLenum mode)
1329   {
1330     LOG_GL("Hint %x %x\n", target, mode);
1331     CHECK_GL( mGlAbstraction, mGlAbstraction.Hint(target, mode) );
1332   }
1333
1334   /**
1335    * Wrapper for OpenGL ES 2.0 glIsBuffer()
1336    */
1337   GLboolean IsBuffer(GLuint buffer)
1338   {
1339     LOG_GL("IsBuffer %d\n", buffer);
1340     GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsBuffer(buffer) );
1341     return val;
1342   }
1343
1344   /**
1345    * Wrapper for OpenGL ES 2.0 glIsEnabled()
1346    */
1347   GLboolean IsEnabled(GLenum cap)
1348   {
1349     LOG_GL("IsEnabled %x\n", cap);
1350     GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsEnabled(cap) );
1351     return val;
1352   }
1353
1354   /**
1355    * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1356    */
1357   GLboolean IsFramebuffer(GLuint framebuffer)
1358   {
1359     LOG_GL("IsFramebuffer %d\n", framebuffer);
1360     GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsFramebuffer(framebuffer) );
1361     return val;
1362   }
1363
1364   /**
1365    * Wrapper for OpenGL ES 3.0 glIsQuery()
1366    */
1367   GLboolean IsQuery(GLuint id)
1368   {
1369     LOG_GL("IsQuery %u\n", id);
1370     GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsQuery(id) );
1371     return val;
1372   }
1373
1374   /**
1375    * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1376    */
1377   GLboolean IsRenderbuffer(GLuint renderbuffer)
1378   {
1379     LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1380     GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1381     return val;
1382   }
1383
1384   /**
1385    * Wrapper for OpenGL ES 2.0 glIsTexture()
1386    */
1387   GLboolean IsTexture(GLuint texture)
1388   {
1389     LOG_GL("IsTexture %d\n", texture);
1390     GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTexture(texture) );
1391     return val;
1392   }
1393
1394   /**
1395    * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1396    */
1397   GLboolean IsTransformFeedback(GLuint id)
1398   {
1399     LOG_GL("IsTransformFeedback %u\n", id);
1400     GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTransformFeedback(id) );
1401     return val;
1402   }
1403
1404   /**
1405    * Wrapper for OpenGL ES 2.0 glLineWidth()
1406    */
1407   void LineWidth(GLfloat width)
1408   {
1409     LOG_GL("LineWidth %f\n", width);
1410     CHECK_GL( mGlAbstraction, mGlAbstraction.LineWidth(width) );
1411   }
1412
1413   /**
1414    * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1415    */
1416   void PauseTransformFeedback()
1417   {
1418     LOG_GL("PauseTransformFeedback\n");
1419     CHECK_GL( mGlAbstraction, mGlAbstraction.PauseTransformFeedback() );
1420   }
1421
1422   /**
1423    * Wrapper for OpenGL ES 2.0 glPixelStorei()
1424    */
1425   void PixelStorei(GLenum pname, GLint param)
1426   {
1427     LOG_GL("PixelStorei %x %d\n", pname, param);
1428     CHECK_GL( mGlAbstraction, mGlAbstraction.PixelStorei(pname, param) );
1429   }
1430
1431   /**
1432    * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1433    */
1434   void PolygonOffset(GLfloat factor, GLfloat units)
1435   {
1436     LOG_GL("PolygonOffset %f %f\n", factor, units);
1437     CHECK_GL( mGlAbstraction, mGlAbstraction.PolygonOffset(factor, units) );
1438   }
1439
1440   /**
1441    * Wrapper for OpenGL ES 2.0 glReadPixels()
1442    */
1443   void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1444   {
1445     LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1446     CHECK_GL( mGlAbstraction, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1447   }
1448
1449   /**
1450    * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1451    */
1452   void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1453   {
1454     LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1455     CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1456   }
1457
1458   /**
1459    * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1460    */
1461   void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1462   {
1463     LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1464     CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1465   }
1466
1467   /**
1468    * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1469    */
1470   void ResumeTransformFeedback()
1471   {
1472     LOG_GL("ResumeTransformFeedback\n");
1473     CHECK_GL( mGlAbstraction, mGlAbstraction.ResumeTransformFeedback() );
1474   }
1475
1476   /**
1477    * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1478    */
1479   void SampleCoverage(GLclampf value, GLboolean invert)
1480   {
1481     LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1482     CHECK_GL( mGlAbstraction, mGlAbstraction.SampleCoverage(value, invert) );
1483   }
1484
1485   /**
1486    * Wrapper for OpenGL ES 2.0 glScissor()
1487    */
1488   void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1489   {
1490     LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1491     CHECK_GL( mGlAbstraction, mGlAbstraction.Scissor(x, y, width, height) );
1492   }
1493
1494   /**
1495    * Wrapper for OpenGL ES 2.0 glStencilFunc()
1496    */
1497   void StencilFunc(GLenum func, GLint ref, GLuint mask)
1498   {
1499
1500
1501     LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1502     CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) );
1503   }
1504
1505   /**
1506    * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1507    */
1508   void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1509   {
1510     LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1511     CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1512   }
1513
1514   /**
1515    * Wrapper for OpenGL ES 2.0 glStencilMask()
1516    */
1517   void StencilMask(GLuint mask)
1518   {
1519     if( mask != mStencilMask )
1520     {
1521       mStencilMask = mask;
1522
1523       LOG_GL("StencilMask %d\n", mask);
1524       CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMask(mask) );
1525     }
1526   }
1527
1528   /**
1529    * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1530    */
1531   void StencilMaskSeparate(GLenum face, GLuint mask)
1532   {
1533     LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1534     CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMaskSeparate(face, mask) );
1535   }
1536
1537   /**
1538    * Wrapper for OpenGL ES 2.0 glStencilOp()
1539    */
1540   void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1541   {
1542     LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1543     CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1544   }
1545
1546   /**
1547    * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1548    */
1549   void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1550   {
1551     LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1552     CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1553   }
1554
1555   /**
1556    * Wrapper for OpenGL ES 2.0 glTexImage2D()
1557    */
1558   void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1559                   GLint border, GLenum format, GLenum type, const void* pixels)
1560   {
1561     LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1562     CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1563   }
1564
1565   /**
1566    * Wrapper for OpenGL ES 3.0 glTexImage3D()
1567    */
1568   void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1569                   GLint border, GLenum format, GLenum type, const void* pixels)
1570   {
1571     LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1572     CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1573   }
1574
1575   /**
1576    * Wrapper for OpenGL ES 2.0 glTexParameterf()
1577    */
1578   void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1579   {
1580     LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1581     CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterf(target, pname, param) );
1582   }
1583
1584   /**
1585    * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1586    */
1587   void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1588   {
1589     LOG_GL("TexParameterfv %x %x\n", target, pname);
1590     CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterfv(target, pname, params) );
1591   }
1592
1593   /**
1594    * Wrapper for OpenGL ES 2.0 glTexParameteri()
1595    */
1596   void TexParameteri(GLenum target, GLenum pname, GLint param)
1597   {
1598     LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1599     CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteri(target, pname, param) );
1600   }
1601
1602   /**
1603    * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1604    */
1605   void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1606   {
1607     LOG_GL("TexParameteriv %x %x\n", target, pname);
1608     CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteriv(target, pname, params) );
1609   }
1610
1611   /**
1612    * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1613    */
1614   void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1615                      GLenum format, GLenum type, const void* pixels)
1616   {
1617     LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1618     CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1619   }
1620
1621   /**
1622    * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1623    */
1624   void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1625                      GLsizei width, GLsizei height, GLsizei depth,
1626                      GLenum format, GLenum type, const void* pixels)
1627   {
1628     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);
1629     CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1630   }
1631
1632   /**
1633    * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1634    */
1635   GLboolean UnmapBuffer(GLenum target)
1636   {
1637     LOG_GL("UnmapBuffer %x \n", target);
1638     GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.UnmapBuffer(target) );
1639     return val;
1640   }
1641   /**
1642    * Wrapper for OpenGL ES 2.0 glViewport()
1643    */
1644   void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1645   {
1646     // check if its same as already set
1647     Rect<int> newViewport( x, y, width, height );
1648     if( mViewPort != newViewport )
1649     {
1650       // set new one
1651       LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1652       CHECK_GL( mGlAbstraction, mGlAbstraction.Viewport(x, y, width, height) );
1653       mViewPort = newViewport; // remember new one
1654     }
1655   }
1656
1657   /**
1658    * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1659    * @return The implementation defined MAX_TEXTURE_SIZE
1660    */
1661   GLint CachedMaxTextureSize() const
1662   {
1663     return mMaxTextureSize;
1664   }
1665
1666   /**
1667    * Get the current viewport.
1668    * @return Viewport rectangle.
1669    */
1670   const Rect< int >& GetViewport();
1671
1672 private: // Implementation
1673
1674   /**
1675    * @return true if next draw operation will write to depth buffer
1676    */
1677   bool DepthBufferWriteEnabled() const
1678   {
1679     return mDepthBufferEnabled && mDepthMaskEnabled;
1680   }
1681
1682   /**
1683    * @return true if next draw operation will write to stencil buffer
1684    */
1685   bool StencilBufferWriteEnabled() const
1686   {
1687     return mStencilBufferEnabled && ( mStencilMask > 0 );
1688   }
1689
1690   /**
1691    * Flushes vertex attribute location changes to the driver
1692    */
1693   void FlushVertexAttributeLocations();
1694
1695   /**
1696    * Either enables or disables a vertex attribute location in the cache
1697    * The cahnges won't take affect until FlushVertexAttributeLocations is called
1698    * @param location attribute location
1699    * @param state attribute state
1700    */
1701   void SetVertexAttributeLocation(unsigned int location, bool state);
1702
1703   /**
1704    * Sets the initial GL state.
1705    */
1706   void InitializeGlState();
1707
1708 private: // Data
1709
1710   Integration::GlAbstraction& mGlAbstraction;
1711
1712   bool mGlContextCreated; ///< True if the OpenGL context has been created
1713
1714   // glEnable/glDisable states
1715   bool mColorMask;
1716   GLuint mStencilMask;
1717   bool mBlendEnabled;
1718   bool mDepthBufferEnabled;
1719   bool mDepthMaskEnabled;
1720   bool mDitherEnabled;
1721   bool mPolygonOffsetFillEnabled;
1722   bool mSampleAlphaToCoverageEnabled;
1723   bool mSampleCoverageEnabled;
1724   bool mScissorTestEnabled;
1725   bool mStencilBufferEnabled;
1726   bool mClearColorSet;
1727   bool mUsingDefaultBlendColor;
1728
1729   // glBindBuffer() state
1730   GLuint mBoundArrayBufferId;        ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1731   GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1732   GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1733
1734   // glBindTexture() state
1735   TextureUnit mActiveTextureUnit;
1736   GLuint mBound2dTextureId[ MAX_TEXTURE_UNITS ];  ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
1737
1738   // glBlendColor() state
1739   Vector4 mBlendColor; ///< Blend color
1740
1741   // glBlendFuncSeparate() state
1742   GLenum mBlendFuncSeparateSrcRGB;   ///< The srcRGB parameter passed to glBlendFuncSeparate()
1743   GLenum mBlendFuncSeparateDstRGB;   ///< The dstRGB parameter passed to glBlendFuncSeparate()
1744   GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1745   GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1746
1747   // glBlendEquationSeparate state
1748   GLenum mBlendEquationSeparateModeRGB;    ///< Controls RGB blend mode
1749   GLenum mBlendEquationSeparateModeAlpha;  ///< Controls Alpha blend mode
1750
1751   GLenum mDepthFunction;  ///The depth function
1752
1753   GLint mMaxTextureSize;      ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1754   Vector4 mClearColor;        ///< clear color
1755
1756   // Face culling mode
1757   Dali::FaceCullingMode::Type mCullFaceMode;
1758
1759   // cached viewport size
1760   Rect< int > mViewPort;
1761
1762   // Vertex Attribute Buffer enable caching
1763   bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ];    ///< Value cache for Enable Vertex Attribute
1764   bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ];   ///< Current state on the driver for Enable Vertex Attribute
1765
1766   FrameBufferStateCache mFrameBufferStateCache;   ///< frame buffer state cache
1767 };
1768
1769 } // namespace Internal
1770
1771 } // namespace Dali
1772
1773 #endif // __DALI_INTERNAL_CONTEXT_H__