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