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 const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
65 static const unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 8 is guaranteed, which is more than DALi uses anyways
68 * Creates the Dali Context object for surface rendering only.
69 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
70 * @pre Context has not been created.
71 * @exception Context already created.
72 * @param glAbstraction the gl abstraction.
74 Context( Integration::GlAbstraction& glAbstraction );
77 * Creates the Dali Context object for texture (and surface rendering if required).
78 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
79 * @pre Context has not been created.
80 * @exception Context already created.
81 * @param glAbstraction the gl abstraction.
82 * @param contexts The list of scene contexts (for surface rendering)
84 Context( Integration::GlAbstraction& glAbstraction, std::vector< Context* >* contexts );
92 * Called when the GL context has been created.
94 void GlContextCreated();
97 * Called when the GL context has been destroyed.
99 void GlContextDestroyed();
102 * Query whether the OpenGL context has been created.
103 * @return True if the OpenGL context has been created.
105 bool IsGlContextCreated() { return mGlContextCreated; }
108 * @return the GLAbstraction
110 Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
115 * Debug helper which prints the currently cached GL state.
117 void PrintCurrentState();
122 * Helper to convert GL error code to string
123 * @param errorCode to convert
126 const char* ErrorToString( GLenum errorCode );
129 * Helper to print GL string to debug log
131 void PrintGlString(const char* stringName, GLenum stringId)
133 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, reinterpret_cast< const char * >( GetString( stringId ) ) );
136 void ResetBufferCache()
138 // reset the cached buffer id's
139 // fixes problem where some drivers will a generate a buffer with the
140 // same id, as the last deleted buffer id.
141 mBoundArrayBufferId = 0;
142 mBoundElementArrayBufferId = 0;
143 mBoundTransformFeedbackBufferId = 0;
146 void ResetTextureCache()
148 // reset the cached texture id's in case the driver re-uses them
149 // when creating new textures
150 for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
152 mBoundTextureId[ i ] = 0;
156 /****************************************************************************************
157 * The following methods are forwarded to Dali::Integration::GlAbstraction.
158 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
159 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
160 * handles them and optimizes any program related state changes
161 ****************************************************************************************/
164 * Wrapper for IsSurfacelessContextSupported of Dali::Integration::GlAbstraction
166 bool IsSurfacelessContextSupported() const
168 return mGlAbstraction.IsSurfacelessContextSupported();
172 * Wrapper for TextureRequiresConverting of Dali::Integration::GlAbstraction
174 bool TextureRequiresConverting( const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage ) const
176 return mGlAbstraction.TextureRequiresConverting( imageGlFormat, textureGlFormat, isSubImage );
180 * Wrapper for OpenGL ES 2.0 glActiveTexture()
182 void ActiveTexture( TextureUnit textureUnit )
184 if ( textureUnit != mActiveTextureUnit )
186 mActiveTextureUnit = textureUnit;
187 LOG_GL("ActiveTexture %x\n", textureUnit);
188 CHECK_GL( mGlAbstraction, mGlAbstraction.ActiveTexture(TextureUnitAsGLenum(textureUnit)) );
193 * Wrapper for OpenGL ES 3.0 glBeginQuery()
195 void BeginQuery(GLenum target, GLuint id)
197 LOG_GL("BeginQuery %d %d\n", target, id);
198 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginQuery(target, id) );
202 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
204 void BeginTransformFeedback(GLenum primitiveMode)
206 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
207 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
211 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
215 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
217 void BindArrayBuffer(GLuint buffer)
219 // Avoid unecessary calls to BindBuffer
220 if (mBoundArrayBufferId != buffer)
222 mBoundArrayBufferId = buffer;
224 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
225 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
230 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
232 void BindElementArrayBuffer(GLuint buffer)
234 // Avoid unecessary calls to BindBuffer
235 if (mBoundElementArrayBufferId!= buffer)
237 mBoundElementArrayBufferId = buffer;
239 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
240 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
245 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
247 void BindTransformFeedbackBuffer(GLuint buffer)
249 // Avoid unecessary calls to BindBuffer
250 if (mBoundTransformFeedbackBufferId != buffer)
252 mBoundTransformFeedbackBufferId = buffer;
254 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
255 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
260 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
262 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
264 // Avoid unecessary calls to BindBufferBase
265 if (mBoundTransformFeedbackBufferId != buffer)
267 mBoundTransformFeedbackBufferId = buffer;
269 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
270 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
275 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
277 void BindFramebuffer(GLenum target, GLuint framebuffer)
279 mFrameBufferStateCache.SetCurrentFrameBuffer( framebuffer );
281 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
282 CHECK_GL( mGlAbstraction, mGlAbstraction.BindFramebuffer(target, framebuffer) );
286 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
288 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
290 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
291 CHECK_GL( mGlAbstraction, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
295 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
297 void BindTransformFeedback(GLenum target, GLuint id)
299 LOG_GL("BindTransformFeedback %d %d\n", target, id);
300 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTransformFeedback(target, id) );
304 * Helper to bind texture for rendering. If given texture is
305 * already bound in the given textureunit, this method does nothing.
306 * Otherwise changes the active texture unit and binds the texture.
307 * Note! after this call active texture unit may not necessarily be the one
308 * passed in as argument so you cannot change texture unit state!!
309 * @param textureunit to bind to
310 * @param texture to bind
312 void BindTextureForUnit( TextureUnit textureunit, int target, GLuint texture )
314 if( mBoundTextureId[ textureunit ] != texture )
316 ActiveTexture( textureunit );
317 BindTexture( target, texture );
322 * Wrapper for OpenGL ES 2.0 glBindTexture( target )
324 void BindTexture( int target, GLuint texture )
326 if (mBoundTextureId[ mActiveTextureUnit ] != texture)
328 mBoundTextureId[ mActiveTextureUnit ] = texture;
330 LOG_GL("BindTexture target(%d) %d\n", target, texture);
331 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(target, texture) );
336 * Wrapper for OpenGL ES 2.0 glBlendColor()
338 void SetDefaultBlendColor()
340 if( ! mUsingDefaultBlendColor )
342 SetCustomBlendColor( Color::TRANSPARENT );
343 mUsingDefaultBlendColor = true;
348 * Wrapper for OpenGL ES 2.0 glBlendColor()
350 void SetCustomBlendColor( const Vector4& color )
352 if( mUsingDefaultBlendColor || mBlendColor != color )
354 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
355 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor( color.r, color.g, color.b, color.a ) );
356 mUsingDefaultBlendColor = false;
362 * Wrapper for OpenGL ES 2.0 glBlendEquation()
364 void BlendEquation(GLenum mode)
366 // use BlendEquationSeparate to set the rgb and alpha modes the same
367 BlendEquationSeparate( mode, mode );
371 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
373 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
375 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
376 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
378 mBlendEquationSeparateModeRGB = modeRGB;
379 mBlendEquationSeparateModeAlpha = modeAlpha;
380 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
381 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
386 * Wrapper for OpenGL ES 2.0 glBlendFunc()
388 void BlendFunc(GLenum sfactor, GLenum dfactor)
390 // reuse the BlendFuncSeparate as thats what the DDK does anyways
391 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
395 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
397 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
399 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
400 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
402 mBlendFuncSeparateSrcRGB = srcRGB;
403 mBlendFuncSeparateDstRGB = dstRGB;
404 mBlendFuncSeparateSrcAlpha = srcAlpha;
405 mBlendFuncSeparateDstAlpha = dstAlpha;
407 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
408 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
413 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
415 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
417 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
418 CHECK_GL( mGlAbstraction, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
422 * Wrapper for OpenGL ES 2.0 glBufferData()
424 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
426 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
427 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferData(target, size, data, usage) );
431 * Wrapper for OpenGL ES 2.0 glBufferSubData()
433 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
435 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
436 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferSubData(target, offset, size, data) );
440 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
442 GLenum CheckFramebufferStatus(GLenum target)
444 LOG_GL("CheckFramebufferStatus %d\n", target);
445 GLenum value = CHECK_GL( mGlAbstraction, mGlAbstraction.CheckFramebufferStatus(target) );
450 * Wrapper for OpenGL ES 2.0 glClear()
452 void Clear(GLbitfield mask, ClearMode mode )
454 bool forceClear = (mode == FORCE_CLEAR );
455 mask = mFrameBufferStateCache.GetClearMask( mask, forceClear , mScissorTestEnabled );
459 LOG_GL("Clear %d\n", mask);
460 CHECK_GL( mGlAbstraction, mGlAbstraction.Clear( mask ) );
465 * Wrapper for OpenGL ES 2.0 glClearColor()
467 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
469 Vector4 newCol(red,green,blue,alpha);
471 if (!mClearColorSet || mClearColor !=newCol )
473 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
474 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearColor(red, green, blue, alpha) );
476 mClearColorSet = true;
477 mClearColor = newCol;
482 * Wrapper for OpenGL ES 2.0 glClearDepthf()
484 void ClearDepthf(GLclampf depth)
486 LOG_GL("ClearDepthf %f\n", depth);
487 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearDepthf(depth) );
491 * Wrapper for OpenGL ES 2.0 glClearStencil()
493 void ClearStencil(GLint s)
495 LOG_GL("ClearStencil %d\n", s);
496 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearStencil(s) );
500 * Wrapper for OpenGL ES 2.0 glColorMask()
501 * @note This has been optimized to a single boolean value (masking individual channels is not required)
503 void ColorMask( bool flag )
505 // only change state if needed
506 if( flag != mColorMask )
509 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
510 CHECK_GL( mGlAbstraction, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
515 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
517 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
518 GLint border, GLsizei imageSize, const void* data)
520 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
521 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
525 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
527 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
528 GLint border, GLsizei imageSize, const void* data)
530 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
531 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
535 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
537 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
538 GLenum format, GLsizei imageSize, const void* data)
540 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
541 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
545 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
547 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
548 GLsizei width, GLsizei height, GLsizei depth,
549 GLenum format, GLsizei imageSize, const void* data)
551 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);
552 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
556 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
558 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
560 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
561 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
565 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
567 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
569 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
570 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
574 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
576 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
578 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
579 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
583 * Wrapper for OpenGL ES 2.0 glCullFace()
584 * enables GL_CULL_FACE if in any of the face culling modes
585 * otherwise disables GL_CULL_FACE
587 void CullFace( Dali::FaceCullingMode::Type mode )
589 // Avoid unnecessary calls to gl
590 if(mCullFaceMode != mode)
592 mCullFaceMode = mode;
595 case Dali::FaceCullingMode::NONE:
597 LOG_GL("Disable GL_CULL_FACE\n");
598 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE) );
602 case Dali::FaceCullingMode::FRONT:
604 LOG_GL("Enable GL_CULL_FACE\n");
605 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
606 LOG_GL("Enable GL_FRONT\n");
607 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT) );
611 case Dali::FaceCullingMode::BACK:
613 LOG_GL("Enable GL_CULL_FACE\n");
614 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
615 LOG_GL("Enable GL_BACK\n");
616 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_BACK) );
620 case Dali::FaceCullingMode::FRONT_AND_BACK:
622 LOG_GL("Enable GL_CULL_FACE\n");
623 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
624 LOG_GL("Enable GL_FRONT_AND_BACK\n");
625 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
636 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
638 void DeleteBuffers(GLsizei n, const GLuint* buffers)
640 if( this->IsGlContextCreated() )
642 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
643 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
648 // Need to reset the buffer cache in the surface contexts
649 // This will only be executed by the surfaceless context when there are contexts for surface rendering
650 if ( mSceneContexts )
652 for ( auto&& context : *mSceneContexts )
656 context->ResetBufferCache();
663 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
665 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
667 mFrameBufferStateCache.FrameBuffersDeleted( n, framebuffers );
669 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
670 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
674 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
676 void DeleteQueries(GLsizei n, GLuint* ids)
678 LOG_GL("DeleteQueries %d %p\n", n, ids);
679 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteQueries(n, ids) );
683 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
685 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
687 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
688 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
692 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
694 void DeleteTextures(GLsizei n, const GLuint* textures)
696 LOG_GL("DeleteTextures %d %p\n", n, textures);
697 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
701 // Need to reset the texture cache in the scene contexts
702 // This will only be executed by the surfaceless context when there are contexts for surface rendering
703 if ( mSceneContexts )
705 for ( auto&& context : *mSceneContexts )
709 context->ResetTextureCache();
716 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
718 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
720 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
721 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
725 * Wrapper for OpenGL ES 2.0 glDepthFunc()
727 void DepthFunc(GLenum func)
729 if( func != mDepthFunction )
731 mDepthFunction = func;
732 LOG_GL("DepthFunc %x\n", func);
733 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthFunc(func) );
738 * Wrapper for OpenGL ES 2.0 glDepthMask()
740 void DepthMask(GLboolean flag)
742 bool booleanFlag = flag != GL_FALSE;
743 // only change state if needed
744 if( booleanFlag != mDepthMaskEnabled )
746 mDepthMaskEnabled = booleanFlag;
747 LOG_GL("DepthMask %s\n", booleanFlag ? "True" : "False");
748 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
753 * Wrapper for OpenGL ES 2.0 glDepthRangef()
755 void DepthRangef(GLclampf zNear, GLclampf zFar)
757 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
758 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthRangef(zNear, zFar) );
762 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
763 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
767 * Wrapper for OpenGL ES 2.0 glDrawArrays()
769 void DrawArrays(GLenum mode, GLint first, GLsizei count)
771 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
772 FlushVertexAttributeLocations();
774 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
775 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArrays(mode, first, count) );
779 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
781 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
783 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
784 FlushVertexAttributeLocations();
786 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
787 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
791 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
793 void DrawBuffers(GLsizei n, const GLenum* bufs)
795 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
796 LOG_GL("DrawBuffers %d %p\n", n, bufs);
797 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawBuffers(n, bufs) );
801 * Wrapper for OpenGL ES 2.0 glDrawElements()
803 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
805 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
807 FlushVertexAttributeLocations();
809 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
810 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElements(mode, count, type, indices) );
814 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
816 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
818 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
820 FlushVertexAttributeLocations();
822 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
823 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
827 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
829 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
831 mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
832 FlushVertexAttributeLocations();
834 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
835 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
839 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
841 void GenQueries(GLsizei n, GLuint* ids)
843 LOG_GL("GenQueries %d %p\n", n, ids);
844 CHECK_GL( mGlAbstraction, mGlAbstraction.GenQueries(n, ids) );
848 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
850 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
852 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
853 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTransformFeedbacks(n, ids) );
857 * @return the current buffer bound for a given target
859 GLuint GetCurrentBoundArrayBuffer(GLenum target)
864 case GL_ARRAY_BUFFER:
866 result = mBoundArrayBufferId;
869 case GL_ELEMENT_ARRAY_BUFFER:
871 result = mBoundElementArrayBufferId;
874 case GL_TRANSFORM_FEEDBACK_BUFFER:
876 result = mBoundTransformFeedbackBufferId;
881 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
887 void EnableVertexAttributeArray( GLuint location )
889 SetVertexAttributeLocation( location, true);
892 void DisableVertexAttributeArray( GLuint location )
894 SetVertexAttributeLocation( location, false);
898 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
900 void VertexAttribDivisor ( GLuint index, GLuint divisor )
902 LOG_GL("VertexAttribDivisor(%d, %d)\n", index, divisor );
903 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
907 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
909 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
911 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
912 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
916 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
918 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
920 LOG_GL("InvalidateFramebuffer\n");
921 CHECK_GL( mGlAbstraction, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
925 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
926 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
930 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
931 * @param[in] enable True if GL_BLEND should be enabled.
933 void SetBlend(bool enable)
935 // Avoid unecessary calls to glEnable/glDisable
936 if (enable != mBlendEnabled)
938 mBlendEnabled = enable;
942 LOG_GL("Enable GL_BLEND\n");
943 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_BLEND) );
947 LOG_GL("Disable GL_BLEND\n");
948 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_BLEND) );
954 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
955 * Note GL_DEPTH_TEST means enable the depth buffer for writing and or testing.
956 * glDepthMask is used to enable / disable writing to depth buffer.
957 * glDepthFunc us used to control if testing is enabled and how it is performed ( default GL_LESS)
959 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
961 void EnableDepthBuffer( bool enable )
963 // Avoid unecessary calls to glEnable/glDisable
964 if( enable != mDepthBufferEnabled )
966 mDepthBufferEnabled = enable;
970 LOG_GL("Enable GL_DEPTH_TEST\n");
971 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DEPTH_TEST) );
975 LOG_GL("Disable GL_DEPTH_TEST\n");
976 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DEPTH_TEST) );
982 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
983 * @param[in] enable True if GL_DITHER should be enabled.
985 void SetDither(bool enable)
987 // Avoid unecessary calls to glEnable/glDisable
988 if (enable != mDitherEnabled)
990 mDitherEnabled = enable;
994 LOG_GL("Enable GL_DITHER\n");
995 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DITHER) );
999 LOG_GL("Disable GL_DITHER\n");
1000 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DITHER) );
1006 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
1007 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
1009 void SetPolygonOffsetFill(bool enable)
1011 // Avoid unecessary calls to glEnable/glDisable
1012 if (enable != mPolygonOffsetFillEnabled)
1014 mPolygonOffsetFillEnabled = enable;
1018 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
1019 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
1023 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
1024 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
1030 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
1031 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
1033 void SetSampleAlphaToCoverage(bool enable)
1035 // Avoid unecessary calls to glEnable/glDisable
1036 if (enable != mSampleAlphaToCoverageEnabled)
1038 mSampleAlphaToCoverageEnabled = enable;
1042 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1043 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1047 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1048 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
1054 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
1055 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
1057 void SetSampleCoverage(bool enable)
1059 // Avoid unecessary calls to glEnable/glDisable
1060 if (enable != mSampleCoverageEnabled)
1062 mSampleCoverageEnabled = enable;
1066 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
1067 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
1071 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
1072 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
1078 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
1079 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
1081 void SetScissorTest(bool enable)
1083 // Avoid unecessary calls to glEnable/glDisable
1084 if (enable != mScissorTestEnabled)
1086 mScissorTestEnabled = enable;
1090 LOG_GL("Enable GL_SCISSOR_TEST\n");
1091 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1095 LOG_GL("Disable GL_SCISSOR_TEST\n");
1096 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1102 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1103 * Note GL_STENCIL_TEST means enable the stencil buffer for writing and or testing.
1104 * glStencilMask is used to control how bits are written to the stencil buffer.
1105 * glStencilFunc is used to control if testing is enabled and how it is performed ( default GL_ALWAYS )
1106 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1108 void EnableStencilBuffer(bool enable)
1110 // Avoid unecessary calls to glEnable/glDisable
1111 if( enable != mStencilBufferEnabled )
1113 mStencilBufferEnabled = enable;
1117 LOG_GL("Enable GL_STENCIL_TEST\n");
1118 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1122 LOG_GL("Disable GL_STENCIL_TEST\n");
1123 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1129 * Wrapper for OpenGL ES 3.0 glEndQuery()
1131 void EndQuery(GLenum target)
1133 LOG_GL("EndQuery %d\n", target);
1134 CHECK_GL( mGlAbstraction, mGlAbstraction.EndQuery(target) );
1138 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1140 void EndTransformFeedback()
1142 LOG_GL("EndTransformFeedback\n");
1143 CHECK_GL( mGlAbstraction, mGlAbstraction.EndTransformFeedback() );
1147 * Wrapper for OpenGL ES 2.0 glFinish()
1152 CHECK_GL( mGlAbstraction, mGlAbstraction.Finish() );
1156 * Wrapper for OpenGL ES 2.0 glFlush()
1161 CHECK_GL( mGlAbstraction, mGlAbstraction.Flush() );
1165 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1167 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1169 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1170 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1174 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1176 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1178 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1179 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1183 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1185 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1187 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1188 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1192 * Wrapper for OpenGL ES 2.0 glFrontFace()
1194 void FrontFace(GLenum mode)
1196 LOG_GL("FrontFace %x\n", mode);
1197 CHECK_GL( mGlAbstraction, mGlAbstraction.FrontFace(mode) );
1201 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1203 void GenBuffers(GLsizei n, GLuint* buffers)
1205 LOG_GL("GenBuffers %d\n", n, buffers);
1206 CHECK_GL( mGlAbstraction, mGlAbstraction.GenBuffers(n, buffers) );
1210 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1212 void GenerateMipmap(GLenum target)
1214 LOG_GL("GenerateMipmap %x\n", target);
1215 CHECK_GL( mGlAbstraction, mGlAbstraction.GenerateMipmap(target) );
1219 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1221 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1223 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1224 CHECK_GL( mGlAbstraction, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1226 mFrameBufferStateCache.FrameBuffersCreated( n, framebuffers );
1230 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1232 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1234 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1235 CHECK_GL( mGlAbstraction, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1239 * Wrapper for OpenGL ES 2.0 glGenTextures()
1241 void GenTextures(GLsizei n, GLuint* textures)
1243 LOG_GL("GenTextures %d %p\n", n, textures);
1244 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTextures(n, textures) );
1248 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1250 void GetBooleanv(GLenum pname, GLboolean* params)
1252 LOG_GL("GetBooleanv %x\n", pname);
1253 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBooleanv(pname, params) );
1257 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1259 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1261 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1262 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1266 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1268 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1270 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1271 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1275 * Wrapper for OpenGL ES 2.0 glGetError()
1277 GLenum GetError(void)
1279 // Not worth logging here
1280 return mGlAbstraction.GetError();
1284 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1286 void GetFloatv(GLenum pname, GLfloat* params)
1288 LOG_GL("GetFloatv %x\n", pname);
1289 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFloatv(pname, params) );
1293 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1295 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1297 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1298 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1302 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1304 void GetIntegerv(GLenum pname, GLint* params)
1306 LOG_GL("GetIntegerv %x\n", pname);
1307 CHECK_GL( mGlAbstraction, mGlAbstraction.GetIntegerv(pname, params) );
1311 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1313 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1315 LOG_GL("GetQueryiv %x %x\n", target, pname);
1316 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryiv(target, pname, params) );
1320 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1322 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1324 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1325 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1329 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1331 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1333 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1334 CHECK_GL( mGlAbstraction, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1338 * Wrapper for OpenGL ES 2.0 glGetString()
1340 const GLubyte* GetString(GLenum name)
1342 LOG_GL("GetString %x\n", name);
1343 const GLubyte* str = CHECK_GL( mGlAbstraction, mGlAbstraction.GetString(name) );
1348 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1350 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1352 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1353 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1357 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1359 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1361 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1362 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1366 * Wrapper for OpenGL ES 2.0 glHint()
1368 void Hint(GLenum target, GLenum mode)
1370 LOG_GL("Hint %x %x\n", target, mode);
1371 CHECK_GL( mGlAbstraction, mGlAbstraction.Hint(target, mode) );
1375 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1377 GLboolean IsBuffer(GLuint buffer)
1379 LOG_GL("IsBuffer %d\n", buffer);
1380 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsBuffer(buffer) );
1385 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1387 GLboolean IsEnabled(GLenum cap)
1389 LOG_GL("IsEnabled %x\n", cap);
1390 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsEnabled(cap) );
1395 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1397 GLboolean IsFramebuffer(GLuint framebuffer)
1399 LOG_GL("IsFramebuffer %d\n", framebuffer);
1400 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsFramebuffer(framebuffer) );
1405 * Wrapper for OpenGL ES 3.0 glIsQuery()
1407 GLboolean IsQuery(GLuint id)
1409 LOG_GL("IsQuery %u\n", id);
1410 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsQuery(id) );
1415 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1417 GLboolean IsRenderbuffer(GLuint renderbuffer)
1419 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1420 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1425 * Wrapper for OpenGL ES 2.0 glIsTexture()
1427 GLboolean IsTexture(GLuint texture)
1429 LOG_GL("IsTexture %d\n", texture);
1430 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTexture(texture) );
1435 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1437 GLboolean IsTransformFeedback(GLuint id)
1439 LOG_GL("IsTransformFeedback %u\n", id);
1440 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTransformFeedback(id) );
1445 * Wrapper for OpenGL ES 2.0 glLineWidth()
1447 void LineWidth(GLfloat width)
1449 LOG_GL("LineWidth %f\n", width);
1450 CHECK_GL( mGlAbstraction, mGlAbstraction.LineWidth(width) );
1454 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1456 void PauseTransformFeedback()
1458 LOG_GL("PauseTransformFeedback\n");
1459 CHECK_GL( mGlAbstraction, mGlAbstraction.PauseTransformFeedback() );
1463 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1465 void PixelStorei(GLenum pname, GLint param)
1467 LOG_GL("PixelStorei %x %d\n", pname, param);
1468 CHECK_GL( mGlAbstraction, mGlAbstraction.PixelStorei(pname, param) );
1472 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1474 void PolygonOffset(GLfloat factor, GLfloat units)
1476 LOG_GL("PolygonOffset %f %f\n", factor, units);
1477 CHECK_GL( mGlAbstraction, mGlAbstraction.PolygonOffset(factor, units) );
1481 * Wrapper for OpenGL ES 2.0 glReadPixels()
1483 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1485 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1486 CHECK_GL( mGlAbstraction, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1490 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1492 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1494 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1495 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1499 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1501 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1503 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1504 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1508 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1510 void ResumeTransformFeedback()
1512 LOG_GL("ResumeTransformFeedback\n");
1513 CHECK_GL( mGlAbstraction, mGlAbstraction.ResumeTransformFeedback() );
1517 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1519 void SampleCoverage(GLclampf value, GLboolean invert)
1521 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1522 CHECK_GL( mGlAbstraction, mGlAbstraction.SampleCoverage(value, invert) );
1526 * Wrapper for OpenGL ES 2.0 glScissor()
1528 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1530 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1531 CHECK_GL( mGlAbstraction, mGlAbstraction.Scissor(x, y, width, height) );
1535 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1537 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1539 if( ( func != mStencilFunc ) || ( ref != mStencilFuncRef ) || ( mask != mStencilFuncMask ) )
1541 mStencilFunc = func;
1542 mStencilFuncRef = ref;
1543 mStencilFuncMask = mask;
1545 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1546 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) );
1551 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1553 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1555 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1556 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1560 * Wrapper for OpenGL ES 2.0 glStencilMask()
1562 void StencilMask(GLuint mask)
1564 if( mask != mStencilMask )
1566 mStencilMask = mask;
1568 LOG_GL("StencilMask %d\n", mask);
1569 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMask(mask) );
1574 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1576 void StencilMaskSeparate(GLenum face, GLuint mask)
1578 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1579 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMaskSeparate(face, mask) );
1583 * Wrapper for OpenGL ES 2.0 glStencilOp()
1585 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1587 if( ( fail != mStencilOpFail ) || ( zfail != mStencilOpDepthFail ) || ( zpass != mStencilOpDepthPass ) )
1589 mStencilOpFail = fail;
1590 mStencilOpDepthFail = zfail;
1591 mStencilOpDepthPass = zpass;
1593 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1594 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1599 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1601 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1603 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1604 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1608 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1610 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1611 GLint border, GLenum format, GLenum type, const void* pixels)
1613 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1614 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1618 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1620 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1621 GLint border, GLenum format, GLenum type, const void* pixels)
1623 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1624 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1628 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1630 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1632 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1633 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterf(target, pname, param) );
1637 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1639 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1641 LOG_GL("TexParameterfv %x %x\n", target, pname);
1642 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterfv(target, pname, params) );
1646 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1648 void TexParameteri(GLenum target, GLenum pname, GLint param)
1650 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1651 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteri(target, pname, param) );
1655 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1657 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1659 LOG_GL("TexParameteriv %x %x\n", target, pname);
1660 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteriv(target, pname, params) );
1664 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1666 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1667 GLenum format, GLenum type, const void* pixels)
1669 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1670 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1674 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1676 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1677 GLsizei width, GLsizei height, GLsizei depth,
1678 GLenum format, GLenum type, const void* pixels)
1680 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);
1681 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1685 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1687 GLboolean UnmapBuffer(GLenum target)
1689 LOG_GL("UnmapBuffer %x \n", target);
1690 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.UnmapBuffer(target) );
1694 * Wrapper for OpenGL ES 2.0 glViewport()
1696 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1698 // check if its same as already set
1699 Rect<int> newViewport( x, y, width, height );
1701 // Temporarily disable the viewport caching, as the implementation of GLES driver in Tizen platform
1702 // share a global viewport between multiple contexts, therefore glViewport has to be called every
1703 // time after glBindFramebuffer regardless of the same vewport size in the same context.
1704 // if( mViewPort != newViewport )
1707 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1708 CHECK_GL( mGlAbstraction, mGlAbstraction.Viewport(x, y, width, height) );
1709 mViewPort = newViewport; // remember new one
1714 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1715 * @return The implementation defined MAX_TEXTURE_SIZE
1717 GLint CachedMaxTextureSize() const
1719 return mMaxTextureSize;
1723 * Get the current viewport.
1724 * @return Viewport rectangle.
1726 const Rect< int >& GetViewport();
1728 private: // Implementation
1731 * @return true if next draw operation will write to depth buffer
1733 bool DepthBufferWriteEnabled() const
1735 return mDepthBufferEnabled && mDepthMaskEnabled;
1739 * @return true if next draw operation will write to stencil buffer
1741 bool StencilBufferWriteEnabled() const
1743 return mStencilBufferEnabled && ( mStencilMask > 0 );
1747 * Flushes vertex attribute location changes to the driver
1749 void FlushVertexAttributeLocations();
1752 * Either enables or disables a vertex attribute location in the cache
1753 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1754 * @param location attribute location
1755 * @param state attribute state
1757 void SetVertexAttributeLocation(unsigned int location, bool state);
1760 * Sets the initial GL state.
1762 void InitializeGlState();
1766 Integration::GlAbstraction& mGlAbstraction;
1768 bool mGlContextCreated; ///< True if the OpenGL context has been created
1770 // glEnable/glDisable states
1772 GLuint mStencilMask;
1774 bool mDepthBufferEnabled;
1775 bool mDepthMaskEnabled;
1776 bool mDitherEnabled;
1777 bool mPolygonOffsetFillEnabled;
1778 bool mSampleAlphaToCoverageEnabled;
1779 bool mSampleCoverageEnabled;
1780 bool mScissorTestEnabled;
1781 bool mStencilBufferEnabled;
1782 bool mClearColorSet;
1783 bool mUsingDefaultBlendColor;
1785 // glBindBuffer() state
1786 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1787 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1788 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1790 // glBindTexture() state
1791 TextureUnit mActiveTextureUnit;
1792 GLuint mBoundTextureId[ MAX_TEXTURE_UNITS ]; ///< The ID passed to glBindTexture()
1794 // glBlendColor() state
1795 Vector4 mBlendColor; ///< Blend color
1797 // glBlendFuncSeparate() state
1798 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1799 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1800 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1801 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1803 // glBlendEquationSeparate state
1804 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1805 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1807 // glStencilFunc() and glStencilOp() state.
1808 GLenum mStencilFunc;
1809 GLint mStencilFuncRef;
1810 GLuint mStencilFuncMask;
1811 GLenum mStencilOpFail;
1812 GLenum mStencilOpDepthFail;
1813 GLenum mStencilOpDepthPass;
1815 GLenum mDepthFunction; ///The depth function
1817 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1818 Vector4 mClearColor; ///< clear color
1820 // Face culling mode
1821 Dali::FaceCullingMode::Type mCullFaceMode;
1823 // cached viewport size
1824 Rect< int > mViewPort;
1826 // Vertex Attribute Buffer enable caching
1827 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1828 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1830 FrameBufferStateCache mFrameBufferStateCache; ///< frame buffer state cache
1832 std::vector< Context* >* mSceneContexts; ///< The pointer of the container of contexts for surface rendering
1835 } // namespace Internal
1839 #endif // DALI_INTERNAL_CONTEXT_H