Remove RenderSurface from Core
[platform/core/uifw/dali-core.git] / dali / internal / render / gl-resources / context.h
index 303b394..be2db89 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_CONTEXT_H__
-#define __DALI_INTERNAL_CONTEXT_H__
+#ifndef DALI_INTERNAL_CONTEXT_H
+#define DALI_INTERNAL_CONTEXT_H
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/actors/renderable-actor.h>
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/math/rect.h>
 #include <dali/public-api/math/vector4.h>
+#include <dali/public-api/rendering/renderer.h>
+#include <dali/devel-api/common/owner-container.h>
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/gl-abstraction.h>
 #include <dali/integration-api/gl-defines.h>
 #include <dali/internal/render/common/performance-monitor.h>
 #include <dali/internal/render/gl-resources/texture-units.h>
+#include <dali/internal/render/gl-resources/frame-buffer-state-cache.h>
 #include <dali/internal/render/gl-resources/gl-call-debug.h>
 
 namespace Dali
@@ -44,6 +46,16 @@ namespace Internal
 class Context
 {
 public:
+
+  /**
+   * FrameBuffer Clear mode
+   */
+  enum ClearMode
+  {
+    FORCE_CLEAR,        ///< always perform the glClear regardless of current state
+    CHECK_CACHED_VALUES ///< check the Frame buffers cached state to see if a clear is required
+  };
+
   /**
    * Size of the VertexAttributeArray enables
    * GLES specification states that there's minimum of 8
@@ -53,7 +65,7 @@ public:
   static const unsigned int MAX_TEXTURE_UNITS = 8; // for GLES 2.0 8 is guaranteed, which is more than DALi uses anyways
 
   /**
-   * Creates the Dali Context object.
+   * Creates the Dali Context object for surface rendering only.
    * This method does not create an OpenGL context i.e. that is done from outside dali-core.
    * @pre Context has not been created.
    * @exception Context already created.
@@ -62,6 +74,16 @@ public:
   Context( Integration::GlAbstraction& glAbstraction );
 
   /**
+   * Creates the Dali Context object for texture (and surface rendering if required).
+   * This method does not create an OpenGL context i.e. that is done from outside dali-core.
+   * @pre Context has not been created.
+   * @exception Context already created.
+   * @param glAbstraction the gl abstraction.
+   * @param contexts The list of scene contexts (for surface rendering)
+   */
+  Context( Integration::GlAbstraction& glAbstraction, std::vector< Context* >* contexts );
+
+  /**
    * Destructor
    */
   ~Context();
@@ -108,7 +130,27 @@ public:
    */
   void PrintGlString(const char* stringName, GLenum stringId)
   {
-    DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, (const char *)GetString( stringId ) );
+    DALI_LOG_INFO(Debug::Filter::gRender, Debug::General, "GL %s = %s\n", stringName, reinterpret_cast< const char * >( GetString( stringId ) ) );
+  }
+
+  void ResetBufferCache()
+  {
+    // reset the cached buffer id's
+    // fixes problem where some drivers will a generate a buffer with the
+    // same id, as the last deleted buffer id.
+    mBoundArrayBufferId = 0;
+    mBoundElementArrayBufferId = 0;
+    mBoundTransformFeedbackBufferId = 0;
+  }
+
+  void ResetTextureCache()
+  {
+    // reset the cached texture id's in case the driver re-uses them
+    // when creating new textures
+    for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
+    {
+       mBoundTextureId[ i ] = 0;
+    }
   }
 
   /****************************************************************************************
@@ -119,6 +161,22 @@ public:
    ****************************************************************************************/
 
   /**
+   * Wrapper for IsSurfacelessContextSupported of Dali::Integration::GlAbstraction
+   */
+  bool IsSurfacelessContextSupported() const
+  {
+    return mGlAbstraction.IsSurfacelessContextSupported();
+  }
+
+  /**
+   * Wrapper for TextureRequiresConverting of Dali::Integration::GlAbstraction
+   */
+  bool TextureRequiresConverting( const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage ) const
+  {
+    return mGlAbstraction.TextureRequiresConverting( imageGlFormat, textureGlFormat, isSubImage );
+  }
+
+  /**
    * Wrapper for OpenGL ES 2.0 glActiveTexture()
    */
   void ActiveTexture( TextureUnit textureUnit )
