1 #ifndef DALI_INTERNAL_CONTEXT_H
2 #define DALI_INTERNAL_CONTEXT_H
5 * Copyright (c) 2019 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 IsSurfacelessContextSupported of Dali::Integration::GlAbstraction
135 bool IsSurfacelessContextSupported() const
137 return mGlAbstraction.IsSurfacelessContextSupported();
141 * Wrapper for TextureRequiresConverting of Dali::Integration::GlAbstraction
143 bool TextureRequiresConverting( const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage ) const
145 return mGlAbstraction.TextureRequiresConverting( imageGlFormat, textureGlFormat, isSubImage );
149 * Wrapper for OpenGL ES 2.0 glActiveTexture()
151 void ActiveTexture( TextureUnit textureUnit )
153 if ( textureUnit != mActiveTextureUnit )
155 mActiveTextureUnit = textureUnit;
156 LOG_GL("ActiveTexture %x\n", textureUnit);
157 CHECK_GL( mGlAbstraction, mGlAbstraction.ActiveTexture(TextureUnitAsGLenum(textureUnit)) );
162 * Wrapper for OpenGL ES 3.0 glBeginQuery()
164 void BeginQuery(GLenum target, GLuint id)
166 LOG_GL("BeginQuery %d %d\n", target, id);
167 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginQuery(target, id) );
171 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
173 void BeginTransformFeedback(GLenum primitiveMode)
175 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
176 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
180 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
184 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
186 void BindArrayBuffer(GLuint buffer)
188 // Avoid unecessary calls to BindBuffer
189 if (mBoundArrayBufferId != buffer)
191 mBoundArrayBufferId = buffer;
193 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
194 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
199 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
201 void BindElementArrayBuffer(GLuint buffer)
203 // Avoid unecessary calls to BindBuffer
204 if (mBoundElementArrayBufferId!= buffer)
206 mBoundElementArrayBufferId = buffer;
208 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
209 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
214 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
216 void BindTransformFeedbackBuffer(GLuint buffer)
218 // Avoid unecessary calls to BindBuffer
219 if (mBoundTransformFeedbackBufferId != buffer)
221 mBoundTransformFeedbackBufferId = buffer;
223 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
224 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
229 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
231 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
233 // Avoid unecessary calls to BindBufferBase
234 if (mBoundTransformFeedbackBufferId != buffer)
236 mBoundTransformFeedbackBufferId = buffer;
238 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
239 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
244 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
246 void BindFramebuffer(GLenum target, GLuint framebuffer)
248 mFrameBufferStateCache.SetCurrentFrameBuffer( framebuffer );
250 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
251 CHECK_GL( mGlAbstraction, mGlAbstraction.BindFramebuffer(target, framebuffer) );
255 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
257 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
259 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
260 CHECK_GL( mGlAbstraction, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
264 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
266 void BindTransformFeedback(GLenum target, GLuint id)
268 LOG_GL("BindTransformFeedback %d %d\n", target, id);
269 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTransformFeedback(target, id) );
273 * Helper to bind texture for rendering. If given texture is
274 * already bound in the given textureunit, this method does nothing.
275 * Otherwise changes the active texture unit and binds the texture.
276 * Note! after this call active texture unit may not necessarily be the one
277 * passed in as argument so you cannot change texture unit state!!
278 * @param textureunit to bind to
279 * @param texture to bind
281 void BindTextureForUnit( TextureUnit textureunit, int target, GLuint texture )
283 if( mBoundTextureId[ textureunit ] != texture )
285 ActiveTexture( textureunit );
286 BindTexture( target, texture );
291 * Wrapper for OpenGL ES 2.0 glBindTexture( target )
293 void BindTexture( int target, GLuint texture )
295 if (mBoundTextureId[ mActiveTextureUnit ] != texture)
297 mBoundTextureId[ mActiveTextureUnit ] = texture;
299 LOG_GL("BindTexture target(%d) %d\n", target, texture);
300 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(target, texture) );
305 * Wrapper for OpenGL ES 2.0 glBlendColor()
307 void SetDefaultBlendColor()
309 if( ! mUsingDefaultBlendColor )
311 SetCustomBlendColor( Color::TRANSPARENT );
312 mUsingDefaultBlendColor = true;
317 * Wrapper for OpenGL ES 2.0 glBlendColor()
319 void SetCustomBlendColor( const Vector4& color )
321 if( mUsingDefaultBlendColor || mBlendColor != color )
323 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
324 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor( color.r, color.g, color.b, color.a ) );
325 mUsingDefaultBlendColor = false;
331 * Wrapper for OpenGL ES 2.0 glBlendEquation()
333 void BlendEquation(GLenum mode)
335 // use BlendEquationSeparate to set the rgb and alpha modes the same
336 BlendEquationSeparate( mode, mode );
340 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
342 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
344 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
345 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
347 mBlendEquationSeparateModeRGB = modeRGB;
348 mBlendEquationSeparateModeAlpha = modeAlpha;
349 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
350 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
355 * Wrapper for OpenGL ES 2.0 glBlendFunc()
357 void BlendFunc(GLenum sfactor, GLenum dfactor)
359 // reuse the BlendFuncSeparate as thats what the DDK does anyways
360 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
364 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
366 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
368 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
369 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
371 mBlendFuncSeparateSrcRGB = srcRGB;
372 mBlendFuncSeparateDstRGB = dstRGB;
373 mBlendFuncSeparateSrcAlpha = srcAlpha;
374 mBlendFuncSeparateDstAlpha = dstAlpha;
376 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
377 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
382 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
384 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
386 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
387 CHECK_GL( mGlAbstraction, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
391 * Wrapper for OpenGL ES 2.0 glBufferData()
393 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
395 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
396 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferData(target, size, data, usage) );
400 * Wrapper for OpenGL ES 2.0 glBufferSubData()
402 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
404 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
405 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferSubData(target, offset, size, data) );
409 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
411 GLenum CheckFramebufferStatus(GLenum target)
413 LOG_GL("CheckFramebufferStatus %d\n", target);
414 GLenum value = CHECK_GL( mGlAbstraction, mGlAbstraction.CheckFramebufferStatus(target) );
419 * Wrapper for OpenGL ES 2.0 glClear()
421 void Clear(GLbitfield mask, ClearMode mode )
423 bool forceClear = (mode == FORCE_CLEAR );
424 mask = mFrameBufferStateCache.GetClearMask( mask, forceClear , mScissorTestEnabled );
428 LOG_GL("Clear %d\n", mask);
429 CHECK_GL( mGlAbstraction, mGlAbstraction.Clear( mask ) );
434 * Wrapper for OpenGL ES 2.0 glClearColor()
436 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
438 Vector4 newCol(red,green,blue,alpha);
440 if (!mClearColorSet || mClearColor !=newCol )
442 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
443 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearColor(red, green, blue, alpha) );
445 mClearColorSet = true;
446 mClearColor = newCol;
451 * Wrapper for OpenGL ES 2.0 glClearDepthf()
453 void ClearDepthf(GLclampf depth)
455 LOG_GL("ClearDepthf %f\n", depth);
456 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearDepthf(depth) );
460 * Wrapper for OpenGL ES 2.0 glClearStencil()
462 void ClearStencil(GLint s)
464 LOG_GL("ClearStencil %d\n", s);
465 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearStencil(s) );
469 * Wrapper for OpenGL ES 2.0 glColorMask()
470 * @note This has been optimized to a single boolean value (masking individual channels is not required)
472 void ColorMask( bool flag )
474 // only change state if needed
475 if( flag != mColorMask )
478 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
479 CHECK_GL( mGlAbstraction, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
484 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
486 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
487 GLint border, GLsizei imageSize, const void* data)
489 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
490 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
494 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
496 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
497 GLint border, GLsizei imageSize, const void* data)
499 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
500 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
504 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
506 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
507 GLenum format, GLsizei imageSize, const void* data)
509 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
510 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
514 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
516 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
517 GLsizei width, GLsizei height, GLsizei depth,
518 GLenum format, GLsizei imageSize, const void* data)
520 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);
521 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
525 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
527 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
529 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
530 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
534 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
536 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
538 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
539 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
543 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
545 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
547 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
548 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
552 * Wrapper for OpenGL ES 2.0 glCullFace()
553 * enables GL_CULL_FACE if in any of the face culling modes
554 * otherwise disables GL_CULL_FACE
556 void CullFace( Dali::FaceCullingMode::Type mode )
558 // Avoid unnecessary calls to gl
559 if(mCullFaceMode != mode)
561 mCullFaceMode = mode;
564 case Dali::FaceCullingMode::NONE:
566 LOG_GL("Disable GL_CULL_FACE\n");
567 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE) );
571 case Dali::FaceCullingMode::FRONT:
573 LOG_GL("Enable GL_CULL_FACE\n");
574 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
575 LOG_GL("Enable GL_FRONT\n");
576 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT) );
580 case Dali::FaceCullingMode::BACK:
582 LOG_GL("Enable GL_CULL_FACE\n");
583 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
584 LOG_GL("Enable GL_BACK\n");
585 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_BACK) );
589 case Dali::FaceCullingMode::FRONT_AND_BACK:
591 LOG_GL("Enable GL_CULL_FACE\n");
592 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
593 LOG_GL("Enable GL_FRONT_AND_BACK\n");
594 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
605 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
607 void DeleteBuffers(GLsizei n, const GLuint* buffers)
609 // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
610 // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
611 if( this->IsGlContextCreated() )
613 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
614 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
616 // reset the cached buffer id's
617 // fixes problem where some drivers will a generate a buffer with the
618 // same id, as the last deleted buffer id.
619 mBoundArrayBufferId = 0;
620 mBoundElementArrayBufferId = 0;
621 mBoundTransformFeedbackBufferId = 0;
625 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
627 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
629 mFrameBufferStateCache.FrameBuffersDeleted( n, framebuffers );
631 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
632 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
636 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
638 void DeleteQueries(GLsizei n, GLuint* ids)
640 LOG_GL("DeleteQueries %d %p\n", n, ids);
641 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteQueries(n, ids) );
645 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
647 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
649 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
650 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
654 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
656 void DeleteTextures(GLsizei n, const GLuint* textures)
658 LOG_GL("DeleteTextures %d %p\n", n, textures);
659 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
661 // reset the cached texture id's incase the driver re-uses them
662 // when creating new textures
663 for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
665 mBoundTextureId[ i ] = 0;
670 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
672 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
674 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
675 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
679 * Wrapper for OpenGL ES 2.0 glDepthFunc()
681 void DepthFunc(GLenum func)
683 if( func != mDepthFunction )
685 mDepthFunction = func;
686 LOG_GL("DepthFunc %x\n", func);
687 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthFunc(func) );
692 * Wrapper for OpenGL ES 2.0 glDepthMask()
694 void DepthMask(GLboolean flag)
696 bool booleanFlag = flag != GL_FALSE;
697 // only change state if needed
698 if( booleanFlag != mDepthMaskEnabled )
700 mDepthMaskEnabled = booleanFlag;
701 LOG_GL("DepthMask %s\n", booleanFlag ? "True" : "False");
702 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
707 * Wrapper for OpenGL ES 2.0 glDepthRangef()
709 void DepthRangef(GLclampf zNear, GLclampf zFar)
711 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
712 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthRangef(zNear, zFar) );
716 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
717 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
721 * Wrapper for OpenGL ES 2.0 glDrawArrays()
723 void DrawArrays(GLenum mode, GLint first, GLsizei count)
725 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
726 FlushVertexAttributeLocations();
728 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
729 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArrays(mode, first, count) );
733 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
735 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
737 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
738 FlushVertexAttributeLocations();
740 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
741 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
745 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
747 void DrawBuffers(GLsizei n, const GLenum* bufs)
749 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
750 LOG_GL("DrawBuffers %d %p\n", n, bufs);
751 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawBuffers(n, bufs) );
755 * Wrapper for OpenGL ES 2.0 glDrawElements()
757 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
759 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
761 FlushVertexAttributeLocations();
763 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
764 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElements(mode, count, type, indices) );
768 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
770 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
772 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
774 FlushVertexAttributeLocations();
776 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
777 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
781 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
783 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
785 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
786 FlushVertexAttributeLocations();
788 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
789 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
793 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
795 void GenQueries(GLsizei n, GLuint* ids)
797 LOG_GL("GenQueries %d %p\n", n, ids);
798 CHECK_GL( mGlAbstraction, mGlAbstraction.GenQueries(n, ids) );
802 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
804 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
806 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
807 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTransformFeedbacks(n, ids) );
811 * @return the current buffer bound for a given target
813 GLuint GetCurrentBoundArrayBuffer(GLenum target)
818 case GL_ARRAY_BUFFER:
820 result = mBoundArrayBufferId;
823 case GL_ELEMENT_ARRAY_BUFFER:
825 result = mBoundElementArrayBufferId;
828 case GL_TRANSFORM_FEEDBACK_BUFFER:
830 result = mBoundTransformFeedbackBufferId;
835 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
841 void EnableVertexAttributeArray( GLuint location )
843 SetVertexAttributeLocation( location, true);
846 void DisableVertexAttributeArray( GLuint location )
848 SetVertexAttributeLocation( location, false);
852 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
854 void VertexAttribDivisor ( GLuint index, GLuint divisor )
856 LOG_GL("VertexAttribDivisor(%d, %d)\n", index, divisor );
857 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
861 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
863 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
865 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
866 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
870 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
872 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
874 LOG_GL("InvalidateFramebuffer\n");
875 CHECK_GL( mGlAbstraction, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
879 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
880 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
884 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
885 * @param[in] enable True if GL_BLEND should be enabled.
887 void SetBlend(bool enable)
889 // Avoid unecessary calls to glEnable/glDisable
890 if (enable != mBlendEnabled)
892 mBlendEnabled = enable;
896 LOG_GL("Enable GL_BLEND\n");
897 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_BLEND) );
901 LOG_GL("Disable GL_BLEND\n");
902 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_BLEND) );
908 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
909 * Note GL_DEPTH_TEST means enable the depth buffer for writing and or testing.
910 * glDepthMask is used to enable / disable writing to depth buffer.
911 * glDepthFunc us used to control if testing is enabled and how it is performed ( default GL_LESS)
913 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
915 void EnableDepthBuffer( bool enable )
917 // Avoid unecessary calls to glEnable/glDisable
918 if( enable != mDepthBufferEnabled )
920 mDepthBufferEnabled = enable;
924 LOG_GL("Enable GL_DEPTH_TEST\n");
925 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DEPTH_TEST) );
929 LOG_GL("Disable GL_DEPTH_TEST\n");
930 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DEPTH_TEST) );
936 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
937 * @param[in] enable True if GL_DITHER should be enabled.
939 void SetDither(bool enable)
941 // Avoid unecessary calls to glEnable/glDisable
942 if (enable != mDitherEnabled)
944 mDitherEnabled = enable;
948 LOG_GL("Enable GL_DITHER\n");
949 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DITHER) );
953 LOG_GL("Disable GL_DITHER\n");
954 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DITHER) );
960 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
961 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
963 void SetPolygonOffsetFill(bool enable)
965 // Avoid unecessary calls to glEnable/glDisable
966 if (enable != mPolygonOffsetFillEnabled)
968 mPolygonOffsetFillEnabled = enable;
972 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
973 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
977 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
978 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
984 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
985 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
987 void SetSampleAlphaToCoverage(bool enable)
989 // Avoid unecessary calls to glEnable/glDisable
990 if (enable != mSampleAlphaToCoverageEnabled)
992 mSampleAlphaToCoverageEnabled = enable;
996 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
997 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1001 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1002 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1008 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
1009 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
1011 void SetSampleCoverage(bool enable)
1013 // Avoid unecessary calls to glEnable/glDisable
1014 if (enable != mSampleCoverageEnabled)
1016 mSampleCoverageEnabled = enable;
1020 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
1021 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
1025 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
1026 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
1032 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
1033 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
1035 void SetScissorTest(bool enable)
1037 // Avoid unecessary calls to glEnable/glDisable
1038 if (enable != mScissorTestEnabled)
1040 mScissorTestEnabled = enable;
1044 LOG_GL("Enable GL_SCISSOR_TEST\n");
1045 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1049 LOG_GL("Disable GL_SCISSOR_TEST\n");
1050 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1056 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1057 * Note GL_STENCIL_TEST means enable the stencil buffer for writing and or testing.
1058 * glStencilMask is used to control how bits are written to the stencil buffer.
1059 * glStencilFunc is used to control if testing is enabled and how it is performed ( default GL_ALWAYS )
1060 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1062 void EnableStencilBuffer(bool enable)
1064 // Avoid unecessary calls to glEnable/glDisable
1065 if( enable != mStencilBufferEnabled )
1067 mStencilBufferEnabled = enable;
1071 LOG_GL("Enable GL_STENCIL_TEST\n");
1072 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1076 LOG_GL("Disable GL_STENCIL_TEST\n");
1077 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1083 * Wrapper for OpenGL ES 3.0 glEndQuery()
1085 void EndQuery(GLenum target)
1087 LOG_GL("EndQuery %d\n", target);
1088 CHECK_GL( mGlAbstraction, mGlAbstraction.EndQuery(target) );
1092 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1094 void EndTransformFeedback()
1096 LOG_GL("EndTransformFeedback\n");
1097 CHECK_GL( mGlAbstraction, mGlAbstraction.EndTransformFeedback() );
1101 * Wrapper for OpenGL ES 2.0 glFinish()
1106 CHECK_GL( mGlAbstraction, mGlAbstraction.Finish() );
1110 * Wrapper for OpenGL ES 2.0 glFlush()
1115 CHECK_GL( mGlAbstraction, mGlAbstraction.Flush() );
1119 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1121 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1123 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1124 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1128 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1130 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1132 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1133 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1137 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1139 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1141 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1142 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1146 * Wrapper for OpenGL ES 2.0 glFrontFace()
1148 void FrontFace(GLenum mode)
1150 LOG_GL("FrontFace %x\n", mode);
1151 CHECK_GL( mGlAbstraction, mGlAbstraction.FrontFace(mode) );
1155 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1157 void GenBuffers(GLsizei n, GLuint* buffers)
1159 LOG_GL("GenBuffers %d\n", n, buffers);
1160 CHECK_GL( mGlAbstraction, mGlAbstraction.GenBuffers(n, buffers) );
1164 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1166 void GenerateMipmap(GLenum target)
1168 LOG_GL("GenerateMipmap %x\n", target);
1169 CHECK_GL( mGlAbstraction, mGlAbstraction.GenerateMipmap(target) );
1173 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1175 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1177 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1178 CHECK_GL( mGlAbstraction, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1180 mFrameBufferStateCache.FrameBuffersCreated( n, framebuffers );
1184 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1186 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1188 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1189 CHECK_GL( mGlAbstraction, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1193 * Wrapper for OpenGL ES 2.0 glGenTextures()
1195 void GenTextures(GLsizei n, GLuint* textures)
1197 LOG_GL("GenTextures %d %p\n", n, textures);
1198 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTextures(n, textures) );
1202 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1204 void GetBooleanv(GLenum pname, GLboolean* params)
1206 LOG_GL("GetBooleanv %x\n", pname);
1207 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBooleanv(pname, params) );
1211 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1213 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1215 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1216 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1220 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1222 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1224 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1225 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1229 * Wrapper for OpenGL ES 2.0 glGetError()
1231 GLenum GetError(void)
1233 // Not worth logging here
1234 return mGlAbstraction.GetError();
1238 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1240 void GetFloatv(GLenum pname, GLfloat* params)
1242 LOG_GL("GetFloatv %x\n", pname);
1243 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFloatv(pname, params) );
1247 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1249 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1251 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1252 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1256 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1258 void GetIntegerv(GLenum pname, GLint* params)
1260 LOG_GL("GetIntegerv %x\n", pname);
1261 CHECK_GL( mGlAbstraction, mGlAbstraction.GetIntegerv(pname, params) );
1265 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1267 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1269 LOG_GL("GetQueryiv %x %x\n", target, pname);
1270 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryiv(target, pname, params) );
1274 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1276 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1278 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1279 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1283 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1285 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1287 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1288 CHECK_GL( mGlAbstraction, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1292 * Wrapper for OpenGL ES 2.0 glGetString()
1294 const GLubyte* GetString(GLenum name)
1296 LOG_GL("GetString %x\n", name);
1297 const GLubyte* str = CHECK_GL( mGlAbstraction, mGlAbstraction.GetString(name) );
1302 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1304 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1306 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1307 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1311 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1313 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1315 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1316 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1320 * Wrapper for OpenGL ES 2.0 glHint()
1322 void Hint(GLenum target, GLenum mode)
1324 LOG_GL("Hint %x %x\n", target, mode);
1325 CHECK_GL( mGlAbstraction, mGlAbstraction.Hint(target, mode) );
1329 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1331 GLboolean IsBuffer(GLuint buffer)
1333 LOG_GL("IsBuffer %d\n", buffer);
1334 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsBuffer(buffer) );
1339 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1341 GLboolean IsEnabled(GLenum cap)
1343 LOG_GL("IsEnabled %x\n", cap);
1344 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsEnabled(cap) );
1349 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1351 GLboolean IsFramebuffer(GLuint framebuffer)
1353 LOG_GL("IsFramebuffer %d\n", framebuffer);
1354 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsFramebuffer(framebuffer) );
1359 * Wrapper for OpenGL ES 3.0 glIsQuery()
1361 GLboolean IsQuery(GLuint id)
1363 LOG_GL("IsQuery %u\n", id);
1364 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsQuery(id) );
1369 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1371 GLboolean IsRenderbuffer(GLuint renderbuffer)
1373 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1374 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1379 * Wrapper for OpenGL ES 2.0 glIsTexture()
1381 GLboolean IsTexture(GLuint texture)
1383 LOG_GL("IsTexture %d\n", texture);
1384 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTexture(texture) );
1389 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1391 GLboolean IsTransformFeedback(GLuint id)
1393 LOG_GL("IsTransformFeedback %u\n", id);
1394 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTransformFeedback(id) );
1399 * Wrapper for OpenGL ES 2.0 glLineWidth()
1401 void LineWidth(GLfloat width)
1403 LOG_GL("LineWidth %f\n", width);
1404 CHECK_GL( mGlAbstraction, mGlAbstraction.LineWidth(width) );
1408 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1410 void PauseTransformFeedback()
1412 LOG_GL("PauseTransformFeedback\n");
1413 CHECK_GL( mGlAbstraction, mGlAbstraction.PauseTransformFeedback() );
1417 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1419 void PixelStorei(GLenum pname, GLint param)
1421 LOG_GL("PixelStorei %x %d\n", pname, param);
1422 CHECK_GL( mGlAbstraction, mGlAbstraction.PixelStorei(pname, param) );
1426 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1428 void PolygonOffset(GLfloat factor, GLfloat units)
1430 LOG_GL("PolygonOffset %f %f\n", factor, units);
1431 CHECK_GL( mGlAbstraction, mGlAbstraction.PolygonOffset(factor, units) );
1435 * Wrapper for OpenGL ES 2.0 glReadPixels()
1437 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1439 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1440 CHECK_GL( mGlAbstraction, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1444 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1446 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1448 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1449 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1453 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1455 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1457 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1458 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1462 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1464 void ResumeTransformFeedback()
1466 LOG_GL("ResumeTransformFeedback\n");
1467 CHECK_GL( mGlAbstraction, mGlAbstraction.ResumeTransformFeedback() );
1471 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1473 void SampleCoverage(GLclampf value, GLboolean invert)
1475 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1476 CHECK_GL( mGlAbstraction, mGlAbstraction.SampleCoverage(value, invert) );
1480 * Wrapper for OpenGL ES 2.0 glScissor()
1482 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1484 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1485 CHECK_GL( mGlAbstraction, mGlAbstraction.Scissor(x, y, width, height) );
1489 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1491 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1493 if( ( func != mStencilFunc ) || ( ref != mStencilFuncRef ) || ( mask != mStencilFuncMask ) )
1495 mStencilFunc = func;
1496 mStencilFuncRef = ref;
1497 mStencilFuncMask = mask;
1499 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1500 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) );
1505 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1507 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1509 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1510 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1514 * Wrapper for OpenGL ES 2.0 glStencilMask()
1516 void StencilMask(GLuint mask)
1518 if( mask != mStencilMask )
1520 mStencilMask = mask;
1522 LOG_GL("StencilMask %d\n", mask);
1523 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMask(mask) );
1528 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1530 void StencilMaskSeparate(GLenum face, GLuint mask)
1532 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1533 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMaskSeparate(face, mask) );
1537 * Wrapper for OpenGL ES 2.0 glStencilOp()
1539 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1541 if( ( fail != mStencilOpFail ) || ( zfail != mStencilOpDepthFail ) || ( zpass != mStencilOpDepthPass ) )
1543 mStencilOpFail = fail;
1544 mStencilOpDepthFail = zfail;
1545 mStencilOpDepthPass = zpass;
1547 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1548 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1553 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1555 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1557 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1558 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1562 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1564 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1565 GLint border, GLenum format, GLenum type, const void* pixels)
1567 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1568 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1572 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1574 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1575 GLint border, GLenum format, GLenum type, const void* pixels)
1577 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1578 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1582 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1584 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1586 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1587 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterf(target, pname, param) );
1591 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1593 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1595 LOG_GL("TexParameterfv %x %x\n", target, pname);
1596 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterfv(target, pname, params) );
1600 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1602 void TexParameteri(GLenum target, GLenum pname, GLint param)
1604 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1605 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteri(target, pname, param) );
1609 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1611 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1613 LOG_GL("TexParameteriv %x %x\n", target, pname);
1614 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteriv(target, pname, params) );
1618 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1620 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1621 GLenum format, GLenum type, const void* pixels)
1623 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1624 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1628 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1630 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1631 GLsizei width, GLsizei height, GLsizei depth,
1632 GLenum format, GLenum type, const void* pixels)
1634 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);
1635 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1639 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1641 GLboolean UnmapBuffer(GLenum target)
1643 LOG_GL("UnmapBuffer %x \n", target);
1644 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.UnmapBuffer(target) );
1648 * Wrapper for OpenGL ES 2.0 glViewport()
1650 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1652 // check if its same as already set
1653 Rect<int> newViewport( x, y, width, height );
1655 // Temporarily disable the viewport caching, as the implementation of GLES driver in Tizen platform
1656 // share a global viewport between multiple contexts, therefore glViewport has to be called every
1657 // time after glBindFramebuffer regardless of the same vewport size in the same context.
1658 // if( mViewPort != newViewport )
1661 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1662 CHECK_GL( mGlAbstraction, mGlAbstraction.Viewport(x, y, width, height) );
1663 mViewPort = newViewport; // remember new one
1668 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1669 * @return The implementation defined MAX_TEXTURE_SIZE
1671 GLint CachedMaxTextureSize() const
1673 return mMaxTextureSize;
1677 * Get the current viewport.
1678 * @return Viewport rectangle.
1680 const Rect< int >& GetViewport();
1682 private: // Implementation
1685 * @return true if next draw operation will write to depth buffer
1687 bool DepthBufferWriteEnabled() const
1689 return mDepthBufferEnabled && mDepthMaskEnabled;
1693 * @return true if next draw operation will write to stencil buffer
1695 bool StencilBufferWriteEnabled() const
1697 return mStencilBufferEnabled && ( mStencilMask > 0 );
1701 * Flushes vertex attribute location changes to the driver
1703 void FlushVertexAttributeLocations();
1706 * Either enables or disables a vertex attribute location in the cache
1707 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1708 * @param location attribute location
1709 * @param state attribute state
1711 void SetVertexAttributeLocation(unsigned int location, bool state);
1714 * Sets the initial GL state.
1716 void InitializeGlState();
1720 Integration::GlAbstraction& mGlAbstraction;
1722 bool mGlContextCreated; ///< True if the OpenGL context has been created
1724 // glEnable/glDisable states
1726 GLuint mStencilMask;
1728 bool mDepthBufferEnabled;
1729 bool mDepthMaskEnabled;
1730 bool mDitherEnabled;
1731 bool mPolygonOffsetFillEnabled;
1732 bool mSampleAlphaToCoverageEnabled;
1733 bool mSampleCoverageEnabled;
1734 bool mScissorTestEnabled;
1735 bool mStencilBufferEnabled;
1736 bool mClearColorSet;
1737 bool mUsingDefaultBlendColor;
1739 // glBindBuffer() state
1740 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1741 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1742 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1744 // glBindTexture() state
1745 TextureUnit mActiveTextureUnit;
1746 GLuint mBoundTextureId[ MAX_TEXTURE_UNITS ]; ///< The ID passed to glBindTexture()
1748 // glBlendColor() state
1749 Vector4 mBlendColor; ///< Blend color
1751 // glBlendFuncSeparate() state
1752 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1753 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1754 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1755 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1757 // glBlendEquationSeparate state
1758 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1759 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1761 // glStencilFunc() and glStencilOp() state.
1762 GLenum mStencilFunc;
1763 GLint mStencilFuncRef;
1764 GLuint mStencilFuncMask;
1765 GLenum mStencilOpFail;
1766 GLenum mStencilOpDepthFail;
1767 GLenum mStencilOpDepthPass;
1769 GLenum mDepthFunction; ///The depth function
1771 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1772 Vector4 mClearColor; ///< clear color
1774 // Face culling mode
1775 Dali::FaceCullingMode::Type mCullFaceMode;
1777 // cached viewport size
1778 Rect< int > mViewPort;
1780 // Vertex Attribute Buffer enable caching
1781 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1782 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1784 FrameBufferStateCache mFrameBufferStateCache; ///< frame buffer state cache
1787 } // namespace Internal
1791 #endif // DALI_INTERNAL_CONTEXT_H