1 #ifndef __DALI_INTERNAL_CONTEXT_H__
2 #define __DALI_INTERNAL_CONTEXT_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/actors/renderable-actor.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/public-api/math/rect.h>
26 #include <dali/public-api/math/vector4.h>
27 #include <dali/integration-api/debug.h>
28 #include <dali/integration-api/gl-abstraction.h>
29 #include <dali/integration-api/gl-defines.h>
30 #include <dali/internal/render/common/performance-monitor.h>
31 #include <dali/internal/render/gl-resources/texture-units.h>
32 #include <dali/internal/render/gl-resources/gl-call-debug.h>
41 * Context records the current GL state, and provides access to the OpenGL ES 2.0 API.
42 * Context avoids duplicate GL calls, if the same setting etc. is requested repeatedly.
48 * Size of the VertexAttributeArray enables
49 * GLES specification states that there's minimum of 8
51 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 8;
53 static const unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 8 is guaranteed, which is more than DALi uses anyways
56 * Creates the Dali Context object.
57 * This method does not create an OpenGL context i.e. that is done from outside dali-core.
58 * @pre Context has not been created.
59 * @exception Context already created.
60 * @param glAbstraction the gl abstraction.
62 Context( Integration::GlAbstraction& glAbstraction );
70 * Called when the GL context has been created.
72 void GlContextCreated();
75 * Called when the GL context has been destroyed.
77 void GlContextDestroyed();
80 * Query whether the OpenGL context has been created.
81 * @return True if the OpenGL context has been created.
83 bool IsGlContextCreated() { return mGlContextCreated; }
86 * @return the GLAbstraction
88 Integration::GlAbstraction& GetAbstraction() { return mGlAbstraction; }
93 * Debug helper which prints the currently cached GL state.
95 void PrintCurrentState();
100 * Helper to convert GL error code to string
101 * @param errorCode to convert
104 const char* ErrorToString( GLenum errorCode );
107 * Helper to print GL string to debug log
109 void PrintGlString(const char* stringName, GLenum stringId)
111 DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, (const char *)GetString( stringId ) );
114 /****************************************************************************************
115 * The following methods are forwarded to Dali::Integration::GlAbstraction.
116 * In some cases the GL state is recorded, to avoid duplicate calls with the same state.
117 * All Shader, Program, Uniform and Attribute related calls are not here, Program class
118 * handles them and optimizes any program related state changes
119 ****************************************************************************************/
122 * Wrapper for OpenGL ES 2.0 glActiveTexture()
124 void ActiveTexture( TextureUnit textureUnit )
126 if ( textureUnit != mActiveTextureUnit )
128 mActiveTextureUnit = textureUnit;
129 LOG_GL("ActiveTexture %x\n", textureUnit);
130 CHECK_GL( mGlAbstraction, mGlAbstraction.ActiveTexture(TextureUnitAsGLenum(textureUnit)) );
135 * Wrapper for OpenGL ES 3.0 glBeginQuery()
137 void BeginQuery(GLenum target, GLuint id)
139 LOG_GL("BeginQuery %d %d\n", target, id);
140 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginQuery(target, id) );
144 * Wrapper for OpenGL ES 3.0 glBeginTransformFeedback()
146 void BeginTransformFeedback(GLenum primitiveMode)
148 LOG_GL("BeginTransformFeedback %x\n", primitiveMode);
149 CHECK_GL( mGlAbstraction, mGlAbstraction.BeginTransformFeedback(primitiveMode) );
153 * The wrapper for OpenGL ES 2.0 glBindBuffer() has been replaced by BindArrayBuffer & BindElementArrayBuffer & BindTransformFeedbackBuffer.
157 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ARRAY_BUFFER, ...)
159 void BindArrayBuffer(GLuint buffer)
161 // Avoid unecessary calls to BindBuffer
162 if (mBoundArrayBufferId != buffer)
164 mBoundArrayBufferId = buffer;
166 LOG_GL("BindBuffer GL_ARRAY_BUFFER %d\n", buffer);
167 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ARRAY_BUFFER, buffer) );
172 * Wrapper for OpenGL ES 2.0 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...)
174 void BindElementArrayBuffer(GLuint buffer)
176 // Avoid unecessary calls to BindBuffer
177 if (mBoundElementArrayBufferId!= buffer)
179 mBoundElementArrayBufferId = buffer;
181 LOG_GL("BindBuffer GL_ELEMENT_ARRAY_BUFFER %d\n", buffer);
182 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer) );
187 * Wrapper for OpenGL ES 3.0 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
189 void BindTransformFeedbackBuffer(GLuint buffer)
191 // Avoid unecessary calls to BindBuffer
192 if (mBoundTransformFeedbackBufferId != buffer)
194 mBoundTransformFeedbackBufferId = buffer;
196 LOG_GL("BindBuffer GL_TRANSFORM_FEEDBACK_BUFFER %d\n", buffer);
197 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER , buffer) );
202 * Wrapper for OpenGL ES 3.0 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
204 void BindTransformFeedbackBufferBase(GLuint index, GLuint buffer)
206 // Avoid unecessary calls to BindBufferBase
207 if (mBoundTransformFeedbackBufferId != buffer)
209 mBoundTransformFeedbackBufferId = buffer;
211 LOG_GL("BindBufferBase GL_TRANSFORM_FEEDBACK_BUFFER %d %d\n", index, buffer);
212 CHECK_GL( mGlAbstraction, mGlAbstraction.BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, index, buffer) );
217 * Wrapper for OpenGL ES 2.0 glBindFramebuffer()
219 void BindFramebuffer(GLenum target, GLuint framebuffer)
221 LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
222 CHECK_GL( mGlAbstraction, mGlAbstraction.BindFramebuffer(target, framebuffer) );
226 * Wrapper for OpenGL ES 2.0 glBindRenderbuffer()
228 void BindRenderbuffer(GLenum target, GLuint renderbuffer)
230 LOG_GL("BindRenderbuffer %d %d\n", target, renderbuffer);
231 CHECK_GL( mGlAbstraction, mGlAbstraction.BindRenderbuffer(target, renderbuffer) );
235 * Wrapper for OpenGL ES 3.0 glBindTransformFeedback()
237 void BindTransformFeedback(GLenum target, GLuint id)
239 LOG_GL("BindTransformFeedback %d %d\n", target, id);
240 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTransformFeedback(target, id) );
244 * Helper to bind texture for rendering. If given texture is
245 * already bound in the given textureunit, this method does nothing.
246 * Otherwise changes the active texture unit and binds the texture.
247 * Note! after this call active texture unit may not necessarily be the one
248 * passed in as argument so you cannot change texture unit state!!
249 * @param textureunit to bind to
250 * @param texture to bind
252 void BindTextureForUnit( TextureUnit textureunit, GLuint texture )
254 if( mBound2dTextureId[ textureunit ] != texture )
256 ActiveTexture( textureunit );
257 Bind2dTexture( texture );
262 * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D)
264 void Bind2dTexture( GLuint texture )
266 if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
268 mBound2dTextureId[ mActiveTextureUnit ] = texture;
270 LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture);
271 CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) );
273 INCREASE_COUNTER(PerformanceMonitor::TEXTURE_STATE_CHANGES);
278 * Wrapper for OpenGL ES 2.0 glBlendColor()
280 void SetDefaultBlendColor()
282 if( !mUsingDefaultBlendColor )
284 LOG_GL( "BlendColor %f %f %f %f\n", 0.0f, 0.0f, 0.0f, 0.0f );
285 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor( 0.0f, 0.0f, 0.0f, 0.0f ) );
286 mUsingDefaultBlendColor = true;
291 * Wrapper for OpenGL ES 2.0 glBlendColor()
293 void SetCustomBlendColor( const Vector4& color )
295 LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
296 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor(color.r, color.g, color.b, color.a) );
297 mUsingDefaultBlendColor = false;
301 * Wrapper for OpenGL ES 2.0 glBlendEquation()
303 void BlendEquation(GLenum mode)
305 // use BlendEquationSeparate to set the rgb and alpha modes the same
306 BlendEquationSeparate( mode, mode );
310 * Wrapper for OpenGL ES 2.0 glBlendEquationSeparate()
312 void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
314 if( ( modeRGB != mBlendEquationSeparateModeRGB ) ||
315 ( modeAlpha != mBlendEquationSeparateModeAlpha ) )
317 mBlendEquationSeparateModeRGB = modeRGB;
318 mBlendEquationSeparateModeAlpha = modeAlpha;
319 LOG_GL("BlendEquationSeparate %d %d\n", modeRGB, modeAlpha);
320 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendEquationSeparate(modeRGB, modeAlpha) );
325 * Wrapper for OpenGL ES 2.0 glBlendFunc()
327 void BlendFunc(GLenum sfactor, GLenum dfactor)
329 // reuse the BlendFuncSeparate as thats what the DDK does anyways
330 BlendFuncSeparate( sfactor, dfactor, sfactor, dfactor );
334 * Wrapper for OpenGL ES 2.0 glBlendFuncSeparate()
336 void BlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha )
338 if( ( mBlendFuncSeparateSrcRGB != srcRGB )||( mBlendFuncSeparateDstRGB != dstRGB )||
339 ( mBlendFuncSeparateSrcAlpha != srcAlpha )||( mBlendFuncSeparateDstAlpha != dstAlpha ) )
341 mBlendFuncSeparateSrcRGB = srcRGB;
342 mBlendFuncSeparateDstRGB = dstRGB;
343 mBlendFuncSeparateSrcAlpha = srcAlpha;
344 mBlendFuncSeparateDstAlpha = dstAlpha;
346 LOG_GL( "BlendFuncSeparate %d %d %d %d\n", srcRGB, dstRGB, srcAlpha, dstAlpha );
347 CHECK_GL( mGlAbstraction, mGlAbstraction.BlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha ) );
352 * Wrapper for OpenGL ES 3.0 glBlitFramebuffer()
354 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
356 LOG_GL( "BlitFramebuffer %d %d %d %d %d %d %d %d %x %d\n", srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter );
357 CHECK_GL( mGlAbstraction, mGlAbstraction.BlitFramebuffer( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter ) );
361 * Wrapper for OpenGL ES 2.0 glBufferData()
363 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
365 LOG_GL("BufferData %d %d %p %d\n", target, size, data, usage);
366 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferData(target, size, data, usage) );
370 * Wrapper for OpenGL ES 2.0 glBufferSubData()
372 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
374 LOG_GL("BufferSubData %d %d %d %p\n", target, offset, size, data);
375 CHECK_GL( mGlAbstraction, mGlAbstraction.BufferSubData(target, offset, size, data) );
379 * Wrapper for OpenGL ES 2.0 glCheckFramebufferStatus()
381 GLenum CheckFramebufferStatus(GLenum target)
383 LOG_GL("CheckFramebufferStatus %d\n", target);
384 GLenum value = CHECK_GL( mGlAbstraction, mGlAbstraction.CheckFramebufferStatus(target) );
389 * Wrapper for OpenGL ES 2.0 glClear()
391 void Clear(GLbitfield mask)
393 LOG_GL("Clear %d\n", mask);
394 CHECK_GL( mGlAbstraction, mGlAbstraction.Clear(mask) );
398 * Wrapper for OpenGL ES 2.0 glClearColor()
400 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
402 Vector4 newCol(red,green,blue,alpha);
404 if (!mClearColorSet || mClearColor !=newCol )
406 LOG_GL("ClearColor %f %f %f %f\n", red, green, blue, alpha);
407 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearColor(red, green, blue, alpha) );
409 mClearColorSet = true;
410 mClearColor = newCol;
415 * Wrapper for OpenGL ES 2.0 glClearDepthf()
417 void ClearDepthf(GLclampf depth)
419 LOG_GL("ClearDepthf %f\n", depth);
420 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearDepthf(depth) );
424 * Wrapper for OpenGL ES 2.0 glClearStencil()
426 void ClearStencil(GLint s)
428 LOG_GL("ClearStencil %d\n", s);
429 CHECK_GL( mGlAbstraction, mGlAbstraction.ClearStencil(s) );
433 * Wrapper for OpenGL ES 2.0 glColorMask()
434 * @note This has been optimized to a single boolean value (masking individual channels is not required)
436 void ColorMask( bool flag )
438 // only change state if needed
439 if( flag != mColorMask )
442 LOG_GL("ColorMask %s %s %s %s\n", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False", flag ? "True" : "False");
443 CHECK_GL( mGlAbstraction, mGlAbstraction.ColorMask(flag, flag, flag, flag) );
448 * Wrapper for OpenGL ES 2.0 glCompressedTexImage2D()
450 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height,
451 GLint border, GLsizei imageSize, const void* data)
453 LOG_GL("CompressedTexImage2D %d %d %x %d %d %d %d %p\n", target, level, internalformat, width, height, border, imageSize, data);
454 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data) );
458 * Wrapper for OpenGL ES 3.0 glCompressedTexImage3D()
460 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth,
461 GLint border, GLsizei imageSize, const void* data)
463 LOG_GL("CompressedTexImage3D %d %d %x %d %d %d %d %d %p\n", target, level, internalformat, width, height, depth, border, imageSize, data);
464 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize, data) );
468 * Wrapper for OpenGL ES 2.0 glCompressedTexSubImage2D()
470 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
471 GLenum format, GLsizei imageSize, const void* data)
473 LOG_GL("CompressedTexSubImage2D %x %d %d %d %d %d %x %d %p\n", target, level, xoffset, yoffset, width, height, format, imageSize, data);
474 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data) );
478 * Wrapper for OpenGL ES 3.0 glCompressedTexSubImage3D()
480 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
481 GLsizei width, GLsizei height, GLsizei depth,
482 GLenum format, GLsizei imageSize, const void* data)
484 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);
485 CHECK_GL( mGlAbstraction, mGlAbstraction.CompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data) );
489 * Wrapper for OpenGL ES 2.0 glCopyTexImage2D()
491 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
493 LOG_GL("CopyTexImage2D %x %d %x %d %d %d %d %d\n", target, level, internalformat, x, y, width, height, border);
494 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexImage2D(target, level, internalformat, x, y, width, height, border) );
498 * Wrapper for OpenGL ES 2.0 glCopyTexSubImage2D()
500 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
502 LOG_GL("CopyTexSubImage2D %x %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, x, y, width, height);
503 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) );
507 * Wrapper for OpenGL ES 3.0 glCopyTexSubImage3D()
509 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
511 LOG_GL("CopyTexSubImage3D %x %d %d %d %d %d %d %d %d\n", target, level, xoffset, yoffset, zoffset, x, y, width, height);
512 CHECK_GL( mGlAbstraction, mGlAbstraction.CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) );
516 * Wrapper for OpenGL ES 2.0 glCullFace()
517 * enables GL_CULL_FACE if in any of the face culling modes
518 * otherwise disables GL_CULL_FACE
520 void CullFace(CullFaceMode mode)
522 // Avoid unnecessary calls to gl
523 if(mCullFaceMode != mode)
525 mCullFaceMode = mode;
530 LOG_GL("Disable GL_CULL_FACE\n");
531 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE) );
537 LOG_GL("Enable GL_CULL_FACE\n");
538 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
539 LOG_GL("Enable GL_FRONT\n");
540 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT) );
546 LOG_GL("Enable GL_CULL_FACE\n");
547 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
548 LOG_GL("Enable GL_BACK\n");
549 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_BACK) );
553 case CullFrontAndBack:
555 LOG_GL("Enable GL_CULL_FACE\n");
556 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
557 LOG_GL("Enable GL_FRONT_AND_BACK\n");
558 CHECK_GL( mGlAbstraction, mGlAbstraction.CullFace(GL_FRONT_AND_BACK) );
569 * Wrapper for OpenGL ES 2.0 glDeleteBuffers()
571 void DeleteBuffers(GLsizei n, const GLuint* buffers)
573 // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
574 // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
575 if( this->IsGlContextCreated() )
577 LOG_GL("DeleteBuffers %d %p\n", n, buffers);
578 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
580 // reset the cached buffer id's
581 // fixes problem where some drivers will a generate a buffer with the
582 // same id, as the last deleted buffer id.
583 mBoundArrayBufferId = 0;
584 mBoundElementArrayBufferId = 0;
585 mBoundTransformFeedbackBufferId = 0;
589 * Wrapper for OpenGL ES 2.0 glDeleteFramebuffers()
591 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
593 LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
594 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
598 * Wrapper for OpenGL ES 3.0 glDeleteQueries()
600 void DeleteQueries(GLsizei n, GLuint* ids)
602 LOG_GL("DeleteQueries %d %p\n", n, ids);
603 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteQueries(n, ids) );
607 * Wrapper for OpenGL ES 2.0 glDeleteRenderbuffers()
609 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
611 LOG_GL("DeleteRenderbuffers %d %p\n", n, renderbuffers);
612 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteRenderbuffers(n, renderbuffers) );
616 * Wrapper for OpenGL ES 2.0 glDeleteTextures()
618 void DeleteTextures(GLsizei n, const GLuint* textures)
620 LOG_GL("DeleteTextures %d %p\n", n, textures);
621 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
623 // reset the cached texture id's incase the driver re-uses them
624 // when creating new textures
625 for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
627 mBound2dTextureId[ i ] = 0;
632 * Wrapper for OpenGL ES 3.0 glDeleteTransformFeedbacks()
634 void DeleteTransformFeedbacks(GLsizei n, GLuint* ids)
636 LOG_GL("DeleteTransformFeedbacks %d %p\n", n, ids);
637 CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTransformFeedbacks(n, ids) );
641 * Wrapper for OpenGL ES 2.0 glDepthFunc()
643 void DepthFunc(GLenum func)
645 LOG_GL("DepthFunc %x\n", func);
646 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthFunc(func) );
650 * Wrapper for OpenGL ES 2.0 glDepthMask()
652 void DepthMask(GLboolean flag)
654 // only change state if needed
655 if( flag != mDepthMaskEnabled )
657 mDepthMaskEnabled = flag;
658 LOG_GL("DepthMask %s\n", flag ? "True" : "False");
659 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
664 * Wrapper for OpenGL ES 2.0 glDepthRangef()
666 void DepthRangef(GLclampf zNear, GLclampf zFar)
668 LOG_GL("DepthRangef %f %f\n", zNear, zFar);
669 CHECK_GL( mGlAbstraction, mGlAbstraction.DepthRangef(zNear, zFar) );
673 * The wrapper for OpenGL ES 2.0 glDisable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
674 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
678 * Wrapper for OpenGL ES 2.0 glDrawArrays()
680 void DrawArrays(GLenum mode, GLint first, GLsizei count)
682 FlushVertexAttributeLocations();
684 LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
685 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArrays(mode, first, count) );
689 * Wrapper for OpenGL ES 3.0 glDrawArraysInstanced()
691 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
693 FlushVertexAttributeLocations();
695 LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
696 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawArraysInstanced(mode, first, count,instanceCount) );
700 * Wrapper for OpenGL ES 3.0 glDrawBuffers()
702 void DrawBuffers(GLsizei n, const GLenum* bufs)
704 LOG_GL("DrawBuffers %d %p\n", n, bufs);
705 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawBuffers(n, bufs) );
709 * Wrapper for OpenGL ES 2.0 glDrawElements()
711 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
713 FlushVertexAttributeLocations();
715 LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
716 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElements(mode, count, type, indices) );
720 * Wrapper for OpenGL ES 3.0 glDrawElementsInstanced()
722 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
724 FlushVertexAttributeLocations();
726 LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
727 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawElementsInstanced(mode, count, type, indices, instanceCount) );
731 * Wrapper for OpenGL ES 3.0 glDrawRangeElements()
733 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
735 FlushVertexAttributeLocations();
737 LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
738 CHECK_GL( mGlAbstraction, mGlAbstraction.DrawRangeElements(mode, start, end, count, type, indices) );
742 * Wrapper for OpenGL ES 3.0 glGenQuerieS()
744 void GenQueries(GLsizei n, GLuint* ids)
746 LOG_GL("GenQueries %d %p\n", n, ids);
747 CHECK_GL( mGlAbstraction, mGlAbstraction.GenQueries(n, ids) );
751 * Wrapper for OpenGL ES 3.0 glGenTransformFeedbacks()
753 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
755 LOG_GL("GenTransformFeedbacks %d %p\n", n, ids);
756 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTransformFeedbacks(n, ids) );
760 * @return the current buffer bound for a given target
762 GLuint GetCurrentBoundArrayBuffer(GLenum target)
767 case GL_ARRAY_BUFFER:
769 result = mBoundArrayBufferId;
772 case GL_ELEMENT_ARRAY_BUFFER:
774 result = mBoundElementArrayBufferId;
777 case GL_TRANSFORM_FEEDBACK_BUFFER:
779 result = mBoundTransformFeedbackBufferId;
784 DALI_ASSERT_DEBUG(0 && "target buffer type not supported");
790 void EnableVertexAttributeArray( GLuint location )
792 SetVertexAttributeLocation( location, true);
795 void DisableVertexAttributeArray( GLuint location )
797 SetVertexAttributeLocation( location, false);
801 * Wrapper for OpenGL ES 3.0 glVertexAttribDivisor()
803 void VertexAttribDivisor ( GLuint index, GLuint divisor )
805 LOG_GL("VertexAttribDivisor(%d, %d)\n", index, divisor );
806 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribDivisor( index, divisor ) );
810 * Wrapper for OpenGL ES 2.0 glVertexAttribPointer()
812 void VertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr )
814 LOG_GL("VertexAttribPointer(%d, %d, %d, %d, %d, %x)\n", index, size, type, normalized, stride, ptr );
815 CHECK_GL( mGlAbstraction, mGlAbstraction.VertexAttribPointer( index, size, type, normalized, stride, ptr ) );
819 * Wrapper for OpenGL ES 3.0 glInvalidateFramebuffer()
821 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
823 LOG_GL("InvalidateFramebuffer\n");
824 CHECK_GL( mGlAbstraction, mGlAbstraction.InvalidateFramebuffer(target, numAttachments, attachments) );
828 * The wrapper for OpenGL ES 2.0 glEnable() has been replaced by SetBlend, SetCullFace, SetDepthTest,
829 * SetDither, SetPolygonOffsetFill, SetSampleAlphaToCoverage, SetSampleCoverage, SetScissorTest & SetStencilTest.
833 * This method replaces glEnable(GL_BLEND) and glDisable(GL_BLEND).
834 * @param[in] enable True if GL_BLEND should be enabled.
836 void SetBlend(bool enable)
838 // Avoid unecessary calls to glEnable/glDisable
839 if (enable != mBlendEnabled)
841 mBlendEnabled = enable;
845 LOG_GL("Enable GL_BLEND\n");
846 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_BLEND) );
850 LOG_GL("Disable GL_BLEND\n");
851 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_BLEND) );
857 * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
858 * @param[in] enable True if GL_DEPTH_TEST should be enabled.
860 void SetDepthTest(bool enable)
862 // Avoid unecessary calls to glEnable/glDisable
863 if (enable != mDepthTestEnabled)
865 mDepthTestEnabled = enable;
869 LOG_GL("Enable GL_DEPTH_TEST\n");
870 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DEPTH_TEST) );
874 LOG_GL("Disable GL_DEPTH_TEST\n");
875 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DEPTH_TEST) );
881 * This method replaces glEnable(GL_DITHER) and glDisable(GL_DITHER).
882 * @param[in] enable True if GL_DITHER should be enabled.
884 void SetDither(bool enable)
886 // Avoid unecessary calls to glEnable/glDisable
887 if (enable != mDitherEnabled)
889 mDitherEnabled = enable;
893 LOG_GL("Enable GL_DITHER\n");
894 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_DITHER) );
898 LOG_GL("Disable GL_DITHER\n");
899 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_DITHER) );
905 * This method replaces glEnable(GL_POLYGON_OFFSET_FILL) and glDisable(GL_POLYGON_OFFSET_FILL).
906 * @param[in] enable True if GL_POLYGON_OFFSET_FILL should be enabled.
908 void SetPolygonOffsetFill(bool enable)
910 // Avoid unecessary calls to glEnable/glDisable
911 if (enable != mPolygonOffsetFillEnabled)
913 mPolygonOffsetFillEnabled = enable;
917 LOG_GL("Enable GL_POLYGON_OFFSET_FILL\n");
918 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_POLYGON_OFFSET_FILL) );
922 LOG_GL("Disable GL_POLYGON_OFFSET_FILL\n");
923 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_POLYGON_OFFSET_FILL) );
929 * This method replaces glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) and glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE).
930 * @param[in] enable True if GL_SAMPLE_ALPHA_TO_COVERAGE should be enabled.
932 void SetSampleAlphaToCoverage(bool enable)
934 // Avoid unecessary calls to glEnable/glDisable
935 if (enable != mSampleAlphaToCoverageEnabled)
937 mSampleAlphaToCoverageEnabled = enable;
941 LOG_GL("Enable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
942 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
946 LOG_GL("Disable GL_SAMPLE_ALPHA_TO_COVERAGE\n");
947 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_ALPHA_TO_COVERAGE) );
953 * This method replaces glEnable(GL_SAMPLE_COVERAGE) and glDisable(GL_SAMPLE_COVERAGE).
954 * @param[in] enable True if GL_SAMPLE_COVERAGE should be enabled.
956 void SetSampleCoverage(bool enable)
958 // Avoid unecessary calls to glEnable/glDisable
959 if (enable != mSampleCoverageEnabled)
961 mSampleCoverageEnabled = enable;
965 LOG_GL("Enable GL_SAMPLE_COVERAGE\n");
966 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SAMPLE_COVERAGE) );
970 LOG_GL("Disable GL_SAMPLE_COVERAGE\n");
971 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SAMPLE_COVERAGE) );
977 * This method replaces glEnable(GL_SCISSOR_TEST) and glDisable(GL_SCISSOR_TEST).
978 * @param[in] enable True if GL_SCISSOR_TEST should be enabled.
980 void SetScissorTest(bool enable)
982 // Avoid unecessary calls to glEnable/glDisable
983 if (enable != mScissorTestEnabled)
985 mScissorTestEnabled = enable;
989 LOG_GL("Enable GL_SCISSOR_TEST\n");
990 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_SCISSOR_TEST) );
994 LOG_GL("Disable GL_SCISSOR_TEST\n");
995 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_SCISSOR_TEST) );
1001 * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
1002 * @param[in] enable True if GL_STENCIL_TEST should be enabled.
1004 void SetStencilTest(bool enable)
1006 // Avoid unecessary calls to glEnable/glDisable
1007 if (enable != mStencilTestEnabled)
1009 mStencilTestEnabled = enable;
1013 LOG_GL("Enable GL_STENCIL_TEST\n");
1014 CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_STENCIL_TEST) );
1018 LOG_GL("Disable GL_STENCIL_TEST\n");
1019 CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_STENCIL_TEST) );
1025 * Wrapper for OpenGL ES 3.0 glEndQuery()
1027 void EndQuery(GLenum target)
1029 LOG_GL("EndQuery %d\n", target);
1030 CHECK_GL( mGlAbstraction, mGlAbstraction.EndQuery(target) );
1034 * Wrapper for OpenGL ES 3.0 glEndTransformFeedback()
1036 void EndTransformFeedback()
1038 LOG_GL("EndTransformFeedback\n");
1039 CHECK_GL( mGlAbstraction, mGlAbstraction.EndTransformFeedback() );
1043 * Wrapper for OpenGL ES 2.0 glFinish()
1048 CHECK_GL( mGlAbstraction, mGlAbstraction.Finish() );
1052 * Wrapper for OpenGL ES 2.0 glFlush()
1057 CHECK_GL( mGlAbstraction, mGlAbstraction.Flush() );
1061 * Wrapper for OpenGL ES 2.0 glFramebufferRenderbuffer()
1063 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
1065 LOG_GL("FramebufferRenderbuffer %x %x %x %d\n", target, attachment, renderbuffertarget, renderbuffer);
1066 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) );
1070 * Wrapper for OpenGL ES 2.0 glFramebufferTexture2D()
1072 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
1074 LOG_GL("FramebufferTexture2D %x %x %x %d %d\n", target, attachment, textarget, texture, level);
1075 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTexture2D(target, attachment, textarget, texture, level) );
1079 * Wrapper for OpenGL ES 3.0 glFramebufferTextureLayer()
1081 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1083 LOG_GL("FramebufferTextureLayer %x %x %d %d %d\n", target, attachment, texture, level, layer);
1084 CHECK_GL( mGlAbstraction, mGlAbstraction.FramebufferTextureLayer(target, attachment, texture, level, layer) );
1088 * Wrapper for OpenGL ES 2.0 glFrontFace()
1090 void FrontFace(GLenum mode)
1092 LOG_GL("FrontFace %x\n", mode);
1093 CHECK_GL( mGlAbstraction, mGlAbstraction.FrontFace(mode) );
1097 * Wrapper for OpenGL ES 2.0 glGenBuffers()
1099 void GenBuffers(GLsizei n, GLuint* buffers)
1101 LOG_GL("GenBuffers %d\n", n, buffers);
1102 CHECK_GL( mGlAbstraction, mGlAbstraction.GenBuffers(n, buffers) );
1106 * Wrapper for OpenGL ES 2.0 glGenerateMipmap()
1108 void GenerateMipmap(GLenum target)
1110 LOG_GL("GenerateMipmap %x\n", target);
1111 CHECK_GL( mGlAbstraction, mGlAbstraction.GenerateMipmap(target) );
1115 * Wrapper for OpenGL ES 2.0 glGenFramebuffers()
1117 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
1119 LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
1120 CHECK_GL( mGlAbstraction, mGlAbstraction.GenFramebuffers(n, framebuffers) );
1124 * Wrapper for OpenGL ES 2.0 glGenRenderbuffers()
1126 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
1128 LOG_GL("GenRenderbuffers %d %p\n", n, renderbuffers);
1129 CHECK_GL( mGlAbstraction, mGlAbstraction.GenRenderbuffers(n, renderbuffers) );
1133 * Wrapper for OpenGL ES 2.0 glGenTextures()
1135 void GenTextures(GLsizei n, GLuint* textures)
1137 LOG_GL("GenTextures %d %p\n", n, textures);
1138 CHECK_GL( mGlAbstraction, mGlAbstraction.GenTextures(n, textures) );
1142 * Wrapper for OpenGL ES 2.0 glGetBooleanv()
1144 void GetBooleanv(GLenum pname, GLboolean* params)
1146 LOG_GL("GetBooleanv %x\n", pname);
1147 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBooleanv(pname, params) );
1151 * Wrapper for OpenGL ES 2.0 glGetBufferParameteriv()
1153 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
1155 LOG_GL("GetBufferParameteriv %x %x %p\n", target, pname, params);
1156 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferParameteriv(target, pname, params) );
1160 * Wrapper for OpenGL ES 3.0 glGetBufferPointer()
1162 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1164 LOG_GL("GetBufferPointerv %x %x %p\n", target, pname, params);
1165 CHECK_GL( mGlAbstraction, mGlAbstraction.GetBufferPointerv(target, pname, params) );
1169 * Wrapper for OpenGL ES 2.0 glGetError()
1171 GLenum GetError(void)
1173 // Not worth logging here
1174 return mGlAbstraction.GetError();
1178 * Wrapper for OpenGL ES 2.0 glGetFloatv()
1180 void GetFloatv(GLenum pname, GLfloat* params)
1182 LOG_GL("GetFloatv %x\n", pname);
1183 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFloatv(pname, params) );
1187 * Wrapper for OpenGL ES 2.0 glGetFramebufferAttachmentParameteriv()
1189 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
1191 LOG_GL("GetFramebufferAttachmentParameteriv %x %x %x\n", target, attachment, pname);
1192 CHECK_GL( mGlAbstraction, mGlAbstraction.GetFramebufferAttachmentParameteriv(target, attachment, pname, params) );
1196 * Wrapper for OpenGL ES 2.0 glGetIntegerv()
1198 void GetIntegerv(GLenum pname, GLint* params)
1200 LOG_GL("GetIntegerv %x\n", pname);
1201 CHECK_GL( mGlAbstraction, mGlAbstraction.GetIntegerv(pname, params) );
1205 * Wrapper for OpenGL ES 3.0 glGetQueryiv()
1207 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1209 LOG_GL("GetQueryiv %x %x\n", target, pname);
1210 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryiv(target, pname, params) );
1214 * Wrapper for OpenGL ES 3.0 glGetQueryObjectuiv()
1216 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1218 LOG_GL("GetQueryObjectuiv %u %x %p\n", id, pname, params);
1219 CHECK_GL( mGlAbstraction, mGlAbstraction.GetQueryObjectuiv(id, pname, params) );
1223 * Wrapper for OpenGL ES 2.0 glGetRenderbufferParameteriv()
1225 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
1227 LOG_GL("GetRenderbufferParameteriv %x %x\n", target, pname);
1228 CHECK_GL( mGlAbstraction, mGlAbstraction.GetRenderbufferParameteriv(target, pname, params) );
1232 * Wrapper for OpenGL ES 2.0 glGetString()
1234 const GLubyte* GetString(GLenum name)
1236 LOG_GL("GetString %x\n", name);
1237 const GLubyte* str = CHECK_GL( mGlAbstraction, mGlAbstraction.GetString(name) );
1242 * Wrapper for OpenGL ES 2.0 glGetTexParameterfv()
1244 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
1246 LOG_GL("GetTexParameterfv %x %x\n", target, pname);
1247 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameterfv(target, pname, params) );
1251 * Wrapper for OpenGL ES 2.0 glGetTexParameteriv()
1253 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
1255 LOG_GL("GetTexParameteriv %x %x\n", target, pname);
1256 CHECK_GL( mGlAbstraction, mGlAbstraction.GetTexParameteriv(target, pname, params) );
1260 * Wrapper for OpenGL ES 2.0 glHint()
1262 void Hint(GLenum target, GLenum mode)
1264 LOG_GL("Hint %x %x\n", target, mode);
1265 CHECK_GL( mGlAbstraction, mGlAbstraction.Hint(target, mode) );
1269 * Wrapper for OpenGL ES 2.0 glIsBuffer()
1271 GLboolean IsBuffer(GLuint buffer)
1273 LOG_GL("IsBuffer %d\n", buffer);
1274 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsBuffer(buffer) );
1279 * Wrapper for OpenGL ES 2.0 glIsEnabled()
1281 GLboolean IsEnabled(GLenum cap)
1283 LOG_GL("IsEnabled %x\n", cap);
1284 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsEnabled(cap) );
1289 * Wrapper for OpenGL ES 2.0 glIsFramebuffer()
1291 GLboolean IsFramebuffer(GLuint framebuffer)
1293 LOG_GL("IsFramebuffer %d\n", framebuffer);
1294 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsFramebuffer(framebuffer) );
1299 * Wrapper for OpenGL ES 3.0 glIsQuery()
1301 GLboolean IsQuery(GLuint id)
1303 LOG_GL("IsQuery %u\n", id);
1304 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsQuery(id) );
1309 * Wrapper for OpenGL ES 2.0 glIsRenderbuffer()
1311 GLboolean IsRenderbuffer(GLuint renderbuffer)
1313 LOG_GL("IsRenderbuffer %d\n", renderbuffer);
1314 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsRenderbuffer(renderbuffer) );
1319 * Wrapper for OpenGL ES 2.0 glIsTexture()
1321 GLboolean IsTexture(GLuint texture)
1323 LOG_GL("IsTexture %d\n", texture);
1324 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTexture(texture) );
1329 * Wrapper for OpenGL ES 3.0 glIsTransformFeedback()
1331 GLboolean IsTransformFeedback(GLuint id)
1333 LOG_GL("IsTransformFeedback %u\n", id);
1334 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.IsTransformFeedback(id) );
1339 * Wrapper for OpenGL ES 2.0 glLineWidth()
1341 void LineWidth(GLfloat width)
1343 LOG_GL("LineWidth %f\n", width);
1344 CHECK_GL( mGlAbstraction, mGlAbstraction.LineWidth(width) );
1348 * Wrapper for OpenGL ES 3.0 glPauseTransformFeedback()
1350 void PauseTransformFeedback()
1352 LOG_GL("PauseTransformFeedback\n");
1353 CHECK_GL( mGlAbstraction, mGlAbstraction.PauseTransformFeedback() );
1357 * Wrapper for OpenGL ES 2.0 glPixelStorei()
1359 void PixelStorei(GLenum pname, GLint param)
1361 LOG_GL("PixelStorei %x %d\n", pname, param);
1362 CHECK_GL( mGlAbstraction, mGlAbstraction.PixelStorei(pname, param) );
1366 * Wrapper for OpenGL ES 2.0 glPolygonOffset()
1368 void PolygonOffset(GLfloat factor, GLfloat units)
1370 LOG_GL("PolygonOffset %f %f\n", factor, units);
1371 CHECK_GL( mGlAbstraction, mGlAbstraction.PolygonOffset(factor, units) );
1375 * Wrapper for OpenGL ES 2.0 glReadPixels()
1377 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
1379 LOG_GL("ReadPixels %d %d %d %d %x %x\n", x, y, width, height, format, type);
1380 CHECK_GL( mGlAbstraction, mGlAbstraction.ReadPixels(x, y, width, height, format, type, pixels) );
1384 * Wrapper for OpenGL ES 2.0 glRenderbufferStorage()
1386 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
1388 LOG_GL("RenderbufferStorage %x %x %d %d\n", target, internalformat, width, height);
1389 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorage(target, internalformat, width, height) );
1393 * Wrapper for OpenGL ES 3.0 glRenderbufferStorageMultisample()
1395 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1397 LOG_GL("RenderbufferStorageMultisample %x %u %x %d %d\n", target, samples, internalformat, width, height);
1398 CHECK_GL( mGlAbstraction, mGlAbstraction.RenderbufferStorageMultisample(target, samples, internalformat, width, height) );
1402 * Wrapper for OpenGL ES 3.0 glResumeTransformFeedback()
1404 void ResumeTransformFeedback()
1406 LOG_GL("ResumeTransformFeedback\n");
1407 CHECK_GL( mGlAbstraction, mGlAbstraction.ResumeTransformFeedback() );
1411 * Wrapper for OpenGL ES 2.0 glSampleCoverage()
1413 void SampleCoverage(GLclampf value, GLboolean invert)
1415 LOG_GL("SampleCoverage %f %s\n", value, invert ? "True" : "False");
1416 CHECK_GL( mGlAbstraction, mGlAbstraction.SampleCoverage(value, invert) );
1420 * Wrapper for OpenGL ES 2.0 glScissor()
1422 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
1424 LOG_GL("Scissor %d %d %d %d\n", x, y, width, height);
1425 CHECK_GL( mGlAbstraction, mGlAbstraction.Scissor(x, y, width, height) );
1429 * Wrapper for OpenGL ES 2.0 glStencilFunc()
1431 void StencilFunc(GLenum func, GLint ref, GLuint mask)
1433 LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
1434 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) );
1438 * Wrapper for OpenGL ES 2.0 glStencilFuncSeparate()
1440 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1442 LOG_GL("StencilFuncSeparate %x %x %d %d\n", face, func, ref, mask);
1443 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFuncSeparate(face, func, ref, mask) );
1447 * Wrapper for OpenGL ES 2.0 glStencilMask()
1449 void StencilMask(GLuint mask)
1451 if( mask != mStencilMask )
1453 mStencilMask = mask;
1455 LOG_GL("StencilMask %d\n", mask);
1456 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMask(mask) );
1461 * Wrapper for OpenGL ES 2.0 glStencilMaskSeparate()
1463 void StencilMaskSeparate(GLenum face, GLuint mask)
1465 LOG_GL("StencilMaskSeparate %x %d\n", face, mask);
1466 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilMaskSeparate(face, mask) );
1470 * Wrapper for OpenGL ES 2.0 glStencilOp()
1472 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1474 LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
1475 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) );
1479 * Wrapper for OpenGL ES 2.0 glStencilOpSeparate()
1481 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1483 LOG_GL("StencilOpSeparate %x %x %x %x\n", face, fail, zfail, zpass);
1484 CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOpSeparate(face, fail, zfail, zpass) );
1488 * Wrapper for OpenGL ES 2.0 glTexImage2D()
1490 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
1491 GLint border, GLenum format, GLenum type, const void* pixels)
1493 LOG_GL("TexImage2D %x %d %d %dx%d %d %x %x %p\n", target, level, internalformat, width, height, border, format, type, pixels);
1494 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage2D(target, level, internalformat, width, height, border, format, type, pixels) );
1498 * Wrapper for OpenGL ES 3.0 glTexImage3D()
1500 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,
1501 GLint border, GLenum format, GLenum type, const void* pixels)
1503 LOG_GL("TexImage3D %x %d %d %dx%dx%d %d %x %x %p\n", target, level, internalformat, width, height, depth, border, format, type, pixels);
1504 CHECK_GL( mGlAbstraction, mGlAbstraction.TexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) );
1508 * Wrapper for OpenGL ES 2.0 glTexParameterf()
1510 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1512 LOG_GL("TexParameterf %x %x %f\n", target, pname, param);
1513 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterf(target, pname, param) );
1517 * Wrapper for OpenGL ES 2.0 glTexParameterfv()
1519 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1521 LOG_GL("TexParameterfv %x %x\n", target, pname);
1522 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameterfv(target, pname, params) );
1526 * Wrapper for OpenGL ES 2.0 glTexParameteri()
1528 void TexParameteri(GLenum target, GLenum pname, GLint param)
1530 LOG_GL("TexParameteri %x %x %d\n", target, pname, param);
1531 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteri(target, pname, param) );
1535 * Wrapper for OpenGL ES 2.0 glTexParameteriv()
1537 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1539 LOG_GL("TexParameteriv %x %x\n", target, pname);
1540 CHECK_GL( mGlAbstraction, mGlAbstraction.TexParameteriv(target, pname, params) );
1544 * Wrapper for OpenGL ES 2.0 glTexSubImage2D()
1546 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
1547 GLenum format, GLenum type, const void* pixels)
1549 LOG_GL("TexSubImage2D %x %d %d %d %d %d %x %x %p\n", target, level, xoffset, yoffset, width, height, format, type, pixels);
1550 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels) );
1554 * Wrapper for OpenGL ES 3.0 glTexSubImage3D()
1556 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
1557 GLsizei width, GLsizei height, GLsizei depth,
1558 GLenum format, GLenum type, const void* pixels)
1560 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);
1561 CHECK_GL( mGlAbstraction, mGlAbstraction.TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) );
1565 * Wrapper for OpenGL ES 3.0 glUnmapBubffer()
1567 GLboolean UnmapBuffer(GLenum target)
1569 LOG_GL("UnmapBuffer %x \n", target);
1570 GLboolean val = CHECK_GL( mGlAbstraction, mGlAbstraction.UnmapBuffer(target) );
1574 * Wrapper for OpenGL ES 2.0 glViewport()
1576 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1578 // check if its same as already set
1579 Rect<int> newViewport( x, y, width, height );
1580 if( mViewPort != newViewport )
1583 LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
1584 CHECK_GL( mGlAbstraction, mGlAbstraction.Viewport(x, y, width, height) );
1585 mViewPort = newViewport; // remember new one
1590 * Get the implementation defined MAX_TEXTURE_SIZE. This values is cached when the context is created
1591 * @return The implementation defined MAX_TEXTURE_SIZE
1593 GLint CachedMaxTextureSize() const
1595 return mMaxTextureSize;
1599 * Get the current viewport.
1600 * @return Viewport rectangle.
1602 const Rect< int >& GetViewport();
1605 * Set the frame count of render thread
1607 inline void SetFrameCount(unsigned int frameCount)
1609 mFrameCount = frameCount;
1613 * Get the frame count
1615 inline unsigned int GetFrameCount()
1621 * Increment the count of culled renderers
1623 inline void IncrementCulledCount()
1629 * Clear the count of culled renderers
1631 inline void ClearCulledCount()
1637 * Get the count of culled renderers in this frame
1639 inline unsigned int GetCulledCount()
1641 return mCulledCount;
1645 * Increment the count of culled renderers
1647 inline void IncrementRendererCount()
1653 * Clear the count of image renderers
1655 inline void ClearRendererCount()
1661 * Get the count of image renderers in this frame
1663 inline unsigned int GetRendererCount()
1665 return mRendererCount;
1669 private: // Implementation
1672 * Flushes vertex attribute location changes to the driver
1674 void FlushVertexAttributeLocations();
1677 * Reset the cached internal vertex attribute state
1679 void ResetVertexAttributeState();
1682 * Either enables or disables a vertex attribute location in the cache
1683 * The cahnges won't take affect until FlushVertexAttributeLocations is called
1684 * @param location attribute location
1685 * @param state attribute state
1687 void SetVertexAttributeLocation(unsigned int location, bool state);
1690 * Sets the initial GL state.
1692 void ResetGlState();
1696 Integration::GlAbstraction& mGlAbstraction;
1698 bool mGlContextCreated; ///< True if the OpenGL context has been created
1700 // glEnable/glDisable states
1702 GLuint mStencilMask;
1704 bool mDepthTestEnabled;
1705 bool mDepthMaskEnabled;
1706 bool mDitherEnabled;
1707 bool mPolygonOffsetFillEnabled;
1708 bool mSampleAlphaToCoverageEnabled;
1709 bool mSampleCoverageEnabled;
1710 bool mScissorTestEnabled;
1711 bool mStencilTestEnabled;
1712 bool mClearColorSet;
1714 // glBindBuffer() state
1715 GLuint mBoundArrayBufferId; ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
1716 GLuint mBoundElementArrayBufferId; ///< The ID passed to glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)
1717 GLuint mBoundTransformFeedbackBufferId; ///< The ID passed to glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER)
1719 // glBindTexture() state
1720 TextureUnit mActiveTextureUnit;
1721 GLuint mBound2dTextureId[ MAX_TEXTURE_UNITS ]; ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
1723 // glBlendColor() state
1724 bool mUsingDefaultBlendColor;
1726 // glBlendFuncSeparate() state
1727 GLenum mBlendFuncSeparateSrcRGB; ///< The srcRGB parameter passed to glBlendFuncSeparate()
1728 GLenum mBlendFuncSeparateDstRGB; ///< The dstRGB parameter passed to glBlendFuncSeparate()
1729 GLenum mBlendFuncSeparateSrcAlpha; ///< The srcAlpha parameter passed to glBlendFuncSeparate()
1730 GLenum mBlendFuncSeparateDstAlpha; ///< The dstAlpha parameter passed to glBlendFuncSeparate()
1732 // glBlendEquationSeparate state
1733 GLenum mBlendEquationSeparateModeRGB; ///< Controls RGB blend mode
1734 GLenum mBlendEquationSeparateModeAlpha; ///< Controls Alpha blend mode
1736 GLint mMaxTextureSize; ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
1737 Vector4 mClearColor; ///< clear color
1739 // Face culling mode
1740 CullFaceMode mCullFaceMode;
1742 // cached viewport size
1743 Rect< int > mViewPort;
1745 // Vertex Attribute Buffer enable caching
1746 bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Value cache for Enable Vertex Attribute
1747 bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ]; ///< Current state on the driver for Enable Vertex Attribute
1749 unsigned int mFrameCount; ///< Number of render frames
1750 unsigned int mCulledCount; ///< Number of culled renderers per frame
1751 unsigned int mRendererCount; ///< Number of image renderers per frame
1754 } // namespace Internal
1758 #endif // __DALI_INTERNAL_CONTEXT_H__