@@ -218,6 +276,8 @@ public:
    */
   void BindFramebuffer(GLenum target, GLuint framebuffer)
   {
+    mFrameBufferStateCache.SetCurrentFrameBuffer( framebuffer );
+
     LOG_GL("BindFramebuffer %d %d\n", target, framebuffer);
     CHECK_GL( mGlAbstraction, mGlAbstraction.BindFramebuffer(target, framebuffer) );
   }
@@ -249,28 +309,26 @@ public:
    * @param textureunit to bind to
    * @param texture to bind
    */
-  void BindTextureForUnit( TextureUnit textureunit, GLuint texture )
+  void BindTextureForUnit( TextureUnit textureunit, int target, GLuint texture )
   {
-    if( mBound2dTextureId[ textureunit ] != texture )
+    if( mBoundTextureId[ textureunit ] != texture )
     {
       ActiveTexture( textureunit );
-      Bind2dTexture( texture );
+      BindTexture( target, texture );
     }
   }
 
   /**
-   * Wrapper for OpenGL ES 2.0 glBindTexture(GL_TEXTURE_2D)
+   * Wrapper for OpenGL ES 2.0 glBindTexture( target )
    */
-  void Bind2dTexture( GLuint texture )
+  void BindTexture( int target, GLuint texture )
   {
-    if (mBound2dTextureId[ mActiveTextureUnit ] != texture)
+    if (mBoundTextureId[ mActiveTextureUnit ] != texture)
     {
-      mBound2dTextureId[ mActiveTextureUnit ] = texture;
-
-      LOG_GL("BindTexture GL_TEXTURE_2D %d\n", texture);
-      CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(GL_TEXTURE_2D, texture) );
+      mBoundTextureId[ mActiveTextureUnit ] = texture;
 
-      INCREASE_COUNTER(PerformanceMonitor::TEXTURE_STATE_CHANGES);
+      LOG_GL("BindTexture target(%d) %d\n", target, texture);
+      CHECK_GL( mGlAbstraction, mGlAbstraction.BindTexture(target, texture) );
     }
   }
 
@@ -279,10 +337,9 @@ public:
    */
   void SetDefaultBlendColor()
   {
-    if( !mUsingDefaultBlendColor )
+    if( ! mUsingDefaultBlendColor )
     {
-      LOG_GL( "BlendColor %f %f %f %f\n", 0.0f, 0.0f, 0.0f, 0.0f );
-      CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor( 0.0f, 0.0f, 0.0f, 0.0f ) );
+      SetCustomBlendColor( Color::TRANSPARENT );
       mUsingDefaultBlendColor = true;
     }
   }
@@ -292,9 +349,13 @@ public:
    */
   void SetCustomBlendColor( const Vector4& color )
   {
-    LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
-    CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor(color.r, color.g, color.b, color.a) );
-    mUsingDefaultBlendColor = false;
+    if( mUsingDefaultBlendColor || mBlendColor != color )
+    {
+      LOG_GL( "BlendColor %f %f %f %f\n", color.r, color.g, color.b, color.a );
+      CHECK_GL( mGlAbstraction, mGlAbstraction.BlendColor( color.r, color.g, color.b, color.a ) );
+      mUsingDefaultBlendColor = false;
+      mBlendColor = color;
+    }
   }
 
   /**
@@ -388,10 +449,16 @@ public:
   /**
    * Wrapper for OpenGL ES 2.0 glClear()
    */
-  void Clear(GLbitfield mask)
+  void Clear(GLbitfield mask, ClearMode mode )
   {
-    LOG_GL("Clear %d\n", mask);
-    CHECK_GL( mGlAbstraction, mGlAbstraction.Clear(mask) );
+    bool forceClear = (mode == FORCE_CLEAR );
+    mask = mFrameBufferStateCache.GetClearMask( mask, forceClear , mScissorTestEnabled );
+
+    if( mask > 0 )
+    {
+      LOG_GL("Clear %d\n", mask);
+      CHECK_GL( mGlAbstraction, mGlAbstraction.Clear( mask ) );
+    }
   }
 
   /**
@@ -517,7 +584,7 @@ public:
    * enables GL_CULL_FACE if in any of the face culling modes
    * otherwise disables GL_CULL_FACE
    */
