1 #ifndef DALI_INTERNAL_CONTEXT_H
2 #define DALI_INTERNAL_CONTEXT_H
5 * Copyright (c) 2021 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/devel-api/common/owner-container.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/integration-api/gl-abstraction.h>
25 #include <dali/integration-api/gl-defines.h>
26 #include <dali/internal/render/common/performance-monitor.h>
27 #include <dali/internal/render/gl-resources/frame-buffer-state-cache.h>
28 #include <dali/internal/render/gl-resources/gl-call-debug.h>
29 #include <dali/internal/render/gl-resources/texture-units.h>
30 #include <dali/public-api/common/dali-common.h>
31 #include <dali/public-api/common/dali-vector.h>
32 #include <dali/public-api/math/rect.h>
33 #include <dali/public-api/math/vector4.h>
34 #include <dali/public-api/rendering/renderer.h>
41 * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
42 * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
48 * FrameBuffer Clear mode
52 FORCE_CLEAR, ///< always perform the glClear regardless of current state
53 CHECK_CACHED_VALUES ///< check the Frame buffers cached state to see if a clear is required
57 * Size of the VertexAttributeArray enables
58 * GLES specification states that there's minimum of 8
60 static constexpr unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
62 static constexpr unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 8 is guaranteed, which is more than DALi uses anyways
63 static constexpr unsigned int MAX_TEXTURE_TARGET = 3; // We support only GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP and GL_TEXTURE_EXTERNAL_OES now
66 * Creates the Dali Context object for surface rendering only.
67 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
68 * @pre Context has not been created.
69 * @exception Context already created.
70 * @param glAbstraction the gl abstraction.
72 Context(Integration::GlAbstraction& glAbstraction);
75 * Creates the Dali Context object for texture (and surface rendering if required).
76 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
77 * @pre Context has not been created.
78 * @exception Context already created.
79 * @param glAbstraction the gl abstraction.
80 * @param contexts The list of scene contexts (for surface rendering)
82 Context(Integration::GlAbstraction& glAbstraction, OwnerContainer<Context*>* contexts);
90 * Called when the GL context has been created.
92 void GlContextCreated();
95 * Called when the GL context has been destroyed.
97 void GlContextDestroyed();
100 * Query whether the OpenGL context has been created.
101 * @return True if the OpenGL context has been created.
103 bool IsGlContextCreated()
105 return mGlContextCreated;
109 * @return the GLAbstraction
111 Integration::GlAbstraction& GetAbstraction()
113 return mGlAbstraction;
119 * Debug helper which prints the currently cached GL state.
121 void PrintCurrentState();
126 * Helper to convert GL error code to string
127 * @param errorCode to convert
130 const char* ErrorToString(GLenum errorCode);
133 * Helper to print GL string to debug log
135 void PrintGlString(const char* stringName, GLenum stringId)
137 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, reinterpret_cast<const char*>(GetString(stringId)));
141 * Reset the cached buffer ids.
143 void ResetBufferCache()
145 // reset the cached buffer id's
146 // fixes problem where some drivers will a generate a buffer with the
147 // same id, as the last deleted buffer id.
148 mBoundArrayBufferId = 0;
149 mBoundElementArrayBufferId = 0;
150 mBoundTransformFeedbackBufferId = 0;
154 * Reset the cached texture ids.
156 void ResetTextureCache()
158 // reset the cached texture id's in case the driver re-uses them
159 // when creating new textures
160 for(unsigned int i = 0; i < MAX_TEXTURE_UNITS; ++i)
162 for(unsigned int j = 0; j < MAX_TEXTURE_TARGET; ++j)
164 mBoundTextureId[i][j] = 0;
170 * Get an index of the cached texture list from the texture target.
171 * @param target The texture target
172 * @return The index of the cached texture list
174 static constexpr int16_t GetTextureIndexFromGlFormat(int target)
182 case GL_TEXTURE_CUBE_MAP:
186 case GL_TEXTURE_EXTERNAL_OES:
197 /****************************************************************************************
198 * The following methods are forwarded to Dali::Integration::GlAbstraction.
199 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
200 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
201 * handles them and optimizes any program related state changes
202 ****************************************************************************************/
205 * Wrapper for IsSurfacelessContextSupported of Dali::Integration::GlAbstraction
207 bool IsSurfacelessContextSupported() const
209 return mGlAbstraction.IsSurfacelessContextSupported();
213 * Wrapper for TextureRequiresConverting of Dali::Integration::GlAbstraction
215 bool TextureRequiresConverting(const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage) const
217 return mGlAbstraction.TextureRequiresConverting(imageGlFormat, textureGlFormat, isSubImage);
221 * Wrapper for OpenGL ES 2.0 glActiveTexture()
223 void ActiveTexture(TextureUnit textureUnit)
225 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
226 mActiveTextureUnit = textureUnit;
227 LOG_GL("ActiveTexture %x\n", textureUnit);
228 CHECK_GL(mGlAbstraction, mGlAbstraction.ActiveTexture(TextureUnitAsGLenum(textureUnit)));
232 * Wrapper for OpenGL ES 3.0 glBeginQuery()
234 void BeginQuery(GLenum target, GLuint id)
236 LOG_GL("BeginQuery %d %d\n", target, id);
237 CHECK_GL(mGlAbstraction, mGlAbstraction.BeginQuery(target, id));
241 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
243 void BeginTransformFeedback(GLenum primitiveMode)
245 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
246 CHECK_GL(mGlAbstraction, mGlAbstraction.BeginTransformFeedback(primitiveMode));
250 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
254 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
256 void BindArrayBuffer(GLuint buffer)
258 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
259 mBoundArrayBufferId = buffer;
261 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
262 CHECK_GL(mGlAbstraction, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer));
266 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
268 void BindElementArrayBuffer(GLuint buffer)
270 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
271 mBoundElementArrayBufferId = buffer;
273 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
274 CHECK_GL(mGlAbstraction, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer));
278 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
280 void BindTransformFeedbackBuffer(GLuint buffer)
282 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
283 mBoundTransformFeedbackBufferId = buffer;
285 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
286 CHECK_GL(mGlAbstraction, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buffer));
290 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
292 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
294 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
295 mBoundTransformFeedbackBufferId = buffer;
297 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
298 CHECK_GL(mGlAbstraction, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer));
302 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
304 void BindFramebuffer(GLenum target, GLuint framebuffer)
306 mFrameBufferStateCache.SetCurrentFrameBuffer(framebuffer);
308 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
309 CHECK_GL(mGlAbstraction, mGlAbstraction.BindFramebuffer(target, framebuffer));
313 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
315 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
317 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
318 CHECK_GL(mGlAbstraction, mGlAbstraction.BindRenderbuffer(target, renderbuffer));
322 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
324 void BindTransformFeedback(GLenum target, GLuint id)
326 LOG_GL("BindTransformFeedback %d %d\n", target, id);
327 CHECK_GL(mGlAbstraction, mGlAbstraction.BindTransformFeedback(target, id));
331 * Helper to bind texture for rendering. If given texture is
332 * already bound in the given textureunit, this method does nothing.
333 * Otherwise changes the active texture unit and binds the texture.
334 * Note! after this call active texture unit may not necessarily be the one
335 * passed in as argument so you cannot change texture unit state!!
336 * @param textureunit to bind to
337 * @param texture to bind
339 void BindTextureForUnit(TextureUnit textureunit, int target, GLuint texture)
341 ActiveTexture(textureunit);
342 BindTexture(target, texture);
346 * Wrapper for OpenGL ES 2.0 glBindTexture( target )
348 void BindTexture(int target, GLuint texture)
350 int16_t index = GetTextureIndexFromGlFormat(target);
353 mBoundTextureId[mActiveTextureUnit][index] = texture;
356 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
357 LOG_GL("BindTexture target(%d) %d\n", target, texture);
358 CHECK_GL(mGlAbstraction, mGlAbstraction.BindTexture(target, texture));
362 * Wrapper for OpenGL ES 2.0 glBlendColor()
364 void SetDefaultBlendColor()
366 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
367 SetCustomBlendColor(Color::TRANSPARENT);
368 mUsingDefaultBlendColor = true;
372 * Wrapper for OpenGL ES 2.0 glBlendColor()
374 void SetCustomBlendColor(const Vector4& color)
376 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
377 LOG_GL("BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a);
378 CHECK_GL(mGlAbstraction, mGlAbstraction.BlendColor(color.r, color.g, color.b, color.a));
379 mUsingDefaultBlendColor = false;
384 * Wrapper for OpenGL ES 2.0 glBlendEquation()
386 void BlendEquation(GLenum mode)
388 // DO NOT USE BlendEquationSeparate to set the same rgb and alpha modes
389 // KHR blending extensions require use of glBlendEquation
391 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
392 mBlendEquationSeparateModeRGB = mode;
393 mBlendEquationSeparateModeAlpha = mode;
394 LOG_GL("BlendEquation %d\n", mode);
395 CHECK_GL(mGlAbstraction, mGlAbstraction.BlendEquation(mode));
399 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
401 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
403 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
404 mBlendEquationSeparateModeRGB = modeRGB;
405 mBlendEquationSeparateModeAlpha = modeAlpha;
406 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
407 CHECK_GL(mGlAbstraction, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha));
411 * Wrapper for OpenGL ES 2.0 glBlendFunc()
413 void BlendFunc(GLenum sfactor, GLenum dfactor)
415 // reuse the BlendFuncSeparate as thats what the DDK does anyways
416 BlendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
420 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
422 void BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
424 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
425 mBlendFuncSeparateSrcRGB = srcRGB;
426 mBlendFuncSeparateDstRGB = dstRGB;
427 mBlendFuncSeparateSrcAlpha = srcAlpha;
428 mBlendFuncSeparateDstAlpha = dstAlpha;
430 LOG_GL("BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha);
431 CHECK_GL(mGlAbstraction, mGlAbstraction.BlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha));
435 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
437 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
439 LOG_GL("BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
440 CHECK_GL(mGlAbstraction, mGlAbstraction.BlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter));
444 * Wrapper for OpenGL ES 2.0 glBufferData()
446 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
448 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
449 CHECK_GL(mGlAbstraction, mGlAbstraction.BufferData(target, size, data, usage));
453 * Wrapper for OpenGL ES 2.0 glBufferSubData()
455 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
457 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
458 CHECK_GL(mGlAbstraction, mGlAbstraction.BufferSubData(target, offset, size, data));
462 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
464 GLenum CheckFramebufferStatus(GLenum target)
466 LOG_GL("CheckFramebufferStatus %d\n", target);
467 GLenum value = CHECK_GL(mGlAbstraction, mGlAbstraction.CheckFramebufferStatus(target));
472 * Wrapper for OpenGL ES 2.0 glClear()
474 void Clear(GLbitfield mask, ClearMode mode)
476 bool forceClear = (mode == FORCE_CLEAR);
477 mask = mFrameBufferStateCache.GetClearMask(mask, forceClear, mScissorTestEnabled);
479 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
480 LOG_GL("Clear %d\n", mask);
481 CHECK_GL(mGlAbstraction, mGlAbstraction.Clear(mask));
485 * Wrapper for OpenGL ES 2.0 glClearColor()
487 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
489 Vector4 newCol(red, green, blue, alpha);
491 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
492 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
493 CHECK_GL(mGlAbstraction, mGlAbstraction.ClearColor(red, green, blue, alpha));
495 mClearColorSet = true;
496 mClearColor = newCol;
500 * Wrapper for OpenGL ES 2.0 glClearDepthf()
502 void ClearDepthf(GLclampf depth)
504 LOG_GL("ClearDepthf %f\n", depth);
505 CHECK_GL(mGlAbstraction, mGlAbstraction.ClearDepthf(depth));
509 * Wrapper for OpenGL ES 2.0 glClearStencil()
511 void ClearStencil(GLint s)
513 LOG_GL("ClearStencil %d\n", s);
514 CHECK_GL(mGlAbstraction, mGlAbstraction.ClearStencil(s));
518 * Wrapper for OpenGL ES 2.0 glColorMask()
519 * @note This has been optimized to a single boolean value (masking individual channels is not required)
521 void ColorMask(bool flag)
523 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
525 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
526 CHECK_GL(mGlAbstraction, mGlAbstraction.ColorMask(flag, flag, flag, flag));
530 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
532 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data)
534 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
535 CHECK_GL(mGlAbstraction, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data));
539 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
541 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void* data)
543 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
544 CHECK_GL(mGlAbstraction, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data));
548 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
550 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* data)
552 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
553 CHECK_GL(mGlAbstraction, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data));
557 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
559 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void* data)
561 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);
562 CHECK_GL(mGlAbstraction, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data));
566 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
568 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
570 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
571 CHECK_GL(mGlAbstraction, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border));
575 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
577 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
579 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
580 CHECK_GL(mGlAbstraction, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height));
584 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
586 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
588 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
589 CHECK_GL(mGlAbstraction, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height));
593 * Wrapper for OpenGL ES 2.0 glCullFace()
594 * enables GL_CULL_FACE if in any of the face culling modes
595 * otherwise disables GL_CULL_FACE
597 void CullFace(Dali::FaceCullingMode::Type mode)
599 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
600 mCullFaceMode = mode;
603 case Dali::FaceCullingMode::NONE:
605 LOG_GL("Disable GL_CULL_FACE\n");
606 CHECK_GL(mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE));
610 case Dali::FaceCullingMode::FRONT:
612 LOG_GL("Enable GL_CULL_FACE\n");
613 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE));
614 LOG_GL("Enable GL_FRONT\n");
615 CHECK_GL(mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT));
619 case Dali::FaceCullingMode::BACK:
621 LOG_GL("Enable GL_CULL_FACE\n");
622 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE));
623 LOG_GL("Enable GL_BACK\n");
624 CHECK_GL(mGlAbstraction, mGlAbstraction.CullFace(GL_BACK));
628 case Dali::FaceCullingMode::FRONT_AND_BACK:
630 LOG_GL("Enable GL_CULL_FACE\n");
631 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE));
632 LOG_GL("Enable GL_FRONT_AND_BACK\n");
633 CHECK_GL(mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT_AND_BACK));
643 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
645 void DeleteBuffers(GLsizei n, const GLuint* buffers)
647 if(this->IsGlContextCreated())
649 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
650 CHECK_GL(mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers));
655 // Need to reset the buffer cache in the surface contexts
656 // This will only be executed by the surfaceless context when there are contexts for surface rendering
659 for(auto&& context : *mSceneContexts)
663 context->ResetBufferCache();
670 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
672 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
674 mFrameBufferStateCache.FrameBuffersDeleted(n, framebuffers);
676 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
677 CHECK_GL(mGlAbstraction, mGlAbstraction.DeleteFramebuffers(n, framebuffers));
681 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
683 void DeleteQueries(GLsizei n, GLuint* ids)
685 LOG_GL("DeleteQueries %d %p\n", n, ids);
686 CHECK_GL(mGlAbstraction, mGlAbstraction.DeleteQueries(n, ids));
690 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
692 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
694 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
695 CHECK_GL(mGlAbstraction, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers));
699 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
701 void DeleteTextures(GLsizei n, const GLuint* textures)
703 LOG_GL("DeleteTextures %d %p\n", n, textures);
704 CHECK_GL(mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures));
708 // Need to reset the texture cache in the scene contexts
709 // This will only be executed by the surfaceless context when there are contexts for surface rendering
712 for(auto&& context : *mSceneContexts)
716 context->ResetTextureCache();
723 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
725 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
727 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
728 CHECK_GL(mGlAbstraction, mGlAbstraction.DeleteTransformFeedbacks(n, ids));
732 * Wrapper for OpenGL ES 2.0 glDepthFunc()
734 void DepthFunc(GLenum func)
736 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
737 mDepthFunction = func;
738 LOG_GL("DepthFunc %x\n", func);
739 CHECK_GL(mGlAbstraction, mGlAbstraction.DepthFunc(func));
743 * Wrapper for OpenGL ES 2.0 glDepthMask()
745 void DepthMask(GLboolean flag)
747 bool booleanFlag = flag != GL_FALSE;
749 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
750 mDepthMaskEnabled = booleanFlag;
751 LOG_GL("DepthMask %s\n", booleanFlag ? "True" : "False");
752 CHECK_GL(mGlAbstraction, mGlAbstraction.DepthMask(mDepthMaskEnabled));
756 * Wrapper for OpenGL ES 2.0 glDepthRangef()
758 void DepthRangef(GLclampf zNear, GLclampf zFar)
760 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
761 CHECK_GL(mGlAbstraction, mGlAbstraction.DepthRangef(zNear, zFar));
765 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
766 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
770 * Wrapper for OpenGL ES 2.0 glDrawArrays()
772 void DrawArrays(GLenum mode, GLint first, GLsizei count)
774 mFrameBufferStateCache.DrawOperation(mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled());
775 FlushVertexAttributeLocations();
777 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
778 CHECK_GL(mGlAbstraction, mGlAbstraction.DrawArrays(mode, first, count));
782 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
784 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
786 mFrameBufferStateCache.DrawOperation(mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled());
787 FlushVertexAttributeLocations();
789 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
790 CHECK_GL(mGlAbstraction, mGlAbstraction.DrawArraysInstanced(mode, first, count, instanceCount));
794 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
796 void DrawBuffers(GLsizei n, const GLenum* bufs)
798 mFrameBufferStateCache.DrawOperation(mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled());
799 LOG_GL("DrawBuffers %d %p\n", n, bufs);
800 CHECK_GL(mGlAbstraction, mGlAbstraction.DrawBuffers(n, bufs));
804 * Wrapper for OpenGL ES 2.0 glDrawElements()
806 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
808 mFrameBufferStateCache.DrawOperation(mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled());
810 FlushVertexAttributeLocations();
812 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
813 CHECK_GL(mGlAbstraction, mGlAbstraction.DrawElements(mode, count, type, indices));
817 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
819 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
821 mFrameBufferStateCache.DrawOperation(mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled());
823 FlushVertexAttributeLocations();
825 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
826 CHECK_GL(mGlAbstraction, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount));
830 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
832 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
834 mFrameBufferStateCache.DrawOperation(mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled());
835 FlushVertexAttributeLocations();
837 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
838 CHECK_GL(mGlAbstraction, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices));
842 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
844 void GenQueries(GLsizei n, GLuint* ids)
846 LOG_GL("GenQueries %d %p\n", n, ids);
847 CHECK_GL(mGlAbstraction, mGlAbstraction.GenQueries(n, ids));
851 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
853 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
855 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
856 CHECK_GL(mGlAbstraction, mGlAbstraction.GenTransformFeedbacks(n, ids));
860 * @return the current buffer bound for a given target
862 GLuint GetCurrentBoundArrayBuffer(GLenum target)
867 case GL_ARRAY_BUFFER:
869 result = mBoundArrayBufferId;
872 case GL_ELEMENT_ARRAY_BUFFER:
874 result = mBoundElementArrayBufferId;
877 case GL_TRANSFORM_FEEDBACK_BUFFER:
879 result = mBoundTransformFeedbackBufferId;
884 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
890 void EnableVertexAttributeArray(GLuint location)
892 SetVertexAttributeLocation(location, true);
895 void DisableVertexAttributeArray(GLuint location)
897 SetVertexAttributeLocation(location, false);
901 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
903 void VertexAttribDivisor(GLuint index, GLuint divisor)
905 LOG_GL("VertexAttribDivisor(%d, %d)\n", index, divisor);
906 CHECK_GL(mGlAbstraction, mGlAbstraction.VertexAttribDivisor(index, divisor));
910 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
912 void VertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr)
914 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr);
915 CHECK_GL(mGlAbstraction, mGlAbstraction.VertexAttribPointer(index, size, type, normalized, stride, ptr));
919 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
921 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
923 LOG_GL("InvalidateFramebuffer\n");
924 CHECK_GL(mGlAbstraction, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments));
928 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
929 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
933 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
934 * @param[in] enable True if GL_BLEND should be enabled.
936 void SetBlend(bool enable)
938 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
939 mBlendEnabled = enable;
943 LOG_GL("Enable GL_BLEND\n");
944 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_BLEND));
948 LOG_GL("Disable GL_BLEND\n");
949 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 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
964 mDepthBufferEnabled = enable;
968 LOG_GL("Enable GL_DEPTH_TEST\n");
969 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_DEPTH_TEST));
973 LOG_GL("Disable GL_DEPTH_TEST\n");
974 CHECK_GL(mGlAbstraction, mGlAbstraction.Disable(GL_DEPTH_TEST));
979 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
980 * @param[in] enable True if GL_DITHER should be enabled.
982 void SetDither(bool enable)
984 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
985 mDitherEnabled = enable;
989 LOG_GL("Enable GL_DITHER\n");
990 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_DITHER));
994 LOG_GL("Disable GL_DITHER\n");
995 CHECK_GL(mGlAbstraction, mGlAbstraction.Disable(GL_DITHER));
1000 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
1001 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
1003 void SetPolygonOffsetFill(bool enable)
1005 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
1006 mPolygonOffsetFillEnabled = enable;
1010 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
1011 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL));
1015 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
1016 CHECK_GL(mGlAbstraction, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL));
1021 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
1022 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
1024 void SetSampleAlphaToCoverage(bool enable)
1026 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
1027 mSampleAlphaToCoverageEnabled = enable;
1031 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1032 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE));
1036 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
1037 CHECK_GL(mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE));
1042 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
1043 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
1045 void SetSampleCoverage(bool enable)
1047 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
1048 mSampleCoverageEnabled = enable;
1052 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
1053 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE));
1057 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
1058 CHECK_GL(mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE));
1063 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
1064 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
1066 void SetScissorTest(bool enable)
1068 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
1069 mScissorTestEnabled = enable;
1073 LOG_GL("Enable GL_SCISSOR_TEST\n");
1074 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_SCISSOR_TEST));
1078 LOG_GL("Disable GL_SCISSOR_TEST\n");
1079 CHECK_GL(mGlAbstraction, mGlAbstraction.Disable(GL_SCISSOR_TEST));
1084 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1085 * Note GL_STENCIL_TEST means enable the stencil buffer for writing and or testing.
1086 * glStencilMask is used to control how bits are written to the stencil buffer.
1087 * glStencilFunc is used to control if testing is enabled and how it is performed ( default GL_ALWAYS )
1088 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1090 void EnableStencilBuffer(bool enable)
1092 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
1093 mStencilBufferEnabled = enable;
1097 LOG_GL("Enable GL_STENCIL_TEST\n");
1098 CHECK_GL(mGlAbstraction, mGlAbstraction.Enable(GL_STENCIL_TEST));
1102 LOG_GL("Disable GL_STENCIL_TEST\n");
1103 CHECK_GL(mGlAbstraction, mGlAbstraction.Disable(GL_STENCIL_TEST));
1108 * Wrapper for OpenGL ES 3.0 glEndQuery()
1110 void EndQuery(GLenum target)
1112 LOG_GL("EndQuery %d\n", target);
1113 CHECK_GL(mGlAbstraction, mGlAbstraction.EndQuery(target));
1117 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1119 void EndTransformFeedback()
1121 LOG_GL("EndTransformFeedback\n");
1122 CHECK_GL(mGlAbstraction, mGlAbstraction.EndTransformFeedback());
1126 * Wrapper for OpenGL ES 2.0 glFinish()
1131 CHECK_GL(mGlAbstraction, mGlAbstraction.Finish());
1135 * Wrapper for OpenGL ES 2.0 glFlush()
1140 CHECK_GL(mGlAbstraction, mGlAbstraction.Flush());
1144 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1146 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1148 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1149 CHECK_GL(mGlAbstraction, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer));
1153 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1155 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1157 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1158 CHECK_GL(mGlAbstraction, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level));
1162 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1164 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1166 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1167 CHECK_GL(mGlAbstraction, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer));
1171 * Wrapper for OpenGL ES 2.0 glFrontFace()
1173 void FrontFace(GLenum mode)
1175 LOG_GL("FrontFace %x\n", mode);
1176 CHECK_GL(mGlAbstraction, mGlAbstraction.FrontFace(mode));
1180 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1182 void GenBuffers(GLsizei n, GLuint* buffers)
1184 LOG_GL("GenBuffers %d\n", n, buffers);
1185 CHECK_GL(mGlAbstraction, mGlAbstraction.GenBuffers(n, buffers));
1189 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1191 void GenerateMipmap(GLenum target)
1193 LOG_GL("GenerateMipmap %x\n", target);
1194 CHECK_GL(mGlAbstraction, mGlAbstraction.GenerateMipmap(target));
1198 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1200 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1202 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1203 CHECK_GL(mGlAbstraction, mGlAbstraction.GenFramebuffers(n, framebuffers));
1205 mFrameBufferStateCache.FrameBuffersCreated(n, framebuffers);
1209 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1211 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1213 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1214 CHECK_GL(mGlAbstraction, mGlAbstraction.GenRenderbuffers(n, renderbuffers));
1218 * Wrapper for OpenGL ES 2.0 glGenTextures()
1220 void GenTextures(GLsizei n, GLuint* textures)
1222 LOG_GL("GenTextures %d %p\n", n, textures);
1223 CHECK_GL(mGlAbstraction, mGlAbstraction.GenTextures(n, textures));
1227 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1229 void GetBooleanv(GLenum pname, GLboolean* params)
1231 LOG_GL("GetBooleanv %x\n", pname);
1232 CHECK_GL(mGlAbstraction, mGlAbstraction.GetBooleanv(pname, params));
1236 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1238 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1240 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1241 CHECK_GL(mGlAbstraction, mGlAbstraction.GetBufferParameteriv(target, pname, params));
1245 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1247 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1249 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1250 CHECK_GL(mGlAbstraction, mGlAbstraction.GetBufferPointerv(target, pname, params));
1254 * Wrapper for OpenGL ES 2.0 glGetError()
1256 GLenum GetError(void)
1258 // Not worth logging here
1259 return mGlAbstraction.GetError();
1263 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1265 void GetFloatv(GLenum pname, GLfloat* params)
1267 LOG_GL("GetFloatv %x\n", pname);
1268 CHECK_GL(mGlAbstraction, mGlAbstraction.GetFloatv(pname, params));
1272 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1274 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1276 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1277 CHECK_GL(mGlAbstraction, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params));
1281 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1283 void GetIntegerv(GLenum pname, GLint* params)
1285 LOG_GL("GetIntegerv %x\n", pname);
1286 CHECK_GL(mGlAbstraction, mGlAbstraction.GetIntegerv(pname, params));
1290 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1292 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1294 LOG_GL("GetQueryiv %x %x\n", target, pname);
1295 CHECK_GL(mGlAbstraction, mGlAbstraction.GetQueryiv(target, pname, params));
1299 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1301 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1303 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1304 CHECK_GL(mGlAbstraction, mGlAbstraction.GetQueryObjectuiv(id, pname, params));
1308 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1310 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1312 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1313 CHECK_GL(mGlAbstraction, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params));
1317 * Wrapper for OpenGL ES 2.0 glGetString()
1319 const GLubyte* GetString(GLenum name)
1321 LOG_GL("GetString %x\n", name);
1322 const GLubyte* str = CHECK_GL(mGlAbstraction, mGlAbstraction.GetString(name));
1327 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1329 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1331 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1332 CHECK_GL(mGlAbstraction, mGlAbstraction.GetTexParameterfv(target, pname, params));
1336 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1338 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1340 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1341 CHECK_GL(mGlAbstraction, mGlAbstraction.GetTexParameteriv(target, pname, params));
1345 * Wrapper for OpenGL ES 2.0 glHint()
1347 void Hint(GLenum target, GLenum mode)
1349 LOG_GL("Hint %x %x\n", target, mode);
1350 CHECK_GL(mGlAbstraction, mGlAbstraction.Hint(target, mode));
1354 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1356 GLboolean IsBuffer(GLuint buffer)
1358 LOG_GL("IsBuffer %d\n", buffer);
1359 GLboolean val = CHECK_GL(mGlAbstraction, mGlAbstraction.IsBuffer(buffer));
1364 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1366 GLboolean IsEnabled(GLenum cap)
1368 LOG_GL("IsEnabled %x\n", cap);
1369 GLboolean val = CHECK_GL(mGlAbstraction, mGlAbstraction.IsEnabled(cap));
1374 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1376 GLboolean IsFramebuffer(GLuint framebuffer)
1378 LOG_GL("IsFramebuffer %d\n", framebuffer);
1379 GLboolean val = CHECK_GL(mGlAbstraction, mGlAbstraction.IsFramebuffer(framebuffer));
1384 * Wrapper for OpenGL ES 3.0 glIsQuery()
1386 GLboolean IsQuery(GLuint id)
1388 LOG_GL("IsQuery %u\n", id);
1389 GLboolean val = CHECK_GL(mGlAbstraction, mGlAbstraction.IsQuery(id));
1394 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1396 GLboolean IsRenderbuffer(GLuint renderbuffer)
1398 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1399 GLboolean val = CHECK_GL(mGlAbstraction, mGlAbstraction.IsRenderbuffer(renderbuffer));
1404 * Wrapper for OpenGL ES 2.0 glIsTexture()
1406 GLboolean IsTexture(GLuint texture)
1408 LOG_GL("IsTexture %d\n", texture);
1409 GLboolean val = CHECK_GL(mGlAbstraction, mGlAbstraction.IsTexture(texture));
1414 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1416 GLboolean IsTransformFeedback(GLuint id)
1418 LOG_GL("IsTransformFeedback %u\n", id);
1419 GLboolean val = CHECK_GL(mGlAbstraction, mGlAbstraction.IsTransformFeedback(id));
1424 * Wrapper for OpenGL ES 2.0 glLineWidth()
1426 void LineWidth(GLfloat width)
1428 LOG_GL("LineWidth %f\n", width);
1429 CHECK_GL(mGlAbstraction, mGlAbstraction.LineWidth(width));
1433 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1435 void PauseTransformFeedback()
1437 LOG_GL("PauseTransformFeedback\n");
1438 CHECK_GL(mGlAbstraction, mGlAbstraction.PauseTransformFeedback());
1442 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1444 void PixelStorei(GLenum pname, GLint param)
1446 LOG_GL("PixelStorei %x %d\n", pname, param);
1447 CHECK_GL(mGlAbstraction, mGlAbstraction.PixelStorei(pname, param));
1451 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1453 void PolygonOffset(GLfloat factor, GLfloat units)
1455 LOG_GL("PolygonOffset %f %f\n", factor, units);
1456 CHECK_GL(mGlAbstraction, mGlAbstraction.PolygonOffset(factor, units));
1460 * Wrapper for OpenGL ES 2.0 glReadPixels()
1462 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1464 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1465 CHECK_GL(mGlAbstraction, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels));
1469 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1471 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1473 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1474 CHECK_GL(mGlAbstraction, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height));
1478 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1480 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1482 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1483 CHECK_GL(mGlAbstraction, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height));
1487 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1489 void ResumeTransformFeedback()
1491 LOG_GL("ResumeTransformFeedback\n");
1492 CHECK_GL(mGlAbstraction, mGlAbstraction.ResumeTransformFeedback());
1496 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1498 void SampleCoverage(GLclampf value, GLboolean invert)
1500 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1501 CHECK_GL(mGlAbstraction, mGlAbstraction.SampleCoverage(value, invert));
1505 * Wrapper for OpenGL ES 2.0 glScissor()
1507 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1509 GLint cx, cy, cw, ch;
1511 // scissor's value should be set based on the default system coordinates.
1512 // when the surface is rotated, the input valus already were set with the rotated angle.
1513 // So, re-calculation is needed.
1514 if(mSurfaceOrientation == 90)
1516 cx = mViewPort.height - (y + height);
1521 else if(mSurfaceOrientation == 180)
1523 cx = mViewPort.width - (x + width);
1524 cy = mViewPort.height - (y + height);
1528 else if(mSurfaceOrientation == 270)
1531 cy = mViewPort.width - (x + width);
1543 LOG_GL("Scissor %d %d %d %d\n", cx, cy, cw, ch);
1544 CHECK_GL(mGlAbstraction, mGlAbstraction.Scissor(cx, cy, cw, ch));
1548 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1550 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1552 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
1553 mStencilFunc = func;
1554 mStencilFuncRef = ref;
1555 mStencilFuncMask = mask;
1557 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1558 CHECK_GL(mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask));
1562 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1564 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1566 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1567 CHECK_GL(mGlAbstraction, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask));
1571 * Wrapper for OpenGL ES 2.0 glStencilMask()
1573 void StencilMask(GLuint mask)
1575 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
1576 mStencilMask = mask;
1578 LOG_GL("StencilMask %d\n", mask);
1579 CHECK_GL(mGlAbstraction, mGlAbstraction.StencilMask(mask));
1583 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1585 void StencilMaskSeparate(GLenum face, GLuint mask)
1587 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1588 CHECK_GL(mGlAbstraction, mGlAbstraction.StencilMaskSeparate(face, mask));
1592 * Wrapper for OpenGL ES 2.0 glStencilOp()
1594 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1596 // TODO: Temporarily removed caching and will need to add it back to avoid unnecessary GL call.
1597 mStencilOpFail = fail;
1598 mStencilOpDepthFail = zfail;
1599 mStencilOpDepthPass = zpass;
1601 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1602 CHECK_GL(mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass));
1606 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1608 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1610 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1611 CHECK_GL(mGlAbstraction, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass));
1615 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1617 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels)
1619 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1620 CHECK_GL(mGlAbstraction, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels));
1624 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1626 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void* pixels)
1628 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1629 CHECK_GL(mGlAbstraction, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels));
1633 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1635 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1637 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1638 CHECK_GL(mGlAbstraction, mGlAbstraction.TexParameterf(target, pname, param));
1642 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1644 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1646 LOG_GL("TexParameterfv %x %x\n", target, pname);
1647 CHECK_GL(mGlAbstraction, mGlAbstraction.TexParameterfv(target, pname, params));
1651 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1653 void TexParameteri(GLenum target, GLenum pname, GLint param)
1655 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1656 CHECK_GL(mGlAbstraction, mGlAbstraction.TexParameteri(target, pname, param));
1660 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1662 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1664 LOG_GL("TexParameteriv %x %x\n", target, pname);
1665 CHECK_GL(mGlAbstraction, mGlAbstraction.TexParameteriv(target, pname, params));
1669 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1671 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels)
1673 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1674 CHECK_GL(mGlAbstraction, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels));
1678 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1680 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void* pixels)
1682 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);
1683 CHECK_GL(mGlAbstraction, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels));
1687 * Wrapper for OpenGL ES 3.0 glUnmapBuffer()
1689 GLboolean UnmapBuffer(GLenum target)
1691 LOG_GL("UnmapBuffer %x \n", target);
1692 GLboolean val = CHECK_GL(mGlAbstraction, mGlAbstraction.UnmapBuffer(target));
1697 * Wrapper for OpenGL ES 2.0 glViewport()
1699 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1701 // check if its same as already set
1704 // viewport's value shoud be set based on the default system size.
1705 // when the surface is rotated, the input width and height already were swapped.
1706 // So, re-swapping is needed.
1707 if(mSurfaceOrientation == 90 || mSurfaceOrientation == 270)
1718 // User uses the rotated viewport size.
1719 Rect<int> newViewport(x, y, width, height);
1721 // Temporarily disable the viewport caching, as the implementation of GLES driver in Tizen platform
1722 // share a global viewport between multiple contexts, therefore glViewport has to be called every
1723 // time after glBindFramebuffer regardless of the same vewport size in the same context.
1724 // if( mViewPort != newViewport )
1727 LOG_GL("Viewport %d %d %d %d\n", x, y, cw, ch);
1728 CHECK_GL(mGlAbstraction, mGlAbstraction.Viewport(x, y, cw, ch));
1729 mViewPort = newViewport; // remember new one
1734 * Wrapper for OpenGL ES 3.2 and GL_KHR_blend_equation_advanced extention glBlendBarrier()
1738 LOG_GL("BlendBarrier\n");
1739 CHECK_GL(mGlAbstraction, mGlAbstraction.BlendBarrier());
1743 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1744 * @return The implementation defined MAX_TEXTURE_SIZE
1746 GLint CachedMaxTextureSize() const
1748 return mMaxTextureSize;
1751 void SetSurfaceOrientation(int orientation)
1753 LOG_GL("SetSurfaceOrientation: orientation: %d\n", orientation);
1754 mSurfaceOrientation = orientation;
1758 * Get the current viewport.
1759 * @return Viewport rectangle.
1761 const Rect<int>& GetViewport();
1763 private: // Implementation
1765 * @return true if next draw operation will write to depth buffer
1767 bool DepthBufferWriteEnabled() const
1769 return mDepthBufferEnabled && mDepthMaskEnabled;
1773 * @return true if next draw operation will write to stencil buffer
1775 bool StencilBufferWriteEnabled() const
1777 return mStencilBufferEnabled && (mStencilMask > 0);
1781 * Flushes vertex attribute location changes to the driver
1783 void FlushVertexAttributeLocations();
1786 * Either enables or disables a vertex attribute location in the cache
1787 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1788 * @param location attribute location
1789 * @param state attribute state
1791 void SetVertexAttributeLocation(unsigned int location, bool state);
1794 * Sets the initial GL state.
1796 void InitializeGlState();
1799 Integration::GlAbstraction& mGlAbstraction;
1801 bool mGlContextCreated; ///< True if the OpenGL context has been created
1803 // glEnable/glDisable states
1805 GLuint mStencilMask;
1807 bool mDepthBufferEnabled;
1808 bool mDepthMaskEnabled;
1809 bool mDitherEnabled;
1810 bool mPolygonOffsetFillEnabled;
1811 bool mSampleAlphaToCoverageEnabled;
1812 bool mSampleCoverageEnabled;
1813 bool mScissorTestEnabled;
1814 bool mStencilBufferEnabled;
1815 bool mClearColorSet;
1816 bool mUsingDefaultBlendColor;
1818 // glBindBuffer() state
1819 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1820 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1821 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1823 // glBindTexture() state
1824 TextureUnit mActiveTextureUnit;
1825 GLuint mBoundTextureId[MAX_TEXTURE_UNITS][MAX_TEXTURE_TARGET]; ///< The ID passed to glBindTexture()
1827 // glBlendColor() state
1828 Vector4 mBlendColor; ///< Blend color
1830 // glBlendFuncSeparate() state
1831 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1832 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1833 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1834 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1836 // glBlendEquationSeparate state
1837 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1838 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1840 // glStencilFunc() and glStencilOp() state.
1841 GLenum mStencilFunc;
1842 GLint mStencilFuncRef;
1843 GLuint mStencilFuncMask;
1844 GLenum mStencilOpFail;
1845 GLenum mStencilOpDepthFail;
1846 GLenum mStencilOpDepthPass;
1848 GLenum mDepthFunction; ///The depth function
1850 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1851 Vector4 mClearColor; ///< clear color
1853 // Face culling mode
1854 Dali::FaceCullingMode::Type mCullFaceMode;
1856 // cached viewport size
1857 Rect<int> mViewPort;
1859 // Vertex Attribute Buffer enable caching
1860 bool mVertexAttributeCachedState[MAX_ATTRIBUTE_CACHE_SIZE]; ///< Value cache for Enable Vertex Attribute
1861 bool mVertexAttributeCurrentState[MAX_ATTRIBUTE_CACHE_SIZE]; ///< Current state on the driver for Enable Vertex Attribute
1863 FrameBufferStateCache mFrameBufferStateCache; ///< frame buffer state cache
1865 OwnerContainer<Context*>* mSceneContexts; ///< The pointer of the container of contexts for surface rendering
1867 int mSurfaceOrientation;
1870 } // namespace Internal
1874 #endif // DALI_INTERNAL_CONTEXT_H