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, GLuint texture )
267 if( mBound2dTextureId[ textureunit ] != texture )
269 ActiveTexture( textureunit );
270 Bind2dTexture( texture );
275 * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D)
277 void Bind2dTexture( GLuint texture )
279 if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
281 mBound2dTextureId[ mActiveTextureUnit ] = texture;
283 LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture);
284 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) );
289 * Wrapper for OpenGL ES 2.0 glBindTexture( target )
291 void BindTexture( int target, GLuint texture )
293 if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
295 mBound2dTextureId[ mActiveTextureUnit ] = texture;
297 LOG_GL("BindTexture target(%d) %d\n", target, texture);
298 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(target, texture) );
303 * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_CUBE_MAP)
305 void BindCubeMapTexture( GLuint texture )
307 LOG_GL("BindTexture GL_TEXTURE_CUBE_MAP %d\n", texture);
308 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(GL_TEXTURE_CUBE_MAP, texture) );
312 * Wrapper for OpenGL ES 2.0 glBlendColor()
314 void SetDefaultBlendColor()
316 if( ! mUsingDefaultBlendColor )
318 SetCustomBlendColor( Color::TRANSPARENT );
319 mUsingDefaultBlendColor = true;
324 * Wrapper for OpenGL ES 2.0 glBlendColor()
326 void SetCustomBlendColor( const Vector4& color )
328 if( mUsingDefaultBlendColor || mBlendColor != color )
330 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
331 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor( color.r, color.g, color.b, color.a ) );
332 mUsingDefaultBlendColor = false;
338 * Wrapper for OpenGL ES 2.0 glBlendEquation()
340 void BlendEquation(GLenum mode)
342 // use BlendEquationSeparate to set the rgb and alpha modes the same
343 BlendEquationSeparate( mode, mode );
347 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
349 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
351 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
352 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
354 mBlendEquationSeparateModeRGB = modeRGB;
355 mBlendEquationSeparateModeAlpha = modeAlpha;
356 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
357 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
362 * Wrapper for OpenGL ES 2.0 glBlendFunc()
364 void BlendFunc(GLenum sfactor, GLenum dfactor)
366 // reuse the BlendFuncSeparate as thats what the DDK does anyways
367 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
371 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
373 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
375 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
376 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
378 mBlendFuncSeparateSrcRGB = srcRGB;
379 mBlendFuncSeparateDstRGB = dstRGB;
380 mBlendFuncSeparateSrcAlpha = srcAlpha;
381 mBlendFuncSeparateDstAlpha = dstAlpha;
383 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
384 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
389 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
391 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
393 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
394 CHECK_GL( mGlAbstraction, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
398 * Wrapper for OpenGL ES 2.0 glBufferData()
400 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
402 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
403 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferData(target, size, data, usage) );
407 * Wrapper for OpenGL ES 2.0 glBufferSubData()
409 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
411 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
412 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferSubData(target, offset, size, data) );
416 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
418 GLenum CheckFramebufferStatus(GLenum target)
420 LOG_GL("CheckFramebufferStatus %d\n", target);
421 GLenum value = CHECK_GL( mGlAbstraction, mGlAbstraction.CheckFramebufferStatus(target) );
426 * Wrapper for OpenGL ES 2.0 glClear()
428 void Clear(GLbitfield mask, ClearMode mode )
430 bool forceClear = (mode == FORCE_CLEAR );
431 mask = mFrameBufferStateCache.GetClearMask( mask, forceClear , mScissorTestEnabled );
435 LOG_GL("Clear %d\n", mask);
436 CHECK_GL( mGlAbstraction, mGlAbstraction.Clear( mask ) );
441 * Wrapper for OpenGL ES 2.0 glClearColor()
443 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
445 Vector4 newCol(red,green,blue,alpha);
447 if (!mClearColorSet || mClearColor !=newCol )
449 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
450 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearColor(red, green, blue, alpha) );
452 mClearColorSet = true;
453 mClearColor = newCol;
458 * Wrapper for OpenGL ES 2.0 glClearDepthf()
460 void ClearDepthf(GLclampf depth)
462 LOG_GL("ClearDepthf %f\n", depth);
463 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearDepthf(depth) );
467 * Wrapper for OpenGL ES 2.0 glClearStencil()
469 void ClearStencil(GLint s)
471 LOG_GL("ClearStencil %d\n", s);
472 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearStencil(s) );
476 * Wrapper for OpenGL ES 2.0 glColorMask()
477 * @note This has been optimized to a single boolean value (masking individual channels is not required)
479 void ColorMask( bool flag )
481 // only change state if needed
482 if( flag != mColorMask )
485 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
486 CHECK_GL( mGlAbstraction, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
491 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
493 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
494 GLint border, GLsizei imageSize, const void* data)
496 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
497 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
501 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
503 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
504 GLint border, GLsizei imageSize, const void* data)
506 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
507 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
511 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
513 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
514 GLenum format, GLsizei imageSize, const void* data)
516 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
517 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
521 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
523 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
524 GLsizei width, GLsizei height, GLsizei depth,
525 GLenum format, GLsizei imageSize, const void* data)
527 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);
528 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
532 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
534 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
536 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
537 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
541 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
543 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
545 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
546 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
550 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
552 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
554 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
555 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
559 * Wrapper for OpenGL ES 2.0 glCullFace()
560 * enables GL_CULL_FACE if in any of the face culling modes
561 * otherwise disables GL_CULL_FACE
563 void CullFace( Dali::FaceCullingMode::Type mode )
565 // Avoid unnecessary calls to gl
566 if(mCullFaceMode != mode)
568 mCullFaceMode = mode;
571 case Dali::FaceCullingMode::NONE:
573 LOG_GL("Disable GL_CULL_FACE\n");
574 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE) );
578 case Dali::FaceCullingMode::FRONT:
580 LOG_GL("Enable GL_CULL_FACE\n");
581 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
582 LOG_GL("Enable GL_FRONT\n");
583 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT) );
587 case Dali::FaceCullingMode::BACK:
589 LOG_GL("Enable GL_CULL_FACE\n");
590 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
591 LOG_GL("Enable GL_BACK\n");
592 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_BACK) );
596 case Dali::FaceCullingMode::FRONT_AND_BACK:
598 LOG_GL("Enable GL_CULL_FACE\n");
599 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
600 LOG_GL("Enable GL_FRONT_AND_BACK\n");
601 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
612 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
614 void DeleteBuffers(GLsizei n, const GLuint* buffers)
616 // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
617 // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
618 if( this->IsGlContextCreated() )
620 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
621 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
623 // reset the cached buffer id's
624 // fixes problem where some drivers will a generate a buffer with the
625 // same id, as the last deleted buffer id.
626 mBoundArrayBufferId = 0;
627 mBoundElementArrayBufferId = 0;
628 mBoundTransformFeedbackBufferId = 0;
632 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
634 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
636 mFrameBufferStateCache.FrameBuffersDeleted( n, framebuffers );
638 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
639 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
643 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
645 void DeleteQueries(GLsizei n, GLuint* ids)
647 LOG_GL("DeleteQueries %d %p\n", n, ids);
648 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteQueries(n, ids) );
652 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
654 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
656 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
657 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
661 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
663 void DeleteTextures(GLsizei n, const GLuint* textures)
665 LOG_GL("DeleteTextures %d %p\n", n, textures);
666 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
668 // reset the cached texture id's incase the driver re-uses them
669 // when creating new textures
670 for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
672 mBound2dTextureId[ i ] = 0;
677 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
679 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
681 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
682 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
686 * Wrapper for OpenGL ES 2.0 glDepthFunc()
688 void DepthFunc(GLenum func)
690 if( func != mDepthFunction )
692 mDepthFunction = func;
693 LOG_GL("DepthFunc %x\n", func);
694 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthFunc(func) );
699 * Wrapper for OpenGL ES 2.0 glDepthMask()
701 void DepthMask(GLboolean flag)
703 bool booleanFlag = flag != GL_FALSE;
704 // only change state if needed
705 if( booleanFlag != mDepthMaskEnabled )
707 mDepthMaskEnabled = booleanFlag;
708 LOG_GL("DepthMask %s\n", booleanFlag ? "True" : "False");
709 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
714 * Wrapper for OpenGL ES 2.0 glDepthRangef()
716 void DepthRangef(GLclampf zNear, GLclampf zFar)
718 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
719 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthRangef(zNear, zFar) );
723 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
724 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
728 * Wrapper for OpenGL ES 2.0 glDrawArrays()
730 void DrawArrays(GLenum mode, GLint first, GLsizei count)
732 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
733 FlushVertexAttributeLocations();
735 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
736 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArrays(mode, first, count) );
740 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
742 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
744 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
745 FlushVertexAttributeLocations();
747 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
748 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
752 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
754 void DrawBuffers(GLsizei n, const GLenum* bufs)
756 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
757 LOG_GL("DrawBuffers %d %p\n", n, bufs);
758 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawBuffers(n, bufs) );
762 * Wrapper for OpenGL ES 2.0 glDrawElements()
764 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
766 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
768 FlushVertexAttributeLocations();
770 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
771 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElements(mode, count, type, indices) );
775 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
777 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
779 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
781 FlushVertexAttributeLocations();
783 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
784 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
788 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
790 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
792 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
793 FlushVertexAttributeLocations();
795 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
796 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
800 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
802 void GenQueries(GLsizei n, GLuint* ids)
804 LOG_GL("GenQueries %d %p\n", n, ids);
805 CHECK_GL( mGlAbstraction, mGlAbstraction.GenQueries(n, ids) );
809 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
811 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
813 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
814 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTransformFeedbacks(n, ids) );
818 * @return the current buffer bound for a given target
820 GLuint GetCurrentBoundArrayBuffer(GLenum target)
825 case GL_ARRAY_BUFFER:
827 result = mBoundArrayBufferId;
830 case GL_ELEMENT_ARRAY_BUFFER:
832 result = mBoundElementArrayBufferId;
835 case GL_TRANSFORM_FEEDBACK_BUFFER:
837 result = mBoundTransformFeedbackBufferId;
842 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
848 void EnableVertexAttributeArray( GLuint location )
850 SetVertexAttributeLocation( location, true);
853 void DisableVertexAttributeArray( GLuint location )
855 SetVertexAttributeLocation( location, false);
859 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
861 void VertexAttribDivisor ( GLuint index, GLuint divisor )
863 LOG_GL("VertexAttribDivisor(%d, %d)\n", index, divisor );
864 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
868 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
870 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
872 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
873 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
877 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
879 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
881 LOG_GL("InvalidateFramebuffer\n");
882 CHECK_GL( mGlAbstraction, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
886 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
887 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
891 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
892 * @param[in] enable True if GL_BLEND should be enabled.
894 void SetBlend(bool enable)
896 // Avoid unecessary calls to glEnable/glDisable
897 if (enable != mBlendEnabled)
899 mBlendEnabled = enable;
903 LOG_GL("Enable GL_BLEND\n");
904 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_BLEND) );
908 LOG_GL("Disable GL_BLEND\n");
909 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_BLEND) );
915 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
916 * Note GL_DEPTH_TEST means enable the depth buffer for writing and or testing.
917 * glDepthMask is used to enable / disable writing to depth buffer.
918 * glDepthFunc us used to control if testing is enabled and how it is performed ( default GL_LESS)
920 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
922 void EnableDepthBuffer( bool enable )
924 // Avoid unecessary calls to glEnable/glDisable
925 if( enable != mDepthBufferEnabled )
927 mDepthBufferEnabled = enable;
931 LOG_GL("Enable GL_DEPTH_TEST\n");
932 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DEPTH_TEST) );
936 LOG_GL("Disable GL_DEPTH_TEST\n");
937 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DEPTH_TEST) );
943 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
944 * @param[in] enable True if GL_DITHER should be enabled.
946 void SetDither(bool enable)
948 // Avoid unecessary calls to glEnable/glDisable
949 if (enable != mDitherEnabled)
951 mDitherEnabled = enable;
955 LOG_GL("Enable GL_DITHER\n");
956 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DITHER) );
960 LOG_GL("Disable GL_DITHER\n");
961 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DITHER) );
967 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
968 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
970 void SetPolygonOffsetFill(bool enable)
972 // Avoid unecessary calls to glEnable/glDisable
973 if (enable != mPolygonOffsetFillEnabled)
975 mPolygonOffsetFillEnabled = enable;
979 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
980 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
984 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
985 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
991 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
992 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
994 void SetSampleAlphaToCoverage(bool enable)
996 // Avoid unecessary calls to glEnable/glDisable
997 if (enable != mSampleAlphaToCoverageEnabled)
999 mSampleAlphaToCoverageEnabled = enable;
1003 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1004 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1008 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1009 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1015 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
1016 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
1018 void SetSampleCoverage(bool enable)
1020 // Avoid unecessary calls to glEnable/glDisable
1021 if (enable != mSampleCoverageEnabled)
1023 mSampleCoverageEnabled = enable;
1027 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
1028 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
1032 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
1033 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
1039 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
1040 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
1042 void SetScissorTest(bool enable)
1044 // Avoid unecessary calls to glEnable/glDisable
1045 if (enable != mScissorTestEnabled)
1047 mScissorTestEnabled = enable;
1051 LOG_GL("Enable GL_SCISSOR_TEST\n");
1052 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1056 LOG_GL("Disable GL_SCISSOR_TEST\n");
1057 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1063 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1064 * Note GL_STENCIL_TEST means enable the stencil buffer for writing and or testing.
1065 * glStencilMask is used to control how bits are written to the stencil buffer.
1066 * glStencilFunc is used to control if testing is enabled and how it is performed ( default GL_ALWAYS )
1067 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1069 void EnableStencilBuffer(bool enable)
1071 // Avoid unecessary calls to glEnable/glDisable
1072 if( enable != mStencilBufferEnabled )
1074 mStencilBufferEnabled = enable;
1078 LOG_GL("Enable GL_STENCIL_TEST\n");
1079 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1083 LOG_GL("Disable GL_STENCIL_TEST\n");
1084 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1090 * Wrapper for OpenGL ES 3.0 glEndQuery()
1092 void EndQuery(GLenum target)
1094 LOG_GL("EndQuery %d\n", target);
1095 CHECK_GL( mGlAbstraction, mGlAbstraction.EndQuery(target) );
1099 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1101 void EndTransformFeedback()
1103 LOG_GL("EndTransformFeedback\n");
1104 CHECK_GL( mGlAbstraction, mGlAbstraction.EndTransformFeedback() );
1108 * Wrapper for OpenGL ES 2.0 glFinish()
1113 CHECK_GL( mGlAbstraction, mGlAbstraction.Finish() );
1117 * Wrapper for OpenGL ES 2.0 glFlush()
1122 CHECK_GL( mGlAbstraction, mGlAbstraction.Flush() );
1126 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1128 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1130 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1131 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1135 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1137 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1139 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1140 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1144 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1146 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1148 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1149 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1153 * Wrapper for OpenGL ES 2.0 glFrontFace()
1155 void FrontFace(GLenum mode)
1157 LOG_GL("FrontFace %x\n", mode);
1158 CHECK_GL( mGlAbstraction, mGlAbstraction.FrontFace(mode) );
1162 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1164 void GenBuffers(GLsizei n, GLuint* buffers)
1166 LOG_GL("GenBuffers %d\n", n, buffers);
1167 CHECK_GL( mGlAbstraction, mGlAbstraction.GenBuffers(n, buffers) );
1171 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1173 void GenerateMipmap(GLenum target)
1175 LOG_GL("GenerateMipmap %x\n", target);
1176 CHECK_GL( mGlAbstraction, mGlAbstraction.GenerateMipmap(target) );
1180 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1182 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1184 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1185 CHECK_GL( mGlAbstraction, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1187 mFrameBufferStateCache.FrameBuffersCreated( n, framebuffers );
1191 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1193 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1195 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1196 CHECK_GL( mGlAbstraction, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1200 * Wrapper for OpenGL ES 2.0 glGenTextures()
1202 void GenTextures(GLsizei n, GLuint* textures)
1204 LOG_GL("GenTextures %d %p\n", n, textures);
1205 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTextures(n, textures) );
1209 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1211 void GetBooleanv(GLenum pname, GLboolean* params)
1213 LOG_GL("GetBooleanv %x\n", pname);
1214 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBooleanv(pname, params) );
1218 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1220 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1222 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1223 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1227 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1229 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1231 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1232 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1236 * Wrapper for OpenGL ES 2.0 glGetError()
1238 GLenum GetError(void)
1240 // Not worth logging here
1241 return mGlAbstraction.GetError();
1245 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1247 void GetFloatv(GLenum pname, GLfloat* params)
1249 LOG_GL("GetFloatv %x\n", pname);
1250 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFloatv(pname, params) );
1254 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1256 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1258 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1259 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1263 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1265 void GetIntegerv(GLenum pname, GLint* params)
1267 LOG_GL("GetIntegerv %x\n", pname);
1268 CHECK_GL( mGlAbstraction, mGlAbstraction.GetIntegerv(pname, params) );
1272 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1274 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1276 LOG_GL("GetQueryiv %x %x\n", target, pname);
1277 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryiv(target, pname, params) );
1281 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1283 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1285 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1286 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1290 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1292 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1294 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1295 CHECK_GL( mGlAbstraction, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1299 * Wrapper for OpenGL ES 2.0 glGetString()
1301 const GLubyte* GetString(GLenum name)
1303 LOG_GL("GetString %x\n", name);
1304 const GLubyte* str = CHECK_GL( mGlAbstraction, mGlAbstraction.GetString(name) );
1309 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1311 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1313 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1314 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1318 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1320 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1322 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1323 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1327 * Wrapper for OpenGL ES 2.0 glHint()
1329 void Hint(GLenum target, GLenum mode)
1331 LOG_GL("Hint %x %x\n", target, mode);
1332 CHECK_GL( mGlAbstraction, mGlAbstraction.Hint(target, mode) );
1336 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1338 GLboolean IsBuffer(GLuint buffer)
1340 LOG_GL("IsBuffer %d\n", buffer);
1341 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsBuffer(buffer) );
1346 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1348 GLboolean IsEnabled(GLenum cap)
1350 LOG_GL("IsEnabled %x\n", cap);
1351 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsEnabled(cap) );
1356 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1358 GLboolean IsFramebuffer(GLuint framebuffer)
1360 LOG_GL("IsFramebuffer %d\n", framebuffer);
1361 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsFramebuffer(framebuffer) );
1366 * Wrapper for OpenGL ES 3.0 glIsQuery()
1368 GLboolean IsQuery(GLuint id)
1370 LOG_GL("IsQuery %u\n", id);
1371 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsQuery(id) );
1376 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1378 GLboolean IsRenderbuffer(GLuint renderbuffer)
1380 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1381 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1386 * Wrapper for OpenGL ES 2.0 glIsTexture()
1388 GLboolean IsTexture(GLuint texture)
1390 LOG_GL("IsTexture %d\n", texture);
1391 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTexture(texture) );
1396 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1398 GLboolean IsTransformFeedback(GLuint id)
1400 LOG_GL("IsTransformFeedback %u\n", id);
1401 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTransformFeedback(id) );
1406 * Wrapper for OpenGL ES 2.0 glLineWidth()
1408 void LineWidth(GLfloat width)
1410 LOG_GL("LineWidth %f\n", width);
1411 CHECK_GL( mGlAbstraction, mGlAbstraction.LineWidth(width) );
1415 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1417 void PauseTransformFeedback()
1419 LOG_GL("PauseTransformFeedback\n");
1420 CHECK_GL( mGlAbstraction, mGlAbstraction.PauseTransformFeedback() );
1424 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1426 void PixelStorei(GLenum pname, GLint param)
1428 LOG_GL("PixelStorei %x %d\n", pname, param);
1429 CHECK_GL( mGlAbstraction, mGlAbstraction.PixelStorei(pname, param) );
1433 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1435 void PolygonOffset(GLfloat factor, GLfloat units)
1437 LOG_GL("PolygonOffset %f %f\n", factor, units);
1438 CHECK_GL( mGlAbstraction, mGlAbstraction.PolygonOffset(factor, units) );
1442 * Wrapper for OpenGL ES 2.0 glReadPixels()
1444 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1446 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1447 CHECK_GL( mGlAbstraction, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1451 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1453 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1455 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1456 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1460 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1462 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1464 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1465 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1469 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1471 void ResumeTransformFeedback()
1473 LOG_GL("ResumeTransformFeedback\n");
1474 CHECK_GL( mGlAbstraction, mGlAbstraction.ResumeTransformFeedback() );
1478 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1480 void SampleCoverage(GLclampf value, GLboolean invert)
1482 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1483 CHECK_GL( mGlAbstraction, mGlAbstraction.SampleCoverage(value, invert) );
1487 * Wrapper for OpenGL ES 2.0 glScissor()
1489 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1491 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1492 CHECK_GL( mGlAbstraction, mGlAbstraction.Scissor(x, y, width, height) );
1496 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1498 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1502 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1503 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) );
1507 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1509 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1511 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1512 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1516 * Wrapper for OpenGL ES 2.0 glStencilMask()
1518 void StencilMask(GLuint mask)
1520 if( mask != mStencilMask )
1522 mStencilMask = mask;
1524 LOG_GL("StencilMask %d\n", mask);
1525 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMask(mask) );
1530 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1532 void StencilMaskSeparate(GLenum face, GLuint mask)
1534 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1535 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMaskSeparate(face, mask) );
1539 * Wrapper for OpenGL ES 2.0 glStencilOp()
1541 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1543 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1544 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1548 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1550 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1552 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1553 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1557 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1559 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1560 GLint border, GLenum format, GLenum type, const void* pixels)
1562 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1563 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1567 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1569 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1570 GLint border, GLenum format, GLenum type, const void* pixels)
1572 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1573 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1577 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1579 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1581 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1582 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterf(target, pname, param) );
1586 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1588 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1590 LOG_GL("TexParameterfv %x %x\n", target, pname);
1591 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterfv(target, pname, params) );
1595 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1597 void TexParameteri(GLenum target, GLenum pname, GLint param)
1599 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1600 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteri(target, pname, param) );
1604 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1606 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1608 LOG_GL("TexParameteriv %x %x\n", target, pname);
1609 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteriv(target, pname, params) );
1613 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1615 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1616 GLenum format, GLenum type, const void* pixels)
1618 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1619 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1623 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1625 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1626 GLsizei width, GLsizei height, GLsizei depth,
1627 GLenum format, GLenum type, const void* pixels)
1629 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);
1630 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1634 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1636 GLboolean UnmapBuffer(GLenum target)
1638 LOG_GL("UnmapBuffer %x \n", target);
1639 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.UnmapBuffer(target) );
1643 * Wrapper for OpenGL ES 2.0 glViewport()
1645 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1647 // check if its same as already set
1648 Rect<int> newViewport( x, y, width, height );
1649 if( mViewPort != newViewport )
1652 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1653 CHECK_GL( mGlAbstraction, mGlAbstraction.Viewport(x, y, width, height) );
1654 mViewPort = newViewport; // remember new one
1659 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1660 * @return The implementation defined MAX_TEXTURE_SIZE
1662 GLint CachedMaxTextureSize() const
1664 return mMaxTextureSize;
1668 * Get the current viewport.
1669 * @return Viewport rectangle.
1671 const Rect< int >& GetViewport();
1673 private: // Implementation
1676 * @return true if next draw operation will write to depth buffer
1678 bool DepthBufferWriteEnabled() const
1680 return mDepthBufferEnabled && mDepthMaskEnabled;
1684 * @return true if next draw operation will write to stencil buffer
1686 bool StencilBufferWriteEnabled() const
1688 return mStencilBufferEnabled && ( mStencilMask > 0 );
1692 * Flushes vertex attribute location changes to the driver
1694 void FlushVertexAttributeLocations();
1697 * Either enables or disables a vertex attribute location in the cache
1698 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1699 * @param location attribute location
1700 * @param state attribute state
1702 void SetVertexAttributeLocation(unsigned int location, bool state);
1705 * Sets the initial GL state.
1707 void InitializeGlState();
1711 Integration::GlAbstraction& mGlAbstraction;
1713 bool mGlContextCreated; ///< True if the OpenGL context has been created
1715 // glEnable/glDisable states
1717 GLuint mStencilMask;
1719 bool mDepthBufferEnabled;
1720 bool mDepthMaskEnabled;
1721 bool mDitherEnabled;
1722 bool mPolygonOffsetFillEnabled;
1723 bool mSampleAlphaToCoverageEnabled;
1724 bool mSampleCoverageEnabled;
1725 bool mScissorTestEnabled;
1726 bool mStencilBufferEnabled;
1727 bool mClearColorSet;
1728 bool mUsingDefaultBlendColor;
1730 // glBindBuffer() state
1731 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1732 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1733 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1735 // glBindTexture() state
1736 TextureUnit mActiveTextureUnit;
1737 GLuint mBound2dTextureId[ MAX_TEXTURE_UNITS ]; ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
1739 // glBlendColor() state
1740 Vector4 mBlendColor; ///< Blend color
1742 // glBlendFuncSeparate() state
1743 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1744 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1745 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1746 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1748 // glBlendEquationSeparate state
1749 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1750 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1752 GLenum mDepthFunction; ///The depth function
1754 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1755 Vector4 mClearColor; ///< clear color
1757 // Face culling mode
1758 Dali::FaceCullingMode::Type mCullFaceMode;
1760 // cached viewport size
1761 Rect< int > mViewPort;
1763 // Vertex Attribute Buffer enable caching
1764 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1765 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1767 FrameBufferStateCache mFrameBufferStateCache; ///< frame buffer state cache
1770 } // namespace Internal
1774 #endif // __DALI_INTERNAL_CONTEXT_H__