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