sperated Compositor and RenderQueue from GlRenderManager
authorDae Young Ryu <karzia@samsung.com>
Mon, 24 Mar 2014 00:29:29 +0000 (09:29 +0900)
committerDae Young Ryu <karzia@samsung.com>
Mon, 24 Mar 2014 00:29:29 +0000 (09:29 +0900)
Change-Id: I85b077db3e39eaa6ff16c807bb06aedebb4e0826
Signed-off-by: Dae Young Ryu <karzia@samsung.com>
13 files changed:
src/ui/CMakeLists.txt
src/ui/animations/FUiAnim_AnimationManager.cpp
src/ui/animations/FUiAnim_GlCompositor.cpp [new file with mode: 0644]
src/ui/animations/FUiAnim_GlCompositor.h [new file with mode: 0644]
src/ui/animations/FUiAnim_GlContext.h
src/ui/animations/FUiAnim_GlNode.h
src/ui/animations/FUiAnim_GlRenderManager.cpp
src/ui/animations/FUiAnim_GlRenderManager.h
src/ui/animations/FUiAnim_GlVisualElementSurfaceImpl.h
src/ui/animations/FUiAnim_ShaderProgramImpl.h
src/ui/animations/FUiAnim_VisualElementFilterImpl.h
src/ui/inc/FUiAnim_MeshImpl.h
src/ui/inc/FUiAnim_VisualElementImpl.h

index 7c266d8..0dd0727 100644 (file)
@@ -57,6 +57,7 @@ SET (${this_target}_SOURCE_FILES
     animations/FUiAnim_GlNode.cpp
        animations/FUiAnim_GlLayer.cpp
        animations/FUiAnim_GlLoader.cpp
+       animations/FUiAnim_GlCompositor.cpp
        animations/FUiAnim_GlRenderManager.cpp
        animations/FUiAnim_GlVisualElementSurfaceImpl.cpp
        animations/FUiAnim_ResourceManager.cpp
index f35f802..a248f2b 100644 (file)
@@ -39,6 +39,7 @@
 #include "FUiAnim_VisualElementAnimationVariantInterpolator.h"
 #include "FUiAnim_AnimationManager.h"
 #include "FUiAnim_DisplayManager.h"
+#include "FUiAnim_GlCompositor.h"
 #include "FUiAnim_GlRenderManager.h"
 
 #include "FUiAnim_Debug.h"
@@ -974,7 +975,7 @@ _AnimationManager::ProcessCommittedTransaction(unsigned int baseTime)
                __renderRoot.__isAnimating = true;
 
                // Wakeup render thread
-               _GlRenderManager::GetInstance()->WakeUp();
+               _GlRenderManager::GetInstance()->GetCompositor()->WakeUp();
        }
 }
 
