1 #ifndef __DALI_INTERNAL_CONTEXT_H__
2 #define __DALI_INTERNAL_CONTEXT_H__
5 * Copyright (c) 2014 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/integration-api/gl-defines.h>
23 #include <dali/public-api/common/map-wrapper.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/actors/renderable-actor.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/integration-api/gl-abstraction.h>
28 #include <dali/internal/render/common/performance-monitor.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/math/rect.h>
31 #include <dali/public-api/math/vector4.h>
39 class Program; // to be able to cache programs
41 // wrap gl calls with CHECK_GL eg "CHECK_GL( *this, glBindTexture(textureId) );"
42 // will LOG any glErrors eg "glError (0x0501) GL_INVALID_VALUE - glBindTexture(textureId)"
43 // only enable if specifically enabled as it slows down GL a lot!
44 #ifdef DALI_GL_ERROR_CHECK
45 #define CHECK_GL(c,a) (a); (c).CheckGlError(#a)
47 #define CHECK_GL(c,a) (a)
50 // Don't put guards around here (LOG_INFO has it's own guards)
51 #define LOG_GL(format, args...) \
52 DALI_LOG_INFO(Context::gGlLogFilter, Debug::General, format, ## args)
55 * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
56 * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
62 * Size of the VertexAttributeArray enables
63 * GLES specification states that there's minimum of 8
65 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
68 * Creates the Dali Context object.
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 );
82 * Called when the GL context has been created.
84 void GlContextCreated();
87 * Called when the GL context has been destroyed.
89 void GlContextDestroyed();
92 * Query whether the OpenGL context has been created.
93 * @return True if the OpenGL context has been created.
95 bool IsGlContextCreated() { return mGlContextCreated; }
98 * @return the GLAbstraction
100 Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
102 #ifdef DALI_CONTEXT_LOGGING
105 * Debug helper which prints the currently cached GL state.
107 void PrintCurrentState();
112 * Helper to convert GL error code to string
113 * @param errorCode to convert
116 const char* ErrorToString( GLenum errorCode );
119 * Helper to check GL error during an operation
120 * @param operation that was performed
122 void CheckGlError( const char* operation )
124 for( GLint error = GetError(); error; error = GetError() )
126 DALI_LOG_ERROR( "glError (0x%x) %s - after %s\n", error, ErrorToString(error), operation );
127 DALI_ASSERT_ALWAYS( error && "GL ERROR"); // if errors are being checked we should assert
132 * Helper to print GL string to debug log
134 void PrintGlString(const char* stringName, GLenum stringId)
136 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, (const char *)GetString( stringId ) );
139 /****************************************************************************************
140 * The following methods are forwarded to Dali::Integration::GlAbstraction.
141 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
142 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
143 * handles them and optimizes any program related state changes
144 ****************************************************************************************/
147 * Wrapper for OpenGL ES 2.0 glActiveTexture()
149 void ActiveTexture(GLenum textureUnit)
151 // GL texture units are #defines in growing order to converting that to index
152 unsigned int unit = textureUnit - GL_TEXTURE0;
154 if ( unit != mActiveTextureUnit )
156 mActiveTextureUnit = unit;
157 LOG_GL("ActiveTexture %x\n", textureUnit);
158 CHECK_GL( *this, mGlAbstraction.ActiveTexture(textureUnit) );
163 * Wrapper for OpenGL ES 3.0 glBeginQuery()
165 void BeginQuery(GLenum target, GLuint id)
167 LOG_GL("BeginQuery %d %d\n", target, id);
168 CHECK_GL( *this, mGlAbstraction.BeginQuery(target, id) );
172 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
174 void BeginTransformFeedback(GLenum primitiveMode)
176 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
177 CHECK_GL( *this, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
181 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
185 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
187 void BindArrayBuffer(GLuint buffer)
189 // Avoid unecessary calls to BindBuffer
190 if (mBoundArrayBufferId != buffer)
192 mBoundArrayBufferId = buffer;
194 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
195 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
200 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
202 void BindElementArrayBuffer(GLuint buffer)
204 // Avoid unecessary calls to BindBuffer
205 if (mBoundElementArrayBufferId!= buffer)
207 mBoundElementArrayBufferId = buffer;
209 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
210 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
215 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
217 void BindTransformFeedbackBuffer(GLuint buffer)
219 // Avoid unecessary calls to BindBuffer
220 if (mBoundTransformFeedbackBufferId != buffer)
222 mBoundTransformFeedbackBufferId = buffer;
224 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
225 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
230 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
232 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
234 // Avoid unecessary calls to BindBufferBase
235 if (mBoundTransformFeedbackBufferId != buffer)
237 mBoundTransformFeedbackBufferId = buffer;
239 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
240 CHECK_GL( *this, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
245 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
247 void BindFramebuffer(GLenum target, GLuint framebuffer)
249 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
250 CHECK_GL( *this, mGlAbstraction.BindFramebuffer(target, framebuffer) );
254 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
256 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
258 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
259 CHECK_GL( *this, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
263 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
265 void BindTransformFeedback(GLenum target, GLuint id)
267 LOG_GL("BindTransformFeedback %d %d\n", target, id);
268 CHECK_GL( *this, mGlAbstraction.BindTransformFeedback(target, id) );
272 * The wrapper for OpenGL ES 2.0 glBindTexture() has been replaced by Bind2dTexture and BindCubeMapTexture.
276 * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D)
278 void Bind2dTexture( GLuint texture )
280 if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
282 mBound2dTextureId[ mActiveTextureUnit ] = texture;
284 LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture);
285 CHECK_GL( *this, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) );
287 INCREASE_COUNTER(PerformanceMonitor::TEXTURE_STATE_CHANGES);
292 * Wrapper for OpenGL ES 2.0 glBlendColor()
294 void SetDefaultBlendColor()
296 if( !mUsingDefaultBlendColor )
298 LOG_GL( "BlendColor %f %f %f %f\n", 0.0f, 0.0f, 0.0f, 0.0f );
299 CHECK_GL( *this, mGlAbstraction.BlendColor( 0.0f, 0.0f, 0.0f, 0.0f ) );
300 mUsingDefaultBlendColor = true;
305 * Wrapper for OpenGL ES 2.0 glBlendColor()
307 void SetCustomBlendColor( const Vector4& color )
309 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
310 CHECK_GL( *this, mGlAbstraction.BlendColor(color.r, color.g, color.b, color.a) );
311 mUsingDefaultBlendColor = false;
315 * Wrapper for OpenGL ES 2.0 glBlendEquation()
317 void BlendEquation(GLenum mode)
319 // use BlendEquationSeparate to set the rgb and alpha modes the same
320 BlendEquationSeparate( mode, mode );
324 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
326 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
328 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
329 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
331 mBlendEquationSeparateModeRGB = modeRGB;
332 mBlendEquationSeparateModeAlpha = modeAlpha;
333 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
334 CHECK_GL( *this, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
339 * Wrapper for OpenGL ES 2.0 glBlendFunc()
341 void BlendFunc(GLenum sfactor, GLenum dfactor)
343 // reuse the BlendFuncSeparate as thats what the DDK does anyways
344 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
348 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
350 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
352 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
353 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
355 mBlendFuncSeparateSrcRGB = srcRGB;
356 mBlendFuncSeparateDstRGB = dstRGB;
357 mBlendFuncSeparateSrcAlpha = srcAlpha;
358 mBlendFuncSeparateDstAlpha = dstAlpha;
360 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
361 CHECK_GL( *this, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
366 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
368 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
370 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
371 CHECK_GL( *this, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
375 * Wrapper for OpenGL ES 2.0 glBufferData()
377 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
379 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
380 CHECK_GL( *this, mGlAbstraction.BufferData(target, size, data, usage) );
384 * Wrapper for OpenGL ES 2.0 glBufferSubData()
386 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
388 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
389 CHECK_GL( *this, mGlAbstraction.BufferSubData(target, offset, size, data) );
393 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
395 GLenum CheckFramebufferStatus(GLenum target)
397 LOG_GL("CheckFramebufferStatus %d\n", target);
398 GLenum value = CHECK_GL( *this, mGlAbstraction.CheckFramebufferStatus(target) );
403 * Wrapper for OpenGL ES 2.0 glClear()
405 void Clear(GLbitfield mask)
407 LOG_GL("Clear %d\n", mask);
408 CHECK_GL( *this, mGlAbstraction.Clear(mask) );
412 * Wrapper for OpenGL ES 2.0 glClearColor()
414 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
416 Vector4 newCol(red,green,blue,alpha);
418 if (!mClearColorSet || mClearColor !=newCol )
420 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
421 CHECK_GL( *this, mGlAbstraction.ClearColor(red, green, blue, alpha) );
423 mClearColorSet = true;
424 mClearColor = newCol;
429 * Wrapper for OpenGL ES 2.0 glClearDepthf()
431 void ClearDepthf(GLclampf depth)
433 LOG_GL("ClearDepthf %f\n", depth);
434 CHECK_GL( *this, mGlAbstraction.ClearDepthf(depth) );
438 * Wrapper for OpenGL ES 2.0 glClearStencil()
440 void ClearStencil(GLint s)
442 LOG_GL("ClearStencil %d\n", s);
443 CHECK_GL( *this, mGlAbstraction.ClearStencil(s) );
447 * Wrapper for OpenGL ES 2.0 glColorMask()
448 * @note This has been optimized to a single boolean value (masking individual channels is not required)
450 void ColorMask( bool flag )
452 // only change state if needed
453 if( flag != mColorMask )
456 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
457 CHECK_GL( *this, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
462 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
464 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
465 GLint border, GLsizei imageSize, const void* data)
467 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
468 CHECK_GL( *this, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
472 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
474 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
475 GLint border, GLsizei imageSize, const void* data)
477 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
478 CHECK_GL( *this, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
482 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
484 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
485 GLenum format, GLsizei imageSize, const void* data)
487 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
488 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
492 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
494 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
495 GLsizei width, GLsizei height, GLsizei depth,
496 GLenum format, GLsizei imageSize, const void* data)
498 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);
499 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
503 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
505 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
507 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
508 CHECK_GL( *this, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
512 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
514 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
516 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
517 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
521 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
523 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
525 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
526 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
530 * Wrapper for OpenGL ES 2.0 glCullFace()
531 * enables GL_CULL_FACE if in any of the face culling modes
532 * otherwise disables GL_CULL_FACE
534 void CullFace(CullFaceMode mode)
536 // Avoid unnecessary calls to gl
537 if(mCullFaceMode != mode)
539 mCullFaceMode = mode;
544 LOG_GL("Disable GL_CULL_FACE\n");
545 CHECK_GL( *this, mGlAbstraction.Disable(GL_CULL_FACE) );
551 LOG_GL("Enable GL_CULL_FACE\n");
552 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
553 LOG_GL("Enable GL_FRONT\n");
554 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT) );
560 LOG_GL("Enable GL_CULL_FACE\n");
561 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
562 LOG_GL("Enable GL_BACK\n");
563 CHECK_GL( *this, mGlAbstraction.CullFace(GL_BACK) );
567 case CullFrontAndBack:
569 LOG_GL("Enable GL_CULL_FACE\n");
570 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
571 LOG_GL("Enable GL_FRONT_AND_BACK\n");
572 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
583 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
585 void DeleteBuffers(GLsizei n, const GLuint* buffers)
587 // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
588 // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
589 if( this->IsGlContextCreated() )
591 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
592 CHECK_GL( *this, mGlAbstraction.DeleteBuffers(n, buffers) );
594 // reset the cached buffer id's
595 // fixes problem where some drivers will a generate a buffer with the
596 // same id, as the last deleted buffer id.
597 mBoundArrayBufferId = 0;
598 mBoundElementArrayBufferId = 0;
599 mBoundTransformFeedbackBufferId = 0;
603 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
605 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
607 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
608 CHECK_GL( *this, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
612 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
614 void DeleteQueries(GLsizei n, GLuint* ids)
616 LOG_GL("DeleteQueries %d %p\n", n, ids);
617 CHECK_GL( *this, mGlAbstraction.DeleteQueries(n, ids) );
621 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
623 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
625 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
626 CHECK_GL( *this, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
630 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
632 void DeleteTextures(GLsizei n, const GLuint* textures)
634 LOG_GL("DeleteTextures %d %p\n", n, textures);
635 CHECK_GL( *this, mGlAbstraction.DeleteTextures(n, textures) );
637 // reset the cached texture id's incase the driver re-uses them
638 // when creating new textures
639 for( int i=0; i < mMaxTextureUnits; ++i )
641 mBound2dTextureId[ i ] = 0;
646 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
648 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
650 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
651 CHECK_GL( *this, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
655 * Wrapper for OpenGL ES 2.0 glDepthFunc()
657 void DepthFunc(GLenum func)
659 LOG_GL("DepthFunc %x\n", func);
660 CHECK_GL( *this, mGlAbstraction.DepthFunc(func) );
664 * Wrapper for OpenGL ES 2.0 glDepthMask()
666 void DepthMask(GLboolean flag)
668 // only change state if needed
669 if( flag != mDepthMaskEnabled )
671 mDepthMaskEnabled = flag;
672 LOG_GL("DepthMask %s\n", flag ? "True" : "False");
673 CHECK_GL( *this, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
678 * Wrapper for OpenGL ES 2.0 glDepthRangef()
680 void DepthRangef(GLclampf zNear, GLclampf zFar)
682 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
683 CHECK_GL( *this, mGlAbstraction.DepthRangef(zNear, zFar) );
687 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
688 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
692 * Wrapper for OpenGL ES 2.0 glDrawArrays()
694 void DrawArrays(GLenum mode, GLint first, GLsizei count)
696 FlushVertexAttributeLocations();
698 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
699 CHECK_GL( *this, mGlAbstraction.DrawArrays(mode, first, count) );
703 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
705 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
707 FlushVertexAttributeLocations();
709 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
710 CHECK_GL( *this, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
714 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
716 void DrawBuffers(GLsizei n, const GLenum* bufs)
718 LOG_GL("DrawBuffers %d %p\n", n, bufs);
719 CHECK_GL( *this, mGlAbstraction.DrawBuffers(n, bufs) );
723 * Wrapper for OpenGL ES 2.0 glDrawElements()
725 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
727 FlushVertexAttributeLocations();
729 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
730 CHECK_GL( *this, mGlAbstraction.DrawElements(mode, count, type, indices) );
734 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
736 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
738 FlushVertexAttributeLocations();
740 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
741 CHECK_GL( *this, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
745 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
747 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
749 FlushVertexAttributeLocations();
751 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
752 CHECK_GL( *this, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
756 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
758 void GenQueries(GLsizei n, GLuint* ids)
760 LOG_GL("GenQueries %d %p\n", n, ids);
761 CHECK_GL( *this, mGlAbstraction.GenQueries(n, ids) );
765 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
767 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
769 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
770 CHECK_GL( *this, mGlAbstraction.GenTransformFeedbacks(n, ids) );
774 * @return the current buffer bound for a given target
776 GLuint GetCurrentBoundArrayBuffer(GLenum target)
781 case GL_ARRAY_BUFFER:
783 result = mBoundArrayBufferId;
786 case GL_ELEMENT_ARRAY_BUFFER:
788 result = mBoundElementArrayBufferId;
791 case GL_TRANSFORM_FEEDBACK_BUFFER:
793 result = mBoundTransformFeedbackBufferId;
798 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
804 void EnableVertexAttributeArray( GLuint location )
806 SetVertexAttributeLocation( location, true);
809 void DisableVertexAttributeArray( GLuint location )
811 SetVertexAttributeLocation( location, false);
815 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
817 void VertexAttribDivisor ( GLuint index, GLuint divisor )
819 LOG_GL("VertexAttribPointer(%d, %d)\n", index, divisor );
820 CHECK_GL( *this, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
824 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
826 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
828 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
829 CHECK_GL( *this, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
833 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
835 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
837 LOG_GL("InvalidateFramebuffer\n");
838 CHECK_GL( *this, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
842 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
843 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
847 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
848 * @param[in] enable True if GL_BLEND should be enabled.
850 void SetBlend(bool enable)
852 // Avoid unecessary calls to glEnable/glDisable
853 if (enable != mBlendEnabled)
855 mBlendEnabled = enable;
859 LOG_GL("Enable GL_BLEND\n");
860 CHECK_GL( *this, mGlAbstraction.Enable(GL_BLEND) );
864 LOG_GL("Disable GL_BLEND\n");
865 CHECK_GL( *this, mGlAbstraction.Disable(GL_BLEND) );
871 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
872 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
874 void SetDepthTest(bool enable)
876 // Avoid unecessary calls to glEnable/glDisable
877 if (enable != mDepthTestEnabled)
879 mDepthTestEnabled = enable;
883 LOG_GL("Enable GL_DEPTH_TEST\n");
884 CHECK_GL( *this, mGlAbstraction.Enable(GL_DEPTH_TEST) );
888 LOG_GL("Disable GL_DEPTH_TEST\n");
889 CHECK_GL( *this, mGlAbstraction.Disable(GL_DEPTH_TEST) );
895 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
896 * @param[in] enable True if GL_DITHER should be enabled.
898 void SetDither(bool enable)
900 // Avoid unecessary calls to glEnable/glDisable
901 if (enable != mDitherEnabled)
903 mDitherEnabled = enable;
907 LOG_GL("Enable GL_DITHER\n");
908 CHECK_GL( *this, mGlAbstraction.Enable(GL_DITHER) );
912 LOG_GL("Disable GL_DITHER\n");
913 CHECK_GL( *this, mGlAbstraction.Disable(GL_DITHER) );
919 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
920 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
922 void SetPolygonOffsetFill(bool enable)
924 // Avoid unecessary calls to glEnable/glDisable
925 if (enable != mPolygonOffsetFillEnabled)
927 mPolygonOffsetFillEnabled = enable;
931 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
932 CHECK_GL( *this, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
936 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
937 CHECK_GL( *this, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
943 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
944 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
946 void SetSampleAlphaToCoverage(bool enable)
948 // Avoid unecessary calls to glEnable/glDisable
949 if (enable != mSampleAlphaToCoverageEnabled)
951 mSampleAlphaToCoverageEnabled = enable;
955 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
956 CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
960 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
961 CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
967 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
968 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
970 void SetSampleCoverage(bool enable)
972 // Avoid unecessary calls to glEnable/glDisable
973 if (enable != mSampleCoverageEnabled)
975 mSampleCoverageEnabled = enable;
979 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
980 CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
984 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
985 CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
991 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
992 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
994 void SetScissorTest(bool enable)
996 // Avoid unecessary calls to glEnable/glDisable
997 if (enable != mScissorTestEnabled)
999 mScissorTestEnabled = enable;
1003 LOG_GL("Enable GL_SCISSOR_TEST\n");
1004 CHECK_GL( *this, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1008 LOG_GL("Disable GL_SCISSOR_TEST\n");
1009 CHECK_GL( *this, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1015 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1016 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1018 void SetStencilTest(bool enable)
1020 // Avoid unecessary calls to glEnable/glDisable
1021 if (enable != mStencilTestEnabled)
1023 mStencilTestEnabled = enable;
1027 LOG_GL("Enable GL_STENCIL_TEST\n");
1028 CHECK_GL( *this, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1032 LOG_GL("Disable GL_STENCIL_TEST\n");
1033 CHECK_GL( *this, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1039 * Wrapper for OpenGL ES 3.0 glEndQuery()
1041 void EndQuery(GLenum target)
1043 LOG_GL("EndQuery %d\n", target);
1044 CHECK_GL( *this, mGlAbstraction.EndQuery(target) );
1048 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1050 void EndTransformFeedback()
1052 LOG_GL("EndTransformFeedback\n");
1053 CHECK_GL( *this, mGlAbstraction.EndTransformFeedback() );
1057 * Wrapper for OpenGL ES 2.0 glFinish()
1062 CHECK_GL( *this, mGlAbstraction.Finish() );
1066 * Wrapper for OpenGL ES 2.0 glFlush()
1071 CHECK_GL( *this, mGlAbstraction.Flush() );
1075 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1077 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1079 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1080 CHECK_GL( *this, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1084 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1086 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1088 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1089 CHECK_GL( *this, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1093 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1095 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1097 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1098 CHECK_GL( *this, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1102 * Wrapper for OpenGL ES 2.0 glFrontFace()
1104 void FrontFace(GLenum mode)
1106 LOG_GL("FrontFace %x\n", mode);
1107 CHECK_GL( *this, mGlAbstraction.FrontFace(mode) );
1111 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1113 void GenBuffers(GLsizei n, GLuint* buffers)
1115 LOG_GL("GenBuffers %d\n", n, buffers);
1116 CHECK_GL( *this, mGlAbstraction.GenBuffers(n, buffers) );
1120 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1122 void GenerateMipmap(GLenum target)
1124 LOG_GL("GenerateMipmap %x\n", target);
1125 CHECK_GL( *this, mGlAbstraction.GenerateMipmap(target) );
1129 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1131 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1133 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1134 CHECK_GL( *this, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1138 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1140 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1142 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1143 CHECK_GL( *this, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1147 * Wrapper for OpenGL ES 2.0 glGenTextures()
1149 void GenTextures(GLsizei n, GLuint* textures)
1151 LOG_GL("GenTextures %d %p\n", n, textures);
1152 CHECK_GL( *this, mGlAbstraction.GenTextures(n, textures) );
1156 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1158 void GetBooleanv(GLenum pname, GLboolean* params)
1160 LOG_GL("GetBooleanv %x\n", pname);
1161 CHECK_GL( *this, mGlAbstraction.GetBooleanv(pname, params) );
1165 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1167 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1169 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1170 CHECK_GL( *this, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1174 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1176 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1178 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1179 CHECK_GL( *this, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1183 * Wrapper for OpenGL ES 2.0 glGetError()
1185 GLenum GetError(void)
1187 // Not worth logging here
1188 return mGlAbstraction.GetError();
1192 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1194 void GetFloatv(GLenum pname, GLfloat* params)
1196 LOG_GL("GetFloatv %x\n", pname);
1197 CHECK_GL( *this, mGlAbstraction.GetFloatv(pname, params) );
1201 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1203 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1205 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1206 CHECK_GL( *this, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1210 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1212 void GetIntegerv(GLenum pname, GLint* params)
1214 LOG_GL("GetIntegerv %x\n", pname);
1215 CHECK_GL( *this, mGlAbstraction.GetIntegerv(pname, params) );
1219 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1221 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1223 LOG_GL("GetQueryiv %x %x\n", target, pname);
1224 CHECK_GL( *this, mGlAbstraction.GetQueryiv(target, pname, params) );
1228 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1230 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1232 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1233 CHECK_GL( *this, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1237 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1239 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1241 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1242 CHECK_GL( *this, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1246 * Wrapper for OpenGL ES 2.0 glGetString()
1248 const GLubyte* GetString(GLenum name)
1250 LOG_GL("GetString %x\n", name);
1251 const GLubyte* str = CHECK_GL( *this, mGlAbstraction.GetString(name) );
1256 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1258 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1260 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1261 CHECK_GL( *this, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1265 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1267 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1269 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1270 CHECK_GL( *this, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1274 * Wrapper for OpenGL ES 2.0 glHint()
1276 void Hint(GLenum target, GLenum mode)
1278 LOG_GL("Hint %x %x\n", target, mode);
1279 CHECK_GL( *this, mGlAbstraction.Hint(target, mode) );
1283 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1285 GLboolean IsBuffer(GLuint buffer)
1287 LOG_GL("IsBuffer %d\n", buffer);
1288 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsBuffer(buffer) );
1293 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1295 GLboolean IsEnabled(GLenum cap)
1297 LOG_GL("IsEnabled %x\n", cap);
1298 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsEnabled(cap) );
1303 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1305 GLboolean IsFramebuffer(GLuint framebuffer)
1307 LOG_GL("IsFramebuffer %d\n", framebuffer);
1308 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsFramebuffer(framebuffer) );
1313 * Wrapper for OpenGL ES 3.0 glIsQuery()
1315 GLboolean IsQuery(GLuint id)
1317 LOG_GL("IsQuery %u\n", id);
1318 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsQuery(id) );
1323 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1325 GLboolean IsRenderbuffer(GLuint renderbuffer)
1327 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1328 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1333 * Wrapper for OpenGL ES 2.0 glIsTexture()
1335 GLboolean IsTexture(GLuint texture)
1337 LOG_GL("IsTexture %d\n", texture);
1338 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTexture(texture) );
1343 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1345 GLboolean IsTransformFeedback(GLuint id)
1347 LOG_GL("IsTransformFeedback %u\n", id);
1348 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTransformFeedback(id) );
1353 * Wrapper for OpenGL ES 2.0 glLineWidth()
1355 void LineWidth(GLfloat width)
1357 LOG_GL("LineWidth %f\n", width);
1358 CHECK_GL( *this, mGlAbstraction.LineWidth(width) );
1362 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1364 void PauseTransformFeedback()
1366 LOG_GL("PauseTransformFeedback\n");
1367 CHECK_GL( *this, mGlAbstraction.PauseTransformFeedback() );
1371 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1373 void PixelStorei(GLenum pname, GLint param)
1375 LOG_GL("PixelStorei %x %d\n", pname, param);
1376 CHECK_GL( *this, mGlAbstraction.PixelStorei(pname, param) );
1380 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1382 void PolygonOffset(GLfloat factor, GLfloat units)
1384 LOG_GL("PolygonOffset %f %f\n", factor, units);
1385 CHECK_GL( *this, mGlAbstraction.PolygonOffset(factor, units) );
1389 * Wrapper for OpenGL ES 2.0 glReadPixels()
1391 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1393 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1394 CHECK_GL( *this, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1398 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1400 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1402 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1403 CHECK_GL( *this, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1407 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1409 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1411 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1412 CHECK_GL( *this, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1416 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1418 void ResumeTransformFeedback()
1420 LOG_GL("ResumeTransformFeedback\n");
1421 CHECK_GL( *this, mGlAbstraction.ResumeTransformFeedback() );
1425 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1427 void SampleCoverage(GLclampf value, GLboolean invert)
1429 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1430 CHECK_GL( *this, mGlAbstraction.SampleCoverage(value, invert) );
1434 * Wrapper for OpenGL ES 2.0 glScissor()
1436 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1438 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1439 CHECK_GL( *this, mGlAbstraction.Scissor(x, y, width, height) );
1443 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1445 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1447 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1448 CHECK_GL( *this, mGlAbstraction.StencilFunc(func, ref, mask) );
1452 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1454 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1456 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1457 CHECK_GL( *this, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1461 * Wrapper for OpenGL ES 2.0 glStencilMask()
1463 void StencilMask(GLuint mask)
1465 if( mask != mStencilMask )
1467 mStencilMask = mask;
1469 LOG_GL("StencilMask %d\n", mask);
1470 CHECK_GL( *this, mGlAbstraction.StencilMask(mask) );
1475 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1477 void StencilMaskSeparate(GLenum face, GLuint mask)
1479 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1480 CHECK_GL( *this, mGlAbstraction.StencilMaskSeparate(face, mask) );
1484 * Wrapper for OpenGL ES 2.0 glStencilOp()
1486 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1488 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1489 CHECK_GL( *this, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1493 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1495 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1497 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1498 CHECK_GL( *this, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1502 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1504 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1505 GLint border, GLenum format, GLenum type, const void* pixels)
1507 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1508 CHECK_GL( *this, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1512 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1514 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1515 GLint border, GLenum format, GLenum type, const void* pixels)
1517 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1518 CHECK_GL( *this, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1522 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1524 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1526 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1527 CHECK_GL( *this, mGlAbstraction.TexParameterf(target, pname, param) );
1531 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1533 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1535 LOG_GL("TexParameterfv %x %x\n", target, pname);
1536 CHECK_GL( *this, mGlAbstraction.TexParameterfv(target, pname, params) );
1540 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1542 void TexParameteri(GLenum target, GLenum pname, GLint param)
1544 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1545 CHECK_GL( *this, mGlAbstraction.TexParameteri(target, pname, param) );
1549 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1551 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1553 LOG_GL("TexParameteriv %x %x\n", target, pname);
1554 CHECK_GL( *this, mGlAbstraction.TexParameteriv(target, pname, params) );
1558 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1560 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1561 GLenum format, GLenum type, const void* pixels)
1563 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1564 CHECK_GL( *this, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1568 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1570 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1571 GLsizei width, GLsizei height, GLsizei depth,
1572 GLenum format, GLenum type, const void* pixels)
1574 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);
1575 CHECK_GL( *this, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1579 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1581 GLboolean UnmapBuffer(GLenum target)
1583 LOG_GL("UnmapBuffer %x \n", target);
1584 GLboolean val = CHECK_GL( *this, mGlAbstraction.UnmapBuffer(target) );
1588 * Wrapper for OpenGL ES 2.0 glViewport()
1590 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1592 // check if its same as already set
1593 Rect<int> newViewport( x, y, width, height );
1594 if( mViewPort != newViewport )
1597 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1598 CHECK_GL( *this, mGlAbstraction.Viewport(x, y, width, height) );
1599 mViewPort = newViewport; // remember new one
1604 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1605 * @return The implementation defined MAX_TEXTURE_SIZE
1607 GLint CachedMaxTextureSize() const
1609 return mMaxTextureSize;
1613 * Get the number of supported program binary formats
1614 * @return The number of supported program binary formats
1616 GLint CachedNumberOfProgramBinaryFormats() const
1618 return mProgramBinaryFormats.size();
1622 * Get a supported program binary format
1623 * @param[in] formatIndex The index of the format to return (default: 0)
1624 * @return A supported program binary format
1626 GLint CachedProgramBinaryFormat( const unsigned int formatIndex = 0 ) const
1628 DALI_ASSERT_ALWAYS( formatIndex < mProgramBinaryFormats.size() && "formatIndex out of bounds");
1630 return mProgramBinaryFormats[ formatIndex ];
1634 * @return current program
1636 const Program* GetCurrentProgram() const
1638 return mCurrentProgram;
1642 * Set current program
1643 * @param [in] program that is in use
1645 void SetCurrentProgram( Program* program )
1647 mCurrentProgram = program;
1651 * Reset the program matrices
1653 void ResetProgramMatrices();
1656 * Get a cached program
1657 * @param [in] hash value
1658 * @return pointer to the program
1660 Program* GetCachedProgram( std::size_t hash ) const;
1664 * @param [in] hash value
1665 * @param [in] pointer to the program
1667 void CacheProgram( std::size_t hash, Program* pointer );
1670 * Get the current viewport.
1671 * @return Viewport rectangle.
1673 const Rect< int >& GetViewport();
1675 #ifdef DEBUG_ENABLED
1677 /// Switch debug level to Concise to disable, General to enable. Note, enabling snapshot logging will do this on the fly.
1678 static Debug::Filter *gGlLogFilter;
1680 #endif // DEBUG_ENABLED
1684 * Set the frame count of render thread
1686 inline void SetFrameCount(unsigned int frameCount)
1688 mFrameCount = frameCount;
1692 * Get the frame count
1694 inline unsigned int GetFrameCount()
1700 * Increment the count of culled renderers
1702 inline void IncrementCulledCount()
1708 * Clear the count of culled renderers
1710 inline void ClearCulledCount()
1716 * Get the count of culled renderers in this frame
1718 inline unsigned int GetCulledCount()
1720 return mCulledCount;
1724 * Increment the count of culled renderers
1726 inline void IncrementRendererCount()
1732 * Clear the count of image renderers
1734 inline void ClearRendererCount()
1740 * Get the count of image renderers in this frame
1742 inline unsigned int GetRendererCount()
1744 return mRendererCount;
1748 private: // Implementation
1751 * Flushes vertex attribute location changes to the driver
1753 void FlushVertexAttributeLocations();
1756 * Reset the cached internal vertex attribute state
1758 void ResetVertexAttributeState();
1761 * Either enables or disables a vertex attribute location in the cache
1762 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1763 * @param location attribute location
1764 * @param state attribute state
1766 void SetVertexAttributeLocation(unsigned int location, bool state);
1769 * Sets the initial GL state.
1771 void ResetGlState();
1775 Integration::GlAbstraction& mGlAbstraction;
1777 bool mGlContextCreated; ///< True if the OpenGL context has been created
1779 // glEnable/glDisable states
1781 GLuint mStencilMask;
1783 bool mDepthTestEnabled;
1784 bool mDepthMaskEnabled;
1785 bool mDitherEnabled;
1786 bool mPolygonOffsetFillEnabled;
1787 bool mSampleAlphaToCoverageEnabled;
1788 bool mSampleCoverageEnabled;
1789 bool mScissorTestEnabled;
1790 bool mStencilTestEnabled;
1791 bool mClearColorSet;
1793 // glBindBuffer() state
1794 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1795 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1796 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1798 // glBindTexture() state
1799 unsigned int mActiveTextureUnit;
1800 std::vector<GLuint> mBound2dTextureId; ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
1802 // glBlendColor() state
1803 bool mUsingDefaultBlendColor;
1805 // glBlendFuncSeparate() state
1806 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1807 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1808 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1809 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1811 // glBlendEquationSeparate state
1812 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1813 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1815 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1816 GLint mMaxTextureUnits; ///< return value from GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS)
1817 Vector4 mClearColor; ///< clear color
1819 std::vector<GLint> mProgramBinaryFormats; ///< array of supported program binary formats
1821 // Face culling mode
1822 CullFaceMode mCullFaceMode;
1824 // cached viewport size
1825 Rect< int > mViewPort;
1827 // Vertex Attribute Buffer enable caching
1828 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1829 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1831 Program* mCurrentProgram;
1832 typedef std::map< std::size_t, Program* > ProgramContainer;
1833 ProgramContainer mProgramCache; ///< Cache of shader programs
1834 unsigned int mFrameCount; ///< Number of render frames
1835 unsigned int mCulledCount; ///< Number of culled renderers per frame
1836 unsigned int mRendererCount; ///< Number of image renderers per frame
1839 } // namespace Internal
1843 #endif // __DALI_INTERNAL_CONTEXT_H__