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/actors/renderable-actor.h>
24 #include <dali/public-api/common/map-wrapper.h>
25 #include <dali/public-api/common/dali-vector.h>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/math/rect.h>
28 #include <dali/public-api/math/vector4.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/integration-api/gl-abstraction.h>
31 #include <dali/internal/render/common/performance-monitor.h>
32 #include <dali/internal/render/gl-resources/texture-units.h>
40 class Program; // to be able to cache programs
42 // wrap gl calls with CHECK_GL eg "CHECK_GL( *this, glBindTexture(textureId) );"
43 // will LOG any glErrors eg "glError (0x0501) GL_INVALID_VALUE - glBindTexture(textureId)"
44 // only enable if specifically enabled as it slows down GL a lot!
45 #ifdef DALI_GL_ERROR_CHECK
46 #define CHECK_GL(c,a) (a); (c).CheckGlError(#a)
48 #define CHECK_GL(c,a) (a)
51 // Don't put guards around here (LOG_INFO has it's own guards)
52 #define LOG_GL(format, args...) \
53 DALI_LOG_INFO(Context::gGlLogFilter, Debug::General, format, ## args)
56 * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
57 * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
63 * Size of the VertexAttributeArray enables
64 * GLES specification states that there's minimum of 8
66 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
68 static const unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 8 is guaranteed, which is more than DALi uses anyways
71 * Creates the Dali Context object.
72 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
73 * @pre Context has not been created.
74 * @exception Context already created.
75 * @param glAbstraction the gl abstraction.
77 Context( Integration::GlAbstraction& glAbstraction );
85 * Called when the GL context has been created.
87 void GlContextCreated();
90 * Called when the GL context has been destroyed.
92 void GlContextDestroyed();
95 * Query whether the OpenGL context has been created.
96 * @return True if the OpenGL context has been created.
98 bool IsGlContextCreated() { return mGlContextCreated; }
101 * @return the GLAbstraction
103 Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
105 #ifdef DALI_CONTEXT_LOGGING
108 * Debug helper which prints the currently cached GL state.
110 void PrintCurrentState();
115 * Helper to convert GL error code to string
116 * @param errorCode to convert
119 const char* ErrorToString( GLenum errorCode );
122 * Helper to check GL error during an operation
123 * @param operation that was performed
125 void CheckGlError( const char* operation )
127 for( GLint error = GetError(); error; error = GetError() )
129 DALI_LOG_ERROR( "glError (0x%x) %s - after %s\n", error, ErrorToString(error), operation );
130 DALI_ASSERT_ALWAYS( error && "GL ERROR"); // if errors are being checked we should assert
135 * Helper to print GL string to debug log
137 void PrintGlString(const char* stringName, GLenum stringId)
139 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, (const char *)GetString( stringId ) );
142 /****************************************************************************************
143 * The following methods are forwarded to Dali::Integration::GlAbstraction.
144 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
145 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
146 * handles them and optimizes any program related state changes
147 ****************************************************************************************/
150 * Wrapper for OpenGL ES 2.0 glActiveTexture()
152 void ActiveTexture( TextureUnit textureUnit )
154 if ( textureUnit != mActiveTextureUnit )
156 mActiveTextureUnit = textureUnit;
157 LOG_GL("ActiveTexture %x\n", textureUnit);
158 CHECK_GL( *this, mGlAbstraction.ActiveTexture(TextureUnitAsGLenum(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 * Helper to bind texture for rendering. If given texture is
273 * already bound in the given textureunit, this method does nothing.
274 * Otherwise changes the active texture unit and binds the texture.
275 * Note! after this call active texture unit may not necessarily be the one
276 * passed in as argument so you cannot change texture unit state!!
277 * @param textureunit to bind to
278 * @param texture to bind
280 void BindTextureForUnit( TextureUnit textureunit, GLuint texture )
282 if( mBound2dTextureId[ textureunit ] != texture )
284 ActiveTexture( textureunit );
285 Bind2dTexture( texture );
290 * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D)
292 void Bind2dTexture( GLuint texture )
294 if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
296 mBound2dTextureId[ mActiveTextureUnit ] = texture;
298 LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture);
299 CHECK_GL( *this, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) );
301 INCREASE_COUNTER(PerformanceMonitor::TEXTURE_STATE_CHANGES);
306 * Wrapper for OpenGL ES 2.0 glBlendColor()
308 void SetDefaultBlendColor()
310 if( !mUsingDefaultBlendColor )
312 LOG_GL( "BlendColor %f %f %f %f\n", 0.0f, 0.0f, 0.0f, 0.0f );
313 CHECK_GL( *this, mGlAbstraction.BlendColor( 0.0f, 0.0f, 0.0f, 0.0f ) );
314 mUsingDefaultBlendColor = true;
319 * Wrapper for OpenGL ES 2.0 glBlendColor()
321 void SetCustomBlendColor( const Vector4& color )
323 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
324 CHECK_GL( *this, mGlAbstraction.BlendColor(color.r, color.g, color.b, color.a) );
325 mUsingDefaultBlendColor = false;
329 * Wrapper for OpenGL ES 2.0 glBlendEquation()
331 void BlendEquation(GLenum mode)
333 // use BlendEquationSeparate to set the rgb and alpha modes the same
334 BlendEquationSeparate( mode, mode );
338 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
340 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
342 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
343 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
345 mBlendEquationSeparateModeRGB = modeRGB;
346 mBlendEquationSeparateModeAlpha = modeAlpha;
347 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
348 CHECK_GL( *this, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
353 * Wrapper for OpenGL ES 2.0 glBlendFunc()
355 void BlendFunc(GLenum sfactor, GLenum dfactor)
357 // reuse the BlendFuncSeparate as thats what the DDK does anyways
358 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
362 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
364 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
366 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
367 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
369 mBlendFuncSeparateSrcRGB = srcRGB;
370 mBlendFuncSeparateDstRGB = dstRGB;
371 mBlendFuncSeparateSrcAlpha = srcAlpha;
372 mBlendFuncSeparateDstAlpha = dstAlpha;
374 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
375 CHECK_GL( *this, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
380 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
382 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
384 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
385 CHECK_GL( *this, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
389 * Wrapper for OpenGL ES 2.0 glBufferData()
391 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
393 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
394 CHECK_GL( *this, mGlAbstraction.BufferData(target, size, data, usage) );
398 * Wrapper for OpenGL ES 2.0 glBufferSubData()
400 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
402 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
403 CHECK_GL( *this, mGlAbstraction.BufferSubData(target, offset, size, data) );
407 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
409 GLenum CheckFramebufferStatus(GLenum target)
411 LOG_GL("CheckFramebufferStatus %d\n", target);
412 GLenum value = CHECK_GL( *this, mGlAbstraction.CheckFramebufferStatus(target) );
417 * Wrapper for OpenGL ES 2.0 glClear()
419 void Clear(GLbitfield mask)
421 LOG_GL("Clear %d\n", mask);
422 CHECK_GL( *this, mGlAbstraction.Clear(mask) );
426 * Wrapper for OpenGL ES 2.0 glClearColor()
428 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
430 Vector4 newCol(red,green,blue,alpha);
432 if (!mClearColorSet || mClearColor !=newCol )
434 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
435 CHECK_GL( *this, mGlAbstraction.ClearColor(red, green, blue, alpha) );
437 mClearColorSet = true;
438 mClearColor = newCol;
443 * Wrapper for OpenGL ES 2.0 glClearDepthf()
445 void ClearDepthf(GLclampf depth)
447 LOG_GL("ClearDepthf %f\n", depth);
448 CHECK_GL( *this, mGlAbstraction.ClearDepthf(depth) );
452 * Wrapper for OpenGL ES 2.0 glClearStencil()
454 void ClearStencil(GLint s)
456 LOG_GL("ClearStencil %d\n", s);
457 CHECK_GL( *this, mGlAbstraction.ClearStencil(s) );
461 * Wrapper for OpenGL ES 2.0 glColorMask()
462 * @note This has been optimized to a single boolean value (masking individual channels is not required)
464 void ColorMask( bool flag )
466 // only change state if needed
467 if( flag != mColorMask )
470 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
471 CHECK_GL( *this, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
476 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
478 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
479 GLint border, GLsizei imageSize, const void* data)
481 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
482 CHECK_GL( *this, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
486 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
488 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
489 GLint border, GLsizei imageSize, const void* data)
491 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
492 CHECK_GL( *this, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
496 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
498 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
499 GLenum format, GLsizei imageSize, const void* data)
501 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
502 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
506 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
508 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
509 GLsizei width, GLsizei height, GLsizei depth,
510 GLenum format, GLsizei imageSize, const void* data)
512 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);
513 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
517 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
519 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
521 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
522 CHECK_GL( *this, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
526 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
528 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
530 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
531 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
535 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
537 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
539 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
540 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
544 * Wrapper for OpenGL ES 2.0 glCullFace()
545 * enables GL_CULL_FACE if in any of the face culling modes
546 * otherwise disables GL_CULL_FACE
548 void CullFace(CullFaceMode mode)
550 // Avoid unnecessary calls to gl
551 if(mCullFaceMode != mode)
553 mCullFaceMode = mode;
558 LOG_GL("Disable GL_CULL_FACE\n");
559 CHECK_GL( *this, mGlAbstraction.Disable(GL_CULL_FACE) );
565 LOG_GL("Enable GL_CULL_FACE\n");
566 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
567 LOG_GL("Enable GL_FRONT\n");
568 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT) );
574 LOG_GL("Enable GL_CULL_FACE\n");
575 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
576 LOG_GL("Enable GL_BACK\n");
577 CHECK_GL( *this, mGlAbstraction.CullFace(GL_BACK) );
581 case CullFrontAndBack:
583 LOG_GL("Enable GL_CULL_FACE\n");
584 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
585 LOG_GL("Enable GL_FRONT_AND_BACK\n");
586 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
597 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
599 void DeleteBuffers(GLsizei n, const GLuint* buffers)
601 // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
602 // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
603 if( this->IsGlContextCreated() )
605 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
606 CHECK_GL( *this, mGlAbstraction.DeleteBuffers(n, buffers) );
608 // reset the cached buffer id's
609 // fixes problem where some drivers will a generate a buffer with the
610 // same id, as the last deleted buffer id.
611 mBoundArrayBufferId = 0;
612 mBoundElementArrayBufferId = 0;
613 mBoundTransformFeedbackBufferId = 0;
617 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
619 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
621 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
622 CHECK_GL( *this, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
626 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
628 void DeleteQueries(GLsizei n, GLuint* ids)
630 LOG_GL("DeleteQueries %d %p\n", n, ids);
631 CHECK_GL( *this, mGlAbstraction.DeleteQueries(n, ids) );
635 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
637 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
639 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
640 CHECK_GL( *this, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
644 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
646 void DeleteTextures(GLsizei n, const GLuint* textures)
648 LOG_GL("DeleteTextures %d %p\n", n, textures);
649 CHECK_GL( *this, mGlAbstraction.DeleteTextures(n, textures) );
651 // reset the cached texture id's incase the driver re-uses them
652 // when creating new textures
653 for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
655 mBound2dTextureId[ i ] = 0;
660 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
662 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
664 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
665 CHECK_GL( *this, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
669 * Wrapper for OpenGL ES 2.0 glDepthFunc()
671 void DepthFunc(GLenum func)
673 LOG_GL("DepthFunc %x\n", func);
674 CHECK_GL( *this, mGlAbstraction.DepthFunc(func) );
678 * Wrapper for OpenGL ES 2.0 glDepthMask()
680 void DepthMask(GLboolean flag)
682 // only change state if needed
683 if( flag != mDepthMaskEnabled )
685 mDepthMaskEnabled = flag;
686 LOG_GL("DepthMask %s\n", flag ? "True" : "False");
687 CHECK_GL( *this, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
692 * Wrapper for OpenGL ES 2.0 glDepthRangef()
694 void DepthRangef(GLclampf zNear, GLclampf zFar)
696 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
697 CHECK_GL( *this, mGlAbstraction.DepthRangef(zNear, zFar) );
701 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
702 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
706 * Wrapper for OpenGL ES 2.0 glDrawArrays()
708 void DrawArrays(GLenum mode, GLint first, GLsizei count)
710 FlushVertexAttributeLocations();
712 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
713 CHECK_GL( *this, mGlAbstraction.DrawArrays(mode, first, count) );
717 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
719 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
721 FlushVertexAttributeLocations();
723 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
724 CHECK_GL( *this, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
728 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
730 void DrawBuffers(GLsizei n, const GLenum* bufs)
732 LOG_GL("DrawBuffers %d %p\n", n, bufs);
733 CHECK_GL( *this, mGlAbstraction.DrawBuffers(n, bufs) );
737 * Wrapper for OpenGL ES 2.0 glDrawElements()
739 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
741 FlushVertexAttributeLocations();
743 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
744 CHECK_GL( *this, mGlAbstraction.DrawElements(mode, count, type, indices) );
748 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
750 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
752 FlushVertexAttributeLocations();
754 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
755 CHECK_GL( *this, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
759 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
761 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
763 FlushVertexAttributeLocations();
765 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
766 CHECK_GL( *this, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
770 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
772 void GenQueries(GLsizei n, GLuint* ids)
774 LOG_GL("GenQueries %d %p\n", n, ids);
775 CHECK_GL( *this, mGlAbstraction.GenQueries(n, ids) );
779 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
781 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
783 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
784 CHECK_GL( *this, mGlAbstraction.GenTransformFeedbacks(n, ids) );
788 * @return the current buffer bound for a given target
790 GLuint GetCurrentBoundArrayBuffer(GLenum target)
795 case GL_ARRAY_BUFFER:
797 result = mBoundArrayBufferId;
800 case GL_ELEMENT_ARRAY_BUFFER:
802 result = mBoundElementArrayBufferId;
805 case GL_TRANSFORM_FEEDBACK_BUFFER:
807 result = mBoundTransformFeedbackBufferId;
812 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
818 void EnableVertexAttributeArray( GLuint location )
820 SetVertexAttributeLocation( location, true);
823 void DisableVertexAttributeArray( GLuint location )
825 SetVertexAttributeLocation( location, false);
829 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
831 void VertexAttribDivisor ( GLuint index, GLuint divisor )
833 LOG_GL("VertexAttribPointer(%d, %d)\n", index, divisor );
834 CHECK_GL( *this, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
838 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
840 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
842 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
843 CHECK_GL( *this, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
847 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
849 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
851 LOG_GL("InvalidateFramebuffer\n");
852 CHECK_GL( *this, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
856 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
857 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
861 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
862 * @param[in] enable True if GL_BLEND should be enabled.
864 void SetBlend(bool enable)
866 // Avoid unecessary calls to glEnable/glDisable
867 if (enable != mBlendEnabled)
869 mBlendEnabled = enable;
873 LOG_GL("Enable GL_BLEND\n");
874 CHECK_GL( *this, mGlAbstraction.Enable(GL_BLEND) );
878 LOG_GL("Disable GL_BLEND\n");
879 CHECK_GL( *this, mGlAbstraction.Disable(GL_BLEND) );
885 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
886 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
888 void SetDepthTest(bool enable)
890 // Avoid unecessary calls to glEnable/glDisable
891 if (enable != mDepthTestEnabled)
893 mDepthTestEnabled = enable;
897 LOG_GL("Enable GL_DEPTH_TEST\n");
898 CHECK_GL( *this, mGlAbstraction.Enable(GL_DEPTH_TEST) );
902 LOG_GL("Disable GL_DEPTH_TEST\n");
903 CHECK_GL( *this, mGlAbstraction.Disable(GL_DEPTH_TEST) );
909 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
910 * @param[in] enable True if GL_DITHER should be enabled.
912 void SetDither(bool enable)
914 // Avoid unecessary calls to glEnable/glDisable
915 if (enable != mDitherEnabled)
917 mDitherEnabled = enable;
921 LOG_GL("Enable GL_DITHER\n");
922 CHECK_GL( *this, mGlAbstraction.Enable(GL_DITHER) );
926 LOG_GL("Disable GL_DITHER\n");
927 CHECK_GL( *this, mGlAbstraction.Disable(GL_DITHER) );
933 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
934 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
936 void SetPolygonOffsetFill(bool enable)
938 // Avoid unecessary calls to glEnable/glDisable
939 if (enable != mPolygonOffsetFillEnabled)
941 mPolygonOffsetFillEnabled = enable;
945 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
946 CHECK_GL( *this, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
950 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
951 CHECK_GL( *this, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
957 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
958 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
960 void SetSampleAlphaToCoverage(bool enable)
962 // Avoid unecessary calls to glEnable/glDisable
963 if (enable != mSampleAlphaToCoverageEnabled)
965 mSampleAlphaToCoverageEnabled = enable;
969 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
970 CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
974 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
975 CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
981 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
982 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
984 void SetSampleCoverage(bool enable)
986 // Avoid unecessary calls to glEnable/glDisable
987 if (enable != mSampleCoverageEnabled)
989 mSampleCoverageEnabled = enable;
993 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
994 CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
998 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
999 CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
1005 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
1006 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
1008 void SetScissorTest(bool enable)
1010 // Avoid unecessary calls to glEnable/glDisable
1011 if (enable != mScissorTestEnabled)
1013 mScissorTestEnabled = enable;
1017 LOG_GL("Enable GL_SCISSOR_TEST\n");
1018 CHECK_GL( *this, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1022 LOG_GL("Disable GL_SCISSOR_TEST\n");
1023 CHECK_GL( *this, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1029 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1030 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1032 void SetStencilTest(bool enable)
1034 // Avoid unecessary calls to glEnable/glDisable
1035 if (enable != mStencilTestEnabled)
1037 mStencilTestEnabled = enable;
1041 LOG_GL("Enable GL_STENCIL_TEST\n");
1042 CHECK_GL( *this, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1046 LOG_GL("Disable GL_STENCIL_TEST\n");
1047 CHECK_GL( *this, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1053 * Wrapper for OpenGL ES 3.0 glEndQuery()
1055 void EndQuery(GLenum target)
1057 LOG_GL("EndQuery %d\n", target);
1058 CHECK_GL( *this, mGlAbstraction.EndQuery(target) );
1062 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1064 void EndTransformFeedback()
1066 LOG_GL("EndTransformFeedback\n");
1067 CHECK_GL( *this, mGlAbstraction.EndTransformFeedback() );
1071 * Wrapper for OpenGL ES 2.0 glFinish()
1076 CHECK_GL( *this, mGlAbstraction.Finish() );
1080 * Wrapper for OpenGL ES 2.0 glFlush()
1085 CHECK_GL( *this, mGlAbstraction.Flush() );
1089 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1091 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1093 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1094 CHECK_GL( *this, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1098 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1100 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1102 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1103 CHECK_GL( *this, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1107 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1109 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1111 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1112 CHECK_GL( *this, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1116 * Wrapper for OpenGL ES 2.0 glFrontFace()
1118 void FrontFace(GLenum mode)
1120 LOG_GL("FrontFace %x\n", mode);
1121 CHECK_GL( *this, mGlAbstraction.FrontFace(mode) );
1125 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1127 void GenBuffers(GLsizei n, GLuint* buffers)
1129 LOG_GL("GenBuffers %d\n", n, buffers);
1130 CHECK_GL( *this, mGlAbstraction.GenBuffers(n, buffers) );
1134 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1136 void GenerateMipmap(GLenum target)
1138 LOG_GL("GenerateMipmap %x\n", target);
1139 CHECK_GL( *this, mGlAbstraction.GenerateMipmap(target) );
1143 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1145 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1147 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1148 CHECK_GL( *this, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1152 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1154 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1156 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1157 CHECK_GL( *this, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1161 * Wrapper for OpenGL ES 2.0 glGenTextures()
1163 void GenTextures(GLsizei n, GLuint* textures)
1165 LOG_GL("GenTextures %d %p\n", n, textures);
1166 CHECK_GL( *this, mGlAbstraction.GenTextures(n, textures) );
1170 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1172 void GetBooleanv(GLenum pname, GLboolean* params)
1174 LOG_GL("GetBooleanv %x\n", pname);
1175 CHECK_GL( *this, mGlAbstraction.GetBooleanv(pname, params) );
1179 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1181 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1183 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1184 CHECK_GL( *this, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1188 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1190 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1192 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1193 CHECK_GL( *this, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1197 * Wrapper for OpenGL ES 2.0 glGetError()
1199 GLenum GetError(void)
1201 // Not worth logging here
1202 return mGlAbstraction.GetError();
1206 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1208 void GetFloatv(GLenum pname, GLfloat* params)
1210 LOG_GL("GetFloatv %x\n", pname);
1211 CHECK_GL( *this, mGlAbstraction.GetFloatv(pname, params) );
1215 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1217 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1219 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1220 CHECK_GL( *this, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1224 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1226 void GetIntegerv(GLenum pname, GLint* params)
1228 LOG_GL("GetIntegerv %x\n", pname);
1229 CHECK_GL( *this, mGlAbstraction.GetIntegerv(pname, params) );
1233 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1235 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1237 LOG_GL("GetQueryiv %x %x\n", target, pname);
1238 CHECK_GL( *this, mGlAbstraction.GetQueryiv(target, pname, params) );
1242 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1244 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1246 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1247 CHECK_GL( *this, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1251 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1253 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1255 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1256 CHECK_GL( *this, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1260 * Wrapper for OpenGL ES 2.0 glGetString()
1262 const GLubyte* GetString(GLenum name)
1264 LOG_GL("GetString %x\n", name);
1265 const GLubyte* str = CHECK_GL( *this, mGlAbstraction.GetString(name) );
1270 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1272 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1274 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1275 CHECK_GL( *this, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1279 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1281 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1283 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1284 CHECK_GL( *this, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1288 * Wrapper for OpenGL ES 2.0 glHint()
1290 void Hint(GLenum target, GLenum mode)
1292 LOG_GL("Hint %x %x\n", target, mode);
1293 CHECK_GL( *this, mGlAbstraction.Hint(target, mode) );
1297 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1299 GLboolean IsBuffer(GLuint buffer)
1301 LOG_GL("IsBuffer %d\n", buffer);
1302 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsBuffer(buffer) );
1307 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1309 GLboolean IsEnabled(GLenum cap)
1311 LOG_GL("IsEnabled %x\n", cap);
1312 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsEnabled(cap) );
1317 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1319 GLboolean IsFramebuffer(GLuint framebuffer)
1321 LOG_GL("IsFramebuffer %d\n", framebuffer);
1322 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsFramebuffer(framebuffer) );
1327 * Wrapper for OpenGL ES 3.0 glIsQuery()
1329 GLboolean IsQuery(GLuint id)
1331 LOG_GL("IsQuery %u\n", id);
1332 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsQuery(id) );
1337 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1339 GLboolean IsRenderbuffer(GLuint renderbuffer)
1341 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1342 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1347 * Wrapper for OpenGL ES 2.0 glIsTexture()
1349 GLboolean IsTexture(GLuint texture)
1351 LOG_GL("IsTexture %d\n", texture);
1352 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTexture(texture) );
1357 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1359 GLboolean IsTransformFeedback(GLuint id)
1361 LOG_GL("IsTransformFeedback %u\n", id);
1362 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTransformFeedback(id) );
1367 * Wrapper for OpenGL ES 2.0 glLineWidth()
1369 void LineWidth(GLfloat width)
1371 LOG_GL("LineWidth %f\n", width);
1372 CHECK_GL( *this, mGlAbstraction.LineWidth(width) );
1376 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1378 void PauseTransformFeedback()
1380 LOG_GL("PauseTransformFeedback\n");
1381 CHECK_GL( *this, mGlAbstraction.PauseTransformFeedback() );
1385 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1387 void PixelStorei(GLenum pname, GLint param)
1389 LOG_GL("PixelStorei %x %d\n", pname, param);
1390 CHECK_GL( *this, mGlAbstraction.PixelStorei(pname, param) );
1394 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1396 void PolygonOffset(GLfloat factor, GLfloat units)
1398 LOG_GL("PolygonOffset %f %f\n", factor, units);
1399 CHECK_GL( *this, mGlAbstraction.PolygonOffset(factor, units) );
1403 * Wrapper for OpenGL ES 2.0 glReadPixels()
1405 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1407 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1408 CHECK_GL( *this, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1412 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1414 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1416 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1417 CHECK_GL( *this, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1421 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1423 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1425 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1426 CHECK_GL( *this, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1430 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1432 void ResumeTransformFeedback()
1434 LOG_GL("ResumeTransformFeedback\n");
1435 CHECK_GL( *this, mGlAbstraction.ResumeTransformFeedback() );
1439 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1441 void SampleCoverage(GLclampf value, GLboolean invert)
1443 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1444 CHECK_GL( *this, mGlAbstraction.SampleCoverage(value, invert) );
1448 * Wrapper for OpenGL ES 2.0 glScissor()
1450 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1452 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1453 CHECK_GL( *this, mGlAbstraction.Scissor(x, y, width, height) );
1457 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1459 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1461 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1462 CHECK_GL( *this, mGlAbstraction.StencilFunc(func, ref, mask) );
1466 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1468 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1470 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1471 CHECK_GL( *this, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1475 * Wrapper for OpenGL ES 2.0 glStencilMask()
1477 void StencilMask(GLuint mask)
1479 if( mask != mStencilMask )
1481 mStencilMask = mask;
1483 LOG_GL("StencilMask %d\n", mask);
1484 CHECK_GL( *this, mGlAbstraction.StencilMask(mask) );
1489 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1491 void StencilMaskSeparate(GLenum face, GLuint mask)
1493 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1494 CHECK_GL( *this, mGlAbstraction.StencilMaskSeparate(face, mask) );
1498 * Wrapper for OpenGL ES 2.0 glStencilOp()
1500 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1502 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1503 CHECK_GL( *this, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1507 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1509 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1511 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1512 CHECK_GL( *this, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1516 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1518 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1519 GLint border, GLenum format, GLenum type, const void* pixels)
1521 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1522 CHECK_GL( *this, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1526 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1528 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1529 GLint border, GLenum format, GLenum type, const void* pixels)
1531 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1532 CHECK_GL( *this, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1536 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1538 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1540 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1541 CHECK_GL( *this, mGlAbstraction.TexParameterf(target, pname, param) );
1545 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1547 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1549 LOG_GL("TexParameterfv %x %x\n", target, pname);
1550 CHECK_GL( *this, mGlAbstraction.TexParameterfv(target, pname, params) );
1554 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1556 void TexParameteri(GLenum target, GLenum pname, GLint param)
1558 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1559 CHECK_GL( *this, mGlAbstraction.TexParameteri(target, pname, param) );
1563 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1565 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1567 LOG_GL("TexParameteriv %x %x\n", target, pname);
1568 CHECK_GL( *this, mGlAbstraction.TexParameteriv(target, pname, params) );
1572 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1574 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1575 GLenum format, GLenum type, const void* pixels)
1577 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1578 CHECK_GL( *this, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1582 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1584 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1585 GLsizei width, GLsizei height, GLsizei depth,
1586 GLenum format, GLenum type, const void* pixels)
1588 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);
1589 CHECK_GL( *this, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1593 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1595 GLboolean UnmapBuffer(GLenum target)
1597 LOG_GL("UnmapBuffer %x \n", target);
1598 GLboolean val = CHECK_GL( *this, mGlAbstraction.UnmapBuffer(target) );
1602 * Wrapper for OpenGL ES 2.0 glViewport()
1604 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1606 // check if its same as already set
1607 Rect<int> newViewport( x, y, width, height );
1608 if( mViewPort != newViewport )
1611 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1612 CHECK_GL( *this, mGlAbstraction.Viewport(x, y, width, height) );
1613 mViewPort = newViewport; // remember new one
1618 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1619 * @return The implementation defined MAX_TEXTURE_SIZE
1621 GLint CachedMaxTextureSize() const
1623 return mMaxTextureSize;
1627 * Get the number of supported program binary formats
1628 * @return The number of supported program binary formats
1630 GLint CachedNumberOfProgramBinaryFormats() const
1632 return mProgramBinaryFormats.Count();
1636 * Get a supported program binary format
1637 * @param[in] formatIndex The index of the format to return (default: 0)
1638 * @return A supported program binary format
1640 GLint CachedProgramBinaryFormat( const unsigned int formatIndex = 0 ) const
1642 DALI_ASSERT_ALWAYS( formatIndex < mProgramBinaryFormats.Count() && "formatIndex out of bounds");
1644 return mProgramBinaryFormats[ formatIndex ];
1648 * @return current program
1650 const Program* GetCurrentProgram() const
1652 return mCurrentProgram;
1656 * Set current program
1657 * @param [in] program that is in use
1659 void SetCurrentProgram( Program* program )
1661 mCurrentProgram = program;
1665 * Reset the program matrices
1667 void ResetProgramMatrices();
1670 * Get a cached program
1671 * @param [in] hash value
1672 * @return pointer to the program
1674 Program* GetCachedProgram( std::size_t hash ) const;
1678 * @param [in] hash value
1679 * @param [in] pointer to the program
1681 void CacheProgram( std::size_t hash, Program* pointer );
1684 * Get the current viewport.
1685 * @return Viewport rectangle.
1687 const Rect< int >& GetViewport();
1689 #ifdef DEBUG_ENABLED
1691 /// Switch debug level to Concise to disable, General to enable. Note, enabling snapshot logging will do this on the fly.
1692 static Debug::Filter *gGlLogFilter;
1694 #endif // DEBUG_ENABLED
1698 * Set the frame count of render thread
1700 inline void SetFrameCount(unsigned int frameCount)
1702 mFrameCount = frameCount;
1706 * Get the frame count
1708 inline unsigned int GetFrameCount()
1714 * Increment the count of culled renderers
1716 inline void IncrementCulledCount()
1722 * Clear the count of culled renderers
1724 inline void ClearCulledCount()
1730 * Get the count of culled renderers in this frame
1732 inline unsigned int GetCulledCount()
1734 return mCulledCount;
1738 * Increment the count of culled renderers
1740 inline void IncrementRendererCount()
1746 * Clear the count of image renderers
1748 inline void ClearRendererCount()
1754 * Get the count of image renderers in this frame
1756 inline unsigned int GetRendererCount()
1758 return mRendererCount;
1762 private: // Implementation
1765 * Flushes vertex attribute location changes to the driver
1767 void FlushVertexAttributeLocations();
1770 * Reset the cached internal vertex attribute state
1772 void ResetVertexAttributeState();
1775 * Either enables or disables a vertex attribute location in the cache
1776 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1777 * @param location attribute location
1778 * @param state attribute state
1780 void SetVertexAttributeLocation(unsigned int location, bool state);
1783 * Sets the initial GL state.
1785 void ResetGlState();
1789 Integration::GlAbstraction& mGlAbstraction;
1791 bool mGlContextCreated; ///< True if the OpenGL context has been created
1793 // glEnable/glDisable states
1795 GLuint mStencilMask;
1797 bool mDepthTestEnabled;
1798 bool mDepthMaskEnabled;
1799 bool mDitherEnabled;
1800 bool mPolygonOffsetFillEnabled;
1801 bool mSampleAlphaToCoverageEnabled;
1802 bool mSampleCoverageEnabled;
1803 bool mScissorTestEnabled;
1804 bool mStencilTestEnabled;
1805 bool mClearColorSet;
1807 // glBindBuffer() state
1808 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1809 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1810 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1812 // glBindTexture() state
1813 TextureUnit mActiveTextureUnit;
1814 GLuint mBound2dTextureId[ MAX_TEXTURE_UNITS ]; ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
1816 // glBlendColor() state
1817 bool mUsingDefaultBlendColor;
1819 // glBlendFuncSeparate() state
1820 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1821 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1822 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1823 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1825 // glBlendEquationSeparate state
1826 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1827 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1829 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1830 Vector4 mClearColor; ///< clear color
1832 Dali::Vector<GLint> mProgramBinaryFormats; ///< array of supported program binary formats
1834 // Face culling mode
1835 CullFaceMode mCullFaceMode;
1837 // cached viewport size
1838 Rect< int > mViewPort;
1840 // Vertex Attribute Buffer enable caching
1841 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1842 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1844 Program* mCurrentProgram;
1845 typedef std::map< std::size_t, Program* > ProgramContainer;
1846 ProgramContainer mProgramCache; ///< Cache of shader programs
1847 unsigned int mFrameCount; ///< Number of render frames
1848 unsigned int mCulledCount; ///< Number of culled renderers per frame
1849 unsigned int mRendererCount; ///< Number of image renderers per frame
1852 } // namespace Internal
1856 #endif // __DALI_INTERNAL_CONTEXT_H__