diff --git a/src/ui/animations/FUiAnim_GlCompositor.cpp b/src/ui/animations/FUiAnim_GlCompositor.cpp
new file mode 100644 (file)
index 0000000..75f00e1
--- /dev/null
@@ -0,0 +1,1045 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 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.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       FUiAnim_GlCompositor.cpp
+ * @brief      This file contains implementation of _GlCompositor class
+ *
+ * This file contains implementation _GlCompositor class.
+ */
+#include <unique_ptr.h>
+
+#include <FBaseErrors.h>
+#include <FBaseSysLog.h>
+#include <FSysSystemTime.h>
+#include <FUiAnimShader.h>
+#include <FUiAnimShaderProgram.h>
+#include <FUiAnimView.h>
+#include <FUiAnimCamera.h>
+
+#include "FBase_StringConverter.h"
+#include "FGrpFloatRectangle.h"
+
+#include "FUiAnim_AnimationManager.h"
+#include "FUiAnim_VisualElementImpl.h"
+#include "FUiAnim_VisualElementEnvironment.h"
+
+#include "FUiAnim_CameraImpl.h"
+#include "FUiAnim_ViewInfo.h"
+#include "FUiAnim_ViewImpl.h"
+#include "FUiAnim_GlCompositor.h"
+#include "FUiAnim_DisplayManager.h"
+#include "FUiAnim_GlVisualElementSurfaceImpl.h"
+#include "FUiAnim_GlLayer.h"
+#include "FUiAnim_GlNode.h"
+#include "FUiAnim_GlContext.h"
+#include "FUiAnim_GlRenderManager.h"
+#include "FUiAnim_VisualElementSurfaceManager.h"
+
+#include "FUiAnim_MeshImpl.h"
+#include "FUiAnim_ShaderImpl.h"
+#include "FUiAnim_ShaderProgramImpl.h"
+#include "FUiAnimLight.h"
+#include "FUiAnimMaterial.h"
+#include "FUiAnim_LightImpl.h"
+#include "FUiAnim_MaterialImpl.h"
+#include "FUiAnim_MeshControllerImpl.h" //skinning
+#include "FUiAnimVisualElementFilter.h"
+#include "FUiAnim_VisualElementFilterImpl.h"
+
+#include "FUiAnim_GlLoader.h"
+#include "FUiAnim_Debug.h"
+
+#ifdef _WIN32
+       #include <GL/glew.h>
+#else
+       #include <GLES2/gl2.h>
+#endif
+
+#ifdef ECORE_X_NATIVE
+#include "FUiAnim_EcoreXLooper.h"
+#endif
+
+using namespace std;
+using namespace Tizen;
+using namespace Tizen::Base;
+using namespace Tizen::Graphics;
+using namespace Tizen::Ui::Animations;
+
+//#define PRINT(...) fprintf(stderr, __VA_ARGS__)
+#define PRINT(...)
+//#define RPRINT(...) fprintf(stderr, __VA_ARGS__)
+#define RPRINT(...)
+
+//static bool __checkCondition(bool condition)
+//{
+//     bool bCond = condition;
+//     if(bCond == false)
+//     {
+//             return bCond;
+//     }
+//     return bCond;
+//}
+//#define ASSERT(__CONDITION__,...) {__checkCondition(__CONDITION__); SysAssertf(__CONDITION__,__VA_ARGS__);}
+#define ASSERT(...) SysAssertf(__VA_ARGS__)
+
+#ifdef VE_USE_GL_MULTI_CONTEXT
+#define        CHECK_GL_CONTEXT(pGlContext)    ASSERT(pGlContext, "Invalid render manager status(no context)");
+#else
+#define        CHECK_GL_CONTEXT()      ASSERT(__pGlContext, "Invalid render manager status(no context)");
+#endif
+
+#define VERTEX_BUFFER_STRIDE           3
+#define TEX_COORD_BUFFER_STRIDE                2
+
+#define        VE_RENDER_OBJECT_VERTEX_COUNT_MAX       120
+#define        VE_RENDER_QUEUE_COUNT_MAX                       100
+#define OFFSET (UNIFORM_VEC3_LIGHT_ATTENUATION - UNIFORM_INT_LIGHT_TYPE + 1)
+
+#define SURF_IMPL(__SURF)      static_cast<_GlVisualElementSurfaceImpl*>(_VisualElementSurfaceImpl::GetInstance(__SURF))
+
+namespace Tizen { namespace Ui { namespace Animations
+{
+
+_GlCompositor* _GlCompositor::__pInstance = null;
+
+_GlCompositor::_GlCompositor(_GlRenderManager* pRenderManager)
+       : __commandId(COMMAND_UNKNOWN)
+       , __commandResult(E_SUCCESS)
+       , __commandTransaction()
+       , __commandLock()
+       , __commandRequest()
+       , __commandReply()
+       , __threadId(0)
+       , __pGlContext(0)
+       , __view()
+       , __projection()
+       , __viewProjection()
+       , __flippedProjection()
+       , __flippedViewProjection()
+       , __viewport()
+       , __queueCount(0)
+       , __needClear(false)
+       , __pTempNode(null)
+       , __globalLightCount(0)
+//     , __materialShininess(0.0f)
+       , __pAnimationManager(0)
+       , __pRenderManager(pRenderManager)
+{
+
+       memset(&__threadInfo, 0x00, sizeof(pthread_t));
+       if (pthread_create(&__threadInfo, NULL, _GlCompositor::CompositeProc, this) != 0)
+       {
+               ASSERT(false, "Creating render-thread failed");
+       }
+
+       __eyePosition[0] = 0.0f;
+       __eyePosition[1] = 0.0f;
+       __eyePosition[2] = 0.0f;
+
+//     __materialAmbient[0] = 0.2f; __materialAmbient[1] = 0.2f; __materialAmbient[2] = 0.2f; __materialAmbient[3] = 1.0f;
+//     __materialDiffuse[0] = 0.8f; __materialDiffuse[1] = 0.8f; __materialDiffuse[2] = 0.8f; __materialDiffuse[3] = 1.0f;
+//     __materialSpecular[0] = 0.0f; __materialSpecular[1] = 0.0f; __materialSpecular[2] = 0.0f; __materialSpecular[3] = 1.0f;
+//     __materialEmissive[0] = 0.0f; __materialEmissive[1] = 0.0f; __materialEmissive[2] = 0.0f; __materialEmissive[3] = 1.0f;
+
+       ClearLastResult();
+
+       __pTempNode = new (std::nothrow) _GlNode;
+
+       // vertex coordinates
+       __pTempNode->__pVertices[0] = 0.0f;
+       __pTempNode->__pVertices[1] = 0.0f;
+       __pTempNode->__pVertices[2] = 0.0f;
+
+       __pTempNode->__pVertices[5] = 0.0f;             // width
+       __pTempNode->__pVertices[6] = 0.0f;
+       __pTempNode->__pVertices[7] = 0.0f;
+
+       __pTempNode->__pVertices[10] = 0.0f;
+       __pTempNode->__pVertices[11] = 0.0f;    // height
+       __pTempNode->__pVertices[12] = 0.0f;
+
+       __pTempNode->__pVertices[15] = 0.0f;    // width
+       __pTempNode->__pVertices[16] = 0.0f;    // height
+       __pTempNode->__pVertices[17] = 0.0f;
+
+       // texture coordinates
+       __pTempNode->__pVertices[3]  = 0.0f;
+       __pTempNode->__pVertices[4]  = 0.0f;
+
+       __pTempNode->__pVertices[8]  = 1.0f;
+       __pTempNode->__pVertices[9]  = 0.0f;
+
+       __pTempNode->__pVertices[13] = 0.0f;
+       __pTempNode->__pVertices[14] = 1.0f;
+
+       __pTempNode->__pVertices[18] = 1.0f;
+       __pTempNode->__pVertices[19] = 1.0f;
+
+       __pTempNode->__transform.SetAsIdentity();
+       __pTempNode->__useTransform = false;
+       __pTempNode->__textureRepeated = false;
+}
+
+_GlCompositor::~_GlCompositor(void)
+{
+       _AutoMutex commandTransactionLock(__commandTransaction);
+       _AutoMutex commandLock(__commandLock);
+
+       __commandId = COMMAND_EXIT;
+       __commandRequest.SendSignal();
+
+       __commandReply.WaitForSignal(&__commandLock);
+
+       pthread_join(__threadInfo, NULL);
+
+       delete __pTempNode;
+}
+
+bool
+_GlCompositor::Composite(_GlLayer* pLayer)
+{
+       _AutoMutex commandTransactionLock(__commandTransaction);
+       _AutoMutex commandLock(__commandLock);
+
+       __commandId = COMMAND_COMPOSITE;
+       __commandArg.__pCommandGlLayer = pLayer;
+       __commandRequest.SendSignal();
+
+       return E_SUCCESS;
+}
+
+void
+_GlCompositor::WakeUp(void)
+{
+       _AutoMutex commandTransactionLock(__commandTransaction);
+       _AutoMutex commandLock(__commandLock);
+
+       __commandId = COMMAND_WAKEUP;
+       __commandRequest.SendSignal();
+}
+
+void
+_GlCompositor::CompositeNode(VisualElement* pRenderObject, Tizen::Base::Collection::ArrayList &parentLight, bool useStencil, unsigned int depth, _GlLayer* pLayer, _ViewInfo* pView)
+{
+       bool updateStencil = false;
+       unsigned int stencilIndex = depth;
+
+       Tizen::Base::Collection::IList* pChildren = pRenderObject->GetChildrenN();
+
+       if (unlikely(!pChildren))
+               return;
+
+       // FIXME: Sync status BEFORE compositing for early-unlock
+
+       int childrenCount = pChildren->GetCount();
+       for (int c = 0; c < childrenCount; c++)
+       {
+               VisualElement* pChild = dynamic_cast< VisualElement* >(pChildren->GetAt(c));
+               if (unlikely(!pChild))
+                       continue;
+
+               _VisualElementImpl* pChildImpl = _VisualElementImpl::GetInstance(*pChild);
+
+// if child is root: it need to test
+               if (pChildImpl->__isRoot)
+               {
+                       _RootVisualElement* pRoot = static_cast<_RootVisualElement*>(pChildImpl->GetPublic());
+                       if (pRoot)
+                       {
+                               _ViewInfo* pNewView = pRoot->GetView();
+                               if (pNewView)
+                               {
+                                       CompositeView(pLayer, pRoot, pNewView);
+                               }
+                               else
+                               {
+                                       CompositeView(pLayer, pRoot, pView);
+                               }
+                       }
+                       continue;
+               }
+
+               _GlNode* pNode = dynamic_cast< _GlNode* >(pChildImpl->GetNativeNode());
+               if (unlikely(!pNode))
+                       continue;
+
+               pNode->SyncStatus(pChildImpl->GetSharedData().pSurface, *pChildImpl);
+
+               if (pNode->__pLight)
+               {
+                       _LightImpl* pLightImpl = _LightImpl::GetInstance(*pNode->__pLight);
+
+                       if (pLightImpl->IsEnabled())
+                       {
+                               pNode->__activeLight.Add(pNode->__pLight);
+                       }
+#if 0
+                       if (__globalLightCount < MAX_LIGHT_COUNT)
+                       {
+                               __globalLight[__globalLightCount] = pNode->__pLight;
+                               __globalLightCount++;
+                       }
+#endif
+
+                       float* pPosition = pLightImpl->GetPosition();
+
+                       if (pLightImpl->GetType() != Light::LIGHT_TYPE_DIRECTIONAL)
+                       {
+                               float position[4];
+
+                               _Matrix4f modelview = __view * _Matrix4f(pChildImpl->GetMatrixToTop());
+
+                               position[0] = (modelview(0, 0) * pPosition[0]) + (modelview(0, 1) * pPosition[1]) + (modelview(0, 2) * pPosition[2]) + modelview(0, 3);
+                               position[1] = (modelview(1, 0) * pPosition[0]) + (modelview(1, 1) * pPosition[1]) + (modelview(1, 2) * pPosition[2]) + modelview(1, 3);
+                               position[2] = (modelview(2, 0) * pPosition[0]) + (modelview(2, 1) * pPosition[1]) + (modelview(2, 2) * pPosition[2]) + modelview(2, 3);
+                               position[3] = (modelview(3, 0) * pPosition[0]) + (modelview(3, 1) * pPosition[1]) + (modelview(3, 2) * pPosition[2]) + modelview(3, 3);
+
+                               pLightImpl->SetPositionInEyeCoords(position);
+
+                               if (pLightImpl->GetType() == Light::LIGHT_TYPE_SPOT)
+                               {
+                                       float* pDirection = pLightImpl->GetDirection();
+                                       float direction[3];
+
+                                       direction[0] = (modelview(0, 0) * pDirection[0]) + (modelview(0, 1) * pDirection[1]) + (modelview(0, 2) * pDirection[2]);
+                                       direction[1] = (modelview(1, 0) * pDirection[0]) + (modelview(1, 1) * pDirection[1]) + (modelview(1, 2) * pDirection[2]);
+                                       direction[2] = (modelview(2, 0) * pDirection[0]) + (modelview(2, 1) * pDirection[1]) + (modelview(2, 2) * pDirection[2]);
+
+                                       pLightImpl->SetDirectionInEyeCoords(direction);
+                               }
+                       }
+                       else
+                       {
+                               pLightImpl->SetPositionInEyeCoords(pPosition);
+                       }
+               }
+
+               for (register int i = 0; i<parentLight.GetCount(); i++ )
+               {
+                       Object* pValue = null;
+                       pValue = parentLight.GetAt(i);
+
+//                     _LightImpl* pLightImplParent = _LightImpl::GetInstance(*(Light*)pValue);
+
+//                     if (pLightImpl != pLightImplParent)
+                       {
+                               pNode->__activeLight.Add(pValue);
+                       }
+               }
+
+#ifndef BUILD_UI_CORE
+               if (!pNode->__isVisible || _FloatCompare(pNode->__opacity, 0.0f))
+               {
+                       continue;
+               }
+#endif
+
+               if (pNode->__visibleRect.IsEmpty())
+               {
+                       if (!pNode->__isClipChildren)
+                       {
+                               CompositeNode(pChild, pNode->__activeLight, useStencil, depth, pLayer, pView);
+                       }
+                       continue;
+               }
+
+               if (!pNode->__pSurface)
+               {
+                       if (_FloatCompare(pNode->__objectColor.Alpha(), 0.0f))
+                       {
+                               CompositeNode(pChild, pNode->__activeLight, useStencil, depth, pLayer, pView);
+                               continue;
+                       }
+               }
+
+               useStencil |= (pNode->__useStencil) ? true : false;
+               updateStencil = (pNode->__useStencil && pChildImpl->GetChildrenCount() > 0) ? true : false;
+
+               if (pNode->__pFilter && pNode->__pFilter->IsEnabled())
+               {
+                       _VisualElementFilterImpl* pFilterImpl = _VisualElementFilterImpl::GetInstance(*pNode->__pFilter);
+                       bool useTempNode = false;
+                       VisualElementSurface* pSurface = null;
+                       TextureInfo* pTextureInfo = null;
+
+
+                       if (pFilterImpl->__pRenderSurface)
+                       {
+                               _GlVisualElementSurfaceImpl* pRenderSurfaceImpl = SURF_IMPL(*pFilterImpl->__pRenderSurface);
+                               TextureInfo* pRenderTextureInfo = (TextureInfo*)pRenderSurfaceImpl->GetNativeHandle();
+
+                               __pRenderManager->GetRenderQueue()->FlushRenderQueue();
+
+                               __pRenderManager->GetRenderQueue()->SetRenderTarget(pRenderSurfaceImpl);
+                               __pRenderManager->GetRenderQueue()->SetClear();
+//                             __pGlContext->BindFramebuffer(pRenderTextureInfo);
+//                             __needClear = true;
+
+                               pNode->__useFilter = false;
+
+                               //glViewport(0, 0, pRenderTextureInfo->width, pRenderTextureInfo->height);
+                               __pRenderManager->GetRenderQueue()->SetViewport(0, 0, pRenderTextureInfo->width, pRenderTextureInfo->height);
+
+                               __pRenderManager->GetRenderQueue()->EnqueueRenderObject(pNode, false, 0, true);
+
+                               __pRenderManager->GetRenderQueue()->FlushRenderQueue();
+
+                               __pRenderManager->GetRenderQueue()->SetRenderTarget(null);
+//                             __pGlContext->BindFramebuffer(null);            // TODO: restore previous framebuffer
+
+                               pNode->__useFilter = true;
+
+                               // for next rendering
+                               useTempNode = true;
+                               pSurface = pFilterImpl->__pRenderSurface;
+                               pTextureInfo = pRenderTextureInfo;
+                       }
+
+                       if (pFilterImpl->__pInternalSurface)
+                       {
+                               _GlVisualElementSurfaceImpl* pInternalSurfaceImpl = SURF_IMPL(*pFilterImpl->__pInternalSurface);
+                               TextureInfo* pInternalTextureInfo = (TextureInfo*)pInternalSurfaceImpl->GetNativeHandle();
+
+                               __pRenderManager->GetRenderQueue()->FlushRenderQueue();
+
+                               __pRenderManager->GetRenderQueue()->SetRenderTarget(pInternalSurfaceImpl);
+                               __pRenderManager->GetRenderQueue()->SetClear();
+//                             __pGlContext->BindFramebuffer(pInternalTextureInfo);
+//                             __needClear = true;
+
+                               pFilterImpl->__isFirstPass = true;
+
+                               __pRenderManager->GetRenderQueue()->SetViewport(0, 0, pInternalTextureInfo->width, pInternalTextureInfo->height);
+                               //glViewport(0, 0, pInternalTextureInfo->width, pInternalTextureInfo->height);
+
+
+                               if (useTempNode)
+                               {
+                                       __pTempNode->__useBlend = pNode->__useBlend;
+                                       __pTempNode->__useStencil = pNode->__useStencil;
+                                       __pTempNode->__childrenCount = pNode->__childrenCount;
+                                       __pTempNode->__opacity = pNode->__opacity;
+                                       __pTempNode->__pFilter = pNode->__pFilter;
+                                       __pTempNode->__useFilter = pNode->__useFilter;
+                                       __pTempNode->__pSurface = pSurface;
+//                                     __pTempNode->__pTextureInfo = pTextureInfo;
+
+                                       __pRenderManager->GetRenderQueue()->EnqueueRenderObject(__pTempNode, false, 0, true);
+                               }
+                               else
+                               {
+                                       __pRenderManager->GetRenderQueue()->EnqueueRenderObject(pNode, false, 0, true);
+                               }
+
+                               __pRenderManager->GetRenderQueue()->FlushRenderQueue();
+
+                               __pRenderManager->GetRenderQueue()->SetRenderTarget(null);
+                               //__pGlContext->BindFramebuffer(null);          // TODO: restore previous framebuffer
+
+                               // for next rendering
+                               useTempNode = true;
+                               pSurface = pFilterImpl->__pInternalSurface;
+                               pTextureInfo = pInternalTextureInfo;
+                       }
+
+                       pFilterImpl->__isFirstPass = false;
+
+                       if (useTempNode)
+                       {
+                               __pTempNode->__useBlend = pNode->__useBlend;
+                               __pTempNode->__useStencil = pNode->__useStencil;
+                               __pTempNode->__childrenCount = pNode->__childrenCount;
+                               __pTempNode->__opacity = pNode->__opacity;
+                               __pTempNode->__pFilter = pNode->__pFilter;
+                               __pTempNode->__useFilter = pNode->__useFilter;
+                               __pTempNode->__pSurface = pSurface;
+//                             __pTempNode->__pTextureInfo = pTextureInfo;
+
+                               if (pFilterImpl->__downSampling)
+                               {
+                                       _GlVisualElementSurfaceImpl* pRenderSurfaceImpl = SURF_IMPL(*pFilterImpl->__pRenderSurface);
+                                       TextureInfo* pRenderTextureInfo = (TextureInfo*)pRenderSurfaceImpl->GetNativeHandle();
+
+                                       __pRenderManager->GetRenderQueue()->SetRenderTarget(pRenderSurfaceImpl);
+                                       __pRenderManager->GetRenderQueue()->SetClear();
+                                       //__pGlContext->BindFramebuffer(pRenderTextureInfo);
+                                       //__needClear = true;
+
+                                       __pRenderManager->GetRenderQueue()->SetViewport(0, 0, pRenderTextureInfo->width, pRenderTextureInfo->height);
+                                       //glViewport(0, 0, pRenderTextureInfo->width, pRenderTextureInfo->height);
+
+                                       __pRenderManager->GetRenderQueue()->EnqueueRenderObject(__pTempNode, false, 0, true);
+
+                                       __pRenderManager->GetRenderQueue()->FlushRenderQueue();
+
+
+                                       __pRenderManager->GetRenderQueue()->SetRenderTarget(null);
+                                       //__pGlContext->BindFramebuffer(null);          // TODO: restore previous framebuffer
+
+                                       // for next rendering
+                                       __pTempNode->__useFilter = false;
+                                       __pTempNode->__pSurface = pFilterImpl->__pRenderSurface;
+//                                     __pTempNode->__pTextureInfo = pRenderTextureInfo;
+                               }
+
+                               __pRenderManager->GetRenderQueue()->SetViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
+                               //glViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
+
+                               __pRenderManager->GetRenderQueue()->EnqueueRenderObject(__pTempNode, useStencil, stencilIndex, true);
+                       }
+                       else
+                       {
+                               __pRenderManager->GetRenderQueue()->EnqueueRenderObject(pNode, useStencil, stencilIndex, true);
+                       }
+               }
+               else
+               {
+                       __pRenderManager->GetRenderQueue()->EnqueueRenderObject(pNode, useStencil, stencilIndex, true);
+               }
+
+               if (updateStencil)
+               {
+                       CompositeNode(pChild, pNode->__activeLight, useStencil, depth + 1, pLayer, pView);
+
+                       if (pNode->__pFilter)
+                       {
+                               // TODO: implement
+                       }
+                       else
+                       {
+                               __pRenderManager->GetRenderQueue()->EnqueueRenderObject(pNode, true, stencilIndex + 1, false);
+                       }
+               }
+               else
+               {
+                       CompositeNode(pChild, pNode->__activeLight, useStencil, depth, pLayer, pView);
+               }
+       }
+
+       //clear light arrayList
+       _VisualElementImpl* pRenderObjectImpl = _VisualElementImpl::GetInstance(*pRenderObject);
+       _GlNode* pRenderObjectNode = dynamic_cast< _GlNode* >(pRenderObjectImpl->GetNativeNode());
+       pRenderObjectNode->__activeLight.RemoveAll();
+
+       delete pChildren;
+}
+
+void
+_GlCompositor::CompositeView(_GlLayer* pLayer, _RootVisualElement* pRoot, _ViewInfo* pView)
+{
+       Tizen::Graphics::FloatRectangle viewport;
+       _Matrix4f view, projection, flippedProjection;
+       float eye[3] = {0.0f,0.0f,0.0f};
+
+       __pRenderManager->GetRenderQueue()->FlushRenderQueue();
+
+       VisualElementSurface* pSurface = pView->GetRenderTarget();
+
+       if (pSurface)
+       {
+               _GlVisualElementSurfaceImpl* pRenderSurfaceImpl = SURF_IMPL(*pSurface);
+               __pRenderManager->GetRenderQueue()->SetRenderTarget(pRenderSurfaceImpl);
+       }
+       else
+       {
+               __pRenderManager->GetRenderQueue()->SetRenderTarget(null);
+       }
+
+//     if (pSurface)
+//     {
+//             __pGlContext->BindFramebuffer(pView->GetRenderTargetInfo());
+//             __needClear = true;
+//     }
+//     else
+//     {
+//             __pGlContext->BindFramebuffer(null);
+//     }
+
+       Tizen::Graphics::FloatRectangle* pViewport = pView->GetViewport();
+       int orientation = pLayer->GetOrientation();
+       if (pViewport)
+       {
+               viewport = __viewport;
+
+               if (pSurface)
+               {
+                       __viewport.y = pViewport->y;
+               }
+               else
+               {
+                       Tizen::Graphics::FloatRectangle bounds = pLayer->GetBounds();
+
+                       if (orientation % 180)
+                       {
+                               __viewport.y = bounds.width - pViewport->y - pViewport->height;
+                       }
+                       else
+                       {
+                               __viewport.y = bounds.height - pViewport->y - pViewport->height;
+                       }
+               }
+
+               __viewport.x = pViewport->x;
+               __viewport.width = pViewport->width;
+               __viewport.height = pViewport->height;
+
+               __pRenderManager->GetRenderQueue()->SetViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
+//             glViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
+       }
+
+       if (orientation != 0)
+       {
+               if (orientation == 90)
+               {
+                       __view.Translate(0.0f, pLayer->GetBounds().width, 0.0f);
+               }
+               else if (orientation == 270)
+               {
+                       __view.Translate(pLayer->GetBounds().height, 0.0f, 0.0f);
+               }
+               else
+               {
+                       __view.Translate(pLayer->GetBounds().width, pLayer->GetBounds().height, 0.0f);
+               }
+
+               __view.Rotate(360-orientation, 0.0f, 0.0f, 1.0f);
+       }
+
+       Camera* pCamera = pView->GetCamera();
+       if (pCamera)
+       {
+               _CameraImpl* pCameraImpl = _CameraImpl::GetInstance(*pCamera);
+               FloatPoint3 eyePosition = pCameraImpl->GetEye();
+
+               view = __view;
+
+               eye[0] = __eyePosition[0];
+               eye[1] = __eyePosition[1];
+               eye[2] = __eyePosition[2];
+
+               __view = pCameraImpl->GetMatrix();
+
+               __eyePosition[0] = eyePosition.x;
+               __eyePosition[1] = eyePosition.y;
+               __eyePosition[2] = eyePosition.z;
+       }
+
+       const FloatMatrix4* pProjection = pView->GetProjection();
+       if (pProjection)
+       {
+               const FloatMatrix4* pFlippedProjection = pView->GetFlippedProjection();
+
+               projection.Assign(__projection);
+               flippedProjection.Assign(__flippedProjection);
+
+               __projection.CopyFrom(*pProjection);
+               __flippedProjection.CopyFrom(*pFlippedProjection);
+       }
+
+       __viewProjection.Assign(__projection);
+       __viewProjection.MultiplyMatrix(__view);
+
+       __flippedViewProjection.Assign(__flippedProjection);
+       __flippedViewProjection.MultiplyMatrix(__view);
+
+       __globalLightCount = 0;
+
+       VisualElement* pRootRender = _VisualElementImpl::GetInstance(*pRoot)->GetRenderObject()->GetPublic();
+
+       Tizen::Base::Collection::ArrayList clearColorArray;
+       clearColorArray.Construct();
+
+       CompositeNode(pRootRender, clearColorArray, false, 0, pLayer, pView);
+
+       // WARNING : need to check.. is it needed?
+//     memset(__pGlContext->__textureId, 0, sizeof(unsigned int) * (EXTRA_SURFACE_MAX + 2));
+
+       clearColorArray.RemoveAll();
+
+       // sub view
+       // Todo: render sub view
+       int count = pView->GetSubViewCount();
+
+       for (int i = 0; i < count; i++)
+       {
+               _ViewInfo* pSubView = pView->GetSubViewInfo(i);
+               if (pSubView)
+               {
+                       CompositeView(pLayer, pRoot, pSubView);
+               }
+       }
+
+       __pRenderManager->GetRenderQueue()->FlushRenderQueue();
+
+       // restore
+       if (pViewport)
+       {
+               __viewport = viewport;
+               __pRenderManager->GetRenderQueue()->SetViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
+
+//             glViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
+       }
+
+       if (pSurface)
+       {
+               __pRenderManager->GetRenderQueue()->SetRenderTarget(null);
+               //__pGlContext->BindFramebuffer(null);
+       }
+
+       if (pCamera)
+       {
+               __view = view;
+
+               __eyePosition[0] = eye[0];
+               __eyePosition[1] = eye[1];
+               __eyePosition[2] = eye[2];
+       }
+
+       if (pProjection)
+       {
+               __projection.Assign(projection);
+               __flippedProjection.Assign(flippedProjection);
+       }
+
+       __viewProjection.Assign(__projection);
+       __viewProjection.MultiplyMatrix(__view);
+
+       __flippedViewProjection.Assign(__flippedProjection);
+       __flippedViewProjection.MultiplyMatrix(__view);
+}
+
+void
+_GlCompositor::CompositeLayer(_GlLayer* pLayer)
+{
+       if (pLayer->GetShowState() == false)
+       {
+               return;
+       }
+
+       __needClear = true;
+
+       _AutoMutex renderLock(*_VisualElementEnvironment::GetTreeLock());
+       bool isUpdated = pLayer->UpdateNativeNodes();
+
+
+       if (isUpdated)
+       {
+               // init matrix
+               __view.LoadIdentity();
+               __projection.LoadIdentity();
+               __flippedProjection.LoadIdentity();
+
+               __eyePosition[0] = 0.0f;
+               __eyePosition[1] = 0.0f;
+               __eyePosition[2] = 0.0f;
+
+               // init temp node's bounds
+               Tizen::Graphics::FloatRectangle bounds = pLayer->GetBounds();
+
+               __pTempNode->__pVertices[5] = bounds.width;
+               __pTempNode->__pVertices[11] = bounds.height;
+               __pTempNode->__pVertices[15] = bounds.width;
+               __pTempNode->__pVertices[16] = bounds.height;
+
+#if 0
+#ifdef VE_USE_GL_MULTI_CONTEXT
+               __pGlContext = (_GlContext*)pLayer->GetContext();
+               __pGlContext->MakeCurrent();
+#else
+               __pGlContext->MakeCurrent(pLayer->GetNativeSurface());
+#endif
+#else
+               __pRenderManager->GetRenderQueue()->SetLayer(pLayer);
+//             __pGlLayerForFlush = pLayer;
+#endif
+
+               int count  = pLayer->GetViewCount();
+
+               for (int i = 0; i < count; i++)
+               {
+                       View* pScene = pLayer->GetView(i);
+
+                       if (pScene)
+                       {
+                               _RootVisualElement* pRoot = _ViewImpl::GetInstance(*pScene);
+                               _ViewInfo* pView = pRoot->GetView();
+
+                               if (pView)
+                               {
+                                       CompositeView(pLayer, pRoot, pView);
+                               }
+                       }
+               }
+
+               __pRenderManager->GetRenderQueue()->FlushRenderQueue();
+               __pRenderManager->GetRenderQueue()->FlushRenderQueueFinish(pLayer);
+               //__pGlContext->SwapBuffers();
+
+               __pTempNode->__pFilter = null;
+               __pTempNode->__pSurface = null;
+       }
+}
+
+void
+_GlCompositor::CommandHandlerComposite(_GlLayer* pGlLayer)
+{
+       long long time1, time2;
+
+       Tizen::System::SystemTime::GetTicks(time1);
+
+#ifndef VE_USE_GL_MULTI_CONTEXT
+       CHECK_GL_CONTEXT();
+#endif
+
+       _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
+
+       if (pGlLayer && pGlLayer->IsMapped())
+       {
+               CompositeLayer(pGlLayer);
+       }
+       else // render all
+       {
+               int count = pDisplayManager->GetLayerCount();
+
+               for (int i = 0; i < count; i++)
+               {
+                       _GlLayer* pGlLayer = dynamic_cast<_GlLayer*>(pDisplayManager->GetLayer(i));
+#ifdef LINUX
+                       if (!pGlLayer || !pGlLayer->IsMapped())
+                       {
+                               continue;
+                       }
+#elif _WIN32
+                       if (!pGlLayer)
+                       {
+                               continue;
+                       }
+#endif
+
+                       CompositeLayer(pGlLayer);
+               }
+       }
+
+       Tizen::System::SystemTime::GetTicks(time2);
+
+//     PRINT("     ### composite time: %lld ms (%.2f fps)\n", time2 - time1, 1000.0f / (time2 - time1));
+}
+
+
+bool
+_GlCompositor::Animate(void)
+{
+       if (!__pAnimationManager->IsAnimating(false))
+       {
+               return true;
+       }
+
+       if (__pAnimationManager->GetTimeout(false) > 0)
+       {
+               return false;
+       }
+
+       __pAnimationManager->ProcessAnimationTick(false);
+
+       return true;
+}
+
+
+#if 0
+
+void*
+_GlCompositor::CompositeProc(void* pData)
+{
+       _GlCompositor* pThis = reinterpret_cast< _GlCompositor* >(pData);
+
+       _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
+
+       pThis->__pAnimationManager = _AnimationManager::GetInstance();
+
+       for (;;)
+       {
+               _GlLayer* pGlLayer = null;
+               bool needFullComposite = false;
+               {
+                       _AutoMutex commandLock(pThis->__commandLock);
+                       pThis->__commandRequest.WaitForSignal(&pThis->__commandLock,pThis->__pAnimationManager->GetTimeout(false));
+                       pGlLayer = pThis->__commandArg.__pCommandGlLayer;
+                       pThis->__commandArg.__pCommandGlLayer = null;
+                       if( pGlLayer == null)
+                       {
+                               needFullComposite = true;
+                       }
+               }
+
+               RPRINT(">> CommandHandlerComposite() COMMAND_COMPOSITE - start \n");
+               needFullComposite = pThis->Animate();
+
+//             _AutoMutex treeLock(*_VisualElementEnvironment::GetTreeLock());
+
+               if(needFullComposite)
+               {
+                       int count = pDisplayManager->GetLayerCount();
+
+                       for (int i = 0; i < count; i++)
+                       {
+                               _GlLayer* pGlLayer = dynamic_cast<_GlLayer*>(pDisplayManager->GetLayer(i));
+       #ifdef LINUX
+                               if (!pGlLayer || !pGlLayer->IsMapped())
+                               {
+                                       continue;
+                               }
+       #elif _WIN32
+                               if (!pGlLayer)
+                               {
+                                       continue;
+                               }
+       #endif
+
+                               pThis->CompositeLayer(pGlLayer);
+                       }
+
+               }
+               else if (pGlLayer && pGlLayer->IsMapped())
+               {
+                       pThis->CompositeLayer(pGlLayer);
+               }
+
+
+
+               RPRINT(">> CommandHandlerComposite() COMMAND_COMPOSITE - end \n");
+
+//             else
+//             {
+
+
+//                     if (commandArg.__pCommandGlLayer)
+//                     {
+//                             pThis->CommandHandlerComposite(commandArg.__pCommandGlLayer);
+//                     }
+//                     RPRINT("pThis->Animate() skipped \n");
+//             }
+       }
+       return null;
+}
+
+#endif
+void*
+_GlCompositor::CompositeProc(void* pData)
+{
+       PRINT(">> _GlCompositor::RenderProc starts. \n");
+
+       _GlCompositor* pThis = reinterpret_cast< _GlCompositor* >(pData);
+
+
+       pThis->__pAnimationManager = _AnimationManager::GetInstance();
+
+       for (;;)
+       {
+               bool needReply = true;
+               int commandId;
+               CommandArg commandArg;
+               bool gotCommand = true;
+
+               {
+                       _AutoMutex commandLock(pThis->__commandLock);
+
+                       while (pThis->__commandId == COMMAND_UNKNOWN && gotCommand)
+                       {
+                               gotCommand = pThis->__commandRequest.WaitForSignal(&pThis->__commandLock, pThis->__pAnimationManager->GetTimeout(false));
+                       }
+
+                       if (unlikely(pThis->__commandId == COMMAND_UNKNOWN))
+                       {
+                               ASSERT(!gotCommand, "No command sent, but got command !");
+
+                               commandId = COMMAND_COMPOSITE;
+                               commandArg = pThis->__commandArg;       // to avoid complier warning
+                               commandArg.__pCommandGlLayer = null;
+                               needReply = false; // no notifying to main thread
+                       }
+                       else
+                       {
+                               commandId = pThis->__commandId;
+                               commandArg = pThis->__commandArg;
+                       }
+
+//                     PRINT(">> command = %d, gotCommand = %d\n", pThis->__commandId, gotCommand);
+
+                       // clear command
+                       pThis->__commandId = COMMAND_UNKNOWN;
+               }
+
+               // ...........
+               switch (commandId)
+               {
+
+
+               case COMMAND_COMPOSITE:
+                       RPRINT(">> CommandHandlerComposite() COMMAND_COMPOSITE - start \n");
+                       if (pThis->Animate())
+                       {
+                               pThis->CommandHandlerComposite(null);
+                       }
+                       else
+                       {
+                               if (commandArg.__pCommandGlLayer)
+                               {
+                                       pThis->CommandHandlerComposite(commandArg.__pCommandGlLayer);
+                               }
+                               RPRINT("pThis->Animate() skipped \n");
+                       }
+                       needReply = false;
+
+                       RPRINT(">> CommandHandlerComposite() COMMAND_COMPOSITE - end \n");
+                       break;
+                       //continue; // WARNING: reply already done
+
+
+               case COMMAND_WAKEUP:
+                       PRINT("COMMAND_WAKEUP\n");
+                       break;
+
+               case COMMAND_EXIT:
+                       PRINT("COMMAND_EXIT\n");
+                       goto exit_compositor;
+
+               default:
+                       break;
+               }
+
+               if (needReply)
+               {
+                       _AutoMutex commandLock(pThis->__commandLock);
+
+                       pThis->__commandResult = E_SUCCESS;
+                       pThis->__commandReply.SendSignal();
+               }
+       }
+
+exit_compositor:
+       {
+               _AutoMutex commandLock(pThis->__commandLock);
+
+               pThis->__commandResult = E_SUCCESS;
+               pThis->__commandReply.SendSignal();
+       }
+
+       return null;
+}
+
+}}}            // Tizen::Ui::Animations
diff --git a/src/ui/animations/FUiAnim_GlCompositor.h b/src/ui/animations/FUiAnim_GlCompositor.h
new file mode 100644 (file)
index 0000000..b51580d
--- /dev/null
@@ -0,0 +1,151 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 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.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file       FUiAnim_GlCompositor.h
+ * @brief      This is the header file for the _GlCompositor class.
+ *
+ * This header file contains the declarations of the _GlCompositor class.
+ */
+
+#ifndef _FUI_ANIM_INTERNAL_GL_COMPOSITOR_H_
+#define _FUI_ANIM_INTERNAL_GL_COMPOSITOR_H_
+
+#include <pthread.h>
+
+#include <FBaseColArrayList.h>
+#include <FUiAnimTypes.h>
+
+#include "FUiAnim_GlLayer.h"
+#include "FUiAnim_Mutex.h"
+#include "FUiAnim_Waiter.h"
+#include "FUi_Colorf.h"
+#include "FUi_Matrix4f.h"
+#include "FUi_Rectanglef.h"
+#include "FUiAnim_ShaderProgramGenerator.h"
+#include "FUiAnim_InternalTypes.h"
+
+#define MAX_LIGHT_COUNT 8
+
+namespace Tizen { namespace Ui { namespace Animations
+{
+
+class VisualElement;
+class _AnimationManager;
+class _GlContext;
+class _GlNode;
+class _GlVisualElementSurfaceImpl;
+class _GlRenderManager;
+class ShaderProgram;
+class _ShaderImpl;
+class _ShaderProgramImpl;
+class _ViewInfo;
+class Mesh;
+class Light;
+class Material;
+class VisualElementFilter;
+
+
+struct TextureInfo;
+
+class _GlCompositor
+{
+public:
+       enum CompositeCommand
+       {
+               COMMAND_UNKNOWN,
+               COMMAND_WAKEUP,
+               COMMAND_EXIT,
+               COMMAND_COMPOSITE
+       };
+
+       pthread_t GetThreadInfo(void) const { return __threadInfo; }
+       bool IsInCompositorThread(void) const { return pthread_equal(__threadInfo, pthread_self()); }
+
+       bool Composite(_GlLayer* pLayer = null);
+
+       void WakeUp(void);
+
+private:
+
+       void CommandHandlerComposite(_GlLayer* pGlLayer);
+
+       // Shader
+       void CompositeLayer(_GlLayer* pLayer);
+       void CompositeNode(VisualElement* pRenderObject, Tizen::Base::Collection::ArrayList &parentLight, bool useStencil, unsigned int depth, _GlLayer* pLayer, _ViewInfo* pView);
+       void CompositeView(_GlLayer* pLayer, _RootVisualElement* pRoot, _ViewInfo* pView);
+
+       bool Animate(void);
+
+       static void* CompositeProc(void* pData);
+
+       _GlCompositor(_GlRenderManager* pRenderManager);
+       virtual ~_GlCompositor(void);
+
+private:
+       static _GlCompositor* __pInstance;
+
+       unsigned int __commandId;
+       CommandArg __commandArg;
+       result __commandResult;
+
+       _Mutex __commandTransaction;
+       _Mutex __commandLock;
+       _Waiter __commandRequest;
+       _Waiter __commandReply;
+
+       pthread_t __threadInfo;
+       pid_t __threadId;
+
+       _GlContext* __pGlContext;
+
+       _Matrix4f __view;
+       _Matrix4f __projection;
+       _Matrix4f __viewProjection;
+       _Matrix4f __flippedProjection;
+       _Matrix4f __flippedViewProjection;
+
+       float __eyePosition[3];
+       Tizen::Graphics::FloatRectangle __viewport;
+
+
+       int __queueCount;
+       bool __needClear;
+
+       _GlNode* __pTempNode;
+
+       unsigned int __globalLightCount;
+       Light* __globalLight[MAX_LIGHT_COUNT];
+
+//     float __materialAmbient[4];
+//     float __materialDiffuse[4];
+//     float __materialSpecular[4];
+//     float __materialEmissive[4];
+//     float __materialShininess;
+       _GlLayer* __pGlLayerForFlush;// todo :CHECK IT , is it needed?
+
+       _AnimationManager* __pAnimationManager;
+       _GlRenderManager* __pRenderManager;
+
+       friend class _GlRenderQueue;
+       friend class _RenderObject;
+       friend class _GlRenderManager;
+}; // _GlCompositor
+
+}}} //namespace Tizen { namespace Ui { namespace Animations
+
+#endif //_FUI_ANIM_INTERNAL_GL_COMPOSITOR_H_
index b9280c5..1c89f7d 100644 (file)
@@ -175,6 +175,7 @@ private:
        _GlContext* __pSharedContext;
 
        friend class _GlRenderManager;
