1 #ifndef __DALI_INTERNAL_CONTEXT_H__
2 #define __DALI_INTERNAL_CONTEXT_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/integration-api/gl-defines.h>
23 #include <dali/public-api/common/map-wrapper.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/actors/renderable-actor.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/integration-api/gl-abstraction.h>
28 #include <dali/internal/render/common/performance-monitor.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/math/rect.h>
31 #include <dali/public-api/math/vector4.h>
39 class Program; // to be able to cache programs
41 // wrap gl calls with CHECK_GL eg "CHECK_GL( *this, glBindTexture(textureId) );"
42 // will LOG any glErrors eg "glError (0x0501) GL_INVALID_VALUE - glBindTexture(textureId)"
43 // only enable if specifically enabled as it slows down GL a lot!
44 #ifdef DALI_GL_ERROR_CHECK
45 #define CHECK_GL(c,a) (a); (c).CheckGlError(#a)
47 #define CHECK_GL(c,a) (a)
50 // Don't put guards around here (LOG_INFO has it's own guards)
51 #define LOG_GL(format, args...) \
52 DALI_LOG_INFO(Context::gGlLogFilter, Debug::General, format, ## args)
55 * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
56 * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
62 * Size of the VertexAttributeArray enables
63 * GLES specification states that there's minimum of 8
65 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
67 static const unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 its 8, which is more than DALi uses anyways
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.
86 void GlContextCreated();
89 * Called when the GL context has been destroyed.
91 void GlContextDestroyed();
94 * Query whether the OpenGL context has been created.
95 * @return True if the OpenGL context has been created.
97 bool IsGlContextCreated() { return mGlContextCreated; }
100 * @return the GLAbstraction
102 Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
104 #ifdef DALI_CONTEXT_LOGGING
107 * Debug helper which prints the currently cached GL state.
109 void PrintCurrentState();
114 * Helper to convert GL error code to string
115 * @param errorCode to convert
118 const char* ErrorToString( GLenum errorCode );
121 * Helper to check GL error during an operation
122 * @param operation that was performed
124 void CheckGlError( const char* operation )
126 for( GLint error = GetError(); error; error = GetError() )
128 DALI_LOG_ERROR( "glError (0x%x) %s - after %s\n", error, ErrorToString(error), operation );
129 DALI_ASSERT_ALWAYS( error && "GL ERROR"); // if errors are being checked we should assert
134 * Helper to print GL string to debug log
136 void PrintGlString(const char* stringName, GLenum stringId)
138 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, (const char *)GetString( stringId ) );
141 /****************************************************************************************
142 * The following methods are forwarded to Dali::Integration::GlAbstraction.
143 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
144 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
145 * handles them and optimizes any program related state changes
146 ****************************************************************************************/
149 * Wrapper for OpenGL ES 2.0 glActiveTexture()
151 void ActiveTexture(GLenum textureUnit)
153 // GL texture units are #defines in growing order to converting that to index
154 unsigned int unit = textureUnit - GL_TEXTURE0;
156 if ( unit != mActiveTextureUnit )
158 mActiveTextureUnit = unit;
159 LOG_GL("ActiveTexture %x\n", textureUnit);
160 CHECK_GL( *this, mGlAbstraction.ActiveTexture(textureUnit) );
165 * Wrapper for OpenGL ES 3.0 glBeginQuery()
167 void BeginQuery(GLenum target, GLuint id)
169 LOG_GL("BeginQuery %d %d\n", target, id);
170 CHECK_GL( *this, mGlAbstraction.BeginQuery(target, id) );
174 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
176 void BeginTransformFeedback(GLenum primitiveMode)
178 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
179 CHECK_GL( *this, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
183 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
187 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
189 void BindArrayBuffer(GLuint buffer)
191 // Avoid unecessary calls to BindBuffer
192 if (mBoundArrayBufferId != buffer)
194 mBoundArrayBufferId = buffer;
196 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
197 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
202 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
204 void BindElementArrayBuffer(GLuint buffer)
206 // Avoid unecessary calls to BindBuffer
207 if (mBoundElementArrayBufferId!= buffer)
209 mBoundElementArrayBufferId = buffer;
211 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
212 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
217 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
219 void BindTransformFeedbackBuffer(GLuint buffer)
221 // Avoid unecessary calls to BindBuffer
222 if (mBoundTransformFeedbackBufferId != buffer)
224 mBoundTransformFeedbackBufferId = buffer;
226 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
227 CHECK_GL( *this, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
232 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
234 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
236 // Avoid unecessary calls to BindBufferBase
237 if (mBoundTransformFeedbackBufferId != buffer)
239 mBoundTransformFeedbackBufferId = buffer;
241 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
242 CHECK_GL( *this, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
247 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
249 void BindFramebuffer(GLenum target, GLuint framebuffer)
251 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
252 CHECK_GL( *this, mGlAbstraction.BindFramebuffer(target, framebuffer) );
256 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
258 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
260 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
261 CHECK_GL( *this, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
265 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
267 void BindTransformFeedback(GLenum target, GLuint id)
269 LOG_GL("BindTransformFeedback %d %d\n", target, id);
270 CHECK_GL( *this, mGlAbstraction.BindTransformFeedback(target, id) );
274 * The wrapper for OpenGL ES 2.0 glBindTexture() has been replaced by Bind2dTexture and BindCubeMapTexture.
278 * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D)
280 void Bind2dTexture( GLuint texture )
282 if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
284 mBound2dTextureId[ mActiveTextureUnit ] = texture;
286 LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture);
287 CHECK_GL( *this, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) );
289 INCREASE_COUNTER(PerformanceMonitor::TEXTURE_STATE_CHANGES);
294 * Wrapper for OpenGL ES 2.0 glBlendColor()
296 void SetDefaultBlendColor()
298 if( !mUsingDefaultBlendColor )
300 LOG_GL( "BlendColor %f %f %f %f\n", 0.0f, 0.0f, 0.0f, 0.0f );
301 CHECK_GL( *this, mGlAbstraction.BlendColor( 0.0f, 0.0f, 0.0f, 0.0f ) );
302 mUsingDefaultBlendColor = true;
307 * Wrapper for OpenGL ES 2.0 glBlendColor()
309 void SetCustomBlendColor( const Vector4& color )
311 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
312 CHECK_GL( *this, mGlAbstraction.BlendColor(color.r, color.g, color.b, color.a) );
313 mUsingDefaultBlendColor = false;
317 * Wrapper for OpenGL ES 2.0 glBlendEquation()
319 void BlendEquation(GLenum mode)
321 // use BlendEquationSeparate to set the rgb and alpha modes the same
322 BlendEquationSeparate( mode, mode );
326 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
328 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
330 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
331 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
333 mBlendEquationSeparateModeRGB = modeRGB;
334 mBlendEquationSeparateModeAlpha = modeAlpha;
335 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
336 CHECK_GL( *this, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
341 * Wrapper for OpenGL ES 2.0 glBlendFunc()
343 void BlendFunc(GLenum sfactor, GLenum dfactor)
345 // reuse the BlendFuncSeparate as thats what the DDK does anyways
346 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
350 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
352 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
354 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
355 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
357 mBlendFuncSeparateSrcRGB = srcRGB;
358 mBlendFuncSeparateDstRGB = dstRGB;
359 mBlendFuncSeparateSrcAlpha = srcAlpha;
360 mBlendFuncSeparateDstAlpha = dstAlpha;
362 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
363 CHECK_GL( *this, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
368 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
370 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
372 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
373 CHECK_GL( *this, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
377 * Wrapper for OpenGL ES 2.0 glBufferData()
379 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
381 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
382 CHECK_GL( *this, mGlAbstraction.BufferData(target, size, data, usage) );
386 * Wrapper for OpenGL ES 2.0 glBufferSubData()
388 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
390 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
391 CHECK_GL( *this, mGlAbstraction.BufferSubData(target, offset, size, data) );
395 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
397 GLenum CheckFramebufferStatus(GLenum target)
399 LOG_GL("CheckFramebufferStatus %d\n", target);
400 GLenum value = CHECK_GL( *this, mGlAbstraction.CheckFramebufferStatus(target) );
405 * Wrapper for OpenGL ES 2.0 glClear()
407 void Clear(GLbitfield mask)
409 LOG_GL("Clear %d\n", mask);
410 CHECK_GL( *this, mGlAbstraction.Clear(mask) );
414 * Wrapper for OpenGL ES 2.0 glClearColor()
416 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
418 Vector4 newCol(red,green,blue,alpha);
420 if (!mClearColorSet || mClearColor !=newCol )
422 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
423 CHECK_GL( *this, mGlAbstraction.ClearColor(red, green, blue, alpha) );
425 mClearColorSet = true;
426 mClearColor = newCol;
431 * Wrapper for OpenGL ES 2.0 glClearDepthf()
433 void ClearDepthf(GLclampf depth)
435 LOG_GL("ClearDepthf %f\n", depth);
436 CHECK_GL( *this, mGlAbstraction.ClearDepthf(depth) );
440 * Wrapper for OpenGL ES 2.0 glClearStencil()
442 void ClearStencil(GLint s)
444 LOG_GL("ClearStencil %d\n", s);
445 CHECK_GL( *this, mGlAbstraction.ClearStencil(s) );
449 * Wrapper for OpenGL ES 2.0 glColorMask()
450 * @note This has been optimized to a single boolean value (masking individual channels is not required)
452 void ColorMask( bool flag )
454 // only change state if needed
455 if( flag != mColorMask )
458 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
459 CHECK_GL( *this, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
464 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
466 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
467 GLint border, GLsizei imageSize, const void* data)
469 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
470 CHECK_GL( *this, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
474 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
476 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
477 GLint border, GLsizei imageSize, const void* data)
479 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
480 CHECK_GL( *this, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
484 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
486 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
487 GLenum format, GLsizei imageSize, const void* data)
489 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
490 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
494 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
496 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
497 GLsizei width, GLsizei height, GLsizei depth,
498 GLenum format, GLsizei imageSize, const void* data)
500 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);
501 CHECK_GL( *this, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
505 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
507 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
509 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
510 CHECK_GL( *this, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
514 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
516 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
518 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
519 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
523 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
525 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
527 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
528 CHECK_GL( *this, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
532 * Wrapper for OpenGL ES 2.0 glCullFace()
533 * enables GL_CULL_FACE if in any of the face culling modes
534 * otherwise disables GL_CULL_FACE
536 void CullFace(CullFaceMode mode)
538 // Avoid unnecessary calls to gl
539 if(mCullFaceMode != mode)
541 mCullFaceMode = mode;
546 LOG_GL("Disable GL_CULL_FACE\n");
547 CHECK_GL( *this, mGlAbstraction.Disable(GL_CULL_FACE) );
553 LOG_GL("Enable GL_CULL_FACE\n");
554 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
555 LOG_GL("Enable GL_FRONT\n");
556 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT) );
562 LOG_GL("Enable GL_CULL_FACE\n");
563 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
564 LOG_GL("Enable GL_BACK\n");
565 CHECK_GL( *this, mGlAbstraction.CullFace(GL_BACK) );
569 case CullFrontAndBack:
571 LOG_GL("Enable GL_CULL_FACE\n");
572 CHECK_GL( *this, mGlAbstraction.Enable(GL_CULL_FACE) );
573 LOG_GL("Enable GL_FRONT_AND_BACK\n");
574 CHECK_GL( *this, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
585 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
587 void DeleteBuffers(GLsizei n, const GLuint* buffers)
589 // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
590 // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
591 if( this->IsGlContextCreated() )
593 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
594 CHECK_GL( *this, mGlAbstraction.DeleteBuffers(n, buffers) );
596 // reset the cached buffer id's
597 // fixes problem where some drivers will a generate a buffer with the
598 // same id, as the last deleted buffer id.
599 mBoundArrayBufferId = 0;
600 mBoundElementArrayBufferId = 0;
601 mBoundTransformFeedbackBufferId = 0;
605 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
607 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
609 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
610 CHECK_GL( *this, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
614 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
616 void DeleteQueries(GLsizei n, GLuint* ids)
618 LOG_GL("DeleteQueries %d %p\n", n, ids);
619 CHECK_GL( *this, mGlAbstraction.DeleteQueries(n, ids) );
623 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
625 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
627 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
628 CHECK_GL( *this, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
632 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
634 void DeleteTextures(GLsizei n, const GLuint* textures)
636 LOG_GL("DeleteTextures %d %p\n", n, textures);
637 CHECK_GL( *this, mGlAbstraction.DeleteTextures(n, textures) );
639 // reset the cached texture id's incase the driver re-uses them
640 // when creating new textures
641 for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
643 mBound2dTextureId[ i ] = 0;
648 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
650 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
652 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
653 CHECK_GL( *this, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
657 * Wrapper for OpenGL ES 2.0 glDepthFunc()
659 void DepthFunc(GLenum func)
661 LOG_GL("DepthFunc %x\n", func);
662 CHECK_GL( *this, mGlAbstraction.DepthFunc(func) );
666 * Wrapper for OpenGL ES 2.0 glDepthMask()
668 void DepthMask(GLboolean flag)
670 // only change state if needed
671 if( flag != mDepthMaskEnabled )
673 mDepthMaskEnabled = flag;
674 LOG_GL("DepthMask %s\n", flag ? "True" : "False");
675 CHECK_GL( *this, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
680 * Wrapper for OpenGL ES 2.0 glDepthRangef()
682 void DepthRangef(GLclampf zNear, GLclampf zFar)
684 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
685 CHECK_GL( *this, mGlAbstraction.DepthRangef(zNear, zFar) );
689 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
690 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
694 * Wrapper for OpenGL ES 2.0 glDrawArrays()
696 void DrawArrays(GLenum mode, GLint first, GLsizei count)
698 FlushVertexAttributeLocations();
700 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
701 CHECK_GL( *this, mGlAbstraction.DrawArrays(mode, first, count) );
705 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
707 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
709 FlushVertexAttributeLocations();
711 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
712 CHECK_GL( *this, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
716 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
718 void DrawBuffers(GLsizei n, const GLenum* bufs)
720 LOG_GL("DrawBuffers %d %p\n", n, bufs);
721 CHECK_GL( *this, mGlAbstraction.DrawBuffers(n, bufs) );
725 * Wrapper for OpenGL ES 2.0 glDrawElements()
727 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
729 FlushVertexAttributeLocations();
731 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
732 CHECK_GL( *this, mGlAbstraction.DrawElements(mode, count, type, indices) );
736 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
738 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
740 FlushVertexAttributeLocations();
742 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
743 CHECK_GL( *this, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
747 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
749 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
751 FlushVertexAttributeLocations();
753 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
754 CHECK_GL( *this, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
758 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
760 void GenQueries(GLsizei n, GLuint* ids)
762 LOG_GL("GenQueries %d %p\n", n, ids);
763 CHECK_GL( *this, mGlAbstraction.GenQueries(n, ids) );
767 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
769 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
771 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
772 CHECK_GL( *this, mGlAbstraction.GenTransformFeedbacks(n, ids) );
776 * @return the current buffer bound for a given target
778 GLuint GetCurrentBoundArrayBuffer(GLenum target)
783 case GL_ARRAY_BUFFER:
785 result = mBoundArrayBufferId;
788 case GL_ELEMENT_ARRAY_BUFFER:
790 result = mBoundElementArrayBufferId;
793 case GL_TRANSFORM_FEEDBACK_BUFFER:
795 result = mBoundTransformFeedbackBufferId;
800 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
806 void EnableVertexAttributeArray( GLuint location )
808 SetVertexAttributeLocation( location, true);
811 void DisableVertexAttributeArray( GLuint location )
813 SetVertexAttributeLocation( location, false);
817 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
819 void VertexAttribDivisor ( GLuint index, GLuint divisor )
821 LOG_GL("VertexAttribPointer(%d, %d)\n", index, divisor );
822 CHECK_GL( *this, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
826 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
828 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
830 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
831 CHECK_GL( *this, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
835 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
837 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
839 LOG_GL("InvalidateFramebuffer\n");
840 CHECK_GL( *this, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
844 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
845 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
849 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
850 * @param[in] enable True if GL_BLEND should be enabled.
852 void SetBlend(bool enable)
854 // Avoid unecessary calls to glEnable/glDisable
855 if (enable != mBlendEnabled)
857 mBlendEnabled = enable;
861 LOG_GL("Enable GL_BLEND\n");
862 CHECK_GL( *this, mGlAbstraction.Enable(GL_BLEND) );
866 LOG_GL("Disable GL_BLEND\n");
867 CHECK_GL( *this, mGlAbstraction.Disable(GL_BLEND) );
873 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
874 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
876 void SetDepthTest(bool enable)
878 // Avoid unecessary calls to glEnable/glDisable
879 if (enable != mDepthTestEnabled)
881 mDepthTestEnabled = enable;
885 LOG_GL("Enable GL_DEPTH_TEST\n");
886 CHECK_GL( *this, mGlAbstraction.Enable(GL_DEPTH_TEST) );
890 LOG_GL("Disable GL_DEPTH_TEST\n");
891 CHECK_GL( *this, mGlAbstraction.Disable(GL_DEPTH_TEST) );
897 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
898 * @param[in] enable True if GL_DITHER should be enabled.
900 void SetDither(bool enable)
902 // Avoid unecessary calls to glEnable/glDisable
903 if (enable != mDitherEnabled)
905 mDitherEnabled = enable;
909 LOG_GL("Enable GL_DITHER\n");
910 CHECK_GL( *this, mGlAbstraction.Enable(GL_DITHER) );
914 LOG_GL("Disable GL_DITHER\n");
915 CHECK_GL( *this, mGlAbstraction.Disable(GL_DITHER) );
921 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
922 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
924 void SetPolygonOffsetFill(bool enable)
926 // Avoid unecessary calls to glEnable/glDisable
927 if (enable != mPolygonOffsetFillEnabled)
929 mPolygonOffsetFillEnabled = enable;
933 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
934 CHECK_GL( *this, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
938 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
939 CHECK_GL( *this, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
945 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
946 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
948 void SetSampleAlphaToCoverage(bool enable)
950 // Avoid unecessary calls to glEnable/glDisable
951 if (enable != mSampleAlphaToCoverageEnabled)
953 mSampleAlphaToCoverageEnabled = enable;
957 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
958 CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
962 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
963 CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
969 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
970 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
972 void SetSampleCoverage(bool enable)
974 // Avoid unecessary calls to glEnable/glDisable
975 if (enable != mSampleCoverageEnabled)
977 mSampleCoverageEnabled = enable;
981 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
982 CHECK_GL( *this, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
986 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
987 CHECK_GL( *this, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
993 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
994 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
996 void SetScissorTest(bool enable)
998 // Avoid unecessary calls to glEnable/glDisable
999 if (enable != mScissorTestEnabled)
1001 mScissorTestEnabled = enable;
1005 LOG_GL("Enable GL_SCISSOR_TEST\n");
1006 CHECK_GL( *this, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
1010 LOG_GL("Disable GL_SCISSOR_TEST\n");
1011 CHECK_GL( *this, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1017 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1018 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1020 void SetStencilTest(bool enable)
1022 // Avoid unecessary calls to glEnable/glDisable
1023 if (enable != mStencilTestEnabled)
1025 mStencilTestEnabled = enable;
1029 LOG_GL("Enable GL_STENCIL_TEST\n");
1030 CHECK_GL( *this, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1034 LOG_GL("Disable GL_STENCIL_TEST\n");
1035 CHECK_GL( *this, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1041 * Wrapper for OpenGL ES 3.0 glEndQuery()
1043 void EndQuery(GLenum target)
1045 LOG_GL("EndQuery %d\n", target);
1046 CHECK_GL( *this, mGlAbstraction.EndQuery(target) );
1050 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1052 void EndTransformFeedback()
1054 LOG_GL("EndTransformFeedback\n");
1055 CHECK_GL( *this, mGlAbstraction.EndTransformFeedback() );
1059 * Wrapper for OpenGL ES 2.0 glFinish()
1064 CHECK_GL( *this, mGlAbstraction.Finish() );
1068 * Wrapper for OpenGL ES 2.0 glFlush()
1073 CHECK_GL( *this, mGlAbstraction.Flush() );
1077 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1079 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1081 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1082 CHECK_GL( *this, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1086 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1088 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1090 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1091 CHECK_GL( *this, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1095 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1097 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1099 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1100 CHECK_GL( *this, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1104 * Wrapper for OpenGL ES 2.0 glFrontFace()
1106 void FrontFace(GLenum mode)
1108 LOG_GL("FrontFace %x\n", mode);
1109 CHECK_GL( *this, mGlAbstraction.FrontFace(mode) );
1113 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1115 void GenBuffers(GLsizei n, GLuint* buffers)
1117 LOG_GL("GenBuffers %d\n", n, buffers);
1118 CHECK_GL( *this, mGlAbstraction.GenBuffers(n, buffers) );
1122 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1124 void GenerateMipmap(GLenum target)
1126 LOG_GL("GenerateMipmap %x\n", target);
1127 CHECK_GL( *this, mGlAbstraction.GenerateMipmap(target) );
1131 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1133 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1135 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1136 CHECK_GL( *this, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1140 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1142 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1144 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1145 CHECK_GL( *this, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1149 * Wrapper for OpenGL ES 2.0 glGenTextures()
1151 void GenTextures(GLsizei n, GLuint* textures)
1153 LOG_GL("GenTextures %d %p\n", n, textures);
1154 CHECK_GL( *this, mGlAbstraction.GenTextures(n, textures) );
1158 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1160 void GetBooleanv(GLenum pname, GLboolean* params)
1162 LOG_GL("GetBooleanv %x\n", pname);
1163 CHECK_GL( *this, mGlAbstraction.GetBooleanv(pname, params) );
1167 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1169 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1171 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1172 CHECK_GL( *this, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1176 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1178 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1180 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1181 CHECK_GL( *this, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1185 * Wrapper for OpenGL ES 2.0 glGetError()
1187 GLenum GetError(void)
1189 // Not worth logging here
1190 return mGlAbstraction.GetError();
1194 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1196 void GetFloatv(GLenum pname, GLfloat* params)
1198 LOG_GL("GetFloatv %x\n", pname);
1199 CHECK_GL( *this, mGlAbstraction.GetFloatv(pname, params) );
1203 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1205 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1207 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1208 CHECK_GL( *this, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1212 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1214 void GetIntegerv(GLenum pname, GLint* params)
1216 LOG_GL("GetIntegerv %x\n", pname);
1217 CHECK_GL( *this, mGlAbstraction.GetIntegerv(pname, params) );
1221 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1223 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1225 LOG_GL("GetQueryiv %x %x\n", target, pname);
1226 CHECK_GL( *this, mGlAbstraction.GetQueryiv(target, pname, params) );
1230 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1232 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1234 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1235 CHECK_GL( *this, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1239 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1241 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1243 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1244 CHECK_GL( *this, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1248 * Wrapper for OpenGL ES 2.0 glGetString()
1250 const GLubyte* GetString(GLenum name)
1252 LOG_GL("GetString %x\n", name);
1253 const GLubyte* str = CHECK_GL( *this, mGlAbstraction.GetString(name) );
1258 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1260 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1262 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1263 CHECK_GL( *this, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1267 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1269 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1271 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1272 CHECK_GL( *this, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1276 * Wrapper for OpenGL ES 2.0 glHint()
1278 void Hint(GLenum target, GLenum mode)
1280 LOG_GL("Hint %x %x\n", target, mode);
1281 CHECK_GL( *this, mGlAbstraction.Hint(target, mode) );
1285 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1287 GLboolean IsBuffer(GLuint buffer)
1289 LOG_GL("IsBuffer %d\n", buffer);
1290 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsBuffer(buffer) );
1295 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1297 GLboolean IsEnabled(GLenum cap)
1299 LOG_GL("IsEnabled %x\n", cap);
1300 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsEnabled(cap) );
1305 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1307 GLboolean IsFramebuffer(GLuint framebuffer)
1309 LOG_GL("IsFramebuffer %d\n", framebuffer);
1310 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsFramebuffer(framebuffer) );
1315 * Wrapper for OpenGL ES 3.0 glIsQuery()
1317 GLboolean IsQuery(GLuint id)
1319 LOG_GL("IsQuery %u\n", id);
1320 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsQuery(id) );
1325 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1327 GLboolean IsRenderbuffer(GLuint renderbuffer)
1329 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1330 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1335 * Wrapper for OpenGL ES 2.0 glIsTexture()
1337 GLboolean IsTexture(GLuint texture)
1339 LOG_GL("IsTexture %d\n", texture);
1340 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTexture(texture) );
1345 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1347 GLboolean IsTransformFeedback(GLuint id)
1349 LOG_GL("IsTransformFeedback %u\n", id);
1350 GLboolean val = CHECK_GL( *this, mGlAbstraction.IsTransformFeedback(id) );
1355 * Wrapper for OpenGL ES 2.0 glLineWidth()
1357 void LineWidth(GLfloat width)
1359 LOG_GL("LineWidth %f\n", width);
1360 CHECK_GL( *this, mGlAbstraction.LineWidth(width) );
1364 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1366 void PauseTransformFeedback()
1368 LOG_GL("PauseTransformFeedback\n");
1369 CHECK_GL( *this, mGlAbstraction.PauseTransformFeedback() );
1373 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1375 void PixelStorei(GLenum pname, GLint param)
1377 LOG_GL("PixelStorei %x %d\n", pname, param);
1378 CHECK_GL( *this, mGlAbstraction.PixelStorei(pname, param) );
1382 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1384 void PolygonOffset(GLfloat factor, GLfloat units)
1386 LOG_GL("PolygonOffset %f %f\n", factor, units);
1387 CHECK_GL( *this, mGlAbstraction.PolygonOffset(factor, units) );
1391 * Wrapper for OpenGL ES 2.0 glReadPixels()
1393 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1395 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1396 CHECK_GL( *this, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1400 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1402 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1404 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1405 CHECK_GL( *this, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1409 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1411 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1413 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1414 CHECK_GL( *this, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1418 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1420 void ResumeTransformFeedback()
1422 LOG_GL("ResumeTransformFeedback\n");
1423 CHECK_GL( *this, mGlAbstraction.ResumeTransformFeedback() );
1427 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1429 void SampleCoverage(GLclampf value, GLboolean invert)
1431 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1432 CHECK_GL( *this, mGlAbstraction.SampleCoverage(value, invert) );
1436 * Wrapper for OpenGL ES 2.0 glScissor()
1438 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1440 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1441 CHECK_GL( *this, mGlAbstraction.Scissor(x, y, width, height) );
1445 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1447 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1449 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1450 CHECK_GL( *this, mGlAbstraction.StencilFunc(func, ref, mask) );
1454 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1456 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1458 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1459 CHECK_GL( *this, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1463 * Wrapper for OpenGL ES 2.0 glStencilMask()
1465 void StencilMask(GLuint mask)
1467 if( mask != mStencilMask )
1469 mStencilMask = mask;
1471 LOG_GL("StencilMask %d\n", mask);
1472 CHECK_GL( *this, mGlAbstraction.StencilMask(mask) );
1477 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1479 void StencilMaskSeparate(GLenum face, GLuint mask)
1481 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1482 CHECK_GL( *this, mGlAbstraction.StencilMaskSeparate(face, mask) );
1486 * Wrapper for OpenGL ES 2.0 glStencilOp()
1488 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1490 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1491 CHECK_GL( *this, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1495 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1497 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1499 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1500 CHECK_GL( *this, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1504 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1506 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1507 GLint border, GLenum format, GLenum type, const void* pixels)
1509 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1510 CHECK_GL( *this, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1514 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1516 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1517 GLint border, GLenum format, GLenum type, const void* pixels)
1519 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1520 CHECK_GL( *this, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1524 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1526 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1528 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1529 CHECK_GL( *this, mGlAbstraction.TexParameterf(target, pname, param) );
1533 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1535 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1537 LOG_GL("TexParameterfv %x %x\n", target, pname);
1538 CHECK_GL( *this, mGlAbstraction.TexParameterfv(target, pname, params) );
1542 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1544 void TexParameteri(GLenum target, GLenum pname, GLint param)
1546 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1547 CHECK_GL( *this, mGlAbstraction.TexParameteri(target, pname, param) );
1551 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1553 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1555 LOG_GL("TexParameteriv %x %x\n", target, pname);
1556 CHECK_GL( *this, mGlAbstraction.TexParameteriv(target, pname, params) );
1560 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1562 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1563 GLenum format, GLenum type, const void* pixels)
1565 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1566 CHECK_GL( *this, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1570 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1572 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1573 GLsizei width, GLsizei height, GLsizei depth,
1574 GLenum format, GLenum type, const void* pixels)
1576 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);
1577 CHECK_GL( *this, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1581 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1583 GLboolean UnmapBuffer(GLenum target)
1585 LOG_GL("UnmapBuffer %x \n", target);
1586 GLboolean val = CHECK_GL( *this, mGlAbstraction.UnmapBuffer(target) );
1590 * Wrapper for OpenGL ES 2.0 glViewport()
1592 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1594 // check if its same as already set
1595 Rect<int> newViewport( x, y, width, height );
1596 if( mViewPort != newViewport )
1599 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1600 CHECK_GL( *this, mGlAbstraction.Viewport(x, y, width, height) );
1601 mViewPort = newViewport; // remember new one
1606 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1607 * @return The implementation defined MAX_TEXTURE_SIZE
1609 GLint CachedMaxTextureSize() const
1611 return mMaxTextureSize;
1615 * Get the number of supported program binary formats
1616 * @return The number of supported program binary formats
1618 GLint CachedNumberOfProgramBinaryFormats() const
1620 return mProgramBinaryFormats.Count();
1624 * Get a supported program binary format
1625 * @param[in] formatIndex The index of the format to return (default: 0)
1626 * @return A supported program binary format
1628 GLint CachedProgramBinaryFormat( const unsigned int formatIndex = 0 ) const
1630 DALI_ASSERT_ALWAYS( formatIndex < mProgramBinaryFormats.Count() && "formatIndex out of bounds");
1632 return mProgramBinaryFormats[ formatIndex ];
1636 * @return current program
1638 const Program* GetCurrentProgram() const
1640 return mCurrentProgram;
1644 * Set current program
1645 * @param [in] program that is in use
1647 void SetCurrentProgram( Program* program )
1649 mCurrentProgram = program;
1653 * Reset the program matrices
1655 void ResetProgramMatrices();
1658 * Get a cached program
1659 * @param [in] hash value
1660 * @return pointer to the program
1662 Program* GetCachedProgram( std::size_t hash ) const;
1666 * @param [in] hash value
1667 * @param [in] pointer to the program
1669 void CacheProgram( std::size_t hash, Program* pointer );
1672 * Get the current viewport.
1673 * @return Viewport rectangle.
1675 const Rect< int >& GetViewport();
1677 #ifdef DEBUG_ENABLED
1679 /// Switch debug level to Concise to disable, General to enable. Note, enabling snapshot logging will do this on the fly.
1680 static Debug::Filter *gGlLogFilter;
1682 #endif // DEBUG_ENABLED
1686 * Set the frame count of render thread
1688 inline void SetFrameCount(unsigned int frameCount)
1690 mFrameCount = frameCount;
1694 * Get the frame count
1696 inline unsigned int GetFrameCount()
1702 * Increment the count of culled renderers
1704 inline void IncrementCulledCount()
1710 * Clear the count of culled renderers
1712 inline void ClearCulledCount()
1718 * Get the count of culled renderers in this frame
1720 inline unsigned int GetCulledCount()
1722 return mCulledCount;
1726 * Increment the count of culled renderers
1728 inline void IncrementRendererCount()
1734 * Clear the count of image renderers
1736 inline void ClearRendererCount()
1742 * Get the count of image renderers in this frame
1744 inline unsigned int GetRendererCount()
1746 return mRendererCount;
1750 private: // Implementation
1753 * Flushes vertex attribute location changes to the driver
1755 void FlushVertexAttributeLocations();
1758 * Reset the cached internal vertex attribute state
1760 void ResetVertexAttributeState();
1763 * Either enables or disables a vertex attribute location in the cache
1764 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1765 * @param location attribute location
1766 * @param state attribute state
1768 void SetVertexAttributeLocation(unsigned int location, bool state);
1771 * Sets the initial GL state.
1773 void ResetGlState();
1777 Integration::GlAbstraction& mGlAbstraction;
1779 bool mGlContextCreated; ///< True if the OpenGL context has been created
1781 // glEnable/glDisable states
1783 GLuint mStencilMask;
1785 bool mDepthTestEnabled;
1786 bool mDepthMaskEnabled;
1787 bool mDitherEnabled;
1788 bool mPolygonOffsetFillEnabled;
1789 bool mSampleAlphaToCoverageEnabled;
1790 bool mSampleCoverageEnabled;
1791 bool mScissorTestEnabled;
1792 bool mStencilTestEnabled;
1793 bool mClearColorSet;
1795 // glBindBuffer() state
1796 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1797 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1798 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1800 // glBindTexture() state
1801 unsigned int mActiveTextureUnit;
1802 GLuint mBound2dTextureId[ MAX_TEXTURE_UNITS ]; ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
1804 // glBlendColor() state
1805 bool mUsingDefaultBlendColor;
1807 // glBlendFuncSeparate() state
1808 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1809 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1810 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1811 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1813 // glBlendEquationSeparate state
1814 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1815 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1817 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1818 Vector4 mClearColor; ///< clear color
1820 Dali::Vector<GLint> mProgramBinaryFormats; ///< array of supported program binary formats
1822 // Face culling mode
1823 CullFaceMode mCullFaceMode;
1825 // cached viewport size
1826 Rect< int > mViewPort;
1828 // Vertex Attribute Buffer enable caching
1829 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1830 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1832 Program* mCurrentProgram;
1833 typedef std::map< std::size_t, Program* > ProgramContainer;
1834 ProgramContainer mProgramCache; ///< Cache of shader programs
1835 unsigned int mFrameCount; ///< Number of render frames
1836 unsigned int mCulledCount; ///< Number of culled renderers per frame
1837 unsigned int mRendererCount; ///< Number of image renderers per frame
1840 } // namespace Internal
1844 #endif // __DALI_INTERNAL_CONTEXT_H__