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