+       friend class _GlCompositor;
        friend class _VisualElementSurfaceManager;
 };
 
index 2e53a0b..e5d097f 100644 (file)
@@ -130,7 +130,9 @@ private:
        friend class _VeDebug;
        friend class _VisualElementImpl;
        friend class _GlLayer;
+       friend class _GlCompositor;
        friend class _GlRenderManager;
+       friend class _GlRenderQueue;
 };             // _GlNode
 
 }}}            // Tizen::Ui::Animations
index 0217f7a..b0762cb 100644 (file)
@@ -41,6 +41,7 @@
 #include "FUiAnim_CameraImpl.h"
 #include "FUiAnim_ViewInfo.h"
 #include "FUiAnim_ViewImpl.h"
+#include "FUiAnim_GlCompositor.h"
 #include "FUiAnim_GlRenderManager.h"
 #include "FUiAnim_DisplayManager.h"
 #include "FUiAnim_GlVisualElementSurfaceImpl.h"
@@ -60,6 +61,7 @@
 #include "FUiAnimVisualElementFilter.h"
 #include "FUiAnim_VisualElementFilterImpl.h"
 
+
 #include "FUiAnim_GlLoader.h"
 #include "FUiAnim_Debug.h"
 
@@ -114,7 +116,7 @@ using namespace Tizen::Ui::Animations;
 namespace Tizen { namespace Ui { namespace Animations
 {
 
-_GlRenderManager::_RenderObject::_RenderObject(void)
+_GlRenderQueue::_RenderObject::_RenderObject(void)
        : __useBlend(false)
        , __useDepthTest(false)
        , __useTransform(false)
@@ -171,13 +173,13 @@ _GlRenderManager::_RenderObject::_RenderObject(void)
        Construct();
 }
 
-_GlRenderManager::_RenderObject::~_RenderObject(void)
+_GlRenderQueue::_RenderObject::~_RenderObject(void)
 {
        Release();
 }
 
 result
-_GlRenderManager::_RenderObject::Construct(void)
+_GlRenderQueue::_RenderObject::Construct(void)
 {
        result r = E_SUCCESS;
 
@@ -197,7 +199,7 @@ CATCH:
 }
 
 result
-_GlRenderManager::_RenderObject::Release(void)
+_GlRenderQueue::_RenderObject::Release(void)
 {
        delete [] __pVertexBuffer;
        __pVertexBuffer = null;
@@ -209,7 +211,7 @@ _GlRenderManager::_RenderObject::Release(void)
 }
 
 ShaderProgram*
-_GlRenderManager::_RenderObject::GetShaderProgram(int type)
+_GlRenderQueue::_RenderObject::GetShaderProgram(int type)
 {
        bool u_color = false;
        bool color = false;
@@ -378,10 +380,16 @@ _GlRenderManager::_RenderObject::GetShaderProgram(int type)
 }
 
 void
-_GlRenderManager::_RenderObject::SetObject(_GlNode* pNode, bool useStencil, unsigned int stencilIndex, bool colorMask)
+_GlRenderQueue::_RenderObject::SetObject(_GlNode* pNode, bool useStencil, unsigned int stencilIndex, bool colorMask)
 {
        int vertexIndex = 0, textureIndex = 0;
        int shaderType = 0;
+       static _GlCompositor* pCompositor  = null;
+
+       if(pCompositor == null)
+       {
+               pCompositor = _GlRenderManager::GetInstance()->GetCompositor();
+       }
 
        __useBlend = pNode->__useBlend;
        __useTransform = pNode->__useTransform;
@@ -390,8 +398,8 @@ _GlRenderManager::_RenderObject::SetObject(_GlNode* pNode, bool useStencil, unsi
        __updateStencil = (pNode->__useStencil && pNode->__childrenCount > 0) ? true : false;
        __stencilIndex = stencilIndex;
 
-       __mvp = _GlRenderManager::GetInstance()->__flippedViewProjection * _Matrix4f(pNode->__transform);
-       __modelview = _GlRenderManager::GetInstance()->__view * _Matrix4f(pNode->__transform);
+       __mvp = pCompositor->__flippedViewProjection * _Matrix4f(pNode->__transform);
+       __modelview = pCompositor->__view * _Matrix4f(pNode->__transform);
 
        __objectColor = pNode->__objectColor;
        __opacity = pNode->__opacity;
@@ -401,9 +409,9 @@ _GlRenderManager::_RenderObject::SetObject(_GlNode* pNode, bool useStencil, unsi
        __invModelview.Invert();
        __invModelview.Transpose();             // TODO: optimize
 
-       __eyePosition[0] = _GlRenderManager::GetInstance()->__eyePosition[0];
-       __eyePosition[1] = _GlRenderManager::GetInstance()->__eyePosition[1];
-       __eyePosition[2] = _GlRenderManager::GetInstance()->__eyePosition[2];
+       __eyePosition[0] = pCompositor->__eyePosition[0];
+       __eyePosition[1] = pCompositor->__eyePosition[1];
+       __eyePosition[2] = pCompositor->__eyePosition[2];
 
        __GPUSkinning = false; //skinning
 
@@ -481,7 +489,7 @@ _GlRenderManager::_RenderObject::SetObject(_GlNode* pNode, bool useStencil, unsi
 
                        if (__pSurfaceInfo->__textureInfo.type == TEXTURE_RENDER_TARGET)
                        {
-                               __mvp = _GlRenderManager::GetInstance()->__viewProjection * _Matrix4f(pNode->__transform);
+                               __mvp = pCompositor->__viewProjection * _Matrix4f(pNode->__transform);
                        }
 
                        __textureRepeated = pNode->__textureRepeated;
@@ -600,7 +608,7 @@ _GlRenderManager::_RenderObject::SetObject(_GlNode* pNode, bool useStencil, unsi
 
                        if (__pSurfaceInfo->__textureInfo.type == TEXTURE_RENDER_TARGET)
                        {
-                               __mvp = _GlRenderManager::GetInstance()->__viewProjection * _Matrix4f(pNode->__transform);
+                               __mvp = pCompositor->__viewProjection * _Matrix4f(pNode->__transform);
                        }
 
                        __textureRepeated = pNode->__textureRepeated;
@@ -759,7 +767,7 @@ _GlRenderManager::_RenderObject::SetObject(_GlNode* pNode, bool useStencil, unsi
 }
 
 void
-_GlRenderManager::_RenderObject::ResetObject(void)
+_GlRenderQueue::_RenderObject::ResetObject(void)
 {
        __vertexCount = 0;
        __indexCount = 0;
@@ -825,7 +833,7 @@ _GlRenderManager::_RenderObject::ResetObject(void)
 }
 
 void
-_GlRenderManager::_RenderObject::AddVertices(_GlNode* pNode)
+_GlRenderQueue::_RenderObject::AddVertices(_GlNode* pNode)
 {
        int vertexIndex, textureIndex;
 
@@ -887,6 +895,157 @@ _GlRenderManager::_RenderObject::AddVertices(_GlNode* pNode)
        return;
 }
 
+_GlRenderQueue::_GlRenderQueue(_GlRenderManager* pManager)
+       : __renderingProps(0)
+       , __viewport()
+       , __queueCount(0)
+       , __pRenderTarget(null)
+       , __pRenderQueue(null)
+       , __pRenderManager(pManager)
+{
+       __pRenderQueue = new (std::nothrow) _RenderObject[VE_RENDER_QUEUE_COUNT_MAX];
+}
+
+_GlRenderQueue::~_GlRenderQueue(void)
+{
+       delete[] __pRenderQueue;
+       __pRenderQueue = null;
+       __pRenderManager = null;
+}
+
+void
+_GlRenderQueue::SetLayer(_GlLayer* pLayer)
+{
+       __renderingProps |= UPDATED_PROP_LAYER;
+       __pLayer = pLayer;
+}
+
+void
+_GlRenderQueue::SetViewport(int x, int y, int width, int height)
+{
+       __renderingProps |= UPDATED_PROP_VIEWPORT;
+       __viewport.SetBounds(x,y,width,height);
+}
+
+void
+_GlRenderQueue::SetRenderTarget(_GlVisualElementSurfaceImpl* pRenderTarget)
+{
+       __renderingProps |= UPDATED_PROP_RENDER_TARGET;
+       if(__pRenderTarget)
+       {
+               __pRenderTarget->Release();
+               __pRenderTarget = null;
+       }
+       if(pRenderTarget)
+       {
+               __pRenderTarget = pRenderTarget;
+               __pRenderTarget->AddRef();
+       }
+}
+
+int
+_GlRenderQueue::FindRenderObject(_GlNode* pNode)
+{
+       if (unlikely(__queueCount == 0))
+       {
+               return -1;
+       }
+
+       if (unlikely(__pRenderQueue[__queueCount - 1].__isMesh || !pNode->__findItemInQueue))
+       {
+               return -1;
+       }
+
+       _Rectanglef bounds(pNode->__pVertices[0], pNode->__pVertices[1],
+                       pNode->__pVertices[15] - pNode->__pVertices[0], pNode->__pVertices[16] - pNode->__pVertices[1]);
+
+       for (int index = __queueCount - 1; index >= 0; index--)
+       {
+               _GlVisualElementSurfaceImpl* pImpl = (pNode->__pSurface)?SURF_IMPL(*pNode->__pSurface):null;
+
+               if ( __pRenderQueue[index].__pSurfaceInfo == pImpl
+                       && __pRenderQueue[index].__objectColor == pNode->__objectColor
+                       && __pRenderQueue[index].__opacity == pNode->__opacity
+                       && __pRenderQueue[index].__useBlend == pNode->__useBlend
+                       && __pRenderQueue[index].__textureRepeated == pNode->__textureRepeated
+//                     && __pRenderQueue[index].__pMaterial == pNode->__pMaterial      // TODO: check light
+                       )
+               {
+                       if (unlikely(__pRenderQueue[index].__vertexCount >= VE_RENDER_OBJECT_VERTEX_COUNT_MAX - 6))
+                       {
+                               PRINT("_GlRenderManager::FindRenderObject: Vertex buffer is full. Use next slot.\n");
+                               return -1;
+                       }
+
+//                     PRINT("_GlRenderManager::FindRenderObject: Found!! [%d]\n", index);
+                       return index;
+               }
+
+               if (__pRenderQueue[index].__bounds.IsIntersected(bounds))
+               {
+                       return -1;
+               }
+       }
+
+       return -1;
+}
+
+void
+_GlRenderQueue::EnqueueRenderObject(_GlNode* pNode, bool useStencil, unsigned int stencilIndex, bool colorMask)
+{
+       int index;
+
+       index = FindRenderObject(pNode);
+
+       if (index != -1)
+       {
+               // Same object is found. This is not a mesh.
+               __pRenderQueue[index].AddVertices(pNode);
+
+               return;
+       }
+
+       __pRenderQueue[__queueCount].SetObject(pNode, useStencil, stencilIndex, colorMask);
+
+       __queueCount++;
+
+       if (__queueCount >= VE_RENDER_QUEUE_COUNT_MAX)
+       {
+               PRINT("_GlRenderManager::EnqueueRenderObject: Queue full. Flush!\n");
+
+               __pRenderManager->FlushRenderQueue();
+       }
+
+
+       return;
+}
+
+void
+_GlRenderQueue::FlushRenderQueue(void)
+{
+       __pRenderManager->FlushRenderQueue();
+}
+
+void
+_GlRenderQueue::FlushRenderQueueFinish(_GlLayer* pLayer)
+{
+       __pRenderManager->FlushRenderQueueFinish(pLayer);
+}
+
+void
+_GlRenderQueue::Reset(void)
+{
+       __renderingProps = 0;
+//     Tizen::Graphics::FloatRectangle __viewport;
+       __queueCount = 0;
+       if(__pRenderTarget)
+       {
+               __pRenderTarget->Release();
+               __pRenderTarget = null;
+       }
+       __pLayer = null;
+}
+
 _GlRenderManager* _GlRenderManager::__pInstance = null;
 
 _GlRenderManager::_GlRenderManager(void)
@@ -898,19 +1057,19 @@ _GlRenderManager::_GlRenderManager(void)
     , __commandReply()
     , __threadId(0)
     , __pGlContext(0)
-       , __view()
-       , __projection()
-       , __viewProjection()
-       , __flippedProjection()
-       , __flippedViewProjection()
-       , __viewport()
+//     , __view()
+//     , __projection()
+//     , __viewProjection()
+//     , __flippedProjection()
+//     , __flippedViewProjection()
+//     , __viewport()
        , __pRenderQueue(null)
-       , __queueCount(0)
-       , __needClear(false)
-       , __pTempNode(null)
+//     , __queueCount(0)
+//     , __needClear(false)
+//     , __pTempNode(null)
        , __globalLightCount(0)
        , __materialShininess(0.0f)
-       , __pAnimationManager(0)
+       , __pCompositor(0)
 {
        memset(&__threadInfo, 0x00, sizeof(pthread_t));
        if (pthread_create(&__threadInfo, NULL, _GlRenderManager::RenderProc, this) != 0)
@@ -918,15 +1077,12 @@ _GlRenderManager::_GlRenderManager(void)
                ASSERT(false, "Creating render-thread failed");
        }
 
-       memset(&__compositeThreadInfo, 0x00, sizeof(pthread_t));
-       if (pthread_create(&__compositeThreadInfo, NULL, _GlRenderManager::CompositeProc, this) != 0)
-       {
-               ASSERT(false, "Creating render-thread failed");
-       }
+       __pCompositor = new _GlCompositor(this);
 
-       __eyePosition[0] = 0.0f;
-       __eyePosition[1] = 0.0f;
-       __eyePosition[2] = 0.0f;
+
+//     __eyePosition[0] = 0.0f;
+//     __eyePosition[1] = 0.0f;
+//     __eyePosition[2] = 0.0f;
 
        __materialAmbient[0] = 0.2f; __materialAmbient[1] = 0.2f; __materialAmbient[2] = 0.2f; __materialAmbient[3] = 1.0f;
        __materialDiffuse[0] = 0.8f; __materialDiffuse[1] = 0.8f; __materialDiffuse[2] = 0.8f; __materialDiffuse[3] = 1.0f;
@@ -935,48 +1091,51 @@ _GlRenderManager::_GlRenderManager(void)
 
        ClearLastResult();
 
-       __pRenderQueue = new (std::nothrow) _RenderObject[VE_RENDER_QUEUE_COUNT_MAX];
-       __pRenderQueueForFlush = new (std::nothrow) _RenderObject[VE_RENDER_QUEUE_COUNT_MAX];
+       __pRenderQueue = new (std::nothrow)_GlRenderQueue(this);// _RenderObject[VE_RENDER_QUEUE_COUNT_MAX];
+       __pRenderQueueForFlush = new (std::nothrow)_GlRenderQueue(this);// _RenderObject[VE_RENDER_QUEUE_COUNT_MAX];
 
-       __pTempNode = new (std::nothrow) _GlNode;
+//     __pTempNode = new (std::nothrow) _GlNode;
 
        // vertex coordinates
-       __pTempNode->__pVertices[0] = 0.0f;
-       __pTempNode->__pVertices[1] = 0.0f;
-       __pTempNode->__pVertices[2] = 0.0f;
+//     __pTempNode->__pVertices[0] = 0.0f;
+//     __pTempNode->__pVertices[1] = 0.0f;
+//     __pTempNode->__pVertices[2] = 0.0f;
 
-       __pTempNode->__pVertices[5] = 0.0f;             // width
-       __pTempNode->__pVertices[6] = 0.0f;
-       __pTempNode->__pVertices[7] = 0.0f;
+//     __pTempNode->__pVertices[5] = 0.0f;             // width
+//     __pTempNode->__pVertices[6] = 0.0f;
+//     __pTempNode->__pVertices[7] = 0.0f;
 
-       __pTempNode->__pVertices[10] = 0.0f;
-       __pTempNode->__pVertices[11] = 0.0f;    // height
-       __pTempNode->__pVertices[12] = 0.0f;
+//     __pTempNode->__pVertices[10] = 0.0f;
+//     __pTempNode->__pVertices[11] = 0.0f;    // height
+//     __pTempNode->__pVertices[12] = 0.0f;
 
-       __pTempNode->__pVertices[15] = 0.0f;    // width
-       __pTempNode->__pVertices[16] = 0.0f;    // height
-       __pTempNode->__pVertices[17] = 0.0f;
+//     __pTempNode->__pVertices[15] = 0.0f;    // width
+//     __pTempNode->__pVertices[16] = 0.0f;    // height
+//     __pTempNode->__pVertices[17] = 0.0f;
 
-       // texture coordinates
-       __pTempNode->__pVertices[3]  = 0.0f;
-       __pTempNode->__pVertices[4]  = 0.0f;
+//     // texture coordinates
+//     __pTempNode->__pVertices[3]  = 0.0f;
+//     __pTempNode->__pVertices[4]  = 0.0f;
 
-       __pTempNode->__pVertices[8]  = 1.0f;
-       __pTempNode->__pVertices[9]  = 0.0f;
+//     __pTempNode->__pVertices[8]  = 1.0f;
+//     __pTempNode->__pVertices[9]  = 0.0f;
 
-       __pTempNode->__pVertices[13] = 0.0f;
-       __pTempNode->__pVertices[14] = 1.0f;
+//     __pTempNode->__pVertices[13] = 0.0f;
+//     __pTempNode->__pVertices[14] = 1.0f;
 
-       __pTempNode->__pVertices[18] = 1.0f;
-       __pTempNode->__pVertices[19] = 1.0f;
+//     __pTempNode->__pVertices[18] = 1.0f;
+//     __pTempNode->__pVertices[19] = 1.0f;
 
-       __pTempNode->__transform.SetAsIdentity();
-       __pTempNode->__useTransform = false;
-       __pTempNode->__textureRepeated = false;
+//     __pTempNode->__transform.SetAsIdentity();
+//     __pTempNode->__useTransform = false;
+//     __pTempNode->__textureRepeated = false;
 }
 
 _GlRenderManager::~_GlRenderManager(void)
 {
+       delete __pCompositor;
+       __pCompositor = null;
+
        _AutoMutex commandTransactionLock(__commandTransaction);
        _AutoMutex commandLock(__commandLock);
 
@@ -987,10 +1146,10 @@ _GlRenderManager::~_GlRenderManager(void)
 
        pthread_join(__threadInfo, NULL);
 
-       delete [] __pRenderQueue;
-       delete [] __pRenderQueueForFlush;
+       delete __pRenderQueue;
+       delete __pRenderQueueForFlush;
 
-       delete __pTempNode;
+//     delete __pTempNode;
 }
 
 result
@@ -1062,111 +1221,16 @@ _GlRenderManager::FinalizeGLLayer(_GlLayer* pGlLayer)
 bool
 _GlRenderManager::Composite(_GlLayer* pLayer)
 {
-       _AutoMutex commandLock(__commandCompositeLock);
-       __commandCompositeArg.__pCommandGlLayer = pLayer;
-       __commandComposite.SendSignal();
-
-#if 0
-       _AutoMutex commandTransactionLock(__commandTransaction);
-       _AutoMutex commandLock(__commandLock);
-
-
-
-//     __commandArg.__pCommandGlLayer = pLayer;
-//     __commandId = COMMAND_COMPOSITE;
-//     __commandRequest.SendSignal();
-
-
-//     __commandReply.WaitForSignal(&__commandLock);
-//     return (__commandResult == E_SUCCESS);
-#endif
-       return E_SUCCESS;
-}
-
-void
-_GlRenderManager::WakeUp(void)
-{
-       _AutoMutex commandTransactionLock(__commandTransaction);
-       _AutoMutex commandLock(__commandLock);
-
-       __commandId = COMMAND_WAKEUP;
-       __commandRequest.SendSignal();
-}
-
-int
-_GlRenderManager::FindRenderObject(_GlNode* pNode)
-{
-       if (unlikely(__queueCount == 0))
-       {
-               return -1;
-       }
-
-       if (unlikely(__pRenderQueue[__queueCount - 1].__isMesh || !pNode->__findItemInQueue))
-       {
-               return -1;
-       }
-
-       _Rectanglef bounds(pNode->__pVertices[0], pNode->__pVertices[1],
-                       pNode->__pVertices[15] - pNode->__pVertices[0], pNode->__pVertices[16] - pNode->__pVertices[1]);
-
-       for (int index = __queueCount - 1; index >= 0; index--)
+       if(__pCompositor)
        {
-               _GlVisualElementSurfaceImpl* pImpl = (pNode->__pSurface)?SURF_IMPL(*pNode->__pSurface):null;
-
-               if ( __pRenderQueue[index].__pSurfaceInfo == pImpl
-                       && __pRenderQueue[index].__objectColor == pNode->__objectColor
-                       && __pRenderQueue[index].__opacity == pNode->__opacity
-                       && __pRenderQueue[index].__useBlend == pNode->__useBlend
-                       && __pRenderQueue[index].__textureRepeated == pNode->__textureRepeated
-//                     && __pRenderQueue[index].__pMaterial == pNode->__pMaterial      // TODO: check light
-                       )
-               {
-                       if (unlikely(__pRenderQueue[index].__vertexCount >= VE_RENDER_OBJECT_VERTEX_COUNT_MAX - 6))
-                       {
-                               PRINT("_GlRenderManager::FindRenderObject: Vertex buffer is full. Use next slot.\n");
-                               return -1;
-                       }
-
-//                     PRINT("_GlRenderManager::FindRenderObject: Found!! [%d]\n", index);
-                       return index;
-               }
-
-               if (__pRenderQueue[index].__bounds.IsIntersected(bounds))
-               {
-                       return -1;
-               }
+               return __pCompositor->Composite(pLayer);
        }
-
-       return -1;
+       return false;
 }
-
-void
-_GlRenderManager::EnqueueRenderObject(_GlNode* pNode, bool useStencil, unsigned int stencilIndex, bool colorMask)
+_GlRenderQueue*
+_GlRenderManager::GetRenderQueue(void)
 {
-       int index;
-
-       index = FindRenderObject(pNode);
-
-       if (index != -1)
-       {
-               // Same object is found. This is not a mesh.
-               __pRenderQueue[index].AddVertices(pNode);
-
-               return;
-       }
-
-       if (__queueCount >= VE_RENDER_QUEUE_COUNT_MAX)
-       {
-               PRINT("_GlRenderManager::EnqueueRenderObject: Queue full. Flush!\n");
-
-               FlushRenderQueue();
-       }
-
-       __pRenderQueue[__queueCount].SetObject(pNode, useStencil, stencilIndex, colorMask);
-
-       __queueCount++;
-
-       return;
+       return __pRenderQueue;
 }
 
 void
@@ -1186,7 +1250,7 @@ _GlRenderManager::FlushRenderQueueFinish(_GlLayer* pLayer)
 void
 _GlRenderManager::FlushRenderQueue(void)
 {
-       if(__queueCount <= 0 && !__needClear)
+       if(__pRenderQueue->__queueCount <= 0 && __pRenderQueue->__renderingProps == 0)
        {
                return;
        }
@@ -1199,989 +1263,37 @@ _GlRenderManager::FlushRenderQueue(void)
        __commandReply.WaitForSignal(&__commandLock);
        RPRINT("FlushRenderQueue() finish \n");
        return;
-#if 0
-       if (__needClear)
-       {
-               glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-               __needClear = false;
-       }
 
-       for (int i = 0; i < __queueCount; i++)
-       {
-               _ShaderProgramImpl* pProgramImpl = _ShaderProgramImpl::GetInstance(*__pRenderQueue[i].__pProgram);
+}
 
-               __pGlContext->UseShaderProgram(pProgramImpl);
 
-               // Set attribute
-               glVertexAttribPointer(__pRenderQueue[i].__aPosition, 3, GL_FLOAT, GL_FALSE, VERTEX_BUFFER_STRIDE * sizeof(float), __pRenderQueue[i].__pVertices);
-               glVertexAttribPointer(__pRenderQueue[i].__aTexCoord, 2, GL_FLOAT, GL_FALSE, TEX_COORD_BUFFER_STRIDE * sizeof(float), __pRenderQueue[i].__pTexCoords);
-               glVertexAttribPointer(__pRenderQueue[i].__aColor, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), __pRenderQueue[i].__pColors);
-               glVertexAttribPointer(__pRenderQueue[i].__aNormal, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), __pRenderQueue[i].__pNormals);
+bool
+_GlRenderManager::CommandHandlerInitializeGLLayer(_GlLayer* pGlLayer)
+{
+#ifdef VE_USE_GL_MULTI_CONTEXT
+#ifdef ECORE_X_NATIVE
+       _EcoreXLooper* pLooper = static_cast<_EcoreXLooper*>(_Looper::GetInstance());
+       pGlLayer->__pContext = _GlContext::CreateN((Handle)pLooper->GetXDisplay(), (Handle)pGlLayer->GetNativeWindow());
 
-               //Skinning
-               if (__pRenderQueue[i].__GPUSkinning)
-               {
-                       glVertexAttribPointer(__pRenderQueue[i].__aWeights,  4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), __pRenderQueue[i].__pWeights);
-                       glVertexAttribPointer(__pRenderQueue[i].__aJointIds, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), __pRenderQueue[i].__pJointIds); //TODO: for GL_INT need glVertexAttribI(!)Pointer
-
-                       int index0 = (int)(__pRenderQueue[i].__pJointIds)[0];
-                       int index1 = (int)(__pRenderQueue[i].__pJointIds)[1];
-                       int index2 = (int)(__pRenderQueue[i].__pJointIds)[2];
-                       int index3 = (int)(__pRenderQueue[i].__pJointIds)[3];
-                       glVertexAttribPointer(__pRenderQueue[i].__aJointIndex0, 1, GL_INT, GL_FALSE, sizeof(int), &index0);
-                       glVertexAttribPointer(__pRenderQueue[i].__aJointIndex1, 1, GL_INT, GL_FALSE, sizeof(int), &index1);
-                       glVertexAttribPointer(__pRenderQueue[i].__aJointIndex2, 1, GL_INT, GL_FALSE, sizeof(int), &index2);
-                       glVertexAttribPointer(__pRenderQueue[i].__aJointIndex3, 1, GL_INT, GL_FALSE, sizeof(int), &index3);
-
-                       glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_ARRAY_JOINTSMATRICES], __pRenderQueue[i].__jointsCount, GL_FALSE, __pRenderQueue[i].__pJointsMatrices);
-               }
+       PRINT("[DEBUG]-003a _GlRenderManager::CommandHandlerInitializeGLLayer: Create surf...  \n" );
+#endif
 
-               // Set uniform
+       __pGlContext = pGlLayer->__pContext;
 
-               //const float* f = __pRenderQueue[i].__mvp.GetItems();//WARNING: it is not used
-               glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MVP], 1, GL_FALSE, __pRenderQueue[i].__mvp.GetItems());
-               glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_OPACITY], __pRenderQueue[i].__opacity);
-               glUniform4f(pProgramImpl->__uniformLocation[UNIFORM_VEC4_COLOR], __pRenderQueue[i].__objectColor.Red(), __pRenderQueue[i].__objectColor.Green(),
-                               __pRenderQueue[i].__objectColor.Blue(), __pRenderQueue[i].__objectColor.Alpha());
+       PRINT(">> CommandHandlerInitializeGLLayer() pContext %p \n", pGlLayer->__pContext);
+#else
+       CHECK_GL_CONTEXT();
 
