1 #ifndef __DALI_INTERNAL_CONTEXT_H__
2 #define __DALI_INTERNAL_CONTEXT_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/public-api/common/map-wrapper.h>
22 #include <dali/public-api/common/set-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 ContextObserver;
39 class Program; // to be able to cache programs
41 // wrap gl calls with CHECK_GL eg "CHECK_GL( *this, glBindTexture(textureId) );"
42 // will LOG any glErrors eg "glError (0x0501) GL_INVALID_VALUE - glBindTexture(textureId)"
43 // only enable if specifically enabled as it slows down GL a lot!
44 #ifdef DALI_GL_ERROR_CHECK
45 #define CHECK_GL(c,a) (a); (c).CheckGlError(#a)
47 #define CHECK_GL(c,a) (a)
50 // Don't put guards around here (LOG_INFO has it's own guards)
51 #define LOG_GL(format, args...) \
52 DALI_LOG_INFO(Context::gGlLogFilter, Debug::General, format, ## args)
55 * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
56 * Observers will be notified when the GL context is created/destroyed.
57 * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
64 * Size of the VertexAttributeArray enables
65 * GLES specification states that there's minimum of 8
67 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
70 * Creates the Dali Context object.
71 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
72 * @pre Context has not been created.
73 * @exception Context already created.
74 * @param glAbstraction the gl abstraction.
76 Context( Integration::GlAbstraction& glAbstraction );
84 * Called when the GL context has been created.
85 * @post Context observers will be notified.
87 void GlContextCreated();
90 * Called when the GL context is about to be destroyed.
91 * @post Context observers will be notified, and should free any GL resources held.
93 void GlContextToBeDestroyed();
96 * Query whether the OpenGL context has been created.
97 * @return True if the OpenGL context has been created.
99 bool IsGlContextCreated() { return mGlContextCreated; }
102 * Adds an observer to the Context object.
103 * The observer is responsible for calling RemoveObserver() before destruction.
104 * @param[in] observer The observer to add.
106 void AddObserver(ContextObserver& observer);
109 * Removes an observer from the Context object.
110 * The observer must call this method before it is destroyed.
111 * @param[in] observer The observer to remove.
113 void RemoveObserver(ContextObserver& observer);
116 * @return the GLAbstraction
118 Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
120 #ifdef DALI_CONTEXT_LOGGING
123 * Debug helper which prints the currently cached GL state.
125 void PrintCurrentState();
130 * Helper to convert GL error code to string
131 * @param errorCode to convert
134 const char* ErrorToString( GLenum errorCode );
137 * Helper to check GL error during an operation
138 * @param operation that was performed
140 void CheckGlError( const char* operation )
142 for( GLint error = GetError(); error; error = GetError() )
144 DALI_LOG_ERROR( "glError (0x%x) %s - after %s\n", error, ErrorToString(error), operation );
145 DALI_ASSERT_ALWAYS( error && "GL ERROR"); // if errors are being checked we should assert
150 * Helper to print GL string to debug log
152 void PrintGlString(const char* stringName, GLenum stringId)
154 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, (const char *)GetString( stringId ) );
157 /****************************************************************************************
158 * The following methods are forwarded to Dali::Integration::GlAbstraction.
159 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
160 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
161 * handles them and optimizes any program related state changes
162 ****************************************************************************************/
165 * Wrapper for OpenGL ES 2.0 glActiveTexture()
167 void ActiveTexture(GLenum textureUnit)
169 // GL texture units are #defines in growing order to converting that to index
170 unsigned int unit = textureUnit - GL_TEXTURE0;
172 if ( unit != mActiveTextureUnit )
174 mActiveTextureUnit = unit;
175 LOG_GL("ActiveTexture %x\n", textureUnit);
176 CHECK_GL( *this, mGlAbstraction.ActiveTexture(textureUnit) );
181 * Wrapper for OpenGL ES 3.0 glBeginQuery()
183 void BeginQuery(GLenum target, GLuint id)
185 LOG_GL("BeginQuery %d %d\n", target, id);
186 CHECK_GL( *this, mGlAbstraction.BeginQuery(target, id) );
190 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
192 void BeginTransformFeedback(GLenum primitiveMode)
194 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
195 CHECK_GL( *this, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
199 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
203 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
205 void BindArrayBuffer(GLuint buffer)
207 // Avoid unecessary calls to BindBuffer
208 if (mBoundArrayBufferId != buffer)
210 mBoundArrayBufferId = buffer;
212 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
213 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
218 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
220 void BindElementArrayBuffer(GLuint buffer)
222 // Avoid unecessary calls to BindBuffer
223 if (mBoundElementArrayBufferId!= buffer)
225 mBoundElementArrayBufferId = buffer;
227 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
228 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
233 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
235 void BindTransformFeedbackBuffer(GLuint buffer)
237 // Avoid unecessary calls to BindBuffer
238 if (mBoundTransformFeedbackBufferId != buffer)
240 mBoundTransformFeedbackBufferId = buffer;
242 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
243 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
248 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
250 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
252 // Avoid unecessary calls to BindBufferBase
253 if (mBoundTransformFeedbackBufferId != buffer)
255 mBoundTransformFeedbackBufferId = buffer;
257 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
258 CHECK_GL( *this, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
263 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
265 void BindFramebuffer(GLenum target, GLuint framebuffer)
267 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
268 CHECK_GL( *this, mGlAbstraction.BindFramebuffer(target, framebuffer) );
272 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
274 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
276 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
277 CHECK_GL( *this, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
281 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
283 void BindTransformFeedback(GLenum target, GLuint id)
285 LOG_GL("BindTransformFeedback %d %d\n", target, id);
286 CHECK_GL( *this, mGlAbstraction.BindTransformFeedback(target, id) );
290 * The wrapper for OpenGL ES 2.0 glBindTexture() has been replaced by Bind2dTexture and BindCubeMapTexture.
294 * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D)
296 void Bind2dTexture( GLuint texture )
298 if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
300 mBound2dTextureId[ mActiveTextureUnit ] = texture;
302 LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture);
303 CHECK_GL( *this, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) );
305 INCREASE_COUNTER(PerformanceMonitor::TEXTURE_STATE_CHANGES);
310 * Wrapper for OpenGL ES 2.0 glBlendColor()
312 void SetDefaultBlendColor()
314 if( !mUsingDefaultBlendColor )
316 LOG_GL( "BlendColor %f %f %f %f\n", 0.0f, 0.0f, 0.0f, 0.0f );
317 CHECK_GL( *this, mGlAbstraction.BlendColor( 0.0f, 0.0f, 0.0f, 0.0f ) );
318 mUsingDefaultBlendColor = true;
323 * Wrapper for OpenGL ES 2.0 glBlendColor()
325 void SetCustomBlendColor( const Vector4& color )
327 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
328 CHECK_GL( *this, mGlAbstraction.BlendColor(color.r, color.g, color.b, color.a) );
329 mUsingDefaultBlendColor = false;
333 * Wrapper for OpenGL ES 2.0 glBlendEquation()
335 void BlendEquation(GLenum mode)
337 // use BlendEquationSeparate to set the rgb and alpha modes the same
338 BlendEquationSeparate( mode, mode );
342 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
344 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
346 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
347 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
349 mBlendEquationSeparateModeRGB = modeRGB;
350 mBlendEquationSeparateModeAlpha = modeAlpha;
351 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
352 CHECK_GL( *this, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
357 * Wrapper for OpenGL ES 2.0 glBlendFunc()
359 void BlendFunc(GLenum sfactor, GLenum dfactor)
361 // reuse the BlendFuncSeparate as thats what the DDK does anyways
362 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
366 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
368 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
370 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
371 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
373 mBlendFuncSeparateSrcRGB = srcRGB;
374 mBlendFuncSeparateDstRGB = dstRGB;
375 mBlendFuncSeparateSrcAlpha = srcAlpha;
376 mBlendFuncSeparateDstAlpha = dstAlpha;
378 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
379 CHECK_GL( *this, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
384 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
386 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
388 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
389 CHECK_GL( *this, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
393 * Wrapper for OpenGL ES 2.0 glBufferData()
395 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
397 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
398 CHECK_GL( *this, mGlAbstraction.BufferData(target, size, data, usage) );
402 * Wrapper for OpenGL ES 2.0 glBufferSubData()
404 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
406 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
407 CHECK_GL( *this, mGlAbstraction.BufferSubData(target, offset, size, data) );
411 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
413 GLenum CheckFramebufferStatus(GLenum target)
415 LOG_GL("CheckFramebufferStatus %d\n", target);
416 GLenum value = CHECK_GL( *this, mGlAbstraction.CheckFramebufferStatus(target) );
421 * Wrapper for OpenGL ES 2.0 glClear()
423 void Clear(GLbitfield mask)
425 LOG_GL("Clear %d\n", mask);
426 CHECK_GL( *this, mGlAbstraction.Clear(mask) );
430 * Wrapper for OpenGL ES 2.0 glClearColor()
432 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
434 Vector4 newCol(red,green,blue,alpha);
436 if (!mClearColorSet || mClearColor !=newCol )
438 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
439 CHECK_GL( *this, mGlAbstraction.ClearColor(red, green, blue, alpha) );
441 mClearColorSet = true;
442 mClearColor = newCol;
447 * Wrapper for OpenGL ES 2.0 glClearDepthf()
449 void ClearDepthf(GLclampf depth)
451 LOG_GL("ClearDepthf %f\n", depth);
452 CHECK_GL( *this, mGlAbstraction.ClearDepthf(depth) );
456 * Wrapper for OpenGL ES 2.0 glClearStencil()
458 void ClearStencil(GLint s)
460 LOG_GL("ClearStencil %d\n", s);
461 CHECK_GL( *this, mGlAbstraction.ClearStencil(s) );
465 * Wrapper for OpenGL ES 2.0 glColorMask()
466 * @note This has been optimized to a single boolean value (masking individual channels is not required)
468 void ColorMask( bool flag )
470 // only change state if needed
471 if( flag != mColorMask )
474 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
475 CHECK_GL( *this, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
480 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
482 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
483 GLint border, GLsizei imageSize, const void* data)
485 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
486 CHECK_GL( *this, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
490 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
492 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
493 GLint border, GLsizei imageSize, const void* data)
495 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
496 CHECK_GL( *this, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
500 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
502 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
503 GLenum format, GLsizei imageSize, const void* data)
505 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
506 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
510 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
512 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
513 GLsizei width, GLsizei height, GLsizei depth,
514 GLenum format, GLsizei imageSize, const void* data)
516 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);
517 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
521 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
523 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
525 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
526 CHECK_GL( *this, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
530 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
532 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
534 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
535 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
539 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
541 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
543 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
544 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
548 * Wrapper for OpenGL ES 2.0 glCullFace()
549 * enables GL_CULL_FACE if in any of the face culling modes
550 * otherwise disables GL_CULL_FACE
552 void CullFace(CullFaceMode mode)
554 // Avoid unnecessary calls to gl
555 if(mCullFaceMode != mode)
557 mCullFaceMode = mode;
562 LOG_GL("Disable GL_CULL_FACE\n");
563 CHECK_GL( *this, mGlAbstraction.Disable(GL_CULL_FACE) );
569 LOG_GL("Enable GL_CULL_FACE\n");
570 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
571 LOG_GL("Enable GL_FRONT\n");
572 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT) );
578 LOG_GL("Enable GL_CULL_FACE\n");
579 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
580 LOG_GL("Enable GL_BACK\n");
581 CHECK_GL( *this, mGlAbstraction.CullFace(GL_BACK) );
585 case CullFrontAndBack:
587 LOG_GL("Enable GL_CULL_FACE\n");
588 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
589 LOG_GL("Enable GL_FRONT_AND_BACK\n");
590 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
601 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
603 void DeleteBuffers(GLsizei n, const GLuint* buffers)
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( int i=0; i < mMaxTextureUnits; ++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.size();
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.size() && "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 * Get a cached program
1666 * @param [in] hash value
1667 * @return pointer to the program
1669 Program* GetCachedProgram( std::size_t hash ) const;
1673 * @param [in] hash value
1674 * @param [in] pointer to the program
1676 void CacheProgram( std::size_t hash, Program* pointer );
1679 * Get the current viewport.
1680 * @return Viewport rectangle.
1682 const Rect< int >& GetViewport();
1684 #ifdef DEBUG_ENABLED
1686 /// Switch debug level to Concise to disable, General to enable. Note, enabling snapshot logging will do this on the fly.
1687 static Debug::Filter *gGlLogFilter;
1689 #endif // DEBUG_ENABLED
1691 private: // Implementation
1694 * Flushes vertex attribute location changes to the driver
1696 void FlushVertexAttributeLocations();
1699 * Reset the cached internal vertex attribute state
1701 void ResetVertexAttributeState();
1704 * Either enables or disables a vertex attribute location in the cache
1705 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1706 * @param location attribute location
1707 * @param state attribute state
1709 void SetVertexAttributeLocation(unsigned int location, bool state);
1712 * Sets the initial GL state.
1714 void ResetGlState();
1718 Integration::GlAbstraction& mGlAbstraction;
1720 bool mGlContextCreated; ///< True if the OpenGL context has been created
1722 // glEnable/glDisable states
1724 GLuint mStencilMask;
1726 bool mDepthTestEnabled;
1727 bool mDepthMaskEnabled;
1728 bool mDitherEnabled;
1729 bool mPolygonOffsetFillEnabled;
1730 bool mSampleAlphaToCoverageEnabled;
1731 bool mSampleCoverageEnabled;
1732 bool mScissorTestEnabled;
1733 bool mStencilTestEnabled;
1734 bool mClearColorSet;
1736 // glBindBuffer() state
1737 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1738 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1739 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1741 // glBindTexture() state
1742 unsigned int mActiveTextureUnit;
1743 std::vector<GLuint> mBound2dTextureId; ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
1745 // glBlendColor() state
1746 bool mUsingDefaultBlendColor;
1748 // glBlendFuncSeparate() state
1749 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1750 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1751 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1752 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1754 // glBlendEquationSeparate state
1755 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1756 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1758 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1759 GLint mMaxTextureUnits; ///< return value from GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS)
1760 Vector4 mClearColor; ///< clear color
1762 std::vector<GLint> mProgramBinaryFormats; ///< array of supported program binary formats
1764 // Face culling mode
1765 CullFaceMode mCullFaceMode;
1767 // cached viewport size
1768 Rect< int > mViewPort;
1770 // Vertex Attribute Buffer enable caching
1771 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1772 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1774 std::set<ContextObserver*> mObservers;
1776 Program* mCurrentProgram;
1777 std::map< std::size_t, Program* > mProgramCache; /// program cache
1781 } // namespace Internal
1785 #endif // __DALI_INTERNAL_CONTEXT_H__