1 #ifndef DALI_INTERNAL_CONTEXT_H
2 #define DALI_INTERNAL_CONTEXT_H
5 * Copyright (c) 2020 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/devel-api/common/owner-container.h>
28 #include <dali/integration-api/debug.h>
29 #include <dali/integration-api/gl-abstraction.h>
30 #include <dali/integration-api/gl-defines.h>
31 #include <dali/internal/render/common/performance-monitor.h>
32 #include <dali/internal/render/gl-resources/texture-units.h>
33 #include <dali/internal/render/gl-resources/frame-buffer-state-cache.h>
34 #include <dali/internal/render/gl-resources/gl-call-debug.h>
43 * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
44 * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
51 * FrameBuffer Clear mode
55 FORCE_CLEAR, ///< always perform the glClear regardless of current state
56 CHECK_CACHED_VALUES ///< check the Frame buffers cached state to see if a clear is required
60 * Size of the VertexAttributeArray enables
61 * GLES specification states that there's minimum of 8
63 static constexpr unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
65 static constexpr unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 8 is guaranteed, which is more than DALi uses anyways
66 static constexpr unsigned int MAX_TEXTURE_TARGET = 3; // We support only GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP and GL_TEXTURE_EXTERNAL_OES now
69 * Creates the Dali Context object for surface rendering only.
70 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
71 * @pre Context has not been created.
72 * @exception Context already created.
73 * @param glAbstraction the gl abstraction.
75 Context( Integration::GlAbstraction& glAbstraction );
78 * Creates the Dali Context object for texture (and surface rendering if required).
79 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
80 * @pre Context has not been created.
81 * @exception Context already created.
82 * @param glAbstraction the gl abstraction.
83 * @param contexts The list of scene contexts (for surface rendering)
85 Context( Integration::GlAbstraction& glAbstraction, OwnerContainer< Context* >* contexts );
93 * Called when the GL context has been created.
95 void GlContextCreated();
98 * Called when the GL context has been destroyed.
100 void GlContextDestroyed();
103 * Query whether the OpenGL context has been created.
104 * @return True if the OpenGL context has been created.
106 bool IsGlContextCreated() { return mGlContextCreated; }
109 * @return the GLAbstraction
111 Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
116 * Debug helper which prints the currently cached GL state.
118 void PrintCurrentState();
123 * Helper to convert GL error code to string
124 * @param errorCode to convert
127 const char* ErrorToString( GLenum errorCode );
130 * Helper to print GL string to debug log
132 void PrintGlString(const char* stringName, GLenum stringId)
134 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, reinterpret_cast< const char * >( GetString( stringId ) ) );
138 * Reset the cached buffer ids.
140 void ResetBufferCache()
142 // reset the cached buffer id's
143 // fixes problem where some drivers will a generate a buffer with the
144 // same id, as the last deleted buffer id.
145 mBoundArrayBufferId = 0;
146 mBoundElementArrayBufferId = 0;
147 mBoundTransformFeedbackBufferId = 0;
151 * Reset the cached texture ids.
153 void ResetTextureCache()
155 // reset the cached texture id's in case the driver re-uses them
156 // when creating new textures
157 for(unsigned int i = 0; i < MAX_TEXTURE_UNITS; ++i)
159 for(unsigned int j = 0; j < MAX_TEXTURE_TARGET; ++j)
161 mBoundTextureId[i][j] = 0;
167 * Get an index of the cached texture list from the texture target.
168 * @param target The texture target
169 * @return The index of the cached texture list
171 static constexpr int16_t GetTextureIndexFromGlFormat(int target)
179 case GL_TEXTURE_CUBE_MAP:
183 case GL_TEXTURE_EXTERNAL_OES:
194 /****************************************************************************************
195 * The following methods are forwarded to Dali::Integration::GlAbstraction.
196 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
197 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
198 * handles them and optimizes any program related state changes
199 ****************************************************************************************/
202 * Wrapper for IsSurfacelessContextSupported of Dali::Integration::GlAbstraction
204 bool IsSurfacelessContextSupported() const
206 return mGlAbstraction.IsSurfacelessContextSupported();
210 * Wrapper for TextureRequiresConverting of Dali::Integration::GlAbstraction
212 bool TextureRequiresConverting( const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage ) const
214 return mGlAbstraction.TextureRequiresConverting( imageGlFormat, textureGlFormat, isSubImage );
218 * Wrapper for OpenGL ES 2.0 glActiveTexture()
220 void ActiveTexture( TextureUnit textureUnit )
222 if ( textureUnit != mActiveTextureUnit )
224 mActiveTextureUnit = textureUnit;
225 LOG_GL("ActiveTexture %x\n", textureUnit);
226 CHECK_GL( mGlAbstraction, mGlAbstraction.ActiveTexture(TextureUnitAsGLenum(textureUnit)) );
231 * Wrapper for OpenGL ES 3.0 glBeginQuery()
233 void BeginQuery(GLenum target, GLuint id)
235 LOG_GL("BeginQuery %d %d\n", target, id);
236 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginQuery(target, id) );
240 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
242 void BeginTransformFeedback(GLenum primitiveMode)
244 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
245 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
249 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
253 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
255 void BindArrayBuffer(GLuint buffer)
257 // Avoid unecessary calls to BindBuffer
258 if (mBoundArrayBufferId != buffer)
260 mBoundArrayBufferId = buffer;
262 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
263 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
268 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
270 void BindElementArrayBuffer(GLuint buffer)
272 // Avoid unecessary calls to BindBuffer
273 if (mBoundElementArrayBufferId!= buffer)
275 mBoundElementArrayBufferId = buffer;
277 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
278 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
283 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
285 void BindTransformFeedbackBuffer(GLuint buffer)
287 // Avoid unecessary calls to BindBuffer
288 if (mBoundTransformFeedbackBufferId != buffer)
290 mBoundTransformFeedbackBufferId = buffer;
292 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
293 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
298 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
300 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
302 // Avoid unecessary calls to BindBufferBase
303 if (mBoundTransformFeedbackBufferId != buffer)
305 mBoundTransformFeedbackBufferId = buffer;
307 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
308 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
313 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
315 void BindFramebuffer(GLenum target, GLuint framebuffer)
317 mFrameBufferStateCache.SetCurrentFrameBuffer( framebuffer );
319 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
320 CHECK_GL( mGlAbstraction, mGlAbstraction.BindFramebuffer(target, framebuffer) );
324 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
326 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
328 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
329 CHECK_GL( mGlAbstraction, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
333 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
335 void BindTransformFeedback(GLenum target, GLuint id)
337 LOG_GL("BindTransformFeedback %d %d\n", target, id);
338 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTransformFeedback(target, id) );
342 * Helper to bind texture for rendering. If given texture is
343 * already bound in the given textureunit, this method does nothing.
344 * Otherwise changes the active texture unit and binds the texture.
345 * Note! after this call active texture unit may not necessarily be the one
346 * passed in as argument so you cannot change texture unit state!!
347 * @param textureunit to bind to
348 * @param texture to bind
350 void BindTextureForUnit( TextureUnit textureunit, int target, GLuint texture )
352 ActiveTexture(textureunit);
353 BindTexture(target, texture);
357 * Wrapper for OpenGL ES 2.0 glBindTexture( target )
359 void BindTexture( int target, GLuint texture )
361 int16_t index = GetTextureIndexFromGlFormat(target);
362 if(index >= 0 && mBoundTextureId[ mActiveTextureUnit ][index] != texture)
364 mBoundTextureId[ mActiveTextureUnit ][index] = texture;
366 LOG_GL("BindTexture target(%d) %d\n", target, texture);
367 CHECK_GL(mGlAbstraction, mGlAbstraction.BindTexture(target, texture));
372 * Wrapper for OpenGL ES 2.0 glBlendColor()
374 void SetDefaultBlendColor()
376 if( ! mUsingDefaultBlendColor )
378 SetCustomBlendColor( Color::TRANSPARENT );
379 mUsingDefaultBlendColor = true;
384 * Wrapper for OpenGL ES 2.0 glBlendColor()
386 void SetCustomBlendColor( const Vector4& color )
388 if( mUsingDefaultBlendColor || mBlendColor != color )
390 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
391 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor( color.r, color.g, color.b, color.a ) );
392 mUsingDefaultBlendColor = false;
398 * Wrapper for OpenGL ES 2.0 glBlendEquation()
400 void BlendEquation(GLenum mode)
402 // use BlendEquationSeparate to set the rgb and alpha modes the same
403 BlendEquationSeparate( mode, mode );
407 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
409 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
411 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
412 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
414 mBlendEquationSeparateModeRGB = modeRGB;
415 mBlendEquationSeparateModeAlpha = modeAlpha;
416 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
417 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
422 * Wrapper for OpenGL ES 2.0 glBlendFunc()
424 void BlendFunc(GLenum sfactor, GLenum dfactor)
426 // reuse the BlendFuncSeparate as thats what the DDK does anyways
427 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
431 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
433 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
435 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
436 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
438 mBlendFuncSeparateSrcRGB = srcRGB;
439 mBlendFuncSeparateDstRGB = dstRGB;
440 mBlendFuncSeparateSrcAlpha = srcAlpha;
441 mBlendFuncSeparateDstAlpha = dstAlpha;
443 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
444 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
449 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
451 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
453 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
454 CHECK_GL( mGlAbstraction, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
458 * Wrapper for OpenGL ES 2.0 glBufferData()
460 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
462 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
463 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferData(target, size, data, usage) );
467 * Wrapper for OpenGL ES 2.0 glBufferSubData()
469 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
471 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
472 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferSubData(target, offset, size, data) );
476 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
478 GLenum CheckFramebufferStatus(GLenum target)
480 LOG_GL("CheckFramebufferStatus %d\n", target);
481 GLenum value = CHECK_GL( mGlAbstraction, mGlAbstraction.CheckFramebufferStatus(target) );
486 * Wrapper for OpenGL ES 2.0 glClear()
488 void Clear(GLbitfield mask, ClearMode mode )
490 bool forceClear = (mode == FORCE_CLEAR );
491 mask = mFrameBufferStateCache.GetClearMask( mask, forceClear , mScissorTestEnabled );
495 LOG_GL("Clear %d\n", mask);
496 CHECK_GL( mGlAbstraction, mGlAbstraction.Clear( mask ) );
501 * Wrapper for OpenGL ES 2.0 glClearColor()
503 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
505 Vector4 newCol(red,green,blue,alpha);
507 if (!mClearColorSet || mClearColor !=newCol )
509 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
510 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearColor(red, green, blue, alpha) );
512 mClearColorSet = true;
513 mClearColor = newCol;
518 * Wrapper for OpenGL ES 2.0 glClearDepthf()
520 void ClearDepthf(GLclampf depth)
522 LOG_GL("ClearDepthf %f\n", depth);
523 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearDepthf(depth) );
527 * Wrapper for OpenGL ES 2.0 glClearStencil()
529 void ClearStencil(GLint s)
531 LOG_GL("ClearStencil %d\n", s);
532 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearStencil(s) );
536 * Wrapper for OpenGL ES 2.0 glColorMask()
537 * @note This has been optimized to a single boolean value (masking individual channels is not required)
539 void ColorMask( bool flag )
541 // only change state if needed
542 if( flag != mColorMask )
545 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
546 CHECK_GL( mGlAbstraction, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
551 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
553 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
554 GLint border, GLsizei imageSize, const void* data)
556 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
557 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
561 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
563 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
564 GLint border, GLsizei imageSize, const void* data)
566 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
567 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
571 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
573 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
574 GLenum format, GLsizei imageSize, const void* data)
576 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
577 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
581 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
583 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
584 GLsizei width, GLsizei height, GLsizei depth,
585 GLenum format, GLsizei imageSize, const void* data)
587 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);
588 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
592 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
594 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
596 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
597 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
601 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
603 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
605 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
606 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
610 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
612 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
614 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
615 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
619 * Wrapper for OpenGL ES 2.0 glCullFace()
620 * enables GL_CULL_FACE if in any of the face culling modes
621 * otherwise disables GL_CULL_FACE
623 void CullFace( Dali::FaceCullingMode::Type mode )
625 // Avoid unnecessary calls to gl
626 if(mCullFaceMode != mode)
628 mCullFaceMode = mode;
631 case Dali::FaceCullingMode::NONE:
633 LOG_GL("Disable GL_CULL_FACE\n");
634 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE) );
638 case Dali::FaceCullingMode::FRONT:
640 LOG_GL("Enable GL_CULL_FACE\n");
641 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
642 LOG_GL("Enable GL_FRONT\n");
643 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT) );
647 case Dali::FaceCullingMode::BACK:
649 LOG_GL("Enable GL_CULL_FACE\n");
650 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
651 LOG_GL("Enable GL_BACK\n");
652 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_BACK) );
656 case Dali::FaceCullingMode::FRONT_AND_BACK:
658 LOG_GL("Enable GL_CULL_FACE\n");
659 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
660 LOG_GL("Enable GL_FRONT_AND_BACK\n");
661 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
672 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
674 void DeleteBuffers(GLsizei n, const GLuint* buffers)
676 if( this->IsGlContextCreated() )
678 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
679 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
684 // Need to reset the buffer cache in the surface contexts
685 // This will only be executed by the surfaceless context when there are contexts for surface rendering
686 if ( mSceneContexts )
688 for ( auto&& context : *mSceneContexts )
692 context->ResetBufferCache();
699 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
701 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
703 mFrameBufferStateCache.FrameBuffersDeleted( n, framebuffers );
705 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
706 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
710 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
712 void DeleteQueries(GLsizei n, GLuint* ids)
714 LOG_GL("DeleteQueries %d %p\n", n, ids);
715 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteQueries(n, ids) );
719 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
721 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
723 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
724 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
728 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
730 void DeleteTextures(GLsizei n, const GLuint* textures)
732 LOG_GL("DeleteTextures %d %p\n", n, textures);
733 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
737 // Need to reset the texture cache in the scene contexts
738 // This will only be executed by the surfaceless context when there are contexts for surface rendering
739 if ( mSceneContexts )
741 for ( auto&& context : *mSceneContexts )
745 context->ResetTextureCache();
752 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
754 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
756 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
757 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
761 * Wrapper for OpenGL ES 2.0 glDepthFunc()
763 void DepthFunc(GLenum func)
765 if( func != mDepthFunction )
767 mDepthFunction = func;
768 LOG_GL("DepthFunc %x\n", func);
769 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthFunc(func) );
774 * Wrapper for OpenGL ES 2.0 glDepthMask()
776 void DepthMask(GLboolean flag)
778 bool booleanFlag = flag != GL_FALSE;
779 // only change state if needed
780 if( booleanFlag != mDepthMaskEnabled )
782 mDepthMaskEnabled = booleanFlag;
783 LOG_GL("DepthMask %s\n", booleanFlag ? "True" : "False");
784 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
789 * Wrapper for OpenGL ES 2.0 glDepthRangef()
791 void DepthRangef(GLclampf zNear, GLclampf zFar)
793 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
794 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthRangef(zNear, zFar) );
798 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
799 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
803 * Wrapper for OpenGL ES 2.0 glDrawArrays()
805 void DrawArrays(GLenum mode, GLint first, GLsizei count)
807 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
808 FlushVertexAttributeLocations();
810 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
811 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArrays(mode, first, count) );
815 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
817 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
819 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
820 FlushVertexAttributeLocations();
822 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
823 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
827 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
829 void DrawBuffers(GLsizei n, const GLenum* bufs)
831 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
832 LOG_GL("DrawBuffers %d %p\n", n, bufs);
833 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawBuffers(n, bufs) );
837 * Wrapper for OpenGL ES 2.0 glDrawElements()
839 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
841 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
843 FlushVertexAttributeLocations();
845 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
846 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElements(mode, count, type, indices) );
850 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
852 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
854 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
856 FlushVertexAttributeLocations();
858 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
859 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
863 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
865 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
867 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
868 FlushVertexAttributeLocations();
870 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
871 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
875 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
877 void GenQueries(GLsizei n, GLuint* ids)
879 LOG_GL("GenQueries %d %p\n", n, ids);
880 CHECK_GL( mGlAbstraction, mGlAbstraction.GenQueries(n, ids) );
884 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
886 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
888 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
889 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTransformFeedbacks(n, ids) );
893 * @return the current buffer bound for a given target
895 GLuint GetCurrentBoundArrayBuffer(GLenum target)
900 case GL_ARRAY_BUFFER:
902 result = mBoundArrayBufferId;
905 case GL_ELEMENT_ARRAY_BUFFER:
907 result = mBoundElementArrayBufferId;
910 case GL_TRANSFORM_FEEDBACK_BUFFER:
912 result = mBoundTransformFeedbackBufferId;
917 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
923 void EnableVertexAttributeArray( GLuint location )
925 SetVertexAttributeLocation( location, true);
928 void DisableVertexAttributeArray( GLuint location )
930 SetVertexAttributeLocation( location, false);
934 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
936 void VertexAttribDivisor ( GLuint index, GLuint divisor )
938 LOG_GL("VertexAttribDivisor(%d, %d)\n", index, divisor );
939 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
943 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
945 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
947 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
948 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
952 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
954 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
956 LOG_GL("InvalidateFramebuffer\n");
957 CHECK_GL( mGlAbstraction, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
961 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
962 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
966 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
967 * @param[in] enable True if GL_BLEND should be enabled.
969 void SetBlend(bool enable)
971 // Avoid unecessary calls to glEnable/glDisable
972 if (enable != mBlendEnabled)
974 mBlendEnabled = enable;
978 LOG_GL("Enable GL_BLEND\n");
979 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_BLEND) );
983 LOG_GL("Disable GL_BLEND\n");
984 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_BLEND) );
990 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
991 * Note GL_DEPTH_TEST means enable the depth buffer for writing and or testing.
992 * glDepthMask is used to enable / disable writing to depth buffer.
993 * glDepthFunc us used to control if testing is enabled and how it is performed ( default GL_LESS)
995 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
997 void EnableDepthBuffer( bool enable )
999 // Avoid unecessary calls to glEnable/glDisable
1000 if( enable != mDepthBufferEnabled )
1002 mDepthBufferEnabled = enable;
1006 LOG_GL("Enable GL_DEPTH_TEST\n");
1007 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DEPTH_TEST) );
1011 LOG_GL("Disable GL_DEPTH_TEST\n");
1012 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DEPTH_TEST) );
1018 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
1019 * @param[in] enable True if GL_DITHER should be enabled.
1021 void SetDither(bool enable)
1023 // Avoid unecessary calls to glEnable/glDisable
1024 if (enable != mDitherEnabled)
1026 mDitherEnabled = enable;
1030 LOG_GL("Enable GL_DITHER\n");
1031 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DITHER) );
1035 LOG_GL("Disable GL_DITHER\n");
1036 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DITHER) );
1042 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
1043 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
1045 void SetPolygonOffsetFill(bool enable)
1047 // Avoid unecessary calls to glEnable/glDisable
1048 if (enable != mPolygonOffsetFillEnabled)
1050 mPolygonOffsetFillEnabled = enable;
1054 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
1055 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
1059 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
1060 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
1066 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
1067 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
1069 void SetSampleAlphaToCoverage(bool enable)
1071 // Avoid unecessary calls to glEnable/glDisable
1072 if (enable != mSampleAlphaToCoverageEnabled)
1074 mSampleAlphaToCoverageEnabled = enable;
1078 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1079 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1083 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1084 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1090 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
1091 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
1093 void SetSampleCoverage(bool enable)
1095 // Avoid unecessary calls to glEnable/glDisable
1096 if (enable != mSampleCoverageEnabled)
1098 mSampleCoverageEnabled = enable;
1102 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
1103 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
1107 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
1108 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
1114 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
1115 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
1117 void SetScissorTest(bool enable)
1119 // Avoid unecessary calls to glEnable/glDisable
1120 if (enable != mScissorTestEnabled)
1122 mScissorTestEnabled = enable;
1126 LOG_GL("Enable GL_SCISSOR_TEST\n");
1127 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1131 LOG_GL("Disable GL_SCISSOR_TEST\n");
1132 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1138 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1139 * Note GL_STENCIL_TEST means enable the stencil buffer for writing and or testing.
1140 * glStencilMask is used to control how bits are written to the stencil buffer.
1141 * glStencilFunc is used to control if testing is enabled and how it is performed ( default GL_ALWAYS )
1142 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1144 void EnableStencilBuffer(bool enable)
1146 // Avoid unecessary calls to glEnable/glDisable
1147 if( enable != mStencilBufferEnabled )
1149 mStencilBufferEnabled = enable;
1153 LOG_GL("Enable GL_STENCIL_TEST\n");
1154 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1158 LOG_GL("Disable GL_STENCIL_TEST\n");
1159 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1165 * Wrapper for OpenGL ES 3.0 glEndQuery()
1167 void EndQuery(GLenum target)
1169 LOG_GL("EndQuery %d\n", target);
1170 CHECK_GL( mGlAbstraction, mGlAbstraction.EndQuery(target) );
1174 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1176 void EndTransformFeedback()
1178 LOG_GL("EndTransformFeedback\n");
1179 CHECK_GL( mGlAbstraction, mGlAbstraction.EndTransformFeedback() );
1183 * Wrapper for OpenGL ES 2.0 glFinish()
1188 CHECK_GL( mGlAbstraction, mGlAbstraction.Finish() );
1192 * Wrapper for OpenGL ES 2.0 glFlush()
1197 CHECK_GL( mGlAbstraction, mGlAbstraction.Flush() );
1201 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1203 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1205 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1206 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1210 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1212 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1214 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1215 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1219 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1221 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1223 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1224 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1228 * Wrapper for OpenGL ES 2.0 glFrontFace()
1230 void FrontFace(GLenum mode)
1232 LOG_GL("FrontFace %x\n", mode);
1233 CHECK_GL( mGlAbstraction, mGlAbstraction.FrontFace(mode) );
1237 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1239 void GenBuffers(GLsizei n, GLuint* buffers)
1241 LOG_GL("GenBuffers %d\n", n, buffers);
1242 CHECK_GL( mGlAbstraction, mGlAbstraction.GenBuffers(n, buffers) );
1246 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1248 void GenerateMipmap(GLenum target)
1250 LOG_GL("GenerateMipmap %x\n", target);
1251 CHECK_GL( mGlAbstraction, mGlAbstraction.GenerateMipmap(target) );
1255 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1257 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1259 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1260 CHECK_GL( mGlAbstraction, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1262 mFrameBufferStateCache.FrameBuffersCreated( n, framebuffers );
1266 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1268 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1270 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1271 CHECK_GL( mGlAbstraction, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1275 * Wrapper for OpenGL ES 2.0 glGenTextures()
1277 void GenTextures(GLsizei n, GLuint* textures)
1279 LOG_GL("GenTextures %d %p\n", n, textures);
1280 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTextures(n, textures) );
1284 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1286 void GetBooleanv(GLenum pname, GLboolean* params)
1288 LOG_GL("GetBooleanv %x\n", pname);
1289 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBooleanv(pname, params) );
1293 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1295 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1297 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1298 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1302 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1304 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1306 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1307 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1311 * Wrapper for OpenGL ES 2.0 glGetError()
1313 GLenum GetError(void)
1315 // Not worth logging here
1316 return mGlAbstraction.GetError();
1320 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1322 void GetFloatv(GLenum pname, GLfloat* params)
1324 LOG_GL("GetFloatv %x\n", pname);
1325 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFloatv(pname, params) );
1329 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1331 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1333 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1334 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1338 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1340 void GetIntegerv(GLenum pname, GLint* params)
1342 LOG_GL("GetIntegerv %x\n", pname);
1343 CHECK_GL( mGlAbstraction, mGlAbstraction.GetIntegerv(pname, params) );
1347 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1349 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1351 LOG_GL("GetQueryiv %x %x\n", target, pname);
1352 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryiv(target, pname, params) );
1356 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1358 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1360 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1361 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1365 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1367 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1369 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1370 CHECK_GL( mGlAbstraction, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1374 * Wrapper for OpenGL ES 2.0 glGetString()
1376 const GLubyte* GetString(GLenum name)
1378 LOG_GL("GetString %x\n", name);
1379 const GLubyte* str = CHECK_GL( mGlAbstraction, mGlAbstraction.GetString(name) );
1384 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1386 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1388 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1389 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1393 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1395 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1397 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1398 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1402 * Wrapper for OpenGL ES 2.0 glHint()
1404 void Hint(GLenum target, GLenum mode)
1406 LOG_GL("Hint %x %x\n", target, mode);
1407 CHECK_GL( mGlAbstraction, mGlAbstraction.Hint(target, mode) );
1411 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1413 GLboolean IsBuffer(GLuint buffer)
1415 LOG_GL("IsBuffer %d\n", buffer);
1416 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsBuffer(buffer) );
1421 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1423 GLboolean IsEnabled(GLenum cap)
1425 LOG_GL("IsEnabled %x\n", cap);
1426 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsEnabled(cap) );
1431 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1433 GLboolean IsFramebuffer(GLuint framebuffer)
1435 LOG_GL("IsFramebuffer %d\n", framebuffer);
1436 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsFramebuffer(framebuffer) );
1441 * Wrapper for OpenGL ES 3.0 glIsQuery()
1443 GLboolean IsQuery(GLuint id)
1445 LOG_GL("IsQuery %u\n", id);
1446 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsQuery(id) );
1451 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1453 GLboolean IsRenderbuffer(GLuint renderbuffer)
1455 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1456 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1461 * Wrapper for OpenGL ES 2.0 glIsTexture()
1463 GLboolean IsTexture(GLuint texture)
1465 LOG_GL("IsTexture %d\n", texture);
1466 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTexture(texture) );
1471 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1473 GLboolean IsTransformFeedback(GLuint id)
1475 LOG_GL("IsTransformFeedback %u\n", id);
1476 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTransformFeedback(id) );
1481 * Wrapper for OpenGL ES 2.0 glLineWidth()
1483 void LineWidth(GLfloat width)
1485 LOG_GL("LineWidth %f\n", width);
1486 CHECK_GL( mGlAbstraction, mGlAbstraction.LineWidth(width) );
1490 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1492 void PauseTransformFeedback()
1494 LOG_GL("PauseTransformFeedback\n");
1495 CHECK_GL( mGlAbstraction, mGlAbstraction.PauseTransformFeedback() );
1499 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1501 void PixelStorei(GLenum pname, GLint param)
1503 LOG_GL("PixelStorei %x %d\n", pname, param);
1504 CHECK_GL( mGlAbstraction, mGlAbstraction.PixelStorei(pname, param) );
1508 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1510 void PolygonOffset(GLfloat factor, GLfloat units)
1512 LOG_GL("PolygonOffset %f %f\n", factor, units);
1513 CHECK_GL( mGlAbstraction, mGlAbstraction.PolygonOffset(factor, units) );
1517 * Wrapper for OpenGL ES 2.0 glReadPixels()
1519 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1521 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1522 CHECK_GL( mGlAbstraction, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1526 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1528 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1530 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1531 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1535 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1537 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1539 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1540 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1544 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1546 void ResumeTransformFeedback()
1548 LOG_GL("ResumeTransformFeedback\n");
1549 CHECK_GL( mGlAbstraction, mGlAbstraction.ResumeTransformFeedback() );
1553 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1555 void SampleCoverage(GLclampf value, GLboolean invert)
1557 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1558 CHECK_GL( mGlAbstraction, mGlAbstraction.SampleCoverage(value, invert) );
1562 * Wrapper for OpenGL ES 2.0 glScissor()
1564 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1566 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1567 CHECK_GL( mGlAbstraction, mGlAbstraction.Scissor(x, y, width, height) );
1571 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1573 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1575 if( ( func != mStencilFunc ) || ( ref != mStencilFuncRef ) || ( mask != mStencilFuncMask ) )
1577 mStencilFunc = func;
1578 mStencilFuncRef = ref;
1579 mStencilFuncMask = mask;
1581 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1582 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) );
1587 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1589 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1591 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1592 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1596 * Wrapper for OpenGL ES 2.0 glStencilMask()
1598 void StencilMask(GLuint mask)
1600 if( mask != mStencilMask )
1602 mStencilMask = mask;
1604 LOG_GL("StencilMask %d\n", mask);
1605 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMask(mask) );
1610 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1612 void StencilMaskSeparate(GLenum face, GLuint mask)
1614 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1615 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMaskSeparate(face, mask) );
1619 * Wrapper for OpenGL ES 2.0 glStencilOp()
1621 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1623 if( ( fail != mStencilOpFail ) || ( zfail != mStencilOpDepthFail ) || ( zpass != mStencilOpDepthPass ) )
1625 mStencilOpFail = fail;
1626 mStencilOpDepthFail = zfail;
1627 mStencilOpDepthPass = zpass;
1629 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1630 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1635 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1637 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1639 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1640 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1644 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1646 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1647 GLint border, GLenum format, GLenum type, const void* pixels)
1649 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1650 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1654 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1656 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1657 GLint border, GLenum format, GLenum type, const void* pixels)
1659 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1660 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1664 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1666 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1668 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1669 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterf(target, pname, param) );
1673 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1675 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1677 LOG_GL("TexParameterfv %x %x\n", target, pname);
1678 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterfv(target, pname, params) );
1682 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1684 void TexParameteri(GLenum target, GLenum pname, GLint param)
1686 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1687 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteri(target, pname, param) );
1691 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1693 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1695 LOG_GL("TexParameteriv %x %x\n", target, pname);
1696 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteriv(target, pname, params) );
1700 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1702 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1703 GLenum format, GLenum type, const void* pixels)
1705 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1706 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1710 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1712 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1713 GLsizei width, GLsizei height, GLsizei depth,
1714 GLenum format, GLenum type, const void* pixels)
1716 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);
1717 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1721 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1723 GLboolean UnmapBuffer(GLenum target)
1725 LOG_GL("UnmapBuffer %x \n", target);
1726 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.UnmapBuffer(target) );
1730 * Wrapper for OpenGL ES 2.0 glViewport()
1732 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1734 // check if its same as already set
1735 Rect<int> newViewport( x, y, width, height );
1737 // Temporarily disable the viewport caching, as the implementation of GLES driver in Tizen platform
1738 // share a global viewport between multiple contexts, therefore glViewport has to be called every
1739 // time after glBindFramebuffer regardless of the same vewport size in the same context.
1740 // if( mViewPort != newViewport )
1743 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1744 CHECK_GL( mGlAbstraction, mGlAbstraction.Viewport(x, y, width, height) );
1745 mViewPort = newViewport; // remember new one
1750 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1751 * @return The implementation defined MAX_TEXTURE_SIZE
1753 GLint CachedMaxTextureSize() const
1755 return mMaxTextureSize;
1759 * Get the current viewport.
1760 * @return Viewport rectangle.
1762 const Rect< int >& GetViewport();
1764 private: // Implementation
1767 * @return true if next draw operation will write to depth buffer
1769 bool DepthBufferWriteEnabled() const
1771 return mDepthBufferEnabled && mDepthMaskEnabled;
1775 * @return true if next draw operation will write to stencil buffer
1777 bool StencilBufferWriteEnabled() const
1779 return mStencilBufferEnabled && ( mStencilMask > 0 );
1783 * Flushes vertex attribute location changes to the driver
1785 void FlushVertexAttributeLocations();
1788 * Either enables or disables a vertex attribute location in the cache
1789 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1790 * @param location attribute location
1791 * @param state attribute state
1793 void SetVertexAttributeLocation(unsigned int location, bool state);
1796 * Sets the initial GL state.
1798 void InitializeGlState();
1802 Integration::GlAbstraction& mGlAbstraction;
1804 bool mGlContextCreated; ///< True if the OpenGL context has been created
1806 // glEnable/glDisable states
1808 GLuint mStencilMask;
1810 bool mDepthBufferEnabled;
1811 bool mDepthMaskEnabled;
1812 bool mDitherEnabled;
1813 bool mPolygonOffsetFillEnabled;
1814 bool mSampleAlphaToCoverageEnabled;
1815 bool mSampleCoverageEnabled;
1816 bool mScissorTestEnabled;
1817 bool mStencilBufferEnabled;
1818 bool mClearColorSet;
1819 bool mUsingDefaultBlendColor;
1821 // glBindBuffer() state
1822 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1823 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1824 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1826 // glBindTexture() state
1827 TextureUnit mActiveTextureUnit;
1828 GLuint mBoundTextureId[ MAX_TEXTURE_UNITS ][MAX_TEXTURE_TARGET]; ///< The ID passed to glBindTexture()
1830 // glBlendColor() state
1831 Vector4 mBlendColor; ///< Blend color
1833 // glBlendFuncSeparate() state
1834 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1835 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1836 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1837 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1839 // glBlendEquationSeparate state
1840 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1841 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1843 // glStencilFunc() and glStencilOp() state.
1844 GLenum mStencilFunc;
1845 GLint mStencilFuncRef;
1846 GLuint mStencilFuncMask;
1847 GLenum mStencilOpFail;
1848 GLenum mStencilOpDepthFail;
1849 GLenum mStencilOpDepthPass;
1851 GLenum mDepthFunction; ///The depth function
1853 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1854 Vector4 mClearColor; ///< clear color
1856 // Face culling mode
1857 Dali::FaceCullingMode::Type mCullFaceMode;
1859 // cached viewport size
1860 Rect< int > mViewPort;
1862 // Vertex Attribute Buffer enable caching
1863 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1864 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1866 FrameBufferStateCache mFrameBufferStateCache; ///< frame buffer state cache
1868 OwnerContainer< Context* >* mSceneContexts; ///< The pointer of the container of contexts for surface rendering
1871 } // namespace Internal
1875 #endif // DALI_INTERNAL_CONTEXT_H