-               glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_EYE_POSITION], 1, __pRenderQueue[i].__eyePosition);
-               glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MODEL_VIEW], 1, GL_FALSE, __pRenderQueue[i].__modelview.GetItems());
-               glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_INV_MODEL_VIEW], 1, GL_FALSE, __pRenderQueue[i].__invModelview.GetItems());
+#endif
 
-               if (__pRenderQueue[i].__activeLightCount > 0)
-               {
-                       static int offset = 0;
-                       static _LightImpl* pLightImpl = null;
+       return true;
+}
 
-                       for (register unsigned int k = 0; k <__pRenderQueue[i].__activeLightCount; k++)
-                       {
-                               offset = OFFSET * k + (UNIFORM_SAMPLER2D_EXTRA_SURFACE - UNIFORM_FLOAT_EXTRA_SURFACE_OPACITY+1)*(EXTRA_SURFACE_MAX - 1);
-                               
-                               pLightImpl = _LightImpl::GetInstance(*__pRenderQueue[i].__activeLight[k]);
-
-                               glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_LIGHT_TYPE + offset], pLightImpl->GetType());
-                               glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_AMBIENT + offset], 1, pLightImpl->GetAmbient());
-                               glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_DIFFUSE + offset], 1, pLightImpl->GetDiffuse());
-                               glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_SPECULAR + offset], 1, pLightImpl->GetSpecular());
-                               glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_POSITION + offset], 1, pLightImpl->GetPositionInEyeCoords());
-                               glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_LIGHT_DIRECTION + offset], 1, pLightImpl->GetDirectionInEyeCoords());
-                               glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_LIGHT_EXPONENT + offset], pLightImpl->GetExponent());
-                               glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_LIGHT_CUTOFF + offset], pLightImpl->GetCutOffCos());
-                               glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_LIGHT_ATTENUATION + offset], 1, pLightImpl->GetAttenuations());
-                       }
-
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_ACTIVE_LIGHT_COUNT], __pRenderQueue[i].__activeLightCount);
-               }
-               else
-               {
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_ACTIVE_LIGHT_COUNT], 0);
-               }
-
-               if (__pRenderQueue[i].__pMaterial)
-               {
-                       _MaterialImpl* pMaterialImpl = _MaterialImpl::GetInstance(*__pRenderQueue[i].__pMaterial);
-
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_AMBIENT], 1, pMaterialImpl->GetAmbient());
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_DIFFUSE], 1, pMaterialImpl->GetDiffuse());
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_SPECULAR], 1, pMaterialImpl->GetSpecular());
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_EMISSIVE], 1, pMaterialImpl->GetEmissive());
-                       glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_MATERIAL_SHININESS], pMaterialImpl->GetShininess());
-               }
-               else if (__pRenderQueue[i].__activeLightCount > 0)
-               {
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_AMBIENT], 1, __materialAmbient);
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_DIFFUSE], 1, __materialDiffuse);
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_SPECULAR], 1, __materialSpecular);
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_EMISSIVE], 1, __materialEmissive);
-                       glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_MATERIAL_SHININESS], __materialShininess);
-               }
-
-               // Custom shader
-               if (pProgramImpl->__customUniformMap.GetCount() > 0)
-               {
-                       Tizen::Base::Collection::IMapEnumeratorT<Tizen::Base::String, _ShaderProgramImpl::UniformValue*>* pMapEnum = pProgramImpl->__customUniformMap.GetMapEnumeratorN();
-
-                       while (pMapEnum->MoveNext() == E_SUCCESS)
-                       {
-                               _ShaderProgramImpl::UniformValue* pValue = null;
-
-                               pMapEnum->GetValue(pValue);
-
-                               VariantType type = pValue->value.GetType();
-
-                               switch (type)
-                               {
-                               case VARIANT_TYPE_INT:
-                                       glUniform1i(pValue->location, pValue->value.ToInt());
-                                       break;
-
-                               case VARIANT_TYPE_FLOAT:
-                                       glUniform1f(pValue->location, pValue->value.ToFloat());
-                                       break;
-
-                               case VARIANT_TYPE_COLOR:
-                                       glUniform4i(pValue->location, pValue->value.ToColor().GetRed(), pValue->value.ToColor().GetRed(),
-                                                               pValue->value.ToColor().GetBlue(), pValue->value.ToColor().GetAlpha());
-                                       break;
-
-                               case VARIANT_TYPE_POINT:
-                                       glUniform2i(pValue->location, pValue->value.ToPoint().x, pValue->value.ToPoint().y);
-                                       break;
-
-                               case VARIANT_TYPE_FLOAT_POINT:
-                                       glUniform2f(pValue->location, pValue->value.ToFloatPoint().x, pValue->value.ToFloatPoint().y);
-                                       break;
-
-                               case VARIANT_TYPE_RECTANGLE:
-                                       glUniform4i(pValue->location, pValue->value.ToRectangle().x, pValue->value.ToRectangle().y,
-                                                               pValue->value.ToRectangle().width, pValue->value.ToRectangle().height);
-                                       break;
-
-                               case VARIANT_TYPE_FLOAT_RECTANGLE:
-                                       glUniform4f(pValue->location, pValue->value.ToFloatRectangle().x, pValue->value.ToFloatRectangle().y,
-                                                               pValue->value.ToFloatRectangle().width, pValue->value.ToFloatRectangle().height);
-                                       break;
-
-                               case VARIANT_TYPE_DIMENSION:
-                                       glUniform2i(pValue->location, pValue->value.ToDimension().width, pValue->value.ToDimension().height);
-                                       break;
-
-                               case VARIANT_TYPE_FLOAT_DIMENSION:
-                                       glUniform2f(pValue->location, pValue->value.ToFloatDimension().width, pValue->value.ToFloatDimension().height);
-                                       break;
-
-                               case VARIANT_TYPE_FLOAT_MATRIX4:
-                                       glUniformMatrix4fv(pValue->location, 1, GL_FALSE, (GLfloat*)pValue->value.ToFloatMatrix4().matrix);
-                                       break;
-
-                               case VARIANT_TYPE_FLOAT_POINT3:
-                                       glUniform3f(pValue->location, pValue->value.ToFloatPoint3().x, pValue->value.ToFloatPoint3().y, pValue->value.ToFloatPoint3().z);
-                                       break;
-
-                               case VARIANT_TYPE_FLOAT_VECTOR4:
-                                       glUniform4f(pValue->location, pValue->value.ToFloatVector4().x, pValue->value.ToFloatVector4().y,
-                                                               pValue->value.ToFloatVector4().z, pValue->value.ToFloatVector4().w);
-                                       break;
-
-                               default:
-//                                     PRINT("_GlRenderManager::FlushRenderQueue: Invalid variant type [%d]\n", type);
-                                       break;
-                               }
-                       }
-
-                       delete pMapEnum;
-               }
-
-               if (__pRenderQueue[i].__pSurfaceInfo)
-               {
-                       __pGlContext->BindTexture(0 , __pRenderQueue[i].__pSurfaceInfo);
-
-                       if (__pGlContext->__textureRepeated != __pRenderQueue[i].__textureRepeated)
-                       {
-                               if (__pRenderQueue[i].__textureRepeated)
-                               {
-                                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-                                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-                               }
-                               else
-                               {
-                                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-                                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-                               }
-
-                               __pGlContext->__textureRepeated = __pRenderQueue[i].__textureRepeated;
-                       }
-
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_TEXTURE], 0);
-
-                       if ( __pRenderQueue[i].__isTexUpdated)
-                       {
-#ifndef __SHARED_CONTEXT__
-                               __pGlContext->InvalidateTexture(__pRenderQueue[i].__pSurfaceInfo);
-#endif
-
-                               __pGlContext->UploadTexture(__pRenderQueue[i].__pSurfaceInfo);
-                       }
-
-                       if (__pRenderQueue[i].__pFilter)
-                       {
-                               _VisualElementFilterImpl* pFilterImpl = _VisualElementFilterImpl::GetInstance(*__pRenderQueue[i].__pFilter);
-                               float x, y;
-
-                               if (!pFilterImpl->__isFirstPass)
-                               {
-                                       x = 1.0f / __pRenderQueue[i].__pSurfaceInfo->__textureInfo.width;
-                                       y = 0.0f;
-                               }
-                               else
-                               {
-                                       x = 0.0f;
-                                       y = 1.0f / __pRenderQueue[i].__pSurfaceInfo->__textureInfo.height;
-                               }
-
-                               glUniform1f(glGetUniformLocation(pProgramImpl->__program, "u_radius"), pFilterImpl->__radius);
-                               glUniform1f(glGetUniformLocation(pProgramImpl->__program, "u_sigma"), pFilterImpl->__sigma);
-                               glUniform2f(glGetUniformLocation(pProgramImpl->__program, "u_directionVec"), x, y);
-                       }
-               }
-               else
-               {
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_TEXTURE], EXTRA_SURFACE_MAX + 2);
-               }
-
-               for (int k = 0; k < EXTRA_SURFACE_MAX; k++)
-               {
-                       int offset = (UNIFORM_SAMPLER2D_EXTRA_SURFACE - UNIFORM_FLOAT_EXTRA_SURFACE_OPACITY+1) * k;
-
-                       if (__pRenderQueue[i].__pExtraSurfaceInfo[k])
-                       {
-                               __pGlContext->BindTexture(k + 1, __pRenderQueue[i].__pExtraSurfaceInfo[k]);
-
-                               glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_EXTRA_SURFACE + offset], k + 1);
-                               glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_EXTRA_SURFACE_OPACITY + offset], __pRenderQueue[i].__extraSurfaceOpacity[k]);
-
-                               if (__pRenderQueue[i].__isExtraSurfaceUpdated[k])
-                               {
-#ifndef __SHARED_CONTEXT__
-                                       __pGlContext->InvalidateTexture(__pRenderQueue[i].__pExtraSurfaceInfo[k]);
-#endif
-
-                                       __pGlContext->UploadTexture(__pRenderQueue[i].__pExtraSurfaceInfo[k]);
-                                       __pRenderQueue[i].__isExtraSurfaceUpdated[k] = false;
-                               }
-                       }
-                       else
-                       {
-                               glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_EXTRA_SURFACE + offset], EXTRA_SURFACE_MAX + 2);
-                       }
-               }
-
-               if (__pRenderQueue[i].__extraSurfaceCount > 0)
-               {
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_EXTRA_SURFACE_COUNT], __pRenderQueue[i].__extraSurfaceCount);
-               }
-               else
-               {
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_EXTRA_SURFACE_COUNT], 0);
-               }
-
-               if (__pRenderQueue[i].__pAlphaMaskSurfaceInfo)
-               {
-                       __pGlContext->BindTexture(EXTRA_SURFACE_MAX + 1, __pRenderQueue[i].__pAlphaMaskSurfaceInfo);
-
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_ALPHA_MASK], EXTRA_SURFACE_MAX + 1);
-
-                       if (__pRenderQueue[i].__isAlphaMaskUpdated)
-                       {
-#ifndef __SHARED_CONTEXT__
-                               __pGlContext->InvalidateTexture(__pRenderQueue[i].__pAlphaMaskSurfaceInfo);
-#endif
-
-                               __pGlContext->UploadTexture(__pRenderQueue[i].__pAlphaMaskSurfaceInfo);
-                               __pRenderQueue[i].__isAlphaMaskUpdated = false;
-                       }
-
-                       glUniform1i(pProgramImpl->__uniformLocation[UNOFORM_INT_ALPHA_MASK_COUNT], 1);
-               }
-               else
-               {
-                       glUniform1i(pProgramImpl->__uniformLocation[UNOFORM_INT_ALPHA_MASK_COUNT], 0);
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_ALPHA_MASK], EXTRA_SURFACE_MAX + 2);
-               }
-
-               if (__pGlContext->__useBlend != __pRenderQueue[i].__useBlend)
-               {
-                       if (__pRenderQueue[i].__useBlend)
-                       {
-                               glEnable(GL_BLEND);
-                       }
-                       else
-                       {
-                               glDisable(GL_BLEND);
-                       }
-
-                       __pGlContext->__useBlend = __pRenderQueue[i].__useBlend;
-               }
-
-               if (__pGlContext->__useDepthTest != __pRenderQueue[i].__useDepthTest)
-               {
-                       if (__pRenderQueue[i].__useDepthTest)
-                       {
-                               glEnable(GL_DEPTH_TEST);
-                       }
-                       else
-                       {
-                               glDisable(GL_DEPTH_TEST);
-                       }
-
-                       __pGlContext->__useDepthTest = __pRenderQueue[i].__useDepthTest;
-               }
-
-               if (__pRenderQueue[i].__useStencil)
-               {
-                       if (!__pGlContext->__useStencil)
-                       {
-                               glEnable(GL_STENCIL_TEST);
-                               __pGlContext->__useStencil = true;
-                       }
-
-                       if (__pRenderQueue[i].__colorMask)
-                       {
-                               glStencilFunc(GL_EQUAL, __pRenderQueue[i].__stencilIndex, 0xFFFFFFFF);
-
-                               if (__pRenderQueue[i].__updateStencil)
-                               {
-                                       glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
-                               }
-                               else
-                               {
-                                       glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
-                               }
-
-                               glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-                       }
-                       else
-                       {
-                               glStencilFunc(GL_EQUAL, __pRenderQueue[i].__stencilIndex, 0xFFFFFFFF);
-                               glStencilOp(GL_KEEP, GL_DECR, GL_DECR);
-
-                               glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-                       }
-               }
-               else
-               {
-                       if (__pGlContext->__useStencil)
-                       {
-                               glDisable(GL_STENCIL_TEST);
-                               __pGlContext->__useStencil = false;
-                       }
-
-                       glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-               }
-
-               if (__pRenderQueue[i].__pIndices)
-               {
-                       glDrawElements(__pRenderQueue[i].__geoType, __pRenderQueue[i].__indexCount, GL_UNSIGNED_SHORT, __pRenderQueue[i].__pIndices);
-               }
-               else
-               {
-                       glDrawArrays(__pRenderQueue[i].__geoType, 0, __pRenderQueue[i].__vertexCount);
-               }
-
-               __pRenderQueue[i].ResetObject();
-       }
-
-       __queueCount = 0;
-#endif
-       return;
-}
-
-void
-_GlRenderManager::CompositeNode(VisualElement* pRenderObject, Tizen::Base::Collection::ArrayList &parentLight, bool useStencil, unsigned int depth, _GlLayer* pLayer, _ViewInfo* pView)
-{
-       bool updateStencil = false;
-       unsigned int stencilIndex = depth;
-
-       Tizen::Base::Collection::IList* pChildren = pRenderObject->GetChildrenN();
-
-       if (unlikely(!pChildren))
-               return;
-
-       // FIXME: Sync status BEFORE compositing for early-unlock
-
-       int childrenCount = pChildren->GetCount();
-       for (int c = 0; c < childrenCount; c++)
-       {
-               VisualElement* pChild = dynamic_cast< VisualElement* >(pChildren->GetAt(c));
-               if (unlikely(!pChild))
-                       continue;
-
-               _VisualElementImpl* pChildImpl = _VisualElementImpl::GetInstance(*pChild);
-
-// if child is root: it need to test
-               if (pChildImpl->__isRoot)
-               {
-                       _RootVisualElement* pRoot = static_cast<_RootVisualElement*>(pChildImpl->GetPublic());
-                       if (pRoot)
-                       {
-                               _ViewInfo* pNewView = pRoot->GetView();
-                               if (pNewView)
-                               {
-                                       CompositeView(pLayer, pRoot, pNewView);
-                               }
-                               else
-                               {
-                                       CompositeView(pLayer, pRoot, pView);
-                               }
-                       }
-                       continue;
-               }
-
-               _GlNode* pNode = dynamic_cast< _GlNode* >(pChildImpl->GetNativeNode());
-               if (unlikely(!pNode))
-                       continue;
-
-               pNode->SyncStatus(pChildImpl->GetSharedData().pSurface, *pChildImpl);
-
-               if (pNode->__pLight)
-               {
-                       _LightImpl* pLightImpl = _LightImpl::GetInstance(*pNode->__pLight);
-
-                       if (pLightImpl->IsEnabled())
-                       {
-                               pNode->__activeLight.Add(pNode->__pLight);
-                       }
-#if 0
-                       if (__globalLightCount < MAX_LIGHT_COUNT)
-                       {
-                               __globalLight[__globalLightCount] = pNode->__pLight;
-                               __globalLightCount++;
-                       }
-#endif
-
-                       float* pPosition = pLightImpl->GetPosition();
-
-                       if (pLightImpl->GetType() != Light::LIGHT_TYPE_DIRECTIONAL)
-                       {
-                               float position[4];
-
-                               _Matrix4f modelview = __view * _Matrix4f(pChildImpl->GetMatrixToTop());
-
-                               position[0] = (modelview(0, 0) * pPosition[0]) + (modelview(0, 1) * pPosition[1]) + (modelview(0, 2) * pPosition[2]) + modelview(0, 3);
-                               position[1] = (modelview(1, 0) * pPosition[0]) + (modelview(1, 1) * pPosition[1]) + (modelview(1, 2) * pPosition[2]) + modelview(1, 3);
-                               position[2] = (modelview(2, 0) * pPosition[0]) + (modelview(2, 1) * pPosition[1]) + (modelview(2, 2) * pPosition[2]) + modelview(2, 3);
-                               position[3] = (modelview(3, 0) * pPosition[0]) + (modelview(3, 1) * pPosition[1]) + (modelview(3, 2) * pPosition[2]) + modelview(3, 3);
-
-                               pLightImpl->SetPositionInEyeCoords(position);
-
-                               if (pLightImpl->GetType() == Light::LIGHT_TYPE_SPOT)
-                               {
-                                       float* pDirection = pLightImpl->GetDirection();
-                                       float direction[3];
-
-                                       direction[0] = (modelview(0, 0) * pDirection[0]) + (modelview(0, 1) * pDirection[1]) + (modelview(0, 2) * pDirection[2]);
-                                       direction[1] = (modelview(1, 0) * pDirection[0]) + (modelview(1, 1) * pDirection[1]) + (modelview(1, 2) * pDirection[2]);
-                                       direction[2] = (modelview(2, 0) * pDirection[0]) + (modelview(2, 1) * pDirection[1]) + (modelview(2, 2) * pDirection[2]);
-
-                                       pLightImpl->SetDirectionInEyeCoords(direction);
-                               }
-                       }
-                       else
-                       {
-                               pLightImpl->SetPositionInEyeCoords(pPosition);
-                       }
-               }
-
-               for (register int i = 0; i<parentLight.GetCount(); i++ )
-               {
-                       Object* pValue = null;
-                       pValue = parentLight.GetAt(i);
-
-//                     _LightImpl* pLightImplParent = _LightImpl::GetInstance(*(Light*)pValue);
-
-//                     if (pLightImpl != pLightImplParent)
-                       {
-                               pNode->__activeLight.Add(pValue);
-                       }
-               }
-
-#ifndef BUILD_UI_CORE          
-               if (!pNode->__isVisible || _FloatCompare(pNode->__opacity, 0.0f))
-               {
-                       continue;
-               }
-#endif
-
-               if (pNode->__visibleRect.IsEmpty())
-               {
-                       if (!pNode->__isClipChildren)
-                       {
-                               CompositeNode(pChild, pNode->__activeLight, useStencil, depth, pLayer, pView);
-                       }
-                       continue;
-               }
-
-               if (!pNode->__pSurface)
-               {
-                       if (_FloatCompare(pNode->__objectColor.Alpha(), 0.0f))
-                       {
-                               CompositeNode(pChild, pNode->__activeLight, useStencil, depth, pLayer, pView);
-                               continue;
-                       }
-               }
-
-               useStencil |= (pNode->__useStencil) ? true : false;
-               updateStencil = (pNode->__useStencil && pChildImpl->GetChildrenCount() > 0) ? true : false;
-
-               if (pNode->__pFilter && pNode->__pFilter->IsEnabled())
-               {
-                       _VisualElementFilterImpl* pFilterImpl = _VisualElementFilterImpl::GetInstance(*pNode->__pFilter);
-                       bool useTempNode = false;
-                       VisualElementSurface* pSurface = null;
-                       TextureInfo* pTextureInfo = null;
-
-                       if (pFilterImpl->__pRenderSurface)
-                       {
-                               _VisualElementSurfaceImpl* pRenderSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pFilterImpl->__pRenderSurface);
-                               TextureInfo* pRenderTextureInfo = (TextureInfo*)pRenderSurfaceImpl->GetNativeHandle();
-
-                               FlushRenderQueue();
-
-                               __pGlContext->BindFramebuffer(pRenderTextureInfo);
-                               __needClear = true;
-
-                               pNode->__useFilter = false;
-
-                               glViewport(0, 0, pRenderTextureInfo->width, pRenderTextureInfo->height);
-
-                               EnqueueRenderObject(pNode, false, 0, true);
-
-                               FlushRenderQueue();
-
-                               __pGlContext->BindFramebuffer(null);            // TODO: restore previous framebuffer
-
-                               pNode->__useFilter = true;
-
-                               // for next rendering
-                               useTempNode = true;
-                               pSurface = pFilterImpl->__pRenderSurface;
-                               pTextureInfo = pRenderTextureInfo;
-                       }
-
-                       if (pFilterImpl->__pInternalSurface)
-                       {
-                               _VisualElementSurfaceImpl* pInternalSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pFilterImpl->__pInternalSurface);
-                               TextureInfo* pInternalTextureInfo = (TextureInfo*)pInternalSurfaceImpl->GetNativeHandle();
-
-                               FlushRenderQueue();
-
-                               __pGlContext->BindFramebuffer(pInternalTextureInfo);
-                               __needClear = true;
-
-                               pFilterImpl->__isFirstPass = true;
-
-                               glViewport(0, 0, pInternalTextureInfo->width, pInternalTextureInfo->height);
-
-                               if (useTempNode)
-                               {
-                                       __pTempNode->__useBlend = pNode->__useBlend;
-                                       __pTempNode->__useStencil = pNode->__useStencil;
-                                       __pTempNode->__childrenCount = pNode->__childrenCount;
-                                       __pTempNode->__opacity = pNode->__opacity;
-                                       __pTempNode->__pFilter = pNode->__pFilter;
-                                       __pTempNode->__useFilter = pNode->__useFilter;
-                                       __pTempNode->__pSurface = pSurface;
-//                                     __pTempNode->__pTextureInfo = pTextureInfo;
-
-                                       EnqueueRenderObject(__pTempNode, false, 0, true);
-                               }
-                               else
-                               {
-                                       EnqueueRenderObject(pNode, false, 0, true);
-                               }
-
-                               FlushRenderQueue();
-
-                               __pGlContext->BindFramebuffer(null);            // TODO: restore previous framebuffer
-
-                               // for next rendering
-                               useTempNode = true;
-                               pSurface = pFilterImpl->__pInternalSurface;
-                               pTextureInfo = pInternalTextureInfo;
-                       }
-
-                       pFilterImpl->__isFirstPass = false;
-
-                       if (useTempNode)
-                       {
-                               __pTempNode->__useBlend = pNode->__useBlend;
-                               __pTempNode->__useStencil = pNode->__useStencil;
-                               __pTempNode->__childrenCount = pNode->__childrenCount;
-                               __pTempNode->__opacity = pNode->__opacity;
-                               __pTempNode->__pFilter = pNode->__pFilter;
-                               __pTempNode->__useFilter = pNode->__useFilter;
-                               __pTempNode->__pSurface = pSurface;
-//                             __pTempNode->__pTextureInfo = pTextureInfo;
-
-                               if (pFilterImpl->__downSampling)
-                               {
-                                       _VisualElementSurfaceImpl* pRenderSurfaceImpl = _VisualElementSurfaceImpl::GetInstance(*pFilterImpl->__pRenderSurface);
-                                       TextureInfo* pRenderTextureInfo = (TextureInfo*)pRenderSurfaceImpl->GetNativeHandle();
-
-                                       __pGlContext->BindFramebuffer(pRenderTextureInfo);
-                                       __needClear = true;
-
-                                       glViewport(0, 0, pRenderTextureInfo->width, pRenderTextureInfo->height);
-
-                                       EnqueueRenderObject(__pTempNode, false, 0, true);
-
-                                       FlushRenderQueue();
-
-                                       __pGlContext->BindFramebuffer(null);            // TODO: restore previous framebuffer
-
-                                       // for next rendering
-                                       __pTempNode->__useFilter = false;
-                                       __pTempNode->__pSurface = pFilterImpl->__pRenderSurface;
-//                                     __pTempNode->__pTextureInfo = pRenderTextureInfo;
-                               }
-
-                               glViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
-
-                               EnqueueRenderObject(__pTempNode, useStencil, stencilIndex, true);
-                       }
-                       else
-                       {
-                               EnqueueRenderObject(pNode, useStencil, stencilIndex, true);
-                       }
-               }
-               else
-               {
-                       EnqueueRenderObject(pNode, useStencil, stencilIndex, true);
-               }
-
-               if (updateStencil)
-               {
-                       CompositeNode(pChild, pNode->__activeLight, useStencil, depth + 1, pLayer, pView);
-
-                       if (pNode->__pFilter)
-                       {
-                               // TODO: implement
-                       }
-                       else
-                       {
-                               EnqueueRenderObject(pNode, true, stencilIndex + 1, false);
-                       }
-               }
-               else
-               {
-                       CompositeNode(pChild, pNode->__activeLight, useStencil, depth, pLayer, pView);
-               }
-       }
-
-       //clear light arrayList
-       _VisualElementImpl* pRenderObjectImpl = _VisualElementImpl::GetInstance(*pRenderObject);
-       _GlNode* pRenderObjectNode = dynamic_cast< _GlNode* >(pRenderObjectImpl->GetNativeNode());
-       pRenderObjectNode->__activeLight.RemoveAll();
-
-       delete pChildren;
-}
-
-void
-_GlRenderManager::CompositeView(_GlLayer* pLayer, _RootVisualElement* pRoot, _ViewInfo* pView)
-{
-       Tizen::Graphics::FloatRectangle viewport;
-       _Matrix4f view, projection, flippedProjection;
-       float eye[3] = {0.0f,0.0f,0.0f};
-
-       FlushRenderQueue();
-
-       VisualElementSurface* pSurface = pView->GetRenderTarget();
-//     if (pSurface)
-//     {
-//             __pGlContext->BindFramebuffer(pView->GetRenderTargetInfo());
-//             __needClear = true;
-//     }
-//     else
-//     {
-//             __pGlContext->BindFramebuffer(null);
-//     }
-
-       Tizen::Graphics::FloatRectangle* pViewport = pView->GetViewport();
-       int orientation = pLayer->GetOrientation();
-       if (pViewport)
-       {
-               viewport = __viewport;
-
-               if (pSurface)
-               {
-                       __viewport.y = pViewport->y;
-               }
-               else
-               {
-                       Tizen::Graphics::FloatRectangle bounds = pLayer->GetBounds();
-
-                       if (orientation % 180)
-                       {
-                               __viewport.y = bounds.width - pViewport->y - pViewport->height;
-                       }
-                       else
-                       {
-                               __viewport.y = bounds.height - pViewport->y - pViewport->height;
-                       }
-               }
-
-               __viewport.x = pViewport->x;
-               __viewport.width = pViewport->width;
-               __viewport.height = pViewport->height;
-
-//             glViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
-       }
-
-       if (orientation != 0)
-       {
-               if (orientation == 90)
-               {
-                       __view.Translate(0.0f, pLayer->GetBounds().width, 0.0f);
-               }
-               else if (orientation == 270)
-               {
-                       __view.Translate(pLayer->GetBounds().height, 0.0f, 0.0f);
-               }
-               else
-               {
-                       __view.Translate(pLayer->GetBounds().width, pLayer->GetBounds().height, 0.0f);
-               }
-
-               __view.Rotate(360-orientation, 0.0f, 0.0f, 1.0f);
-       }
-
-       Camera* pCamera = pView->GetCamera();
-       if (pCamera)
-       {
-               _CameraImpl* pCameraImpl = _CameraImpl::GetInstance(*pCamera);
-               FloatPoint3 eyePosition = pCameraImpl->GetEye();
-
-               view = __view;
-
-               eye[0] = __eyePosition[0];
-               eye[1] = __eyePosition[1];
-               eye[2] = __eyePosition[2];
-
-               __view = pCameraImpl->GetMatrix();
-
-               __eyePosition[0] = eyePosition.x;
-               __eyePosition[1] = eyePosition.y;
-               __eyePosition[2] = eyePosition.z;
-       }
-
-       const FloatMatrix4* pProjection = pView->GetProjection();
-       if (pProjection)
-       {
-               const FloatMatrix4* pFlippedProjection = pView->GetFlippedProjection();
-
-               projection.Assign(__projection);
-               flippedProjection.Assign(__flippedProjection);
-
-               __projection.CopyFrom(*pProjection);
-               __flippedProjection.CopyFrom(*pFlippedProjection);
-       }
-
-       __viewProjection.Assign(__projection);
-       __viewProjection.MultiplyMatrix(__view);
-
-       __flippedViewProjection.Assign(__flippedProjection);
-       __flippedViewProjection.MultiplyMatrix(__view);
-
-       __globalLightCount = 0;
-
-       VisualElement* pRootRender = _VisualElementImpl::GetInstance(*pRoot)->GetRenderObject()->GetPublic();
-
-       Tizen::Base::Collection::ArrayList clearColorArray;
-       clearColorArray.Construct();
-
-       CompositeNode(pRootRender, clearColorArray, false, 0, pLayer, pView);
-
-       memset(__pGlContext->__textureId, 0, sizeof(unsigned int) * (EXTRA_SURFACE_MAX + 2));
-
-       clearColorArray.RemoveAll();
-
-       // sub view
-       // Todo: render sub view
-       int count = pView->GetSubViewCount();
-
-       for (int i = 0; i < count; i++)
-       {
-               _ViewInfo* pSubView = pView->GetSubViewInfo(i);
-               if (pSubView)
-               {
-                       CompositeView(pLayer, pRoot, pSubView);
-               }
-       }
-
-       FlushRenderQueue();
-
-       // restore
-       if (pViewport)
-       {
-               __viewport = viewport;
-
-               glViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
-       }
-
-       if (pSurface)
-       {
-               __pGlContext->BindFramebuffer(null);
-       }
-
-       if (pCamera)
-       {
-               __view = view;
-
-               __eyePosition[0] = eye[0];
-               __eyePosition[1] = eye[1];
-               __eyePosition[2] = eye[2];
-       }
-
-       if (pProjection)
-       {
-               __projection.Assign(projection);
-               __flippedProjection.Assign(flippedProjection);
-       }
-
-       __viewProjection.Assign(__projection);
-       __viewProjection.MultiplyMatrix(__view);
-
-       __flippedViewProjection.Assign(__flippedProjection);
-       __flippedViewProjection.MultiplyMatrix(__view);
-}
-
-void
-_GlRenderManager::CompositeLayer(_GlLayer* pLayer)
-{
-       if (pLayer->GetShowState() == false)
-       {
-               return;
-       }
-
-       __needClear = true;
-
-       _AutoMutex renderLock(*_VisualElementEnvironment::GetTreeLock());
-       bool isUpdated = pLayer->UpdateNativeNodes();
-
-
-       if (isUpdated)
-       {
-               // init matrix
-               __view.LoadIdentity();
-               __projection.LoadIdentity();
-               __flippedProjection.LoadIdentity();
-
-               __eyePosition[0] = 0.0f;
-               __eyePosition[1] = 0.0f;
-               __eyePosition[2] = 0.0f;
-
-               // init temp node's bounds
-               Tizen::Graphics::FloatRectangle bounds = pLayer->GetBounds();
-
-               __pTempNode->__pVertices[5] = bounds.width;
-               __pTempNode->__pVertices[11] = bounds.height;
-               __pTempNode->__pVertices[15] = bounds.width;
-               __pTempNode->__pVertices[16] = bounds.height;
-
-#if 0
-#ifdef VE_USE_GL_MULTI_CONTEXT
-               __pGlContext = (_GlContext*)pLayer->GetContext();
-               __pGlContext->MakeCurrent();
-#else
-               __pGlContext->MakeCurrent(pLayer->GetNativeSurface());
-#endif
-#else
-               __pGlLayerForFlush = pLayer;
-#endif
-
-               int count  = pLayer->GetViewCount();
-
-               for (int i = 0; i < count; i++)
-               {
-                       View* pScene = pLayer->GetView(i);
-
-                       if (pScene)
-                       {
-                               _RootVisualElement* pRoot = _ViewImpl::GetInstance(*pScene);
-                               _ViewInfo* pView = pRoot->GetView();
-
-                               if (pView)
-                               {
-                                       CompositeView(pLayer, pRoot, pView);
-                               }
-                       }
-               }
-
-               FlushRenderQueue();
-#if 0
-               __pGlContext->SwapBuffers();
-#else
-               FlushRenderQueueFinish(pLayer);
-#endif
-               __pTempNode->__pFilter = null;
-               __pTempNode->__pSurface = null;
-       }
-}
-
-void
-_GlRenderManager::CommandHandlerComposite(_GlLayer* pGlLayer)
-{
-       long long time1, time2;
-
-       Tizen::System::SystemTime::GetTicks(time1);
-
-#ifndef VE_USE_GL_MULTI_CONTEXT
-       CHECK_GL_CONTEXT();
-#endif
-
-       _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
-
-       _AutoMutex treeLock(*_VisualElementEnvironment::GetTreeLock());
-
-       if (pGlLayer && pGlLayer->IsMapped())
-       {
-               CompositeLayer(pGlLayer);
-       }
-       else // render all
-       {
-               int count = pDisplayManager->GetLayerCount();
-
-               for (int i = 0; i < count; i++)
-               {
-                       _GlLayer* pGlLayer = dynamic_cast<_GlLayer*>(pDisplayManager->GetLayer(i));
-#ifdef LINUX
-                       if (!pGlLayer || !pGlLayer->IsMapped())
-                       {
-                               continue;
-                       }
-#elif _WIN32
-                       if (!pGlLayer)
-                       {
-                               continue;
-                       }
-#endif
-
-                       CompositeLayer(pGlLayer);
-               }
-       }
-
-       Tizen::System::SystemTime::GetTicks(time2);
-
-//     PRINT("     ### composite time: %lld ms (%.2f fps)\n", time2 - time1, 1000.0f / (time2 - time1));
-}
-
-bool
-_GlRenderManager::CommandHandlerInitializeGLLayer(_GlLayer* pGlLayer)
-{
-#ifdef VE_USE_GL_MULTI_CONTEXT
-#ifdef ECORE_X_NATIVE
-       _EcoreXLooper* pLooper = static_cast<_EcoreXLooper*>(_Looper::GetInstance());
-       pGlLayer->__pContext = _GlContext::CreateN((Handle)pLooper->GetXDisplay(), (Handle)pGlLayer->GetNativeWindow());
-
-       PRINT("[DEBUG]-003a _GlRenderManager::CommandHandlerInitializeGLLayer: Create surf...  \n" );
-#endif
-
-       __pGlContext = pGlLayer->__pContext;
-
-       PRINT(">> CommandHandlerInitializeGLLayer() pContext %p \n", pGlLayer->__pContext);
-#else
-       CHECK_GL_CONTEXT();
-
-#endif
-
-       return true;
-}
-
-bool
-_GlRenderManager::CommandHandlerFinalizeGLLayer(_GlLayer* pGlLayer)
-{
-#ifdef VE_USE_GL_MULTI_CONTEXT
-       PRINT(">> CommandHandlerFinalizeGLLayer() pContext %p \n", pGlLayer->__pContext);
+bool
+_GlRenderManager::CommandHandlerFinalizeGLLayer(_GlLayer* pGlLayer)
+{
+#ifdef VE_USE_GL_MULTI_CONTEXT
+       PRINT(">> CommandHandlerFinalizeGLLayer() pContext %p \n", pGlLayer->__pContext);
 
 #ifdef __DELETE_TEXTURE_IN_RENDER_MANAGER__
        AppLog("khee85:: #if defined (__DELETE_TEXTURE_IN_RENDER_MANAGER__) && (VE_USE_GL_MULTI_CONTEXT) : [EMULATOR]");
@@ -2235,7 +1347,13 @@ _GlRenderManager::CommandHandlerDeleteShaderProgram(_ShaderProgramImpl* pShaderP
 void
 _GlRenderManager::CommandHandlerFlushFinish(_GlLayer* pLayer)
 {
-       __pGlContext->MakeCurrent(pLayer->GetNativeSurface());
+//     __pGlContext->MakeCurrent(pLayer->GetNativeSurface());
+#ifdef VE_USE_GL_MULTI_CONTEXT
+               __pGlContext = (_GlContext*)pLayer->GetContext();
+               __pGlContext->MakeCurrent();
+#else
+               __pGlContext->MakeCurrent(pLayer->GetNativeSurface());
+#endif
        __pGlContext->SwapBuffers();
        
 #ifdef __DELETE_TEXTURE_IN_RENDER_MANAGER__
@@ -2245,24 +1363,6 @@ _GlRenderManager::CommandHandlerFlushFinish(_GlLayer* pLayer)
 }
 
 bool
-_GlRenderManager::Animate(void)
-{
-       if (!__pAnimationManager->IsAnimating(false))
-       {
-               return true;
-       }
-
-       if (__pAnimationManager->GetTimeout(false) > 0)
-       {
-               return false;
-       }
-
-       __pAnimationManager->ProcessAnimationTick(false);
-
-       return true;
-}
-
-bool
 _GlRenderManager::BuildShader(_ShaderImpl* pShader)
 {
        if (unlikely(IsInRenderThread()))
@@ -2341,136 +1441,61 @@ _GlRenderManager::DeleteShaderProgram(_ShaderProgramImpl* pShaderProgram)
        return (__commandResult == E_SUCCESS);
 }
 
-void*
-_GlRenderManager::CompositeProc(void* pData)
-{
-       _GlRenderManager* pThis = reinterpret_cast< _GlRenderManager* >(pData);
-
-       _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
-
-       pThis->__pAnimationManager = _AnimationManager::GetInstance();
-
-       for (;;)
-       {
-               _GlLayer* pGlLayer = null;
-               bool needFullComposite = false;
-               {
-                       _AutoMutex commandLock(pThis->__commandCompositeLock);
-                       pThis->__commandComposite.WaitForSignal(&pThis->__commandCompositeLock,pThis->__pAnimationManager->GetTimeout(false));
-                       pGlLayer = pThis->__commandCompositeArg.__pCommandGlLayer;
-                       pThis->__commandCompositeArg.__pCommandGlLayer = null;
-                       if( pGlLayer == null)
-                       {
-                               needFullComposite = true;
-                       }
-               }
-
-               RPRINT(">> CommandHandlerComposite() COMMAND_COMPOSITE - start \n");
-               needFullComposite = pThis->Animate();
-
-//             _AutoMutex treeLock(*_VisualElementEnvironment::GetTreeLock());
-
-               if(needFullComposite)
-               {
-                       int count = pDisplayManager->GetLayerCount();
-
-                       for (int i = 0; i < count; i++)
-                       {
-                               _GlLayer* pGlLayer = dynamic_cast<_GlLayer*>(pDisplayManager->GetLayer(i));
-       #ifdef LINUX
-                               if (!pGlLayer || !pGlLayer->IsMapped())
-                               {
-                                       continue;
-                               }
-       #elif _WIN32
-                               if (!pGlLayer)
-                               {
-                                       continue;
-                               }
-       #endif
-
-                               pThis->CompositeLayer(pGlLayer);
-                       }
-
-               }
-               else if (pGlLayer && pGlLayer->IsMapped())
-               {
-                       pThis->CompositeLayer(pGlLayer);
-               }
-
-
-
-               RPRINT(">> CommandHandlerComposite() COMMAND_COMPOSITE - end \n");
-
-//             else
-//             {
-
-
-//                     if (commandArg.__pCommandGlLayer)
-//                     {
-//                             pThis->CommandHandlerComposite(commandArg.__pCommandGlLayer);
-//                     }
-//                     RPRINT("pThis->Animate() skipped \n");
-//             }
-       }
-       return null;
-}
-
 void
-_GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
+_GlRenderManager::CommandHandlerFlush(void)//(_GlLayer* pLayer)
 {
        _GlRenderManager* pThis = this;
        _GlContext* pGlContext = pThis->__pGlContext;
 
-       _RenderObject* pRenderQueue = null;
-       bool __needClear = true;
+       _GlRenderQueue* pRenderQueue = null;
+       _GlRenderQueue::_RenderObject* pRenderObjects = null;
        int queueCount = 0;
-       float __materialAmbient[4];
-       float __materialDiffuse[4];
-       float __materialSpecular[4];
-       float __materialEmissive[4];
-       float __materialShininess;
 
-       if( __queueCount <= 0 )
-       {
-               /// reply signal send
-               _AutoMutex commandLock(__commandLock);
-               __commandResult = E_SUCCESS;
-               RPRINT("FlushRenderQueueI empty \n");
-               __commandReply.SendSignal();
-               RPRINT("FlushRenderQueueI empty 2\n");
-               return;
-       }
+//     float __materialAmbient[4];
+//     float __materialDiffuse[4];
+//     float __materialSpecular[4];
+//     float __materialEmissive[4];
+//     float __materialShininess;
 
        pRenderQueue = pThis->__pRenderQueue;
+       pRenderObjects = pRenderQueue->__pRenderQueue;
+       queueCount = pRenderQueue->__queueCount;
+       //swap
        pThis->__pRenderQueue = pThis->__pRenderQueueForFlush;
        pThis->__pRenderQueueForFlush = pRenderQueue;
-       __needClear = pThis->__needClear;
-       queueCount = pThis->__queueCount;
+//     __needClear = pThis->__needClear;
+
+//     pThis->__needClear = false;
+//     pThis->__queueCount = 0; // is it needed?
 
-       pThis->__needClear = false;
-       pThis->__queueCount = 0;
+//     __materialAmbient[0] = pThis->__materialAmbient[0];
+//     __materialAmbient[1] = pThis->__materialAmbient[1];
+//     __materialAmbient[2] = pThis->__materialAmbient[2];
+//     __materialAmbient[3] = pThis->__materialAmbient[3];
 
-       __materialAmbient[0] = pThis->__materialAmbient[0];
-       __materialAmbient[1] = pThis->__materialAmbient[1];
-       __materialAmbient[2] = pThis->__materialAmbient[2];
-       __materialAmbient[3] = pThis->__materialAmbient[3];
+//     __materialDiffuse[0] = pThis->__materialDiffuse[0];
+//     __materialDiffuse[1] = pThis->__materialDiffuse[1];
+//     __materialDiffuse[2] = pThis->__materialDiffuse[2];
+//     __materialDiffuse[3] = pThis->__materialDiffuse[3];
 
-       __materialDiffuse[0] = pThis->__materialDiffuse[0];
-       __materialDiffuse[1] = pThis->__materialDiffuse[1];
-       __materialDiffuse[2] = pThis->__materialDiffuse[2];
-       __materialDiffuse[3] = pThis->__materialDiffuse[3];
+//     __materialSpecular[0] = pThis->__materialSpecular[0];
+//     __materialSpecular[1] = pThis->__materialSpecular[1];
+//     __materialSpecular[2] = pThis->__materialSpecular[2];
+//     __materialSpecular[3] = pThis->__materialSpecular[3];
 
-       __materialSpecular[0] = pThis->__materialSpecular[0];
-       __materialSpecular[1] = pThis->__materialSpecular[1];
-       __materialSpecular[2] = pThis->__materialSpecular[2];
-       __materialSpecular[3] = pThis->__materialSpecular[3];
+//     __materialEmissive[0] = pThis->__materialEmissive[0];
+//     __materialEmissive[1] = pThis->__materialEmissive[1];
+//     __materialEmissive[2] = pThis->__materialEmissive[2];
+//     __materialEmissive[3] = pThis->__materialEmissive[3];
+//     __materialShininess = pThis->__materialShininess;
 
-       __materialEmissive[0] = pThis->__materialEmissive[0];
-       __materialEmissive[1] = pThis->__materialEmissive[1];
-       __materialEmissive[2] = pThis->__materialEmissive[2];
-       __materialEmissive[3] = pThis->__materialEmissive[3];
-       __materialShininess = pThis->__materialShininess;
+       if(pRenderQueue->__renderingProps & _GlRenderQueue::UPDATED_PROP_LAYER)
+       {
+               if(pRenderQueue->__pLayer)
+               {
+                       pGlContext->MakeCurrent(pRenderQueue->__pLayer->GetNativeSurface());
+               }
+       }
 
        /// reply signal send
        {
@@ -2479,70 +1504,79 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                __commandReply.SendSignal();
        }
 
-       pGlContext->MakeCurrent(pLayer->GetNativeSurface());
-
-
-       glViewport(__viewport.x, __viewport.y, __viewport.width, __viewport.height);
-
+       if(pRenderQueue->__renderingProps & _GlRenderQueue::UPDATED_PROP_RENDER_TARGET)
+       {
+               TextureInfo* pTextureInfo = null;
+               if(pRenderQueue->__pRenderTarget)
+               {
+                       pTextureInfo = &pRenderQueue->__pRenderTarget->__textureInfo;
+               }
+               __pGlContext->BindFramebuffer(pTextureInfo); // if __pRenderTarget == null, should do BindFramebuffer(null)
+       }
 
+       if(pRenderQueue->__renderingProps & _GlRenderQueue::UPDATED_PROP_VIEWPORT)
+       {
+               glViewport(pRenderQueue->__viewport.x, pRenderQueue->__viewport.y, pRenderQueue->__viewport.width, pRenderQueue->__viewport.height);
+       }
        // queue flush
-       if (__needClear)
+       if (pRenderQueue->__renderingProps & _GlRenderQueue::UPDATED_PROP_CLEAR)
        {
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        }
 
+
        for (int i = 0; i < queueCount; i++)
        {
-               _ShaderProgramImpl* pProgramImpl = _ShaderProgramImpl::GetInstance(*pRenderQueue[i].__pProgram);
+               _ShaderProgramImpl* pProgramImpl = _ShaderProgramImpl::GetInstance(*pRenderObjects[i].__pProgram);
 
                pGlContext->UseShaderProgram(pProgramImpl);
 
                // Set attribute
-               glVertexAttribPointer(pRenderQueue[i].__aPosition, 3, GL_FLOAT, GL_FALSE, VERTEX_BUFFER_STRIDE * sizeof(float), pRenderQueue[i].__pVertices);
-               glVertexAttribPointer(pRenderQueue[i].__aTexCoord, 2, GL_FLOAT, GL_FALSE, TEX_COORD_BUFFER_STRIDE * sizeof(float), pRenderQueue[i].__pTexCoords);
-               glVertexAttribPointer(pRenderQueue[i].__aColor, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), pRenderQueue[i].__pColors);
-               glVertexAttribPointer(pRenderQueue[i].__aNormal, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), pRenderQueue[i].__pNormals);
+               glVertexAttribPointer(pRenderObjects[i].__aPosition, 3, GL_FLOAT, GL_FALSE, VERTEX_BUFFER_STRIDE * sizeof(float), pRenderObjects[i].__pVertices);
+               glVertexAttribPointer(pRenderObjects[i].__aTexCoord, 2, GL_FLOAT, GL_FALSE, TEX_COORD_BUFFER_STRIDE * sizeof(float), pRenderObjects[i].__pTexCoords);
+               glVertexAttribPointer(pRenderObjects[i].__aColor, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), pRenderObjects[i].__pColors);
+               glVertexAttribPointer(pRenderObjects[i].__aNormal, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), pRenderObjects[i].__pNormals);
 
                //Skinning
-               if (pRenderQueue[i].__GPUSkinning)
+               if (pRenderObjects[i].__GPUSkinning)
                {
-                       glVertexAttribPointer(pRenderQueue[i].__aWeights,  4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), pRenderQueue[i].__pWeights);
-                       glVertexAttribPointer(pRenderQueue[i].__aJointIds, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), pRenderQueue[i].__pJointIds); //TODO: for GL_INT need glVertexAttribI(!)Pointer
-
-                       int index0 = (int)(pRenderQueue[i].__pJointIds)[0];
-                       int index1 = (int)(pRenderQueue[i].__pJointIds)[1];
-                       int index2 = (int)(pRenderQueue[i].__pJointIds)[2];
-                       int index3 = (int)(pRenderQueue[i].__pJointIds)[3];
-                       glVertexAttribPointer(pRenderQueue[i].__aJointIndex0, 1, GL_INT, GL_FALSE, sizeof(int), &index0);
-                       glVertexAttribPointer(pRenderQueue[i].__aJointIndex1, 1, GL_INT, GL_FALSE, sizeof(int), &index1);
-                       glVertexAttribPointer(pRenderQueue[i].__aJointIndex2, 1, GL_INT, GL_FALSE, sizeof(int), &index2);
-                       glVertexAttribPointer(pRenderQueue[i].__aJointIndex3, 1, GL_INT, GL_FALSE, sizeof(int), &index3);
-
-                       glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_ARRAY_JOINTSMATRICES], pRenderQueue[i].__jointsCount, GL_FALSE, pRenderQueue[i].__pJointsMatrices);
+                       glVertexAttribPointer(pRenderObjects[i].__aWeights,  4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), pRenderObjects[i].__pWeights);
+                       glVertexAttribPointer(pRenderObjects[i].__aJointIds, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), pRenderObjects[i].__pJointIds); //TODO: for GL_INT need glVertexAttribI(!)Pointer
+
+                       int index0 = (int)(pRenderObjects[i].__pJointIds)[0];
+                       int index1 = (int)(pRenderObjects[i].__pJointIds)[1];
+                       int index2 = (int)(pRenderObjects[i].__pJointIds)[2];
+                       int index3 = (int)(pRenderObjects[i].__pJointIds)[3];
+                       glVertexAttribPointer(pRenderObjects[i].__aJointIndex0, 1, GL_INT, GL_FALSE, sizeof(int), &index0);
+                       glVertexAttribPointer(pRenderObjects[i].__aJointIndex1, 1, GL_INT, GL_FALSE, sizeof(int), &index1);
+                       glVertexAttribPointer(pRenderObjects[i].__aJointIndex2, 1, GL_INT, GL_FALSE, sizeof(int), &index2);
+                       glVertexAttribPointer(pRenderObjects[i].__aJointIndex3, 1, GL_INT, GL_FALSE, sizeof(int), &index3);
+
+                       glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_ARRAY_JOINTSMATRICES], pRenderObjects[i].__jointsCount, GL_FALSE, pRenderObjects[i].__pJointsMatrices);
                }
 
                // Set uniform
 
