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/public-api/common/map-wrapper.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/actors/renderable-actor.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/gl-abstraction.h>
27 #include <dali/internal/render/common/performance-monitor.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/math/rect.h>
30 #include <dali/public-api/math/vector4.h>
38 class Program; // to be able to cache programs
40 // wrap gl calls with CHECK_GL eg "CHECK_GL( *this, glBindTexture(textureId) );"
41 // will LOG any glErrors eg "glError (0x0501) GL_INVALID_VALUE - glBindTexture(textureId)"
42 // only enable if specifically enabled as it slows down GL a lot!
43 #ifdef DALI_GL_ERROR_CHECK
44 #define CHECK_GL(c,a) (a); (c).CheckGlError(#a)
46 #define CHECK_GL(c,a) (a)
49 // Don't put guards around here (LOG_INFO has it's own guards)
50 #define LOG_GL(format, args...) \
51 DALI_LOG_INFO(Context::gGlLogFilter, Debug::General, format, ## args)
54 * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
55 * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
61 * Size of the VertexAttributeArray enables
62 * GLES specification states that there's minimum of 8
64 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
67 * Creates the Dali Context object.
68 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
69 * @pre Context has not been created.
70 * @exception Context already created.
71 * @param glAbstraction the gl abstraction.
73 Context( Integration::GlAbstraction& glAbstraction );
81 * Called when the GL context has been created.
83 void GlContextCreated();
86 * Called when the GL context is about to be destroyed.
88 void GlContextDestroyed();
91 * Query whether the OpenGL context has been created.
92 * @return True if the OpenGL context has been created.
94 bool IsGlContextCreated() { return mGlContextCreated; }
97 * @return the GLAbstraction
99 Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
101 #ifdef DALI_CONTEXT_LOGGING
104 * Debug helper which prints the currently cached GL state.
106 void PrintCurrentState();
111 * Helper to convert GL error code to string
112 * @param errorCode to convert
115 const char* ErrorToString( GLenum errorCode );
118 * Helper to check GL error during an operation
119 * @param operation that was performed
121 void CheckGlError( const char* operation )
123 for( GLint error = GetError(); error; error = GetError() )
125 DALI_LOG_ERROR( "glError (0x%x) %s - after %s\n", error, ErrorToString(error), operation );
126 DALI_ASSERT_ALWAYS( error && "GL ERROR"); // if errors are being checked we should assert
131 * Helper to print GL string to debug log
133 void PrintGlString(const char* stringName, GLenum stringId)
135 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, (const char *)GetString( stringId ) );
138 /****************************************************************************************
139 * The following methods are forwarded to Dali::Integration::GlAbstraction.
140 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
141 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
142 * handles them and optimizes any program related state changes
143 ****************************************************************************************/
146 * Wrapper for OpenGL ES 2.0 glActiveTexture()
148 void ActiveTexture(GLenum textureUnit)
150 // GL texture units are #defines in growing order to converting that to index
151 unsigned int unit = textureUnit - GL_TEXTURE0;
153 if ( unit != mActiveTextureUnit )
155 mActiveTextureUnit = unit;
156 LOG_GL("ActiveTexture %x\n", textureUnit);
157 CHECK_GL( *this, mGlAbstraction.ActiveTexture(textureUnit) );
162 * Wrapper for OpenGL ES 3.0 glBeginQuery()
164 void BeginQuery(GLenum target, GLuint id)
166 LOG_GL("BeginQuery %d %d\n", target, id);
167 CHECK_GL( *this, mGlAbstraction.BeginQuery(target, id) );
171 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
173 void BeginTransformFeedback(GLenum primitiveMode)
175 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
176 CHECK_GL( *this, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
180 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
184 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
186 void BindArrayBuffer(GLuint buffer)
188 // Avoid unecessary calls to BindBuffer
189 if (mBoundArrayBufferId != buffer)
191 mBoundArrayBufferId = buffer;
193 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
194 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
199 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
201 void BindElementArrayBuffer(GLuint buffer)
203 // Avoid unecessary calls to BindBuffer
204 if (mBoundElementArrayBufferId!= buffer)
206 mBoundElementArrayBufferId = buffer;
208 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
209 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
214 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
216 void BindTransformFeedbackBuffer(GLuint buffer)
218 // Avoid unecessary calls to BindBuffer
219 if (mBoundTransformFeedbackBufferId != buffer)
221 mBoundTransformFeedbackBufferId = buffer;
223 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
224 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
229 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
231 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
233 // Avoid unecessary calls to BindBufferBase
234 if (mBoundTransformFeedbackBufferId != buffer)
236 mBoundTransformFeedbackBufferId = buffer;
238 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
239 CHECK_GL( *this, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
244 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
246 void BindFramebuffer(GLenum target, GLuint framebuffer)
248 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
249 CHECK_GL( *this, mGlAbstraction.BindFramebuffer(target, framebuffer) );
253 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
255 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
257 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
258 CHECK_GL( *this, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
262 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
264 void BindTransformFeedback(GLenum target, GLuint id)
266 LOG_GL("BindTransformFeedback %d %d\n", target, id);
267 CHECK_GL( *this, mGlAbstraction.BindTransformFeedback(target, id) );
271 * The wrapper for OpenGL ES 2.0 glBindTexture() has been replaced by Bind2dTexture and BindCubeMapTexture.
275 * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D)
277 void Bind2dTexture( GLuint texture )
279 if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
281 mBound2dTextureId[ mActiveTextureUnit ] = texture;
283 LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture);
284 CHECK_GL( *this, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) );
286 INCREASE_COUNTER(PerformanceMonitor::TEXTURE_STATE_CHANGES);
291 * Wrapper for OpenGL ES 2.0 glBlendColor()
293 void SetDefaultBlendColor()
295 if( !mUsingDefaultBlendColor )
297 LOG_GL( "BlendColor %f %f %f %f\n", 0.0f, 0.0f, 0.0f, 0.0f );
298 CHECK_GL( *this, mGlAbstraction.BlendColor( 0.0f, 0.0f, 0.0f, 0.0f ) );
299 mUsingDefaultBlendColor = true;
304 * Wrapper for OpenGL ES 2.0 glBlendColor()
306 void SetCustomBlendColor( const Vector4& color )
308 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
309 CHECK_GL( *this, mGlAbstraction.BlendColor(color.r, color.g, color.b, color.a) );
310 mUsingDefaultBlendColor = false;
314 * Wrapper for OpenGL ES 2.0 glBlendEquation()
316 void BlendEquation(GLenum mode)
318 // use BlendEquationSeparate to set the rgb and alpha modes the same
319 BlendEquationSeparate( mode, mode );
323 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
325 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
327 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
328 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
330 mBlendEquationSeparateModeRGB = modeRGB;
331 mBlendEquationSeparateModeAlpha = modeAlpha;
332 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
333 CHECK_GL( *this, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
338 * Wrapper for OpenGL ES 2.0 glBlendFunc()
340 void BlendFunc(GLenum sfactor, GLenum dfactor)
342 // reuse the BlendFuncSeparate as thats what the DDK does anyways
343 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
347 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
349 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
351 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
352 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
354 mBlendFuncSeparateSrcRGB = srcRGB;
355 mBlendFuncSeparateDstRGB = dstRGB;
356 mBlendFuncSeparateSrcAlpha = srcAlpha;
357 mBlendFuncSeparateDstAlpha = dstAlpha;
359 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
360 CHECK_GL( *this, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
365 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
367 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
369 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
370 CHECK_GL( *this, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
374 * Wrapper for OpenGL ES 2.0 glBufferData()
376 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
378 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
379 CHECK_GL( *this, mGlAbstraction.BufferData(target, size, data, usage) );
383 * Wrapper for OpenGL ES 2.0 glBufferSubData()
385 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
387 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
388 CHECK_GL( *this, mGlAbstraction.BufferSubData(target, offset, size, data) );
392 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
394 GLenum CheckFramebufferStatus(GLenum target)
396 LOG_GL("CheckFramebufferStatus %d\n", target);
397 GLenum value = CHECK_GL( *this, mGlAbstraction.CheckFramebufferStatus(target) );
402 * Wrapper for OpenGL ES 2.0 glClear()
404 void Clear(GLbitfield mask)
406 LOG_GL("Clear %d\n", mask);
407 CHECK_GL( *this, mGlAbstraction.Clear(mask) );
411 * Wrapper for OpenGL ES 2.0 glClearColor()
413 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
415 Vector4 newCol(red,green,blue,alpha);
417 if (!mClearColorSet || mClearColor !=newCol )
419 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
420 CHECK_GL( *this, mGlAbstraction.ClearColor(red, green, blue, alpha) );
422 mClearColorSet = true;
423 mClearColor = newCol;
428 * Wrapper for OpenGL ES 2.0 glClearDepthf()
430 void ClearDepthf(GLclampf depth)
432 LOG_GL("ClearDepthf %f\n", depth);
433 CHECK_GL( *this, mGlAbstraction.ClearDepthf(depth) );
437 * Wrapper for OpenGL ES 2.0 glClearStencil()
439 void ClearStencil(GLint s)
441 LOG_GL("ClearStencil %d\n", s);
442 CHECK_GL( *this, mGlAbstraction.ClearStencil(s) );
446 * Wrapper for OpenGL ES 2.0 glColorMask()
447 * @note This has been optimized to a single boolean value (masking individual channels is not required)
449 void ColorMask( bool flag )
451 // only change state if needed
452 if( flag != mColorMask )
455 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
456 CHECK_GL( *this, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
461 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
463 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
464 GLint border, GLsizei imageSize, const void* data)
466 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
467 CHECK_GL( *this, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
471 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
473 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
474 GLint border, GLsizei imageSize, const void* data)
476 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
477 CHECK_GL( *this, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
481 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
483 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
484 GLenum format, GLsizei imageSize, const void* data)
486 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
487 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
491 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
493 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
494 GLsizei width, GLsizei height, GLsizei depth,
495 GLenum format, GLsizei imageSize, const void* data)
497 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);
498 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
502 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
504 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
506 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
507 CHECK_GL( *this, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
511 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
513 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
515 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
516 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
520 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
522 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
524 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
525 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
529 * Wrapper for OpenGL ES 2.0 glCullFace()
530 * enables GL_CULL_FACE if in any of the face culling modes
531 * otherwise disables GL_CULL_FACE
533 void CullFace(CullFaceMode mode)
535 // Avoid unnecessary calls to gl
536 if(mCullFaceMode != mode)
538 mCullFaceMode = mode;
543 LOG_GL("Disable GL_CULL_FACE\n");
544 CHECK_GL( *this, mGlAbstraction.Disable(GL_CULL_FACE) );
550 LOG_GL("Enable GL_CULL_FACE\n");
551 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
552 LOG_GL("Enable GL_FRONT\n");
553 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT) );
559 LOG_GL("Enable GL_CULL_FACE\n");
560 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
561 LOG_GL("Enable GL_BACK\n");
562 CHECK_GL( *this, mGlAbstraction.CullFace(GL_BACK) );
566 case CullFrontAndBack:
568 LOG_GL("Enable GL_CULL_FACE\n");
569 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
570 LOG_GL("Enable GL_FRONT_AND_BACK\n");
571 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
582 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
584 void DeleteBuffers(GLsizei n, const GLuint* buffers)
586 // TODO: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
587 // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
588 if( this->IsGlContextCreated() )
590 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
591 CHECK_GL( *this, mGlAbstraction.DeleteBuffers(n, buffers) );
593 // reset the cached buffer id's
594 // fixes problem where some drivers will a generate a buffer with the
595 // same id, as the last deleted buffer id.
596 mBoundArrayBufferId = 0;
597 mBoundElementArrayBufferId = 0;
598 mBoundTransformFeedbackBufferId = 0;
602 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
604 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
606 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
607 CHECK_GL( *this, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
611 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
613 void DeleteQueries(GLsizei n, GLuint* ids)
615 LOG_GL("DeleteQueries %d %p\n", n, ids);
616 CHECK_GL( *this, mGlAbstraction.DeleteQueries(n, ids) );
620 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
622 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
624 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
625 CHECK_GL( *this, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
629 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
631 void DeleteTextures(GLsizei n, const GLuint* textures)
633 LOG_GL("DeleteTextures %d %p\n", n, textures);
634 CHECK_GL( *this, mGlAbstraction.DeleteTextures(n, textures) );
636 // reset the cached texture id's incase the driver re-uses them
637 // when creating new textures
638 for( int i=0; i < mMaxTextureUnits; ++i )
640 mBound2dTextureId[ i ] = 0;
645 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
647 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
649 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
650 CHECK_GL( *this, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
654 * Wrapper for OpenGL ES 2.0 glDepthFunc()
656 void DepthFunc(GLenum func)
658 LOG_GL("DepthFunc %x\n", func);
659 CHECK_GL( *this, mGlAbstraction.DepthFunc(func) );
663 * Wrapper for OpenGL ES 2.0 glDepthMask()
665 void DepthMask(GLboolean flag)
667 // only change state if needed
668 if( flag != mDepthMaskEnabled )
670 mDepthMaskEnabled = flag;
671 LOG_GL("DepthMask %s\n", flag ? "True" : "False");
672 CHECK_GL( *this, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
677 * Wrapper for OpenGL ES 2.0 glDepthRangef()
679 void DepthRangef(GLclampf zNear, GLclampf zFar)
681 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
682 CHECK_GL( *this, mGlAbstraction.DepthRangef(zNear, zFar) );
686 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
687 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
691 * Wrapper for OpenGL ES 2.0 glDrawArrays()
693 void DrawArrays(GLenum mode, GLint first, GLsizei count)
695 FlushVertexAttributeLocations();
697 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
698 CHECK_GL( *this, mGlAbstraction.DrawArrays(mode, first, count) );
702 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
704 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
706 FlushVertexAttributeLocations();
708 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
709 CHECK_GL( *this, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
713 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
715 void DrawBuffers(GLsizei n, const GLenum* bufs)
717 LOG_GL("DrawBuffers %d %p\n", n, bufs);
718 CHECK_GL( *this, mGlAbstraction.DrawBuffers(n, bufs) );
722 * Wrapper for OpenGL ES 2.0 glDrawElements()
724 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
726 FlushVertexAttributeLocations();
728 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
729 CHECK_GL( *this, mGlAbstraction.DrawElements(mode, count, type, indices) );
733 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
735 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
737 FlushVertexAttributeLocations();
739 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
740 CHECK_GL( *this, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
744 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
746 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
748 FlushVertexAttributeLocations();
750 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
751 CHECK_GL( *this, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
755 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
757 void GenQueries(GLsizei n, GLuint* ids)
759 LOG_GL("GenQueries %d %p\n", n, ids);
760 CHECK_GL( *this, mGlAbstraction.GenQueries(n, ids) );
764 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
766 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
768 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
769 CHECK_GL( *this, mGlAbstraction.GenTransformFeedbacks(n, ids) );
773 * @return the current buffer bound for a given target
775 GLuint GetCurrentBoundArrayBuffer(GLenum target)
780 case GL_ARRAY_BUFFER:
782 result = mBoundArrayBufferId;
785 case GL_ELEMENT_ARRAY_BUFFER:
787 result = mBoundElementArrayBufferId;
790 case GL_TRANSFORM_FEEDBACK_BUFFER:
792 result = mBoundTransformFeedbackBufferId;
797 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
803 void EnableVertexAttributeArray( GLuint location )
805 SetVertexAttributeLocation( location, true);
808 void DisableVertexAttributeArray( GLuint location )
810 SetVertexAttributeLocation( location, false);
814 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
816 void VertexAttribDivisor ( GLuint index, GLuint divisor )
818 LOG_GL("VertexAttribPointer(%d, %d)\n", index, divisor );
819 CHECK_GL( *this, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
823 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
825 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
827 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
828 CHECK_GL( *this, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
832 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
834 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
836 LOG_GL("InvalidateFramebuffer\n");
837 CHECK_GL( *this, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
841 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
842 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
846 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
847 * @param[in] enable True if GL_BLEND should be enabled.
849 void SetBlend(bool enable)
851 // Avoid unecessary calls to glEnable/glDisable
852 if (enable != mBlendEnabled)
854 mBlendEnabled = enable;
858 LOG_GL("Enable GL_BLEND\n");
859 CHECK_GL( *this, mGlAbstraction.Enable(GL_BLEND) );
863 LOG_GL("Disable GL_BLEND\n");
864 CHECK_GL( *this, mGlAbstraction.Disable(GL_BLEND) );
870 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
871 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
873 void SetDepthTest(bool enable)
875 // Avoid unecessary calls to glEnable/glDisable
876 if (enable != mDepthTestEnabled)
878 mDepthTestEnabled = enable;
882 LOG_GL("Enable GL_DEPTH_TEST\n");
883 CHECK_GL( *this, mGlAbstraction.Enable(GL_DEPTH_TEST) );
887 LOG_GL("Disable GL_DEPTH_TEST\n");
888 CHECK_GL( *this, mGlAbstraction.Disable(GL_DEPTH_TEST) );
894 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
895 * @param[in] enable True if GL_DITHER should be enabled.
897 void SetDither(bool enable)
899 // Avoid unecessary calls to glEnable/glDisable
900 if (enable != mDitherEnabled)
902 mDitherEnabled = enable;
906 LOG_GL("Enable GL_DITHER\n");
907 CHECK_GL( *this, mGlAbstraction.Enable(GL_DITHER) );
911 LOG_GL("Disable GL_DITHER\n");
912 CHECK_GL( *this, mGlAbstraction.Disable(GL_DITHER) );
918 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
919 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
921 void SetPolygonOffsetFill(bool enable)
923 // Avoid unecessary calls to glEnable/glDisable
924 if (enable != mPolygonOffsetFillEnabled)
926 mPolygonOffsetFillEnabled = enable;
930 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
931 CHECK_GL( *this, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
935 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
936 CHECK_GL( *this, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
942 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
943 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
945 void SetSampleAlphaToCoverage(bool enable)
947 // Avoid unecessary calls to glEnable/glDisable
948 if (enable != mSampleAlphaToCoverageEnabled)
950 mSampleAlphaToCoverageEnabled = enable;
954 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
955 CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
959 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
960 CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
966 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
967 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
969 void SetSampleCoverage(bool enable)
971 // Avoid unecessary calls to glEnable/glDisable
972 if (enable != mSampleCoverageEnabled)
974 mSampleCoverageEnabled = enable;
978 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
979 CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
983 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
984 CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
990 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
991 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
993 void SetScissorTest(bool enable)
995 // Avoid unecessary calls to glEnable/glDisable
996 if (enable != mScissorTestEnabled)
998 mScissorTestEnabled = enable;
1002 LOG_GL("Enable GL_SCISSOR_TEST\n");
1003 CHECK_GL( *this, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1007 LOG_GL("Disable GL_SCISSOR_TEST\n");
1008 CHECK_GL( *this, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1014 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1015 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1017 void SetStencilTest(bool enable)
1019 // Avoid unecessary calls to glEnable/glDisable
1020 if (enable != mStencilTestEnabled)
1022 mStencilTestEnabled = enable;
1026 LOG_GL("Enable GL_STENCIL_TEST\n");
1027 CHECK_GL( *this, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1031 LOG_GL("Disable GL_STENCIL_TEST\n");
1032 CHECK_GL( *this, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1038 * Wrapper for OpenGL ES 3.0 glEndQuery()
1040 void EndQuery(GLenum target)
1042 LOG_GL("EndQuery %d\n", target);
1043 CHECK_GL( *this, mGlAbstraction.EndQuery(target) );
1047 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1049 void EndTransformFeedback()
1051 LOG_GL("EndTransformFeedback\n");
1052 CHECK_GL( *this, mGlAbstraction.EndTransformFeedback() );
1056 * Wrapper for OpenGL ES 2.0 glFinish()
1061 CHECK_GL( *this, mGlAbstraction.Finish() );
1065 * Wrapper for OpenGL ES 2.0 glFlush()
1070 CHECK_GL( *this, mGlAbstraction.Flush() );
1074 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1076 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1078 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1079 CHECK_GL( *this, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1083 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1085 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1087 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1088 CHECK_GL( *this, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1092 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1094 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1096 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1097 CHECK_GL( *this, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1101 * Wrapper for OpenGL ES 2.0 glFrontFace()
1103 void FrontFace(GLenum mode)
1105 LOG_GL("FrontFace %x\n", mode);
1106 CHECK_GL( *this, mGlAbstraction.FrontFace(mode) );
1110 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1112 void GenBuffers(GLsizei n, GLuint* buffers)
1114 LOG_GL("GenBuffers %d\n", n, buffers);
1115 CHECK_GL( *this, mGlAbstraction.GenBuffers(n, buffers) );
1119 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1121 void GenerateMipmap(GLenum target)
1123 LOG_GL("GenerateMipmap %x\n", target);
1124 CHECK_GL( *this, mGlAbstraction.GenerateMipmap(target) );
1128 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1130 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1132 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1133 CHECK_GL( *this, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1137 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1139 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1141 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1142 CHECK_GL( *this, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1146 * Wrapper for OpenGL ES 2.0 glGenTextures()
1148 void GenTextures(GLsizei n, GLuint* textures)
1150 LOG_GL("GenTextures %d %p\n", n, textures);
1151 CHECK_GL( *this, mGlAbstraction.GenTextures(n, textures) );
1155 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1157 void GetBooleanv(GLenum pname, GLboolean* params)
1159 LOG_GL("GetBooleanv %x\n", pname);
1160 CHECK_GL( *this, mGlAbstraction.GetBooleanv(pname, params) );
1164 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1166 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1168 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1169 CHECK_GL( *this, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1173 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1175 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1177 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1178 CHECK_GL( *this, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1182 * Wrapper for OpenGL ES 2.0 glGetError()
1184 GLenum GetError(void)
1186 // Not worth logging here
1187 return mGlAbstraction.GetError();
1191 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1193 void GetFloatv(GLenum pname, GLfloat* params)
1195 LOG_GL("GetFloatv %x\n", pname);
1196 CHECK_GL( *this, mGlAbstraction.GetFloatv(pname, params) );
1200 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1202 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1204 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1205 CHECK_GL( *this, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1209 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1211 void GetIntegerv(GLenum pname, GLint* params)
1213 LOG_GL("GetIntegerv %x\n", pname);
1214 CHECK_GL( *this, mGlAbstraction.GetIntegerv(pname, params) );
1218 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1220 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1222 LOG_GL("GetQueryiv %x %x\n", target, pname);
1223 CHECK_GL( *this, mGlAbstraction.GetQueryiv(target, pname, params) );
1227 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1229 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1231 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1232 CHECK_GL( *this, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1236 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1238 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1240 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1241 CHECK_GL( *this, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1245 * Wrapper for OpenGL ES 2.0 glGetString()
1247 const GLubyte* GetString(GLenum name)
1249 LOG_GL("GetString %x\n", name);
1250 const GLubyte* str = CHECK_GL( *this, mGlAbstraction.GetString(name) );
1255 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1257 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1259 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1260 CHECK_GL( *this, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1264 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1266 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1268 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1269 CHECK_GL( *this, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1273 * Wrapper for OpenGL ES 2.0 glHint()
1275 void Hint(GLenum target, GLenum mode)
1277 LOG_GL("Hint %x %x\n", target, mode);
1278 CHECK_GL( *this, mGlAbstraction.Hint(target, mode) );
1282 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1284 GLboolean IsBuffer(GLuint buffer)
1286 LOG_GL("IsBuffer %d\n", buffer);
1287 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsBuffer(buffer) );
1292 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1294 GLboolean IsEnabled(GLenum cap)
1296 LOG_GL("IsEnabled %x\n", cap);
1297 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsEnabled(cap) );
1302 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1304 GLboolean IsFramebuffer(GLuint framebuffer)
1306 LOG_GL("IsFramebuffer %d\n", framebuffer);
1307 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsFramebuffer(framebuffer) );
1312 * Wrapper for OpenGL ES 3.0 glIsQuery()
1314 GLboolean IsQuery(GLuint id)
1316 LOG_GL("IsQuery %u\n", id);
1317 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsQuery(id) );
1322 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1324 GLboolean IsRenderbuffer(GLuint renderbuffer)
1326 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1327 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1332 * Wrapper for OpenGL ES 2.0 glIsTexture()
1334 GLboolean IsTexture(GLuint texture)
1336 LOG_GL("IsTexture %d\n", texture);
1337 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTexture(texture) );
1342 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1344 GLboolean IsTransformFeedback(GLuint id)
1346 LOG_GL("IsTransformFeedback %u\n", id);
1347 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTransformFeedback(id) );
1352 * Wrapper for OpenGL ES 2.0 glLineWidth()
1354 void LineWidth(GLfloat width)
1356 LOG_GL("LineWidth %f\n", width);
1357 CHECK_GL( *this, mGlAbstraction.LineWidth(width) );
1361 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1363 void PauseTransformFeedback()
1365 LOG_GL("PauseTransformFeedback\n");
1366 CHECK_GL( *this, mGlAbstraction.PauseTransformFeedback() );
1370 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1372 void PixelStorei(GLenum pname, GLint param)
1374 LOG_GL("PixelStorei %x %d\n", pname, param);
1375 CHECK_GL( *this, mGlAbstraction.PixelStorei(pname, param) );
1379 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1381 void PolygonOffset(GLfloat factor, GLfloat units)
1383 LOG_GL("PolygonOffset %f %f\n", factor, units);
1384 CHECK_GL( *this, mGlAbstraction.PolygonOffset(factor, units) );
1388 * Wrapper for OpenGL ES 2.0 glReadPixels()
1390 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1392 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1393 CHECK_GL( *this, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1397 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1399 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1401 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1402 CHECK_GL( *this, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1406 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1408 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1410 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1411 CHECK_GL( *this, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1415 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1417 void ResumeTransformFeedback()
1419 LOG_GL("ResumeTransformFeedback\n");
1420 CHECK_GL( *this, mGlAbstraction.ResumeTransformFeedback() );
1424 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1426 void SampleCoverage(GLclampf value, GLboolean invert)
1428 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1429 CHECK_GL( *this, mGlAbstraction.SampleCoverage(value, invert) );
1433 * Wrapper for OpenGL ES 2.0 glScissor()
1435 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1437 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1438 CHECK_GL( *this, mGlAbstraction.Scissor(x, y, width, height) );
1442 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1444 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1446 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1447 CHECK_GL( *this, mGlAbstraction.StencilFunc(func, ref, mask) );
1451 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1453 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1455 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1456 CHECK_GL( *this, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1460 * Wrapper for OpenGL ES 2.0 glStencilMask()
1462 void StencilMask(GLuint mask)
1464 if( mask != mStencilMask )
1466 mStencilMask = mask;
1468 LOG_GL("StencilMask %d\n", mask);
1469 CHECK_GL( *this, mGlAbstraction.StencilMask(mask) );
1474 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1476 void StencilMaskSeparate(GLenum face, GLuint mask)
1478 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1479 CHECK_GL( *this, mGlAbstraction.StencilMaskSeparate(face, mask) );
1483 * Wrapper for OpenGL ES 2.0 glStencilOp()
1485 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1487 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1488 CHECK_GL( *this, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1492 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1494 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1496 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1497 CHECK_GL( *this, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1501 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1503 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1504 GLint border, GLenum format, GLenum type, const void* pixels)
1506 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1507 CHECK_GL( *this, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1511 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1513 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1514 GLint border, GLenum format, GLenum type, const void* pixels)
1516 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1517 CHECK_GL( *this, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1521 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1523 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1525 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1526 CHECK_GL( *this, mGlAbstraction.TexParameterf(target, pname, param) );
1530 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1532 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1534 LOG_GL("TexParameterfv %x %x\n", target, pname);
1535 CHECK_GL( *this, mGlAbstraction.TexParameterfv(target, pname, params) );
1539 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1541 void TexParameteri(GLenum target, GLenum pname, GLint param)
1543 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1544 CHECK_GL( *this, mGlAbstraction.TexParameteri(target, pname, param) );
1548 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1550 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1552 LOG_GL("TexParameteriv %x %x\n", target, pname);
1553 CHECK_GL( *this, mGlAbstraction.TexParameteriv(target, pname, params) );
1557 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1559 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1560 GLenum format, GLenum type, const void* pixels)
1562 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1563 CHECK_GL( *this, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1567 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1569 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1570 GLsizei width, GLsizei height, GLsizei depth,
1571 GLenum format, GLenum type, const void* pixels)
1573 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);
1574 CHECK_GL( *this, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1578 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1580 GLboolean UnmapBuffer(GLenum target)
1582 LOG_GL("UnmapBuffer %x \n", target);
1583 GLboolean val = CHECK_GL( *this, mGlAbstraction.UnmapBuffer(target) );
1587 * Wrapper for OpenGL ES 2.0 glViewport()
1589 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1591 // check if its same as already set
1592 Rect<int> newViewport( x, y, width, height );
1593 if( mViewPort != newViewport )
1596 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1597 CHECK_GL( *this, mGlAbstraction.Viewport(x, y, width, height) );
1598 mViewPort = newViewport; // remember new one
1603 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1604 * @return The implementation defined MAX_TEXTURE_SIZE
1606 GLint CachedMaxTextureSize() const
1608 return mMaxTextureSize;
1612 * Get the number of supported program binary formats
1613 * @return The number of supported program binary formats
1615 GLint CachedNumberOfProgramBinaryFormats() const
1617 return mProgramBinaryFormats.size();
1621 * Get a supported program binary format
1622 * @param[in] formatIndex The index of the format to return (default: 0)
1623 * @return A supported program binary format
1625 GLint CachedProgramBinaryFormat( const unsigned int formatIndex = 0 ) const
1627 DALI_ASSERT_ALWAYS( formatIndex < mProgramBinaryFormats.size() && "formatIndex out of bounds");
1629 return mProgramBinaryFormats[ formatIndex ];
1633 * @return current program
1635 const Program* GetCurrentProgram() const
1637 return mCurrentProgram;
1641 * Set current program
1642 * @param [in] program that is in use
1644 void SetCurrentProgram( Program* program )
1646 mCurrentProgram = program;
1650 * Get a cached program
1651 * @param [in] hash value
1652 * @return pointer to the program
1654 Program* GetCachedProgram( std::size_t hash ) const;
1658 * @param [in] hash value
1659 * @param [in] pointer to the program
1661 void CacheProgram( std::size_t hash, Program* pointer );
1664 * Get the current viewport.
1665 * @return Viewport rectangle.
1667 const Rect< int >& GetViewport();
1669 #ifdef DEBUG_ENABLED
1671 /// Switch debug level to Concise to disable, General to enable. Note, enabling snapshot logging will do this on the fly.
1672 static Debug::Filter *gGlLogFilter;
1674 #endif // DEBUG_ENABLED
1678 * Set the frame count of render thread
1680 inline void SetFrameCount(unsigned int frameCount)
1682 mFrameCount = frameCount;
1686 * Get the frame count
1688 inline unsigned int GetFrameCount()
1694 * Increment the count of culled renderers
1696 inline void IncrementCulledCount()
1702 * Clear the count of culled renderers
1704 inline void ClearCulledCount()
1710 * Get the count of culled renderers in this frame
1712 inline unsigned int GetCulledCount()
1714 return mCulledCount;
1718 * Increment the count of culled renderers
1720 inline void IncrementRendererCount()
1726 * Clear the count of image renderers
1728 inline void ClearRendererCount()
1734 * Get the count of image renderers in this frame
1736 inline unsigned int GetRendererCount()
1738 return mRendererCount;
1742 private: // Implementation
1745 * Flushes vertex attribute location changes to the driver
1747 void FlushVertexAttributeLocations();
1750 * Reset the cached internal vertex attribute state
1752 void ResetVertexAttributeState();
1755 * Either enables or disables a vertex attribute location in the cache
1756 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1757 * @param location attribute location
1758 * @param state attribute state
1760 void SetVertexAttributeLocation(unsigned int location, bool state);
1763 * Sets the initial GL state.
1765 void ResetGlState();
1769 Integration::GlAbstraction& mGlAbstraction;
1771 bool mGlContextCreated; ///< True if the OpenGL context has been created
1773 // glEnable/glDisable states
1775 GLuint mStencilMask;
1777 bool mDepthTestEnabled;
1778 bool mDepthMaskEnabled;
1779 bool mDitherEnabled;
1780 bool mPolygonOffsetFillEnabled;
1781 bool mSampleAlphaToCoverageEnabled;
1782 bool mSampleCoverageEnabled;
1783 bool mScissorTestEnabled;
1784 bool mStencilTestEnabled;
1785 bool mClearColorSet;
1787 // glBindBuffer() state
1788 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1789 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1790 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1792 // glBindTexture() state
1793 unsigned int mActiveTextureUnit;
1794 std::vector<GLuint> mBound2dTextureId; ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
1796 // glBlendColor() state
1797 bool mUsingDefaultBlendColor;
1799 // glBlendFuncSeparate() state
1800 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1801 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1802 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1803 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1805 // glBlendEquationSeparate state
1806 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1807 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1809 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1810 GLint mMaxTextureUnits; ///< return value from GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS)
1811 Vector4 mClearColor; ///< clear color
1813 std::vector<GLint> mProgramBinaryFormats; ///< array of supported program binary formats
1815 // Face culling mode
1816 CullFaceMode mCullFaceMode;
1818 // cached viewport size
1819 Rect< int > mViewPort;
1821 // Vertex Attribute Buffer enable caching
1822 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1823 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1825 Program* mCurrentProgram;
1826 typedef std::map< std::size_t, Program* > ProgramContainer;
1827 ProgramContainer mProgramCache; ///< Cache of shader programs
1828 unsigned int mFrameCount; ///< Number of render frames
1829 unsigned int mCulledCount; ///< Number of culled renderers per frame
1830 unsigned int mRendererCount; ///< Number of image renderers per frame
1833 } // namespace Internal
1837 #endif // __DALI_INTERNAL_CONTEXT_H__