-  void CullFace(CullFaceMode mode)
+  void CullFace( Dali::FaceCullingMode::Type mode )
   {
     // Avoid unnecessary calls to gl
     if(mCullFaceMode != mode)
@@ -525,14 +592,14 @@ public:
       mCullFaceMode = mode;
       switch(mode)
       {
-        case CullNone:
+        case Dali::FaceCullingMode::NONE:
         {
           LOG_GL("Disable GL_CULL_FACE\n");
           CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE) );
           break;
         }
 
-        case CullFront:
+        case Dali::FaceCullingMode::FRONT:
         {
           LOG_GL("Enable GL_CULL_FACE\n");
           CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
@@ -541,7 +608,7 @@ public:
           break;
         }
 
-        case CullBack:
+        case Dali::FaceCullingMode::BACK:
         {
           LOG_GL("Enable GL_CULL_FACE\n");
           CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
@@ -550,7 +617,7 @@ public:
           break;
         }
 
-        case CullFrontAndBack:
+        case Dali::FaceCullingMode::FRONT_AND_BACK:
         {
           LOG_GL("Enable GL_CULL_FACE\n");
           CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
@@ -570,19 +637,26 @@ public:
    */
   void DeleteBuffers(GLsizei n, const GLuint* buffers)
   {
-    // @todo: this is to prevent mesh destructor from doing GL calls when DALi core is being deleted
-    // can be taken out once render manages either knows about meshes or gpubuffers and can tell them directly that context is lost
     if( this->IsGlContextCreated() )
     {
       LOG_GL("DeleteBuffers %d %p\n", n, buffers);
       CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteBuffers(n, buffers) );
     }
-    // reset the cached buffer id's
-    // fixes problem where some drivers will a generate a buffer with the
-    // same id, as the last deleted buffer id.
-    mBoundArrayBufferId = 0;
-    mBoundElementArrayBufferId = 0;
-    mBoundTransformFeedbackBufferId = 0;
+
+    ResetBufferCache();
+
+    // Need to reset the buffer cache in the surface contexts
+    // This will only be executed by the surfaceless context when there are contexts for surface rendering
+    if ( mSceneContexts )
+    {
+      for ( auto&& context : *mSceneContexts )
+      {
+        if ( context )
+        {
+          context->ResetBufferCache();
+        }
+      }
+    }
   }
 
   /**
@@ -590,6 +664,8 @@ public:
    */
   void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
   {
+    mFrameBufferStateCache.FrameBuffersDeleted( n, framebuffers );
+
     LOG_GL("DeleteFramebuffers %d %p\n", n, framebuffers);
     CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteFramebuffers(n, framebuffers) );
   }
@@ -620,11 +696,19 @@ public:
     LOG_GL("DeleteTextures %d %p\n", n, textures);
     CHECK_GL( mGlAbstraction, mGlAbstraction.DeleteTextures(n, textures) );
 
-    // reset the cached texture id's incase the driver re-uses them
-    // when creating new textures
-    for( unsigned int i=0; i < MAX_TEXTURE_UNITS; ++i )
+    ResetTextureCache();
+
+    // Need to reset the texture cache in the scene contexts
+    // This will only be executed by the surfaceless context when there are contexts for surface rendering
+    if ( mSceneContexts )
     {
-       mBound2dTextureId[ i ] = 0;
+      for ( auto&& context : *mSceneContexts )
+      {
+        if ( context )
+        {
+          context->ResetTextureCache();
+        }
+      }
     }
   }
 