-               //const float* f = pRenderQueue[i].__mvp.GetItems();//WARNING: it is not used
-               glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MVP], 1, GL_FALSE, pRenderQueue[i].__mvp.GetItems());
-               glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_OPACITY], pRenderQueue[i].__opacity);
-               glUniform4f(pProgramImpl->__uniformLocation[UNIFORM_VEC4_COLOR], pRenderQueue[i].__objectColor.Red(), pRenderQueue[i].__objectColor.Green(),
-                               pRenderQueue[i].__objectColor.Blue(), pRenderQueue[i].__objectColor.Alpha());
+               //const float* f = pRenderObjects[i].__mvp.GetItems();//WARNING: it is not used
+               glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MVP], 1, GL_FALSE, pRenderObjects[i].__mvp.GetItems());
+               glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_OPACITY], pRenderObjects[i].__opacity);
+               glUniform4f(pProgramImpl->__uniformLocation[UNIFORM_VEC4_COLOR], pRenderObjects[i].__objectColor.Red(), pRenderObjects[i].__objectColor.Green(),
+                               pRenderObjects[i].__objectColor.Blue(), pRenderObjects[i].__objectColor.Alpha());
 
-               glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_EYE_POSITION], 1, pRenderQueue[i].__eyePosition);
-               glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MODEL_VIEW], 1, GL_FALSE, pRenderQueue[i].__modelview.GetItems());
-               glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_INV_MODEL_VIEW], 1, GL_FALSE, pRenderQueue[i].__invModelview.GetItems());
+               glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_EYE_POSITION], 1, pRenderObjects[i].__eyePosition);
+               glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MODEL_VIEW], 1, GL_FALSE, pRenderObjects[i].__modelview.GetItems());
+               glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_INV_MODEL_VIEW], 1, GL_FALSE, pRenderObjects[i].__invModelview.GetItems());
 
