1 #ifndef __DALI_INTERNAL_CONTEXT_H__
2 #define __DALI_INTERNAL_CONTEXT_H__
5 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/math/vector4.h>
26 #include <dali/public-api/rendering/renderer.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/integration-api/gl-abstraction.h>
29 #include <dali/integration-api/gl-defines.h>
30 #include <dali/internal/render/common/performance-monitor.h>
31 #include <dali/internal/render/gl-resources/texture-units.h>
32 #include <dali/internal/render/gl-resources/frame-buffer-state-cache.h>
33 #include <dali/internal/render/gl-resources/gl-call-debug.h>
42 * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
43 * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
50 * FrameBuffer Clear mode
54 FORCE_CLEAR, ///< always perform the glClear regardless of current state
55 CHECK_CACHED_VALUES ///< check the Frame buffers cached state to see if a clear is required
59 * Size of the VertexAttributeArray enables
60 * GLES specification states that there's minimum of 8
62 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
64 static const unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 8 is guaranteed, which is more than DALi uses anyways
67 * Creates the Dali Context object.
68 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
69 * @pre Context has not been created.
70 * @exception Context already created.
71 * @param glAbstraction the gl abstraction.
73 Context( Integration::GlAbstraction& glAbstraction );
81 * Called when the GL context has been created.
83 void GlContextCreated();
86 * Called when the GL context has been destroyed.
88 void GlContextDestroyed();
91 * Query whether the OpenGL context has been created.
92 * @return True if the OpenGL context has been created.
94 bool IsGlContextCreated() { return mGlContextCreated; }
97 * @return the GLAbstraction
99 Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
104 * Debug helper which prints the currently cached GL state.
106 void PrintCurrentState();
111 * Helper to convert GL error code to string
112 * @param errorCode to convert
115 const char* ErrorToString( GLenum errorCode );
118 * Helper to print GL string to debug log
120 void PrintGlString(const char* stringName, GLenum stringId)
122 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, reinterpret_cast< const char * >( GetString( stringId ) ) );
125 /****************************************************************************************
126 * The following methods are forwarded to Dali::Integration::GlAbstraction.
127 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
128 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
129 * handles them and optimizes any program related state changes
130 ****************************************************************************************/
133 * Wrapper for OpenGL ES 2.0 glActiveTexture()
135 void ActiveTexture( TextureUnit textureUnit )
137 if ( textureUnit != mActiveTextureUnit )
139 mActiveTextureUnit = textureUnit;
140 LOG_GL("ActiveTexture %x\n", textureUnit);
141 CHECK_GL( mGlAbstraction, mGlAbstraction.ActiveTexture(TextureUnitAsGLenum(textureUnit)) );
146 * Wrapper for OpenGL ES 3.0 glBeginQuery()
148 void BeginQuery(GLenum target, GLuint id)
150 LOG_GL("BeginQuery %d %d\n", target, id);
151 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginQuery(target, id) );
155 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
157 void BeginTransformFeedback(GLenum primitiveMode)
159 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
160 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
164 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
168 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
170 void BindArrayBuffer(GLuint buffer)
172 // Avoid unecessary calls to BindBuffer
173 if (mBoundArrayBufferId != buffer)
175 mBoundArrayBufferId = buffer;
177 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
178 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
183 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
185 void BindElementArrayBuffer(GLuint buffer)
187 // Avoid unecessary calls to BindBuffer
188 if (mBoundElementArrayBufferId!= buffer)
190 mBoundElementArrayBufferId = buffer;
192 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
193 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
198 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
200 void BindTransformFeedbackBuffer(GLuint buffer)
202 // Avoid unecessary calls to BindBuffer
203 if (mBoundTransformFeedbackBufferId != buffer)
205 mBoundTransformFeedbackBufferId = buffer;
207 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
208 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
213 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
215 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
217 // Avoid unecessary calls to BindBufferBase
218 if (mBoundTransformFeedbackBufferId != buffer)
220 mBoundTransformFeedbackBufferId = buffer;
222 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
223 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
228 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
230 void BindFramebuffer(GLenum target, GLuint framebuffer)
232 mFrameBufferStateCache.SetCurrentFrameBuffer( framebuffer );
234 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
235 CHECK_GL( mGlAbstraction, mGlAbstraction.BindFramebuffer(target, framebuffer) );
239 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
241 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
243 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
244 CHECK_GL( mGlAbstraction, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
248 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
250 void BindTransformFeedback(GLenum target, GLuint id)
252 LOG_GL("BindTransformFeedback %d %d\n", target, id);
253 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTransformFeedback(target, id) );
257 * Helper to bind texture for rendering. If given texture is
258 * already bound in the given textureunit, this method does nothing.
259 * Otherwise changes the active texture unit and binds the texture.
260 * Note! after this call active texture unit may not necessarily be the one
261 * passed in as argument so you cannot change texture unit state!!
262 * @param textureunit to bind to
263 * @param texture to bind
265 void BindTextureForUnit( TextureUnit textureunit, int target, GLuint texture )
267 if( mBoundTextureId[ textureunit ] != texture )
269 ActiveTexture( textureunit );
270 BindTexture( target, texture );
275 * Wrapper for OpenGL ES 2.0 glBindTexture( target )
277 void BindTexture( int target, GLuint texture )
279 if (mBoundTextureId[ mActiveTextureUnit ] != texture)
281 mBoundTextureId[ mActiveTextureUnit ] = texture;
283 LOG_GL("BindTexture target(%d) %d\n", target, texture);
284 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(target, texture) );
289 * Wrapper for OpenGL ES 2.0 glBlendColor()
291 void SetDefaultBlendColor()
293 if( ! mUsingDefaultBlendColor )
295 SetCustomBlendColor( Color::TRANSPARENT );
296 mUsingDefaultBlendColor = true;
301 * Wrapper for OpenGL ES 2.0 glBlendColor()
303 void SetCustomBlendColor( const Vector4& color )
305 if( mUsingDefaultBlendColor || mBlendColor != color )
307 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
308 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor( color.r, color.g, color.b, color.a ) );
309 mUsingDefaultBlendColor = false;
315 * Wrapper for OpenGL ES 2.0 glBlendEquation()
317 void BlendEquation(GLenum mode)
319 // use BlendEquationSeparate to set the rgb and alpha modes the same
320 BlendEquationSeparate( mode, mode );
324 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
326 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
328 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
329 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
331 mBlendEquationSeparateModeRGB = modeRGB;
332 mBlendEquationSeparateModeAlpha = modeAlpha;
333 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
334 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
339 * Wrapper for OpenGL ES 2.0 glBlendFunc()
341 void BlendFunc(GLenum sfactor, GLenum dfactor)
343 // reuse the BlendFuncSeparate as thats what the DDK does anyways
344 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
348 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
350 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
352 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
353 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
355 mBlendFuncSeparateSrcRGB = srcRGB;
356 mBlendFuncSeparateDstRGB = dstRGB;
357 mBlendFuncSeparateSrcAlpha = srcAlpha;
358 mBlendFuncSeparateDstAlpha = dstAlpha;
360 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
361 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
366 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
368 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
370 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
371 CHECK_GL( mGlAbstraction, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
375 * Wrapper for OpenGL ES 2.0 glBufferData()
377 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
379 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
380 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferData(target, size, data, usage) );
384 * Wrapper for OpenGL ES 2.0 glBufferSubData()
386 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
388 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
389 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferSubData(target, offset, size, data) );
393 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
395 GLenum CheckFramebufferStatus(GLenum target)
397 LOG_GL("CheckFramebufferStatus %d\n", target);
398 GLenum value = CHECK_GL( mGlAbstraction, mGlAbstraction.CheckFramebufferStatus(target) );
403 * Wrapper for OpenGL ES 2.0 glClear()
405 void Clear(GLbitfield mask, ClearMode mode )
407 bool forceClear = (mode == FORCE_CLEAR );
408 mask = mFrameBufferStateCache.GetClearMask( mask, forceClear , mScissorTestEnabled );
412 LOG_GL("Clear %d\n", mask);
413 CHECK_GL( mGlAbstraction, mGlAbstraction.Clear( mask ) );
418 * Wrapper for OpenGL ES 2.0 glClearColor()
420 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
422 Vector4 newCol(red,green,blue,alpha);
424 if (!mClearColorSet || mClearColor !=newCol )
426 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
427 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearColor(red, green, blue, alpha) );
429 mClearColorSet = true;
430 mClearColor = newCol;
435 * Wrapper for OpenGL ES 2.0 glClearDepthf()
437 void ClearDepthf(GLclampf depth)
439 LOG_GL("ClearDepthf %f\n", depth);
440 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearDepthf(depth) );
444 * Wrapper for OpenGL ES 2.0 glClearStencil()
446 void ClearStencil(GLint s)
448 LOG_GL("ClearStencil %d\n", s);
449 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearStencil(s) );
453 * Wrapper for OpenGL ES 2.0 glColorMask()
454 * @note This has been optimized to a single boolean value (masking individual channels is not required)
456 void ColorMask( bool flag )
458 // only change state if needed
459 if( flag != mColorMask )
462 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
463 CHECK_GL( mGlAbstraction, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
468 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
470 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
471 GLint border, GLsizei imageSize, const void* data)
473 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
474 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
478 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
480 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
481 GLint border, GLsizei imageSize, const void* data)
483 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
484 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
488 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
490 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
491 GLenum format, GLsizei imageSize, const void* data)
493 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
494 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
498 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
500 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
501 GLsizei width, GLsizei height, GLsizei depth,
502 GLenum format, GLsizei imageSize, const void* data)
504 LOG_GL("CompressedTexSubImage3D %x %d %d %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, xoffset, width, height, depth, format, imageSize, data);
505 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
509 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
511 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
513 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
514 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
518 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
520 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
522 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
523 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
527 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
529 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
531 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
532 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
536 * Wrapper for OpenGL ES 2.0 glCullFace()
537 * enables GL_CULL_FACE if in any of the face culling modes
538 * otherwise disables GL_CULL_FACE
540 void CullFace( Dali::FaceCullingMode::Type mode )
542 // Avoid unnecessary calls to gl
543 if(mCullFaceMode != mode)
545 mCullFaceMode = mode;
548 case Dali::FaceCullingMode::NONE:
550 LOG_GL("Disable GL_CULL_FACE\n");
551 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE) );
555 case Dali::FaceCullingMode::FRONT:
557 LOG_GL("Enable GL_CULL_FACE\n");
558 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
559 LOG_GL("Enable GL_FRONT\n");
560 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT) );
564 case Dali::FaceCullingMode::BACK:
566 LOG_GL("Enable GL_CULL_FACE\n");
567 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
568 LOG_GL("Enable GL_BACK\n");
569 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_BACK) );
573 case Dali::FaceCullingMode::FRONT_AND_BACK:
575 LOG_GL("Enable GL_CULL_FACE\n");
576 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
577 LOG_GL("Enable GL_FRONT_AND_BACK\n");
578 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
589 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
591 void DeleteBuffers(GLsizei n, const GLuint* buffers)
593 // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
594 // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
595 if( this->IsGlContextCreated() )
597 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
598 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
600 // reset the cached buffer id's
601 // fixes problem where some drivers will a generate a buffer with the
602 // same id, as the last deleted buffer id.
603 mBoundArrayBufferId = 0;
604 mBoundElementArrayBufferId = 0;
605 mBoundTransformFeedbackBufferId = 0;
609 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
611 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
613 mFrameBufferStateCache.FrameBuffersDeleted( n, framebuffers );
615 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
616 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
620 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
622 void DeleteQueries(GLsizei n, GLuint* ids)
624 LOG_GL("DeleteQueries %d %p\n", n, ids);
625 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteQueries(n, ids) );
629 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
631 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
633 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
634 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
638 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
640 void DeleteTextures(GLsizei n, const GLuint* textures)
642 LOG_GL("DeleteTextures %d %p\n", n, textures);
643 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
645 // reset the cached texture id's incase the driver re-uses them
646 // when creating new textures
647 for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
649 mBoundTextureId[ i ] = 0;
654 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
656 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
658 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
659 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
663 * Wrapper for OpenGL ES 2.0 glDepthFunc()
665 void DepthFunc(GLenum func)
667 if( func != mDepthFunction )
669 mDepthFunction = func;
670 LOG_GL("DepthFunc %x\n", func);
671 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthFunc(func) );
676 * Wrapper for OpenGL ES 2.0 glDepthMask()
678 void DepthMask(GLboolean flag)
680 bool booleanFlag = flag != GL_FALSE;
681 // only change state if needed
682 if( booleanFlag != mDepthMaskEnabled )
684 mDepthMaskEnabled = booleanFlag;
685 LOG_GL("DepthMask %s\n", booleanFlag ? "True" : "False");
686 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
691 * Wrapper for OpenGL ES 2.0 glDepthRangef()
693 void DepthRangef(GLclampf zNear, GLclampf zFar)
695 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
696 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthRangef(zNear, zFar) );
700 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
701 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
705 * Wrapper for OpenGL ES 2.0 glDrawArrays()
707 void DrawArrays(GLenum mode, GLint first, GLsizei count)
709 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
710 FlushVertexAttributeLocations();
712 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
713 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArrays(mode, first, count) );
717 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
719 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
721 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
722 FlushVertexAttributeLocations();
724 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
725 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
729 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
731 void DrawBuffers(GLsizei n, const GLenum* bufs)
733 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
734 LOG_GL("DrawBuffers %d %p\n", n, bufs);
735 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawBuffers(n, bufs) );
739 * Wrapper for OpenGL ES 2.0 glDrawElements()
741 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
743 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
745 FlushVertexAttributeLocations();
747 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
748 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElements(mode, count, type, indices) );
752 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
754 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
756 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
758 FlushVertexAttributeLocations();
760 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
761 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
765 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
767 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
769 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
770 FlushVertexAttributeLocations();
772 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
773 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
777 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
779 void GenQueries(GLsizei n, GLuint* ids)
781 LOG_GL("GenQueries %d %p\n", n, ids);
782 CHECK_GL( mGlAbstraction, mGlAbstraction.GenQueries(n, ids) );
786 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
788 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
790 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
791 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTransformFeedbacks(n, ids) );
795 * @return the current buffer bound for a given target
797 GLuint GetCurrentBoundArrayBuffer(GLenum target)
802 case GL_ARRAY_BUFFER:
804 result = mBoundArrayBufferId;
807 case GL_ELEMENT_ARRAY_BUFFER:
809 result = mBoundElementArrayBufferId;
812 case GL_TRANSFORM_FEEDBACK_BUFFER:
814 result = mBoundTransformFeedbackBufferId;
819 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
825 void EnableVertexAttributeArray( GLuint location )
827 SetVertexAttributeLocation( location, true);
830 void DisableVertexAttributeArray( GLuint location )
832 SetVertexAttributeLocation( location, false);
836 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
838 void VertexAttribDivisor ( GLuint index, GLuint divisor )
840 LOG_GL("VertexAttribDivisor(%d, %d)\n", index, divisor );
841 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
845 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
847 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
849 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
850 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
854 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
856 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
858 LOG_GL("InvalidateFramebuffer\n");
859 CHECK_GL( mGlAbstraction, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
863 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
864 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
868 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
869 * @param[in] enable True if GL_BLEND should be enabled.
871 void SetBlend(bool enable)
873 // Avoid unecessary calls to glEnable/glDisable
874 if (enable != mBlendEnabled)
876 mBlendEnabled = enable;
880 LOG_GL("Enable GL_BLEND\n");
881 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_BLEND) );
885 LOG_GL("Disable GL_BLEND\n");
886 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_BLEND) );
892 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
893 * Note GL_DEPTH_TEST means enable the depth buffer for writing and or testing.
894 * glDepthMask is used to enable / disable writing to depth buffer.
895 * glDepthFunc us used to control if testing is enabled and how it is performed ( default GL_LESS)
897 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
899 void EnableDepthBuffer( bool enable )
901 // Avoid unecessary calls to glEnable/glDisable
902 if( enable != mDepthBufferEnabled )
904 mDepthBufferEnabled = enable;
908 LOG_GL("Enable GL_DEPTH_TEST\n");
909 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DEPTH_TEST) );
913 LOG_GL("Disable GL_DEPTH_TEST\n");
914 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DEPTH_TEST) );
920 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
921 * @param[in] enable True if GL_DITHER should be enabled.
923 void SetDither(bool enable)
925 // Avoid unecessary calls to glEnable/glDisable
926 if (enable != mDitherEnabled)
928 mDitherEnabled = enable;
932 LOG_GL("Enable GL_DITHER\n");
933 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DITHER) );
937 LOG_GL("Disable GL_DITHER\n");
938 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DITHER) );
944 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
945 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
947 void SetPolygonOffsetFill(bool enable)
949 // Avoid unecessary calls to glEnable/glDisable
950 if (enable != mPolygonOffsetFillEnabled)
952 mPolygonOffsetFillEnabled = enable;
956 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
957 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
961 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
962 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
968 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
969 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
971 void SetSampleAlphaToCoverage(bool enable)
973 // Avoid unecessary calls to glEnable/glDisable
974 if (enable != mSampleAlphaToCoverageEnabled)
976 mSampleAlphaToCoverageEnabled = enable;
980 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
981 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
985 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
986 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
992 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
993 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
995 void SetSampleCoverage(bool enable)
997 // Avoid unecessary calls to glEnable/glDisable
998 if (enable != mSampleCoverageEnabled)
1000 mSampleCoverageEnabled = enable;
1004 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
1005 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
1009 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
1010 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
1016 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
1017 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
1019 void SetScissorTest(bool enable)
1021 // Avoid unecessary calls to glEnable/glDisable
1022 if (enable != mScissorTestEnabled)
1024 mScissorTestEnabled = enable;
1028 LOG_GL("Enable GL_SCISSOR_TEST\n");
1029 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1033 LOG_GL("Disable GL_SCISSOR_TEST\n");
1034 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1040 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1041 * Note GL_STENCIL_TEST means enable the stencil buffer for writing and or testing.
1042 * glStencilMask is used to control how bits are written to the stencil buffer.
1043 * glStencilFunc is used to control if testing is enabled and how it is performed ( default GL_ALWAYS )
1044 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1046 void EnableStencilBuffer(bool enable)
1048 // Avoid unecessary calls to glEnable/glDisable
1049 if( enable != mStencilBufferEnabled )
1051 mStencilBufferEnabled = enable;
1055 LOG_GL("Enable GL_STENCIL_TEST\n");
1056 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1060 LOG_GL("Disable GL_STENCIL_TEST\n");
1061 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1067 * Wrapper for OpenGL ES 3.0 glEndQuery()
1069 void EndQuery(GLenum target)
1071 LOG_GL("EndQuery %d\n", target);
1072 CHECK_GL( mGlAbstraction, mGlAbstraction.EndQuery(target) );
1076 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1078 void EndTransformFeedback()
1080 LOG_GL("EndTransformFeedback\n");
1081 CHECK_GL( mGlAbstraction, mGlAbstraction.EndTransformFeedback() );
1085 * Wrapper for OpenGL ES 2.0 glFinish()
1090 CHECK_GL( mGlAbstraction, mGlAbstraction.Finish() );
1094 * Wrapper for OpenGL ES 2.0 glFlush()
1099 CHECK_GL( mGlAbstraction, mGlAbstraction.Flush() );
1103 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1105 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1107 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1108 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1112 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1114 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1116 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1117 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1121 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1123 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1125 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1126 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1130 * Wrapper for OpenGL ES 2.0 glFrontFace()
1132 void FrontFace(GLenum mode)
1134 LOG_GL("FrontFace %x\n", mode);
1135 CHECK_GL( mGlAbstraction, mGlAbstraction.FrontFace(mode) );
1139 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1141 void GenBuffers(GLsizei n, GLuint* buffers)
1143 LOG_GL("GenBuffers %d\n", n, buffers);
1144 CHECK_GL( mGlAbstraction, mGlAbstraction.GenBuffers(n, buffers) );
1148 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1150 void GenerateMipmap(GLenum target)
1152 LOG_GL("GenerateMipmap %x\n", target);
1153 CHECK_GL( mGlAbstraction, mGlAbstraction.GenerateMipmap(target) );
1157 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1159 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1161 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1162 CHECK_GL( mGlAbstraction, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1164 mFrameBufferStateCache.FrameBuffersCreated( n, framebuffers );
1168 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1170 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1172 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1173 CHECK_GL( mGlAbstraction, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1177 * Wrapper for OpenGL ES 2.0 glGenTextures()
1179 void GenTextures(GLsizei n, GLuint* textures)
1181 LOG_GL("GenTextures %d %p\n", n, textures);
1182 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTextures(n, textures) );
1186 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1188 void GetBooleanv(GLenum pname, GLboolean* params)
1190 LOG_GL("GetBooleanv %x\n", pname);
1191 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBooleanv(pname, params) );
1195 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1197 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1199 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1200 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1204 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1206 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1208 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1209 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1213 * Wrapper for OpenGL ES 2.0 glGetError()
1215 GLenum GetError(void)
1217 // Not worth logging here
1218 return mGlAbstraction.GetError();
1222 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1224 void GetFloatv(GLenum pname, GLfloat* params)
1226 LOG_GL("GetFloatv %x\n", pname);
1227 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFloatv(pname, params) );
1231 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1233 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1235 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1236 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1240 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1242 void GetIntegerv(GLenum pname, GLint* params)
1244 LOG_GL("GetIntegerv %x\n", pname);
1245 CHECK_GL( mGlAbstraction, mGlAbstraction.GetIntegerv(pname, params) );
1249 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1251 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1253 LOG_GL("GetQueryiv %x %x\n", target, pname);
1254 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryiv(target, pname, params) );
1258 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1260 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1262 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1263 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1267 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1269 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1271 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1272 CHECK_GL( mGlAbstraction, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1276 * Wrapper for OpenGL ES 2.0 glGetString()
1278 const GLubyte* GetString(GLenum name)
1280 LOG_GL("GetString %x\n", name);
1281 const GLubyte* str = CHECK_GL( mGlAbstraction, mGlAbstraction.GetString(name) );
1286 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1288 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1290 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1291 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1295 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1297 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1299 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1300 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1304 * Wrapper for OpenGL ES 2.0 glHint()
1306 void Hint(GLenum target, GLenum mode)
1308 LOG_GL("Hint %x %x\n", target, mode);
1309 CHECK_GL( mGlAbstraction, mGlAbstraction.Hint(target, mode) );
1313 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1315 GLboolean IsBuffer(GLuint buffer)
1317 LOG_GL("IsBuffer %d\n", buffer);
1318 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsBuffer(buffer) );
1323 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1325 GLboolean IsEnabled(GLenum cap)
1327 LOG_GL("IsEnabled %x\n", cap);
1328 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsEnabled(cap) );
1333 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1335 GLboolean IsFramebuffer(GLuint framebuffer)
1337 LOG_GL("IsFramebuffer %d\n", framebuffer);
1338 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsFramebuffer(framebuffer) );
1343 * Wrapper for OpenGL ES 3.0 glIsQuery()
1345 GLboolean IsQuery(GLuint id)
1347 LOG_GL("IsQuery %u\n", id);
1348 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsQuery(id) );
1353 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1355 GLboolean IsRenderbuffer(GLuint renderbuffer)
1357 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1358 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1363 * Wrapper for OpenGL ES 2.0 glIsTexture()
1365 GLboolean IsTexture(GLuint texture)
1367 LOG_GL("IsTexture %d\n", texture);
1368 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTexture(texture) );
1373 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1375 GLboolean IsTransformFeedback(GLuint id)
1377 LOG_GL("IsTransformFeedback %u\n", id);
1378 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTransformFeedback(id) );
1383 * Wrapper for OpenGL ES 2.0 glLineWidth()
1385 void LineWidth(GLfloat width)
1387 LOG_GL("LineWidth %f\n", width);
1388 CHECK_GL( mGlAbstraction, mGlAbstraction.LineWidth(width) );
1392 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1394 void PauseTransformFeedback()
1396 LOG_GL("PauseTransformFeedback\n");
1397 CHECK_GL( mGlAbstraction, mGlAbstraction.PauseTransformFeedback() );
1401 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1403 void PixelStorei(GLenum pname, GLint param)
1405 LOG_GL("PixelStorei %x %d\n", pname, param);
1406 CHECK_GL( mGlAbstraction, mGlAbstraction.PixelStorei(pname, param) );
1410 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1412 void PolygonOffset(GLfloat factor, GLfloat units)
1414 LOG_GL("PolygonOffset %f %f\n", factor, units);
1415 CHECK_GL( mGlAbstraction, mGlAbstraction.PolygonOffset(factor, units) );
1419 * Wrapper for OpenGL ES 2.0 glReadPixels()
1421 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1423 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1424 CHECK_GL( mGlAbstraction, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1428 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1430 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1432 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1433 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1437 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1439 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1441 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1442 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1446 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1448 void ResumeTransformFeedback()
1450 LOG_GL("ResumeTransformFeedback\n");
1451 CHECK_GL( mGlAbstraction, mGlAbstraction.ResumeTransformFeedback() );
1455 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1457 void SampleCoverage(GLclampf value, GLboolean invert)
1459 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1460 CHECK_GL( mGlAbstraction, mGlAbstraction.SampleCoverage(value, invert) );
1464 * Wrapper for OpenGL ES 2.0 glScissor()
1466 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1468 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1469 CHECK_GL( mGlAbstraction, mGlAbstraction.Scissor(x, y, width, height) );
1473 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1475 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1477 if( ( func != mStencilFunc ) || ( ref != mStencilFuncRef ) || ( mask != mStencilFuncMask ) )
1479 mStencilFunc = func;
1480 mStencilFuncRef = ref;
1481 mStencilFuncMask = mask;
1483 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1484 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) );
1489 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1491 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1493 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1494 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1498 * Wrapper for OpenGL ES 2.0 glStencilMask()
1500 void StencilMask(GLuint mask)
1502 if( mask != mStencilMask )
1504 mStencilMask = mask;
1506 LOG_GL("StencilMask %d\n", mask);
1507 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMask(mask) );
1512 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1514 void StencilMaskSeparate(GLenum face, GLuint mask)
1516 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1517 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMaskSeparate(face, mask) );
1521 * Wrapper for OpenGL ES 2.0 glStencilOp()
1523 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1525 if( ( fail != mStencilOpFail ) || ( zfail != mStencilOpDepthFail ) || ( zpass != mStencilOpDepthPass ) )
1527 mStencilOpFail = fail;
1528 mStencilOpDepthFail = zfail;
1529 mStencilOpDepthPass = zpass;
1531 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1532 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1537 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1539 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1541 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1542 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1546 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1548 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1549 GLint border, GLenum format, GLenum type, const void* pixels)
1551 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1552 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1556 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1558 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1559 GLint border, GLenum format, GLenum type, const void* pixels)
1561 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1562 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1566 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1568 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1570 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1571 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterf(target, pname, param) );
1575 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1577 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1579 LOG_GL("TexParameterfv %x %x\n", target, pname);
1580 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterfv(target, pname, params) );
1584 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1586 void TexParameteri(GLenum target, GLenum pname, GLint param)
1588 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1589 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteri(target, pname, param) );
1593 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1595 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1597 LOG_GL("TexParameteriv %x %x\n", target, pname);
1598 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteriv(target, pname, params) );
1602 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1604 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1605 GLenum format, GLenum type, const void* pixels)
1607 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1608 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1612 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1614 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1615 GLsizei width, GLsizei height, GLsizei depth,
1616 GLenum format, GLenum type, const void* pixels)
1618 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);
1619 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1623 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1625 GLboolean UnmapBuffer(GLenum target)
1627 LOG_GL("UnmapBuffer %x \n", target);
1628 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.UnmapBuffer(target) );
1632 * Wrapper for OpenGL ES 2.0 glViewport()
1634 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1636 // check if its same as already set
1637 Rect<int> newViewport( x, y, width, height );
1639 // Temporarily disable the viewport caching, as the implementation of GLES driver in Tizen platform
1640 // share a global viewport between multiple contexts, therefore glViewport has to be called every
1641 // time after glBindFramebuffer regardless of the same vewport size in the same context.
1642 // if( mViewPort != newViewport )
1645 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1646 CHECK_GL( mGlAbstraction, mGlAbstraction.Viewport(x, y, width, height) );
1647 mViewPort = newViewport; // remember new one
1652 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1653 * @return The implementation defined MAX_TEXTURE_SIZE
1655 GLint CachedMaxTextureSize() const
1657 return mMaxTextureSize;
1661 * Get the current viewport.
1662 * @return Viewport rectangle.
1664 const Rect< int >& GetViewport();
1666 private: // Implementation
1669 * @return true if next draw operation will write to depth buffer
1671 bool DepthBufferWriteEnabled() const
1673 return mDepthBufferEnabled && mDepthMaskEnabled;
1677 * @return true if next draw operation will write to stencil buffer
1679 bool StencilBufferWriteEnabled() const
1681 return mStencilBufferEnabled && ( mStencilMask > 0 );
1685 * Flushes vertex attribute location changes to the driver
1687 void FlushVertexAttributeLocations();
1690 * Either enables or disables a vertex attribute location in the cache
1691 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1692 * @param location attribute location
1693 * @param state attribute state
1695 void SetVertexAttributeLocation(unsigned int location, bool state);
1698 * Sets the initial GL state.
1700 void InitializeGlState();
1704 Integration::GlAbstraction& mGlAbstraction;
1706 bool mGlContextCreated; ///< True if the OpenGL context has been created
1708 // glEnable/glDisable states
1710 GLuint mStencilMask;
1712 bool mDepthBufferEnabled;
1713 bool mDepthMaskEnabled;
1714 bool mDitherEnabled;
1715 bool mPolygonOffsetFillEnabled;
1716 bool mSampleAlphaToCoverageEnabled;
1717 bool mSampleCoverageEnabled;
1718 bool mScissorTestEnabled;
1719 bool mStencilBufferEnabled;
1720 bool mClearColorSet;
1721 bool mUsingDefaultBlendColor;
1723 // glBindBuffer() state
1724 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1725 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1726 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1728 // glBindTexture() state
1729 TextureUnit mActiveTextureUnit;
1730 GLuint mBoundTextureId[ MAX_TEXTURE_UNITS ]; ///< The ID passed to glBindTexture()
1732 // glBlendColor() state
1733 Vector4 mBlendColor; ///< Blend color
1735 // glBlendFuncSeparate() state
1736 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1737 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1738 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1739 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1741 // glBlendEquationSeparate state
1742 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1743 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1745 // glStencilFunc() and glStencilOp() state.
1746 GLenum mStencilFunc;
1747 GLint mStencilFuncRef;
1748 GLuint mStencilFuncMask;
1749 GLenum mStencilOpFail;
1750 GLenum mStencilOpDepthFail;
1751 GLenum mStencilOpDepthPass;
1753 GLenum mDepthFunction; ///The depth function
1755 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1756 Vector4 mClearColor; ///< clear color
1758 // Face culling mode
1759 Dali::FaceCullingMode::Type mCullFaceMode;
1761 // cached viewport size
1762 Rect< int > mViewPort;
1764 // Vertex Attribute Buffer enable caching
1765 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1766 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1768 FrameBufferStateCache mFrameBufferStateCache; ///< frame buffer state cache
1771 } // namespace Internal
1775 #endif // __DALI_INTERNAL_CONTEXT_H__