@@ -642,8 +726,12 @@ public:
    */
   void DepthFunc(GLenum func)
   {
-    LOG_GL("DepthFunc %x\n", func);
-    CHECK_GL( mGlAbstraction, mGlAbstraction.DepthFunc(func) );
+    if( func != mDepthFunction )
+    {
+      mDepthFunction = func;
+      LOG_GL("DepthFunc %x\n", func);
+      CHECK_GL( mGlAbstraction, mGlAbstraction.DepthFunc(func) );
+    }
   }
 
   /**
@@ -651,11 +739,12 @@ public:
    */
   void DepthMask(GLboolean flag)
   {
+    bool booleanFlag = flag != GL_FALSE;
     // only change state if needed
-    if( flag != mDepthMaskEnabled )
+    if( booleanFlag != mDepthMaskEnabled )
     {
-      mDepthMaskEnabled = flag;
-      LOG_GL("DepthMask %s\n", flag ? "True" : "False");
+      mDepthMaskEnabled = booleanFlag;
+      LOG_GL("DepthMask %s\n", booleanFlag ? "True" : "False");
       CHECK_GL( mGlAbstraction, mGlAbstraction.DepthMask( mDepthMaskEnabled ) );
     }
   }
@@ -679,6 +768,7 @@ public:
    */
   void DrawArrays(GLenum mode, GLint first, GLsizei count)
   {
+    mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
     FlushVertexAttributeLocations();
 
     LOG_GL("DrawArrays %x %d %d\n", mode, first, count);
@@ -690,6 +780,7 @@ public:
    */
   void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
   {
+    mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
     FlushVertexAttributeLocations();
 
     LOG_GL("DrawArraysInstanced %x %d %d %d\n", mode, first, count, instanceCount);
@@ -701,6 +792,7 @@ public:
    */
   void DrawBuffers(GLsizei n, const GLenum* bufs)
   {
+    mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
     LOG_GL("DrawBuffers %d %p\n", n, bufs);
     CHECK_GL( mGlAbstraction, mGlAbstraction.DrawBuffers(n, bufs) );
   }
@@ -710,6 +802,8 @@ public:
    */
   void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
   {
+    mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
+
     FlushVertexAttributeLocations();
 
     LOG_GL("DrawElements %x %d %d %p\n", mode, count, type, indices);
@@ -721,6 +815,8 @@ public:
    */
   void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void* indices, GLsizei instanceCount)
   {
+    mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
+
     FlushVertexAttributeLocations();
 
     LOG_GL("DrawElementsInstanced %x %d %d %p %d\n", mode, count, type, indices, instanceCount);
@@ -732,6 +828,7 @@ public:
    */
   void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices)
   {
+    mFrameBufferStateCache.DrawOperation( mColorMask, DepthBufferWriteEnabled(), StencilBufferWriteEnabled() );
     FlushVertexAttributeLocations();
 
     LOG_GL("DrawRangeElements %x %u %u %d %d %p\n", mode, start, end, count, type, indices);
@@ -855,14 +952,18 @@ public:
 
   /**
    * This method replaces glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST).
+   * Note GL_DEPTH_TEST means enable the depth buffer for writing and or testing.
+   * glDepthMask is used to enable / disable writing to depth buffer.
+   * glDepthFunc us used to control if testing is enabled and how it is performed ( default GL_LESS)
+   *
    * @param[in] enable True if GL_DEPTH_TEST should be enabled.
    */
-  void SetDepthTest(bool enable)
+  void EnableDepthBuffer( bool enable )
   {
     // Avoid unecessary calls to glEnable/glDisable
-    if (enable != mDepthTestEnabled)
+    if( enable != mDepthBufferEnabled )
     {
-      mDepthTestEnabled = enable;
+      mDepthBufferEnabled = enable;
 
       if (enable)
       {
@@ -999,14 +1100,17 @@ public:
 
   /**
    * This method replaces glEnable(GL_STENCIL_TEST) and glDisable(GL_STENCIL_TEST).
+   * Note GL_STENCIL_TEST means enable the stencil buffer for writing and or testing.
+   * glStencilMask is used to control how bits are written to the stencil buffer.
+   * glStencilFunc is used to control if testing is enabled and how it is performed ( default GL_ALWAYS )
    * @param[in] enable True if GL_STENCIL_TEST should be enabled.
    */
-  void SetStencilTest(bool enable)
+  void EnableStencilBuffer(bool enable)
   {
     // Avoid unecessary calls to glEnable/glDisable
-    if (enable != mStencilTestEnabled)
+    if( enable != mStencilBufferEnabled )
     {
-      mStencilTestEnabled = enable;
+      mStencilBufferEnabled = enable;
 
       if (enable)
       {
@@ -1118,6 +1222,8 @@ public:
   {
     LOG_GL("GenFramebuffers %d %p\n", n, framebuffers);
     CHECK_GL( mGlAbstraction, mGlAbstraction.GenFramebuffers(n, framebuffers) );
+
+    mFrameBufferStateCache.FrameBuffersCreated( n, framebuffers );
   }
 
   /**
@@ -1430,8 +1536,15 @@ public:
    */
   void StencilFunc(GLenum func, GLint ref, GLuint mask)
   {
-    LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
-    CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) );
+    if( ( func != mStencilFunc ) || ( ref != mStencilFuncRef ) || ( mask != mStencilFuncMask ) )
+    {
+      mStencilFunc = func;
+      mStencilFuncRef = ref;
+      mStencilFuncMask = mask;
+
+      LOG_GL("StencilFunc %x %d %d\n", func, ref, mask);
+      CHECK_GL( mGlAbstraction, mGlAbstraction.StencilFunc(func, ref, mask) );
+    }
   }
 
   /**
@@ -1471,8 +1584,15 @@ public:
    */
   void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
   {
-    LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
-    CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) );
+    if( ( fail != mStencilOpFail ) || ( zfail != mStencilOpDepthFail ) || ( zpass != mStencilOpDepthPass ) )
+    {
+      mStencilOpFail = fail;
+      mStencilOpDepthFail = zfail;
+      mStencilOpDepthPass = zpass;
+
+      LOG_GL("StencilOp %x %x %x\n", fail, zfail, zpass);
+      CHECK_GL( mGlAbstraction, mGlAbstraction.StencilOp(fail, zfail, zpass) );
+    }
   }
 
   /**
@@ -1577,7 +1697,11 @@ public:
   {
     // check if its same as already set
     Rect<int> newViewport( x, y, width, height );
-    if( mViewPort != newViewport )
+
+    // Temporarily disable the viewport caching, as the implementation of GLES driver in Tizen platform
+    // share a global viewport between multiple contexts, therefore glViewport has to be called every
+    // time after glBindFramebuffer regardless of the same vewport size in the same context.
+//    if( mViewPort != newViewport )
     {
       // set new one
       LOG_GL("Viewport %d %d %d %d\n", x, y, width, height);
@@ -1601,84 +1725,30 @@ public:
    */
   const Rect< int >& GetViewport();
 
-  /**
-   * Set the frame count of render thread
-   */
-  inline void SetFrameCount(unsigned int frameCount)
-  {
-    mFrameCount = frameCount;
-  }
-
-  /**
-   * Get the frame count
-   */
-  inline unsigned int GetFrameCount()
-  {
-    return mFrameCount;
-  }
-
-  /**
-   * Increment the count of culled renderers
-   */
-  inline void IncrementCulledCount()
-  {
-    mCulledCount++;
-  }
-
-  /**
-   * Clear the count of culled renderers
-   */
-  inline void ClearCulledCount()
-  {
-    mCulledCount = 0;
-  }
-
-  /**
-   * Get the count of culled renderers in this frame
-   */
-  inline unsigned int GetCulledCount()
-  {
-    return mCulledCount;
-  }
-
-  /**
-   * Increment the count of culled renderers
-   */
-  inline void IncrementRendererCount()
-  {
-    mRendererCount++;
-  }
+private: // Implementation
 
   /**
-   * Clear the count of image renderers
+   * @return true if next draw operation will write to depth buffer
    */
-  inline void ClearRendererCount()
+  bool DepthBufferWriteEnabled() const
   {
-    mRendererCount = 0;
+    return mDepthBufferEnabled && mDepthMaskEnabled;
   }
 
   /**
-   * Get the count of image renderers in this frame
+   * @return true if next draw operation will write to stencil buffer
    */
-  inline unsigned int GetRendererCount()
+  bool StencilBufferWriteEnabled() const
   {
-    return mRendererCount;
+    return mStencilBufferEnabled && ( mStencilMask > 0 );
   }
 
-
-private: // Implementation
-
   /**
    * Flushes vertex attribute location changes to the driver
    */
   void FlushVertexAttributeLocations();
 
   /**
-   * Reset the cached internal vertex attribute state
-   */
-  void ResetVertexAttributeState();
-
-  /**
    * Either enables or disables a vertex attribute location in the cache
    * The cahnges won't take affect until FlushVertexAttributeLocations is called
    * @param location attribute location
@@ -1689,7 +1759,7 @@ private: // Implementation
   /**
    * Sets the initial GL state.
    */
-  void ResetGlState();
+  void InitializeGlState();
 
 private: // Data
 
@@ -1701,15 +1771,16 @@ private: // Data
   bool mColorMask;
   GLuint mStencilMask;
   bool mBlendEnabled;
-  bool mDepthTestEnabled;
+  bool mDepthBufferEnabled;
   bool mDepthMaskEnabled;
   bool mDitherEnabled;
   bool mPolygonOffsetFillEnabled;
   bool mSampleAlphaToCoverageEnabled;
   bool mSampleCoverageEnabled;
   bool mScissorTestEnabled;
-  bool mStencilTestEnabled;
+  bool mStencilBufferEnabled;
   bool mClearColorSet;
+  bool mUsingDefaultBlendColor;
 
   // glBindBuffer() state
   GLuint mBoundArrayBufferId;        ///< The ID passed to glBindBuffer(GL_ARRAY_BUFFER)
@@ -1718,10 +1789,10 @@ private: // Data
 
   // glBindTexture() state
   TextureUnit mActiveTextureUnit;
-  GLuint mBound2dTextureId[ MAX_TEXTURE_UNITS ];  ///< The ID passed to glBindTexture(GL_TEXTURE_2D)
+  GLuint mBoundTextureId[ MAX_TEXTURE_UNITS ];  ///< The ID passed to glBindTexture()
 
   // glBlendColor() state
-  bool mUsingDefaultBlendColor;
+  Vector4 mBlendColor; ///< Blend color
 
   // glBlendFuncSeparate() state
   GLenum mBlendFuncSeparateSrcRGB;   ///< The srcRGB parameter passed to glBlendFuncSeparate()
@@ -1733,11 +1804,21 @@ private: // Data
   GLenum mBlendEquationSeparateModeRGB;    ///< Controls RGB blend mode
   GLenum mBlendEquationSeparateModeAlpha;  ///< Controls Alpha blend mode
 
+  // glStencilFunc() and glStencilOp() state.
+  GLenum mStencilFunc;
+  GLint mStencilFuncRef;
+  GLuint mStencilFuncMask;
+  GLenum mStencilOpFail;
+  GLenum mStencilOpDepthFail;
+  GLenum mStencilOpDepthPass;
+
+  GLenum mDepthFunction;  ///The depth function
+
   GLint mMaxTextureSize;      ///< return value from GetIntegerv(GL_MAX_TEXTURE_SIZE)
   Vector4 mClearColor;        ///< clear color
 
   // Face culling mode
-  CullFaceMode mCullFaceMode;
+  Dali::FaceCullingMode::Type mCullFaceMode;
 
   // cached viewport size
   Rect< int > mViewPort;
@@ -1746,13 +1827,13 @@ private: // Data
   bool mVertexAttributeCachedState[ MAX_ATTRIBUTE_CACHE_SIZE ];    ///< Value cache for Enable Vertex Attribute
   bool mVertexAttributeCurrentState[ MAX_ATTRIBUTE_CACHE_SIZE ];   ///< Current state on the driver for Enable Vertex Attribute
 
-  unsigned int mFrameCount;       ///< Number of render frames
-  unsigned int mCulledCount;      ///< Number of culled renderers per frame
-  unsigned int mRendererCount;    ///< Number of image renderers per frame
+  FrameBufferStateCache mFrameBufferStateCache;   ///< frame buffer state cache
+
+  std::vector< Context* >* mSceneContexts;      ///< The pointer of the container of contexts for surface rendering
 };
 
 } // namespace Internal
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_CONTEXT_H__
+#endif // DALI_INTERNAL_CONTEXT_H