-               if (pRenderQueue[i].__activeLightCount > 0)
+               if (pRenderObjects[i].__activeLightCount > 0)
                {
                        static int offset = 0;
                        static _LightImpl* pLightImpl = null;
 
-                       for (register unsigned int k = 0; k <pRenderQueue[i].__activeLightCount; k++)
+                       for (register unsigned int k = 0; k <pRenderObjects[i].__activeLightCount; k++)
                        {
                                offset = OFFSET * k + (UNIFORM_SAMPLER2D_EXTRA_SURFACE - UNIFORM_FLOAT_EXTRA_SURFACE_OPACITY+1)*(EXTRA_SURFACE_MAX - 1);
 
-                               pLightImpl = _LightImpl::GetInstance(*pRenderQueue[i].__activeLight[k]);
+                               pLightImpl = _LightImpl::GetInstance(*pRenderObjects[i].__activeLight[k]);
 
                                glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_LIGHT_TYPE + offset], pLightImpl->GetType());
                                glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_AMBIENT + offset], 1, pLightImpl->GetAmbient());
@@ -2555,16 +1589,16 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                                glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_LIGHT_ATTENUATION + offset], 1, pLightImpl->GetAttenuations());
                        }
 
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_ACTIVE_LIGHT_COUNT], pRenderQueue[i].__activeLightCount);
+                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_ACTIVE_LIGHT_COUNT], pRenderObjects[i].__activeLightCount);
                }
                else
                {
                        glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_ACTIVE_LIGHT_COUNT], 0);
                }
 
-               if (pRenderQueue[i].__pMaterial)
+               if (pRenderObjects[i].__pMaterial)
                {
-                       _MaterialImpl* pMaterialImpl = _MaterialImpl::GetInstance(*pRenderQueue[i].__pMaterial);
+                       _MaterialImpl* pMaterialImpl = _MaterialImpl::GetInstance(*pRenderObjects[i].__pMaterial);
 
                        glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_AMBIENT], 1, pMaterialImpl->GetAmbient());
                        glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_DIFFUSE], 1, pMaterialImpl->GetDiffuse());
@@ -2572,13 +1606,13 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                        glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_EMISSIVE], 1, pMaterialImpl->GetEmissive());
                        glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_MATERIAL_SHININESS], pMaterialImpl->GetShininess());
                }
-               else if (pRenderQueue[i].__activeLightCount > 0)
+               else if (pRenderObjects[i].__activeLightCount > 0)
                {
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_AMBIENT], 1, __materialAmbient);
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_DIFFUSE], 1, __materialDiffuse);
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_SPECULAR], 1, __materialSpecular);
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_EMISSIVE], 1, __materialEmissive);
-                       glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_MATERIAL_SHININESS], __materialShininess);
+                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_AMBIENT], 1, pThis->__materialAmbient);
+                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_DIFFUSE], 1, pThis->__materialDiffuse);
+                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_SPECULAR], 1, pThis->__materialSpecular);
+                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_MATERIAL_EMISSIVE], 1, pThis->__materialEmissive);
+                       glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_MATERIAL_SHININESS], pThis->__materialShininess);
                }
 
                // Custom shader
@@ -2657,13 +1691,13 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                        delete pMapEnum;
                }
 
-               if (pRenderQueue[i].__pSurfaceInfo)
+               if (pRenderObjects[i].__pSurfaceInfo)
                {
-                       pGlContext->BindTexture(0 , &pRenderQueue[i].__pSurfaceInfo->__textureInfo);
+                       pGlContext->BindTexture(0 , &pRenderObjects[i].__pSurfaceInfo->__textureInfo);
 
-                       if (pGlContext->__textureRepeated != pRenderQueue[i].__textureRepeated)
+                       if (pGlContext->__textureRepeated != pRenderObjects[i].__textureRepeated)
                        {
-                               if (pRenderQueue[i].__textureRepeated)
+                               if (pRenderObjects[i].__textureRepeated)
                                {
                                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
                                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@@ -2674,34 +1708,34 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
                                }
 
-                               pGlContext->__textureRepeated = pRenderQueue[i].__textureRepeated;
+                               pGlContext->__textureRepeated = pRenderObjects[i].__textureRepeated;
                        }
 
                        glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_TEXTURE], 0);
 
-                       if ( pRenderQueue[i].__isTexUpdated)
+                       if ( pRenderObjects[i].__isTexUpdated)
                        {
 #ifndef __SHARED_CONTEXT__
-                               pGlContext->InvalidateTexture(&pRenderQueue[i].__pSurfaceInfo->__textureInfo);
+                               pGlContext->InvalidateTexture(&pRenderObjects[i].__pSurfaceInfo->__textureInfo);
 #endif
 
-                               pGlContext->UploadTexture(&pRenderQueue[i].__pSurfaceInfo->__textureInfo);
+                               pGlContext->UploadTexture(&pRenderObjects[i].__pSurfaceInfo->__textureInfo);
                        }
 
-                       if (pRenderQueue[i].__pFilter)
+                       if (pRenderObjects[i].__pFilter)
                        {
-                               _VisualElementFilterImpl* pFilterImpl = _VisualElementFilterImpl::GetInstance(*pRenderQueue[i].__pFilter);
+                               _VisualElementFilterImpl* pFilterImpl = _VisualElementFilterImpl::GetInstance(*pRenderObjects[i].__pFilter);
                                float x, y;
 
                                if (!pFilterImpl->__isFirstPass)
                                {
-                                       x = 1.0f / pRenderQueue[i].__pSurfaceInfo->__textureInfo.width;
+                                       x = 1.0f / pRenderObjects[i].__pSurfaceInfo->__textureInfo.width;
                                        y = 0.0f;
                                }
                                else
                                {
                                        x = 0.0f;
-                                       y = 1.0f / pRenderQueue[i].__pSurfaceInfo->__textureInfo.height;
+                                       y = 1.0f / pRenderObjects[i].__pSurfaceInfo->__textureInfo.height;
                                }
 
                                glUniform1f(glGetUniformLocation(pProgramImpl->__program, "u_radius"), pFilterImpl->__radius);
@@ -2718,21 +1752,21 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                {
                        int offset = (UNIFORM_SAMPLER2D_EXTRA_SURFACE - UNIFORM_FLOAT_EXTRA_SURFACE_OPACITY+1) * k;
 
-                       if (pRenderQueue[i].__pExtraSurfaceInfo[k])
+                       if (pRenderObjects[i].__pExtraSurfaceInfo[k])
                        {
-                               pGlContext->BindTexture(k + 1, &pRenderQueue[i].__pExtraSurfaceInfo[k]->__textureInfo);
+                               pGlContext->BindTexture(k + 1, &pRenderObjects[i].__pExtraSurfaceInfo[k]->__textureInfo);
 
                                glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_EXTRA_SURFACE + offset], k + 1);
-                               glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_EXTRA_SURFACE_OPACITY + offset], pRenderQueue[i].__extraSurfaceOpacity[k]);
+                               glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_EXTRA_SURFACE_OPACITY + offset], pRenderObjects[i].__extraSurfaceOpacity[k]);
 
-                               if (pRenderQueue[i].__isExtraSurfaceUpdated[k])
+                               if (pRenderObjects[i].__isExtraSurfaceUpdated[k])
                                {
 #ifndef __SHARED_CONTEXT__
-                                       pGlContext->InvalidateTexture(&pRenderQueue[i].__pExtraSurfaceInfo[k]->__textureInfo);
+                                       pGlContext->InvalidateTexture(&pRenderObjects[i].__pExtraSurfaceInfo[k]->__textureInfo);
 #endif
 
-                                       pGlContext->UploadTexture(&pRenderQueue[i].__pExtraSurfaceInfo[k]->__textureInfo);
-                                       pRenderQueue[i].__isExtraSurfaceUpdated[k] = false;
+                                       pGlContext->UploadTexture(&pRenderObjects[i].__pExtraSurfaceInfo[k]->__textureInfo);
+                                       pRenderObjects[i].__isExtraSurfaceUpdated[k] = false;
                                }
                        }
                        else
@@ -2741,29 +1775,29 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                        }
                }
 
-               if (pRenderQueue[i].__extraSurfaceCount > 0)
+               if (pRenderObjects[i].__extraSurfaceCount > 0)
                {
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_EXTRA_SURFACE_COUNT], pRenderQueue[i].__extraSurfaceCount);
+                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_EXTRA_SURFACE_COUNT], pRenderObjects[i].__extraSurfaceCount);
                }
                else
                {
                        glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_EXTRA_SURFACE_COUNT], 0);
                }
 
-               if (pRenderQueue[i].__pAlphaMaskSurfaceInfo)
+               if (pRenderObjects[i].__pAlphaMaskSurfaceInfo)
                {
-                       pGlContext->BindTexture(EXTRA_SURFACE_MAX + 1, &pRenderQueue[i].__pAlphaMaskSurfaceInfo->__textureInfo);
+                       pGlContext->BindTexture(EXTRA_SURFACE_MAX + 1, &pRenderObjects[i].__pAlphaMaskSurfaceInfo->__textureInfo);
 
                        glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_ALPHA_MASK], EXTRA_SURFACE_MAX + 1);
 
-                       if (pRenderQueue[i].__isAlphaMaskUpdated)
+                       if (pRenderObjects[i].__isAlphaMaskUpdated)
                        {
 #ifndef __SHARED_CONTEXT__
-                               pGlContext->InvalidateTexture(&pRenderQueue[i].__pAlphaMaskSurfaceInfo->__textureInfo);
+                               pGlContext->InvalidateTexture(&pRenderObjects[i].__pAlphaMaskSurfaceInfo->__textureInfo);
 #endif
 
-                               pGlContext->UploadTexture(&pRenderQueue[i].__pAlphaMaskSurfaceInfo->__textureInfo);
-                               pRenderQueue[i].__isAlphaMaskUpdated = false;
+                               pGlContext->UploadTexture(&pRenderObjects[i].__pAlphaMaskSurfaceInfo->__textureInfo);
+                               pRenderObjects[i].__isAlphaMaskUpdated = false;
                        }
 
                        glUniform1i(pProgramImpl->__uniformLocation[UNOFORM_INT_ALPHA_MASK_COUNT], 1);
@@ -2774,9 +1808,9 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                        glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_SAMPLER2D_ALPHA_MASK], EXTRA_SURFACE_MAX + 2);
                }
 
-               if (pGlContext->__useBlend != pRenderQueue[i].__useBlend)
+               if (pGlContext->__useBlend != pRenderObjects[i].__useBlend)
                {
-                       if (pRenderQueue[i].__useBlend)
+                       if (pRenderObjects[i].__useBlend)
                        {
                                glEnable(GL_BLEND);
                        }
@@ -2785,12 +1819,12 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                                glDisable(GL_BLEND);
                        }
 
-                       pGlContext->__useBlend = pRenderQueue[i].__useBlend;
+                       pGlContext->__useBlend = pRenderObjects[i].__useBlend;
                }
 
-               if (pGlContext->__useDepthTest != pRenderQueue[i].__useDepthTest)
+               if (pGlContext->__useDepthTest != pRenderObjects[i].__useDepthTest)
                {
-                       if (pRenderQueue[i].__useDepthTest)
+                       if (pRenderObjects[i].__useDepthTest)
                        {
                                glEnable(GL_DEPTH_TEST);
                        }
@@ -2799,10 +1833,10 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                                glDisable(GL_DEPTH_TEST);
                        }
 
-                       pGlContext->__useDepthTest = pRenderQueue[i].__useDepthTest;
+                       pGlContext->__useDepthTest = pRenderObjects[i].__useDepthTest;
                }
 
-               if (pRenderQueue[i].__useStencil)
+               if (pRenderObjects[i].__useStencil)
                {
                        if (!pGlContext->__useStencil)
                        {
@@ -2810,11 +1844,11 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                                pGlContext->__useStencil = true;
                        }
 
-                       if (pRenderQueue[i].__colorMask)
+                       if (pRenderObjects[i].__colorMask)
                        {
-                               glStencilFunc(GL_EQUAL, pRenderQueue[i].__stencilIndex, 0xFFFFFFFF);
+                               glStencilFunc(GL_EQUAL, pRenderObjects[i].__stencilIndex, 0xFFFFFFFF);
 
-                               if (pRenderQueue[i].__updateStencil)
+                               if (pRenderObjects[i].__updateStencil)
                                {
                                        glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
                                }
@@ -2827,7 +1861,7 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                        }
                        else
                        {
-                               glStencilFunc(GL_EQUAL, pRenderQueue[i].__stencilIndex, 0xFFFFFFFF);
+                               glStencilFunc(GL_EQUAL, pRenderObjects[i].__stencilIndex, 0xFFFFFFFF);
                                glStencilOp(GL_KEEP, GL_DECR, GL_DECR);
 
                                glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
@@ -2844,19 +1878,18 @@ _GlRenderManager::CommandHandlerFlush(_GlLayer* pLayer)
                        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
                }
 
-               if (pRenderQueue[i].__pIndices)
+               if (pRenderObjects[i].__pIndices)
                {
-                       glDrawElements(pRenderQueue[i].__geoType, pRenderQueue[i].__indexCount, GL_UNSIGNED_SHORT, pRenderQueue[i].__pIndices);
+                       glDrawElements(pRenderObjects[i].__geoType, pRenderObjects[i].__indexCount, GL_UNSIGNED_SHORT, pRenderObjects[i].__pIndices);
                }
                else
                {
-                       glDrawArrays(pRenderQueue[i].__geoType, 0, pRenderQueue[i].__vertexCount);
+                       glDrawArrays(pRenderObjects[i].__geoType, 0, pRenderObjects[i].__vertexCount);
                }
 
-               pRenderQueue[i].ResetObject();
+               pRenderObjects[i].ResetObject();
        }
-
-       queueCount = 0;
+       pRenderQueue->Reset();
 }
 
 
@@ -2879,9 +1912,6 @@ _GlRenderManager::RenderProc(void* pData)
 #endif
 
 
-
-       pThis->__pAnimationManager = _AnimationManager::GetInstance();
-
        for (;;)
        {
                bool needReply = true;
@@ -2894,19 +1924,12 @@ _GlRenderManager::RenderProc(void* pData)
 
                        while (pThis->__commandId == COMMAND_UNKNOWN && gotCommand)
                        {
-                               //gotCommand = pThis->__commandRequest.WaitForSignal(&pThis->__commandLock, pThis->__pAnimationManager->GetTimeout(false));
                                gotCommand = pThis->__commandRequest.WaitForSignal(&pThis->__commandLock);
                        }
 
-                       if (unlikely(pThis->__commandId == COMMAND_UNKNOWN))
+                       if (unlikely(pThis->__commandId == COMMAND_UNKNOWN)) // it is error case
                        {
                                continue;
-
-                               ASSERT(!gotCommand, "No command sent, but got command !");
-
-                               commandId = COMMAND_COMPOSITE;
-                               commandArg = pThis->__commandArg;       // to avoid complier warning
-                               commandArg.__pCommandGlLayer = null;
                                needReply = false; // no notifying to main thread
                        }
                        else
@@ -2948,30 +1971,10 @@ _GlRenderManager::RenderProc(void* pData)
                case COMMAND_DELETE_SHADER:
                        pThis->CommandHandlerDeleteShader(commandArg.__pCommandShader);
                        break;
-#if 0
-               case COMMAND_COMPOSITE:
-                       RPRINT(">> CommandHandlerComposite() COMMAND_COMPOSITE - start \n");
-                       if (pThis->Animate())
-                       {
-                               pThis->CommandHandlerComposite(null);
-                       }
-                       else
-                       {
-                               if (commandArg.__pCommandGlLayer)
-                               {
-                                       pThis->CommandHandlerComposite(commandArg.__pCommandGlLayer);
-                               }
-                               RPRINT("pThis->Animate() skipped \n");
-                       }
-                       needReply = false;
 
-                       RPRINT(">> CommandHandlerComposite() COMMAND_COMPOSITE - end \n");
-                       break;
-                       //continue; // WARNING: reply already done
-#endif
                case COMMAND_FLUSH:
                        RPRINT(">> COMMAND_FLUSH - start \n");
-                       pThis->CommandHandlerFlush(commandArg.__pCommandGlLayer);
+                       pThis->CommandHandlerFlush();//commandArg.__pCommandGlLayer);
                        needReply = false;
 
                        RPRINT(">> COMMAND_FLUSH - end \n");
@@ -2982,10 +1985,6 @@ _GlRenderManager::RenderProc(void* pData)
                        RPRINT(">> COMMAND_FLUSH - end \n");
                        break;
 
-               case COMMAND_WAKEUP:
-                       PRINT("COMMAND_WAKEUP\n");
-                       break;
-
                case COMMAND_SYNCINIT:
                        PRINT("SYNC DONE\n");
                        break;
index 6413d00..e9cf7d5 100644 (file)
 #include "FUiAnim_ShaderProgramGenerator.h"
 #include "FUiAnim_InternalTypes.h"
 
+
 #define MAX_LIGHT_COUNT 8
 
 namespace Tizen { namespace Ui { namespace Animations
 {
 
 class VisualElement;
-class _AnimationManager;
 class _GlContext;
 class _GlNode;
 class _GlVisualElementSurfaceImpl;
+class _GlCompositor;
 class ShaderProgram;
 class _ShaderImpl;
 class _ShaderProgramImpl;
@@ -57,6 +58,7 @@ class Mesh;
 class Light;
 class Material;
 class VisualElementFilter;
+class _GlRenderQueue;
 
 
 struct TextureInfo;
@@ -67,17 +69,12 @@ public:
        enum RenderCommand
        {
                COMMAND_UNKNOWN,
-               COMMAND_WAKEUP,
                COMMAND_SYNCINIT,
                COMMAND_EXIT,
 
                COMMAND_INITIALIZE_GLLAYER,
                COMMAND_FINALIZE_GLLAYER,
-#if 0 // move to surface manager
-               COMMAND_CREATE_TEXTURE,
-               COMMAND_DELETE_TEXTURE,
-#endif
-               COMMAND_COMPOSITE,
+
                COMMAND_BUILD_SHADER,
                COMMAND_DELETE_SHADER,
                COMMAND_BUILD_SHADER_PROGRAM,
@@ -94,7 +91,7 @@ public:
        static result CreateInstance(void);
        static result ReleaseInstance(void);
 
-    pthread_t GetRenderThread(void) const { return __threadInfo; }
+       pthread_t GetRenderThread(void) const { return __threadInfo; }
     bool IsInRenderThread(void) const { return pthread_equal(__threadInfo, pthread_self()); }
 
        bool SyncRenderManager(void);
@@ -103,18 +100,18 @@ public:
        bool FinalizeGLLayer(_GlLayer* pGlLayer);
        bool Composite(_GlLayer* pLayer = null);
 
-       void WakeUp(void);
-
        bool BuildShader(_ShaderImpl* pShader);
        bool DeleteShader(_ShaderImpl* pShader);
        bool BuildShaderProgram(_ShaderProgramImpl* pShaderProgram);
        bool DeleteShaderProgram(_ShaderProgramImpl* pShaderProgram);
 
+       _GlCompositor* GetCompositor(void){return __pCompositor;}
+       _GlRenderQueue* GetRenderQueue(void);
+
 private:
 
        bool CommandHandlerInitializeGLLayer(_GlLayer* pGlLayer);
        bool CommandHandlerFinalizeGLLayer(_GlLayer* pGlLayer);
-       void CommandHandlerComposite(_GlLayer* pGlLayer);
        void CommandHandlerFlushFinish(_GlLayer* pLayer);
 
        // Shader
@@ -122,16 +119,11 @@ private:
        void CommandHandlerDeleteShader(_ShaderImpl* pShader);
        void CommandHandlerBuildShaderProgram(_ShaderProgramImpl* pShaderProgram);
        void CommandHandlerDeleteShaderProgram(_ShaderProgramImpl* pShaderProgram);
-       void CommandHandlerFlush(_GlLayer* pLayer);
-
-       void CompositeLayer(_GlLayer* pLayer);
-       void CompositeNode(VisualElement* pRenderObject, Tizen::Base::Collection::ArrayList &parentLight, bool useStencil, unsigned int depth, _GlLayer* pLayer, _ViewInfo* pView);
-       void CompositeView(_GlLayer* pLayer, _RootVisualElement* pRoot, _ViewInfo* pView);
+       void CommandHandlerFlush(void);//(_GlLayer* pLayer);
 
-       bool Animate(void);
 
-       int FindRenderObject(_GlNode* pNode);
-       void EnqueueRenderObject(_GlNode* pNode, bool useStencil, unsigned int stencilIndex, bool colorMask);
+//     int FindRenderObject(_GlNode* pNode);
+//     void EnqueueRenderObject(_GlNode* pNode, bool useStencil, unsigned int stencilIndex, bool colorMask);
 
        void FlushRenderQueue(void);
        void FlushRenderQueueFinish(_GlLayer* pLayer);
@@ -139,7 +131,6 @@ private:
 
 
        static void* RenderProc(void* pData);
-       static void* CompositeProc(void* pData);
 
        _GlRenderManager(void);
        virtual ~_GlRenderManager(void);
@@ -147,6 +138,83 @@ private:
 private:
        static _GlRenderManager* __pInstance;
 
+
+       unsigned int __commandId;
+       CommandArg __commandArg;
+       result __commandResult;
+
+       _Mutex __commandTransaction;
+       _Mutex __commandLock;
+       _Waiter __commandRequest;
+       _Waiter __commandReply;
+
+       pthread_t __threadInfo;
+       pid_t __threadId;
+
+       _GlContext* __pGlContext;
+
+//     _Matrix4f __view;
+//     _Matrix4f __projection;
+//     _Matrix4f __viewProjection;
+//     _Matrix4f __flippedProjection;
+//     _Matrix4f __flippedViewProjection;
+
+//     float __eyePosition[3];
+//     Tizen::Graphics::FloatRectangle __viewport;
+
+       _GlRenderQueue* __pRenderQueue;
+       _GlRenderQueue* __pRenderQueueForFlush;
+
+//     int __queueCount;
+//     bool __needClear;
+
+//     _GlNode* __pTempNode;
+
+       unsigned int __globalLightCount;
+       Light* __globalLight[MAX_LIGHT_COUNT];
+
+       float __materialAmbient[4];
+       float __materialDiffuse[4];
+       float __materialSpecular[4];
+       float __materialEmissive[4];
+       float __materialShininess;
+       _GlLayer* __pGlLayerForFlush;// todo :CHECK IT , is it needed?
+
+       _GlCompositor* __pCompositor;
+
+       friend class _GlCompositor;
+//     friend class _RenderObject;
+       friend class _GlRenderQueue;    
+       friend class _VisualElementSurfaceManager;
+}; // _GlRenderManager
+
+
+
+class _GlRenderQueue
+{
+public:
+       enum //rendering property
+       {
+               UPDATED_PROP_VIEWPORT,
+               UPDATED_PROP_CLEAR,
+               UPDATED_PROP_RENDER_TARGET,
+               UPDATED_PROP_PROJECTION,
+               UPDATED_PROP_LAYER
+       };
+       _GlRenderQueue(_GlRenderManager* pManager);
+       ~_GlRenderQueue(void);
+
+       void SetLayer(_GlLayer* pLayer);
+       void SetViewport(int x, int y, int width, int height);
+       void SetClear(void) { __renderingProps|=UPDATED_PROP_CLEAR; }
+       void SetRenderTarget(_GlVisualElementSurfaceImpl* pRenderTarget);
+       int FindRenderObject(_GlNode* pNode);
+       void EnqueueRenderObject(_GlNode* pNode, bool useStencil, unsigned int stencilIndex, bool colorMask);
+       void FlushRenderQueue(void);
+       void FlushRenderQueueFinish(_GlLayer* pLayer);
+       void Reset(void);
+
+
        class _RenderObject : public Tizen::Base::Object
        {
        public:
@@ -240,59 +308,17 @@ private:
                const float* __pJointsMatrices;
                unsigned int __jointsCount;
        };
-
-       unsigned int __commandId;
-       CommandArg __commandArg;
-       result __commandResult;
-
-       _Mutex __commandTransaction;
-       _Mutex __commandLock;
-       _Waiter __commandRequest;
-       _Waiter __commandReply;
-
-       pthread_t __threadInfo;
-       pid_t __threadId;
-
-       _GlContext* __pGlContext;
-
-       _Matrix4f __view;
-       _Matrix4f __projection;
-       _Matrix4f __viewProjection;
-       _Matrix4f __flippedProjection;
-       _Matrix4f __flippedViewProjection;
-
-       float __eyePosition[3];
+private:
+       unsigned int __renderingProps;
        Tizen::Graphics::FloatRectangle __viewport;
-
-       _RenderObject* __pRenderQueue;
-       _RenderObject* __pRenderQueueForFlush;
-       
-// for composite thread
-       CommandArg __commandCompositeArg;
-       pthread_t __compositeThreadInfo;
-       _Mutex __commandCompositeLock;
-       _Waiter __commandComposite;
-
        int __queueCount;
-       bool __needClear;
-
-       _GlNode* __pTempNode;
-
-       unsigned int __globalLightCount;
-       Light* __globalLight[MAX_LIGHT_COUNT];
-
-       float __materialAmbient[4];
-       float __materialDiffuse[4];
-       float __materialSpecular[4];
-       float __materialEmissive[4];
-       float __materialShininess;
-       _GlLayer* __pGlLayerForFlush;// todo :CHECK IT , is it needed?
-
-       _AnimationManager* __pAnimationManager;
+       _GlVisualElementSurfaceImpl* __pRenderTarget;
+       _GlLayer* __pLayer;
+       _RenderObject* __pRenderQueue;
+       _GlRenderManager* __pRenderManager;
 
-       friend class _RenderObject;
-       friend class _VisualElementSurfaceManager;
-}; // _GlRenderManager
+       friend class _GlRenderManager;
+};
 
 }}} //namespace Tizen { namespace Ui { namespace Animations
 
index baec993..4024657 100644 (file)
@@ -106,6 +106,7 @@ private:
 
        friend class _VisualElementSurfaceImpl;
        friend class _GlRenderManager;
+       friend class _GlRenderQueue;
        friend class _RenderObject;
 };             // _GlVisualElementSurfaceImpl
 
index 68b0d13..ad588df 100644 (file)
@@ -197,6 +197,7 @@ private:
 
        friend class _GlContext;
        friend class _GlRenderManager;
+       friend class _GlRenderQueue;
        friend class _GeometryInfo;
 };
 
index 8a87ee8..efdc497 100644 (file)
@@ -82,6 +82,7 @@ private:
        bool __downSampling;
        bool __isFirstPass;
 
+       friend class _GlCompositor;
        friend class _GlRenderManager;
 }; // _VisualElementFilterImpl
 
index 0bac735..8147c69 100644 (file)
@@ -207,6 +207,7 @@ private:
     friend class Mesh;
        friend class _MeshImportSample;
        friend class _GlRenderManager;
+       friend class _GlRenderQueue;
        friend class _VisualElementImpl;
        friend struct Header;
        friend class _MeshGeneratorImpl;
index 7b3e179..2abf6d0 100644 (file)
@@ -1533,7 +1533,7 @@ private:
        friend class _RootVisualElement;
        friend class _AnimationManager;
        friend class _DisplayManager;
-       friend class _GlRenderManager;
+       friend class _GlCompositor;
        friend class _NativeLayer;
        friend class _TransactionNode;
        friend class _GlNode;