0026122: Visualization, TKOpenGl - clipping and capping is broken when ffp is disable...
[occt.git] / src / OpenGl / OpenGl_Workspace.cxx
index d2619f9..ede088c 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <OpenGl_GlCore15.hxx>
-#include <OpenGl_ArbFBO.hxx>
+#include <OpenGl_Workspace.hxx>
 
 #include <InterfaceGraphic.hxx>
 
+#include <OpenGl_ArbFBO.hxx>
 #include <OpenGl_AspectLine.hxx>
 #include <OpenGl_AspectFace.hxx>
 #include <OpenGl_AspectMarker.hxx>
 #include <OpenGl_Context.hxx>
 #include <OpenGl_Element.hxx>
 #include <OpenGl_FrameBuffer.hxx>
+#include <OpenGl_GlCore15.hxx>
+#include <OpenGl_SceneGeometry.hxx>
 #include <OpenGl_Structure.hxx>
 #include <OpenGl_Sampler.hxx>
-#include <OpenGl_ShaderManager.hxx>
 #include <OpenGl_Texture.hxx>
-#include <OpenGl_Utils.hxx>
 #include <OpenGl_View.hxx>
-#include <OpenGl_Workspace.hxx>
+#include <OpenGl_Window.hxx>
 
 #include <Graphic3d_TextureParams.hxx>
-#include <Graphic3d_GraphicDriver.hxx>
-
-#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE)
-  #include <OpenGl_AVIWriter.hxx>
+#include <Graphic3d_TransformUtils.hxx>
+
+#ifdef HAVE_GL2PS
+  #include <gl2ps.h>
+  /* OCC22216 NOTE: linker dependency can be switched off by undefining macro.
+     Pragma comment for gl2ps.lib is defined only here. */
+  #ifdef _MSC_VER
+  #pragma comment( lib, "gl2ps.lib" )
+  #endif
 #endif
 
-
 namespace
 {
   static const TEL_COLOUR  THE_WHITE_COLOR = { { 1.0f, 1.0f, 1.0f, 1.0f } };
@@ -49,7 +53,6 @@ namespace
   static const OpenGl_AspectLine myDefaultAspectLine;
   static const OpenGl_AspectFace myDefaultAspectFace;
   static const OpenGl_AspectMarker myDefaultAspectMarker;
-  static const OpenGl_AspectText myDefaultAspectText;
 
   static const OpenGl_TextParam myDefaultTextParam =
   {
@@ -136,27 +139,15 @@ void OpenGl_Material::Init (const OPENGL_SURF_PROP& theProp)
 // function : OpenGl_Workspace
 // purpose  :
 // =======================================================================
-OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDriver,
-                                    const CALL_DEF_WINDOW&        theCWindow,
-                                    Aspect_RenderingContext       theGContext,
-                                    const Handle(OpenGl_Caps)&    theCaps,
-                                    const Handle(OpenGl_Context)& theShareCtx)
-: OpenGl_Window (theDriver, theCWindow, theGContext, theCaps, theShareCtx),
-  NamedStatus (0),
+OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow)
+: NamedStatus (0),
   HighlightColor (&THE_WHITE_COLOR),
-  //
-  myHasFboBlit (Standard_True),
-  //
-  myViewId               (-1),
-  myAntiAliasingMode     (3),
-  myTransientDrawToFront (Standard_True),
-  myBackBufferRestored   (Standard_False),
-  myIsImmediateDrawn     (Standard_False),
+  myView (theView),
+  myWindow (theWindow),
+  myGlContext (!theWindow.IsNull() ? theWindow->GetGlContext() : NULL),
   myUseZBuffer    (Standard_True),
   myUseDepthWrite (Standard_True),
   myUseGLLight (Standard_True),
-  myIsCullingEnabled (Standard_False),
-  myFrameCounter (0),
   //
   AspectLine_set (&myDefaultAspectLine),
   AspectLine_applied (NULL),
@@ -164,54 +155,41 @@ OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDrive
   AspectFace_applied (NULL),
   AspectMarker_set (&myDefaultAspectMarker),
   AspectMarker_applied (NULL),
-  AspectText_set (&myDefaultAspectText),
-  AspectText_applied (NULL),
-  TextParam_set (&myDefaultTextParam),
-  TextParam_applied (NULL),
   ViewMatrix_applied (&myDefaultMatrix),
   StructureMatrix_applied (&myDefaultMatrix),
   myCullingMode (TelCullUndefined),
   myModelViewMatrix (myDefaultMatrix),
   PolygonOffset_applied (THE_DEFAULT_POFFSET)
 {
-  myGlContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
-  myMainSceneFbos[0]      = new OpenGl_FrameBuffer();
-  myMainSceneFbos[1]      = new OpenGl_FrameBuffer();
-  myImmediateSceneFbos[0] = new OpenGl_FrameBuffer();
-  myImmediateSceneFbos[1] = new OpenGl_FrameBuffer();
-
-  if (!myGlContext->GetResource ("OpenGl_LineAttributes", myLineAttribs))
+  if (!myGlContext.IsNull() && myGlContext->MakeCurrent())
   {
-    // share and register for release once the resource is no longer used
-    myLineAttribs = new OpenGl_LineAttributes();
-    myGlContext->ShareResource ("OpenGl_LineAttributes", myLineAttribs);
-    myLineAttribs->Init (myGlContext);
-  }
+    myGlContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
 
-  // General initialization of the context
+    if (!myGlContext->GetResource ("OpenGl_LineAttributes", myLineAttribs))
+    {
+      // share and register for release once the resource is no longer used
+      myLineAttribs = new OpenGl_LineAttributes();
+      myGlContext->ShareResource ("OpenGl_LineAttributes", myLineAttribs);
+      myLineAttribs->Init (myGlContext);
+    }
 
-#if !defined(GL_ES_VERSION_2_0)
-  if (myGlContext->core11 != NULL)
-  {
-    // Eviter d'avoir les faces mal orientees en noir.
-    // Pourrait etre utiliser pour detecter les problemes d'orientation
-    glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
+    // General initialization of the context
 
-    // Optimisation pour le Fog et l'antialiasing
-    glHint (GL_FOG_HINT,            GL_FASTEST);
-    glHint (GL_POINT_SMOOTH_HINT,   GL_FASTEST);
-  }
+  #if !defined(GL_ES_VERSION_2_0)
+    if (myGlContext->core11 != NULL)
+    {
+      // Eviter d'avoir les faces mal orientees en noir.
+      // Pourrait etre utiliser pour detecter les problemes d'orientation
+      glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
 
-  glHint (GL_LINE_SMOOTH_HINT,    GL_FASTEST);
-  glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
-#endif
+      // Optimisation pour le Fog et l'antialiasing
+      glHint (GL_FOG_HINT,            GL_FASTEST);
+      glHint (GL_POINT_SMOOTH_HINT,   GL_FASTEST);
+    }
 
-  // AA mode
-  const char* anAaEnv = ::getenv ("CALL_OPENGL_ANTIALIASING_MODE");
-  if (anAaEnv != NULL)
-  {
-    int v;
-    if (sscanf (anAaEnv, "%d", &v) > 0) myAntiAliasingMode = v;
+    glHint (GL_LINE_SMOOTH_HINT,    GL_FASTEST);
+    glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
+  #endif
   }
 
   myDefaultCappingAlgoFilter         = new OpenGl_CappingAlgoFilter();
@@ -221,27 +199,6 @@ OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDrive
   myFrontCulling.ChangeEdge()        = 0;
 }
 
-// =======================================================================
-// function : SetImmediateModeDrawToFront
-// purpose  :
-// =======================================================================
-Standard_Boolean OpenGl_Workspace::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer)
-{
-  const Standard_Boolean aPrevMode = myTransientDrawToFront;
-  myTransientDrawToFront = theDrawToFrontBuffer;
-  return aPrevMode;
-}
-
-inline void nullifyGlResource (Handle(OpenGl_Resource)&      theResource,
-                               const Handle(OpenGl_Context)& theCtx)
-{
-  if (!theResource.IsNull())
-  {
-    theResource->Release (theCtx.operator->());
-    theResource.Nullify();
-  }
-}
-
 // =======================================================================
 // function : ~OpenGl_Workspace
 // purpose  :
@@ -253,13 +210,6 @@ OpenGl_Workspace::~OpenGl_Workspace()
     myLineAttribs.Nullify();
     myGlContext->ReleaseResource ("OpenGl_LineAttributes", Standard_True);
   }
-
-  nullifyGlResource (myMainSceneFbos[0],      myGlContext);
-  nullifyGlResource (myMainSceneFbos[1],      myGlContext);
-  nullifyGlResource (myImmediateSceneFbos[0], myGlContext);
-  nullifyGlResource (myImmediateSceneFbos[1], myGlContext);
-
-  myFullScreenQuad.Release (myGlContext.operator->());
 }
 
 // =======================================================================
@@ -268,8 +218,10 @@ OpenGl_Workspace::~OpenGl_Workspace()
 // =======================================================================
 Standard_Boolean OpenGl_Workspace::Activate()
 {
-  if (!OpenGl_Window::Activate())
+  if (myWindow.IsNull() || !myWindow->Activate())
+  {
     return Standard_False;
+  }
 
   ViewMatrix_applied      = &myDefaultMatrix;
   StructureMatrix_applied = &myDefaultMatrix;
@@ -295,10 +247,6 @@ void OpenGl_Workspace::ResetAppliedAspect()
   AspectFace_applied    = NULL;
   AspectMarker_set      = &myDefaultAspectMarker;
   AspectMarker_applied  = NULL;
-  AspectText_set        = &myDefaultAspectText;
-  AspectText_applied    = NULL;
-  TextParam_set         = &myDefaultTextParam;
-  TextParam_applied     = NULL;
   PolygonOffset_applied = THE_DEFAULT_POFFSET;
   myCullingMode         = TelCullUndefined;
 
@@ -398,21 +346,8 @@ void OpenGl_Workspace::setTextureParams (Handle(OpenGl_Texture)&
   }
 
 #if !defined(GL_ES_VERSION_2_0)
-  GLint aMatrixMode = GL_TEXTURE;
   if (myGlContext->core11 != NULL)
   {
-    glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
-
-    // setup texture matrix
-    glMatrixMode (GL_TEXTURE);
-    OpenGl_Mat4 aTextureMat;
-    const Graphic3d_Vec2& aScale = aParams->Scale();
-    const Graphic3d_Vec2& aTrans = aParams->Translation();
-    OpenGl_Utils::Scale     (aTextureMat,  aScale.x(),  aScale.y(), 1.0f);
-    OpenGl_Utils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f);
-    OpenGl_Utils::Rotate    (aTextureMat, -aParams->Rotation(), 0.0f, 0.0f, 1.0f);
-    glLoadMatrixf (aTextureMat);
-
     GLint anEnvMode = GL_MODULATE; // lighting mode
     if (!aParams->IsModulate())
     {
@@ -469,12 +404,12 @@ void OpenGl_Workspace::setTextureParams (Handle(OpenGl_Texture)&
       }
       case Graphic3d_TOTM_SPRITE:
       {
-        if (GetGlContext()->core20fwd != NULL)
+        if (myGlContext->core20fwd != NULL)
         {
           glEnable  (GL_POINT_SPRITE);
           glTexEnvi (GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
           anEnvMode = GL_REPLACE;
-          GetGlContext()->core15->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
+          myGlContext->core15->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
         }
         break;
       }
@@ -625,12 +560,6 @@ void OpenGl_Workspace::setTextureParams (Handle(OpenGl_Texture)&
     default: break;
   }
 
-#if !defined(GL_ES_VERSION_2_0)
-  if (myGlContext->core11 != NULL)
-  {
-    glMatrixMode (aMatrixMode); // turn back active matrix
-  }
-#endif
   theTexture->SetParams (aParams);
 }
 
@@ -671,883 +600,714 @@ Handle(OpenGl_Texture) OpenGl_Workspace::EnableTexture (const Handle(OpenGl_Text
 }
 
 // =======================================================================
-// function : bindDefaultFbo
+// function : TelUpdatePolygonOffsets
 // purpose  :
 // =======================================================================
-void OpenGl_Workspace::bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo)
+static void TelUpdatePolygonOffsets (const TEL_POFFSET_PARAM& theOffsetData)
 {
-  OpenGl_FrameBuffer* anFbo = (theCustomFbo != NULL && theCustomFbo->IsValid())
-                            ?  theCustomFbo
-                            : (!myGlContext->DefaultFrameBuffer().IsNull()
-                             && myGlContext->DefaultFrameBuffer()->IsValid()
-                              ? myGlContext->DefaultFrameBuffer().operator->()
-                              : NULL);
-  if (anFbo != NULL)
+  if ((theOffsetData.mode & Aspect_POM_Fill) == Aspect_POM_Fill)
   {
-    anFbo->BindBuffer (myGlContext);
+    glEnable (GL_POLYGON_OFFSET_FILL);
   }
   else
   {
-  #if !defined(GL_ES_VERSION_2_0)
-    myGlContext->SetReadDrawBuffer (GL_BACK);
-  #else
-    if (myGlContext->arbFBO != NULL)
-    {
-      myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
-    }
-  #endif
+    glDisable (GL_POLYGON_OFFSET_FILL);
+  }
+
+#if !defined(GL_ES_VERSION_2_0)
+  if ((theOffsetData.mode & Aspect_POM_Line) == Aspect_POM_Line)
+  {
+    glEnable (GL_POLYGON_OFFSET_LINE);
+  }
+  else
+  {
+    glDisable (GL_POLYGON_OFFSET_LINE);
+  }
+
+  if ((theOffsetData.mode & Aspect_POM_Point) == Aspect_POM_Point)
+  {
+    glEnable (GL_POLYGON_OFFSET_POINT);
+  }
+  else
+  {
+    glDisable (GL_POLYGON_OFFSET_POINT);
   }
-  myGlContext->core11fwd->glViewport (0, 0, myWidth, myHeight);
+#endif
+
+  glPolygonOffset (theOffsetData.factor, theOffsetData.units);
 }
 
 // =======================================================================
-// function : blitBuffers
+// function : updateMaterial
 // purpose  :
 // =======================================================================
-bool OpenGl_Workspace::blitBuffers (OpenGl_FrameBuffer* theReadFbo,
-                                    OpenGl_FrameBuffer* theDrawFbo)
+void OpenGl_Workspace::updateMaterial (const int theFlag)
 {
-  if (theReadFbo == NULL)
-  {
-    return false;
-  }
-  else if (theReadFbo == theDrawFbo)
+  // Case of hidden line
+  if (AspectFace_set->InteriorStyle() == Aspect_IS_HIDDENLINE)
   {
-    return true;
+    myAspectFaceHl = *AspectFace_set; // copy all values including line edge aspect
+    myAspectFaceHl.ChangeIntFront().matcol     = myView->BackgroundColor();
+    myAspectFaceHl.ChangeIntFront().color_mask = 0;
+    myAspectFaceHl.ChangeIntFront().color_mask = 0;
+
+    AspectFace_set = &myAspectFaceHl;
+    return;
   }
 
-  // clear destination before blitting
-  if (theDrawFbo != NULL
-  &&  theDrawFbo->IsValid())
+  const OPENGL_SURF_PROP* aProps = &AspectFace_set->IntFront();
+  GLenum aFace = GL_FRONT_AND_BACK;
+  if (theFlag == TEL_BACK_MATERIAL)
   {
-    theDrawFbo->BindBuffer (myGlContext);
+    aFace  = GL_BACK;
+    aProps = &AspectFace_set->IntBack();
   }
-  else
+  else if (AspectFace_set->DistinguishingMode() == TOn
+        && !(NamedStatus & OPENGL_NS_RESMAT))
   {
-    myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
+    aFace = GL_FRONT;
   }
-#if !defined(GL_ES_VERSION_2_0)
-  myGlContext->core20fwd->glClearDepth  (1.0);
-#else
-  myGlContext->core20fwd->glClearDepthf (1.0f);
-#endif
-  myGlContext->core20fwd->glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
-/*#if !defined(GL_ES_VERSION_2_0)
-  if (myGlContext->arbFBOBlit != NULL)
+  myMatTmp.Init (*aProps);
+
+  // handling transparency
+  if (NamedStatus & OPENGL_NS_2NDPASSDO)
   {
-    theReadFbo->BindReadBuffer (myGlContext);
-    if (theDrawFbo != NULL
-     && theDrawFbo->IsValid())
-    {
-      theDrawFbo->BindDrawBuffer (myGlContext);
-    }
-    else
+    // second pass
+    myMatTmp.Diffuse.a() = aProps->env_reflexion;
+  }
+  else
+  {
+    if (aProps->env_reflexion != 0.0f)
     {
-      myGlContext->arbFBO->glBindFramebuffer (GL_DRAW_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
+      // if the material reflects the environment scene, the second pass is needed
+      NamedStatus |= OPENGL_NS_2NDPASSNEED;
     }
-    // we don't copy stencil buffer here... does it matter for performance?
-    myGlContext->arbFBOBlit->glBlitFramebuffer (0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(),
-                                                0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(),
-                                                GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
 
-    if (theDrawFbo != NULL
-      && theDrawFbo->IsValid())
+    if (aProps->trans != 1.0f)
     {
-      theDrawFbo->BindBuffer (myGlContext);
+      // render transparent
+      myMatTmp.Diffuse.a() = aProps->trans;
+      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+      glEnable    (GL_BLEND);
+      if (myUseDepthWrite)
+      {
+        glDepthMask (GL_FALSE);
+      }
     }
     else
     {
-      myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
+      // render opaque
+      if ((NamedStatus & OPENGL_NS_ANTIALIASING) == 0)
+      {
+        glBlendFunc (GL_ONE, GL_ZERO);
+        glDisable   (GL_BLEND);
+      }
+      if (myUseDepthWrite)
+      {
+        glDepthMask (GL_TRUE);
+      }
     }
   }
-  else
-#endif*/
+
+  // do not update material properties in case of zero reflection mode,
+  // because GL lighting will be disabled by OpenGl_PrimitiveArray::DrawArray() anyway.
+  if (aProps->color_mask == 0)
   {
-    myGlContext->core20fwd->glDepthFunc (GL_ALWAYS);
-    myGlContext->core20fwd->glDepthMask (GL_TRUE);
-    myGlContext->core20fwd->glEnable (GL_DEPTH_TEST);
+    return;
+  }
 
-    DisableTexture();
-    if (!myFullScreenQuad.IsValid())
+  // reset material
+  if (NamedStatus & OPENGL_NS_RESMAT)
+  {
+  #if !defined(GL_ES_VERSION_2_0)
+    if (myGlContext->core11 != NULL)
     {
-      OpenGl_Vec4 aQuad[4] =
-      {
-        OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 0.0f),
-        OpenGl_Vec4( 1.0f,  1.0f, 1.0f, 1.0f),
-        OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 0.0f),
-        OpenGl_Vec4(-1.0f,  1.0f, 0.0f, 1.0f)
-      };
-      myFullScreenQuad.Init (myGlContext, 4, 4, aQuad[0].GetData());
+      myGlContext->core11->glMaterialfv (aFace, GL_AMBIENT,   myMatTmp.Ambient.GetData());
+      myGlContext->core11->glMaterialfv (aFace, GL_DIFFUSE,   myMatTmp.Diffuse.GetData());
+      myGlContext->core11->glMaterialfv (aFace, GL_SPECULAR,  myMatTmp.Specular.GetData());
+      myGlContext->core11->glMaterialfv (aFace, GL_EMISSION,  myMatTmp.Emission.GetData());
+      myGlContext->core11->glMaterialf  (aFace, GL_SHININESS, myMatTmp.Shine());
     }
+  #endif
 
-    const Handle(OpenGl_ShaderManager)& aManager = myGlContext->ShaderManager();
-    if (myFullScreenQuad.IsValid()
-     && aManager->BindFboBlitProgram())
+    if (theFlag == TEL_FRONT_MATERIAL)
     {
-      theReadFbo->ColorTexture()       ->Bind   (myGlContext, GL_TEXTURE0 + 0);
-      theReadFbo->DepthStencilTexture()->Bind   (myGlContext, GL_TEXTURE0 + 1);
-      myFullScreenQuad.BindVertexAttrib (myGlContext, Graphic3d_TOA_POS);
+      myMatFront = myMatTmp;
+      myMatBack  = myMatTmp;
+    }
+    else
+    {
+      myMatBack = myMatTmp;
+    }
 
-      myGlContext->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
+    NamedStatus &= ~OPENGL_NS_RESMAT;
+    return;
+  }
 
-      myFullScreenQuad.UnbindVertexAttrib (myGlContext, Graphic3d_TOA_POS);
-      theReadFbo->DepthStencilTexture()->Unbind (myGlContext, GL_TEXTURE0 + 1);
-      theReadFbo->ColorTexture()       ->Unbind (myGlContext, GL_TEXTURE0 + 0);
+  // reduce updates
+  OpenGl_Material& anOld = (theFlag == TEL_FRONT_MATERIAL)
+                         ? myMatFront
+                         : myMatBack;
+#if !defined(GL_ES_VERSION_2_0)
+  if (myGlContext->core11 != NULL)
+  {
+    if (myMatTmp.Ambient.r() != anOld.Ambient.r()
+     || myMatTmp.Ambient.g() != anOld.Ambient.g()
+     || myMatTmp.Ambient.b() != anOld.Ambient.b())
+    {
+      myGlContext->core11->glMaterialfv (aFace, GL_AMBIENT, myMatTmp.Ambient.GetData());
     }
-    else
+    if (myMatTmp.Diffuse.r() != anOld.Diffuse.r()
+     || myMatTmp.Diffuse.g() != anOld.Diffuse.g()
+     || myMatTmp.Diffuse.b() != anOld.Diffuse.b()
+     || fabs (myMatTmp.Diffuse.a() - anOld.Diffuse.a()) > 0.01f)
     {
-      TCollection_ExtendedString aMsg = TCollection_ExtendedString()
-        + "Error! FBO blitting has failed";
-      myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
-                                GL_DEBUG_TYPE_ERROR_ARB,
-                                0,
-                                GL_DEBUG_SEVERITY_HIGH_ARB,
-                                aMsg);
-      myHasFboBlit = Standard_False;
-      theReadFbo->Release (myGlContext.operator->());
-      return true;
+      myGlContext->core11->glMaterialfv (aFace, GL_DIFFUSE, myMatTmp.Diffuse.GetData());
+    }
+    if (myMatTmp.Specular.r() != anOld.Specular.r()
+     || myMatTmp.Specular.g() != anOld.Specular.g()
+     || myMatTmp.Specular.b() != anOld.Specular.b())
+    {
+      myGlContext->core11->glMaterialfv (aFace, GL_SPECULAR, myMatTmp.Specular.GetData());
+    }
+    if (myMatTmp.Emission.r() != anOld.Emission.r()
+     || myMatTmp.Emission.g() != anOld.Emission.g()
+     || myMatTmp.Emission.b() != anOld.Emission.b())
+    {
+      myGlContext->core11->glMaterialfv (aFace, GL_EMISSION, myMatTmp.Emission.GetData());
+    }
+    if (myMatTmp.Shine() != anOld.Shine())
+    {
+      myGlContext->core11->glMaterialf (aFace, GL_SHININESS, myMatTmp.Shine());
     }
   }
-  return true;
+#endif
+  anOld = myMatTmp;
+  if (aFace == GL_FRONT_AND_BACK)
+  {
+    myMatBack = myMatTmp;
+  }
 }
 
 // =======================================================================
-// function : drawStereoPair
+// function : SetAspectLine
 // purpose  :
 // =======================================================================
-void OpenGl_Workspace::drawStereoPair (const Graphic3d_CView& theCView)
+const OpenGl_AspectLine * OpenGl_Workspace::SetAspectLine(const OpenGl_AspectLine *AnAspect)
 {
-  OpenGl_FrameBuffer* aPair[2] =
-  {
-    myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL,
-    myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL
-  };
-  if (aPair[0] == NULL
-  ||  aPair[1] == NULL
-  || !myTransientDrawToFront)
-  {
-    aPair[0] = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL;
-    aPair[1] = myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL;
-  }
+  const OpenGl_AspectLine *AspectLine_old = AspectLine_set;
+  AspectLine_set = AnAspect;
+  return AspectLine_old;
+}
 
-  if (aPair[0] == NULL
-   || aPair[1] == NULL)
-  {
-    return;
-  }
+// =======================================================================
+// function : SetAspectFace
+// purpose  :
+// =======================================================================
+const OpenGl_AspectFace * OpenGl_Workspace::SetAspectFace(const OpenGl_AspectFace *AnAspect)
+{
+  const OpenGl_AspectFace *AspectFace_old = AspectFace_set;
+  AspectFace_set = AnAspect;
+  return AspectFace_old;
+}
 
-  Standard_Boolean toReverse = theCView.RenderParams.ToReverseStereo;
-  const Standard_Boolean isOddY = (theCView.DefWindow.top + theCView.DefWindow.dy) % 2 == 1;
-  const Standard_Boolean isOddX =  theCView.DefWindow.left % 2 == 1;
-  if (isOddY
-   && (theCView.RenderParams.StereoMode == Graphic3d_StereoMode_RowInterlaced
-    || theCView.RenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard))
-  {
-    toReverse = !toReverse;
-  }
-  if (isOddX
-   && (theCView.RenderParams.StereoMode == Graphic3d_StereoMode_ColumnInterlaced
-    || theCView.RenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard))
-  {
-    toReverse = !toReverse;
-  }
+// =======================================================================
+// function : SetAspectMarker
+// purpose  :
+// =======================================================================
+const OpenGl_AspectMarker * OpenGl_Workspace::SetAspectMarker(const OpenGl_AspectMarker *AnAspect)
+{
+  const OpenGl_AspectMarker *AspectMarker_old = AspectMarker_set;
+  AspectMarker_set = AnAspect;
+  return AspectMarker_old;
+}
+
+// =======================================================================
+// function : SetAspectText
+// purpose  :
+// =======================================================================
+const OpenGl_AspectText * OpenGl_Workspace::SetAspectText(const OpenGl_AspectText *AnAspect)
+{
+  const OpenGl_AspectText *AspectText_old = AspectText_set;
+  AspectText_set = AnAspect;
+  return AspectText_old;
+}
 
-  if (toReverse)
+// =======================================================================
+// function : AspectLine
+// purpose  :
+// =======================================================================
+const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean theWithApply)
+{
+  if (theWithApply)
   {
-    std::swap (aPair[0], aPair[1]);
+    AspectLine_applied = AspectLine_set;
   }
 
-  myGlContext->core20fwd->glDepthFunc (GL_ALWAYS);
-  myGlContext->core20fwd->glDepthMask (GL_TRUE);
-  myGlContext->core20fwd->glEnable (GL_DEPTH_TEST);
+  return AspectLine_set;
+}
 
-  DisableTexture();
-  if (!myFullScreenQuad.IsValid())
+// =======================================================================
+// function : AspectFace
+// purpose  :
+// =======================================================================
+const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean theToApply)
+{
+  if (!theToApply)
   {
-    OpenGl_Vec4 aQuad[4] =
-    {
-      OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 0.0f),
-      OpenGl_Vec4( 1.0f,  1.0f, 1.0f, 1.0f),
-      OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 0.0f),
-      OpenGl_Vec4(-1.0f,  1.0f, 0.0f, 1.0f)
-    };
-    myFullScreenQuad.Init (myGlContext, 4, 4, aQuad[0].GetData());
+    return AspectFace_set;
   }
 
-  const Handle(OpenGl_ShaderManager)& aManager = myGlContext->ShaderManager();
-  if (myFullScreenQuad.IsValid()
-   && aManager->BindStereoProgram (theCView.RenderParams.StereoMode))
+  if (myView->BackfacingModel() == Graphic3d_TOBM_AUTOMATIC)
   {
-    if (theCView.RenderParams.StereoMode == Graphic3d_StereoMode_Anaglyph)
+    // manage back face culling mode, disable culling when clipping is enabled
+    TelCullMode aCullingMode = (myGlContext->Clipping().IsClippingOrCappingOn()
+                             || AspectFace_set->InteriorStyle() == Aspect_IS_HATCH)
+                             ? TelCullNone
+                             : (TelCullMode )AspectFace_set->CullingMode();
+    if (aCullingMode != TelCullNone
+     && !(NamedStatus & OPENGL_NS_2NDPASSDO))
     {
-      OpenGl_Mat4 aFilterL, aFilterR;
-      aFilterL.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
-      aFilterR.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
-      switch (theCView.RenderParams.AnaglyphFilter)
+      // disable culling in case of translucent shading aspect
+      if (AspectFace_set->IntFront().trans != 1.0f)
       {
-        case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple:
-        {
-          aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
-          aFilterR.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
-          aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
-          break;
-        }
-        case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized:
-        {
-          aFilterL.SetRow (0, Graphic3d_Vec4 ( 0.4154f,      0.4710f,      0.16666667f, 0.0f));
-          aFilterL.SetRow (1, Graphic3d_Vec4 (-0.0458f,     -0.0484f,     -0.0257f,     0.0f));
-          aFilterL.SetRow (2, Graphic3d_Vec4 (-0.0547f,     -0.0615f,      0.0128f,     0.0f));
-          aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f,         0.0f,         0.0f,        0.0f));
-          aFilterR.SetRow (0, Graphic3d_Vec4 (-0.01090909f, -0.03636364f, -0.00606061f, 0.0f));
-          aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.37560000f,  0.73333333f,  0.01111111f, 0.0f));
-          aFilterR.SetRow (2, Graphic3d_Vec4 (-0.06510000f, -0.12870000f,  1.29710000f, 0.0f));
-          aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f,                0.0f,  0.0f,        0.0f));
-          break;
-        }
-        case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple:
-        {
-          aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
-          aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
-          aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
-          break;
-        }
-        case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized:
+        aCullingMode = TelCullNone;
+      }
+    }
+    if (myCullingMode != aCullingMode)
+    {
+      myCullingMode = aCullingMode;
+      switch (myCullingMode)
+      {
+        case TelCullNone:
+        case TelCullUndefined:
         {
-          aFilterL.SetRow (0, Graphic3d_Vec4 ( 1.062f, -0.205f,  0.299f, 0.0f));
-          aFilterL.SetRow (1, Graphic3d_Vec4 (-0.026f,  0.908f,  0.068f, 0.0f));
-          aFilterL.SetRow (2, Graphic3d_Vec4 (-0.038f, -0.173f,  0.022f, 0.0f));
-          aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f,    0.0f,    0.0f,   0.0f));
-          aFilterR.SetRow (0, Graphic3d_Vec4 (-0.016f, -0.123f, -0.017f, 0.0f));
-          aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.006f,  0.062f, -0.017f, 0.0f));
-          aFilterR.SetRow (2, Graphic3d_Vec4 ( 0.094f,  0.185f,  0.911f, 0.0f));
-          aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f,    0.0f,    0.0f,   0.0f));
+          glDisable (GL_CULL_FACE);
           break;
         }
-        case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple:
+        case TelCullFront:
         {
-          aFilterR.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
-          aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
-          aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
+          glCullFace (GL_FRONT);
+          glEnable (GL_CULL_FACE);
           break;
         }
-        case Graphic3d_RenderingParams::Anaglyph_UserDefined:
+        case TelCullBack:
         {
-          aFilterL = theCView.RenderParams.AnaglyphLeft;
-          aFilterR = theCView.RenderParams.AnaglyphRight;
+          glCullFace (GL_BACK);
+          glEnable (GL_CULL_FACE);
           break;
         }
       }
-      myGlContext->ActiveProgram()->SetUniform (myGlContext, "uMultL", aFilterL);
-      myGlContext->ActiveProgram()->SetUniform (myGlContext, "uMultR", aFilterR);
     }
-
-    aPair[0]->ColorTexture()->Bind (myGlContext, GL_TEXTURE0 + 0);
-    aPair[1]->ColorTexture()->Bind (myGlContext, GL_TEXTURE0 + 1);
-    myFullScreenQuad.BindVertexAttrib (myGlContext, 0);
-
-    myGlContext->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
-
-    myFullScreenQuad.UnbindVertexAttrib (myGlContext, 0);
-    aPair[1]->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + 1);
-    aPair[0]->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + 0);
-  }
-  else
-  {
-    TCollection_ExtendedString aMsg = TCollection_ExtendedString()
-      + "Error! Anaglyph has failed";
-    myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
-                              GL_DEBUG_TYPE_ERROR_ARB,
-                              0,
-                              GL_DEBUG_SEVERITY_HIGH_ARB,
-                              aMsg);
-  }
-}
-
-// =======================================================================
-// function : Redraw
-// purpose  :
-// =======================================================================
-void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView,
-                               const Aspect_CLayer2d& theCUnderLayer,
-                               const Aspect_CLayer2d& theCOverLayer)
-{
-  if (!Activate())
-  {
-    return;
   }
 
-  if (mySwapInterval != myGlContext->caps->swapInterval)
+  if (AspectFace_set == AspectFace_applied)
   {
-    mySwapInterval = myGlContext->caps->swapInterval;
-    myGlContext->SetSwapInterval (mySwapInterval);
+    return AspectFace_set;
   }
 
-  ++myFrameCounter;
-  myIsCullingEnabled = theCView.IsCullingEnabled;
-  const Graphic3d_StereoMode      aStereoMode  = theCView.RenderParams.StereoMode;
-  const Handle(Graphic3d_Camera)& aCamera      = myView->Camera();
-  Graphic3d_Camera::Projection    aProjectType = aCamera->ProjectionType();
-
-  // release pending GL resources
-  myGlContext->ReleaseDelayed();
-
-  // fetch OpenGl context state
-  myGlContext->FetchState();
-
-  OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO;
-  bool toSwap = myGlContext->IsRender()
-            && !myGlContext->caps->buffersNoSwap
-            &&  aFrameBuffer == NULL;
-
-  Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWidth;
-  Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myHeight;
-
-  if ( aFrameBuffer == NULL
-   && !myGlContext->DefaultFrameBuffer().IsNull()
-   &&  myGlContext->DefaultFrameBuffer()->IsValid())
-  {
-    aFrameBuffer = myGlContext->DefaultFrameBuffer().operator->();
-  }
-
-  if (myHasFboBlit
-   && (myTransientDrawToFront || aProjectType == Graphic3d_Camera::Projection_Stereo))
+#if !defined(GL_ES_VERSION_2_0)
+  const Aspect_InteriorStyle anIntstyle = AspectFace_set->InteriorStyle();
+  if (AspectFace_applied == NULL || AspectFace_applied->InteriorStyle() != anIntstyle)
   {
-    if (myMainSceneFbos[0]->GetVPSizeX() != aSizeX
-     || myMainSceneFbos[0]->GetVPSizeY() != aSizeY)
+    switch (anIntstyle)
     {
-      // prepare FBOs containing main scene
-      // for further blitting and rendering immediate presentations on top
-      if (myGlContext->core20fwd != NULL)
+      case Aspect_IS_EMPTY:
+      case Aspect_IS_HOLLOW:
       {
-        myMainSceneFbos[0]->Init (myGlContext, aSizeX, aSizeY);
+        glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+        break;
       }
-    }
-  }
-  else
-  {
-    myMainSceneFbos     [0]->Release (myGlContext.operator->());
-    myMainSceneFbos     [1]->Release (myGlContext.operator->());
-    myImmediateSceneFbos[0]->Release (myGlContext.operator->());
-    myImmediateSceneFbos[1]->Release (myGlContext.operator->());
-    myMainSceneFbos     [0]->ChangeViewport (0, 0);
-    myMainSceneFbos     [1]->ChangeViewport (0, 0);
-    myImmediateSceneFbos[0]->ChangeViewport (0, 0);
-    myImmediateSceneFbos[1]->ChangeViewport (0, 0);
-  }
-
-  if (aProjectType == Graphic3d_Camera::Projection_Stereo
-   && myMainSceneFbos[0]->IsValid())
-  {
-    myMainSceneFbos[1]->InitLazy (myGlContext, aSizeX, aSizeY);
-    if (!myMainSceneFbos[1]->IsValid())
-    {
-      // no enough memory?
-      aProjectType = Graphic3d_Camera::Projection_Perspective;
-    }
-    else if (!myTransientDrawToFront)
-    {
-      //
-    }
-    else if (!myGlContext->HasStereoBuffers()
-           || aStereoMode != Graphic3d_StereoMode_QuadBuffer)
-    {
-      myImmediateSceneFbos[0]->InitLazy (myGlContext, aSizeX, aSizeY);
-      myImmediateSceneFbos[1]->InitLazy (myGlContext, aSizeX, aSizeY);
-      if (!myImmediateSceneFbos[0]->IsValid()
-       || !myImmediateSceneFbos[1]->IsValid())
+      case Aspect_IS_HATCH:
+      {
+        glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+        myLineAttribs->SetTypeOfHatch (AspectFace_applied != NULL ? AspectFace_applied->Hatch() : TEL_HS_SOLID);
+        break;
+      }
+      case Aspect_IS_SOLID:
+      case Aspect_IS_HIDDENLINE:
+      {
+        glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+        if (myGlContext->core11 != NULL)
+        {
+          glDisable (GL_POLYGON_STIPPLE);
+        }
+        break;
+      }
+      case Aspect_IS_POINT:
       {
-        aProjectType = Graphic3d_Camera::Projection_Perspective;
+        glPolygonMode (GL_FRONT_AND_BACK, GL_POINT);
+        break;
       }
     }
   }
 
-  if (aProjectType == Graphic3d_Camera::Projection_Stereo)
+  if (anIntstyle == Aspect_IS_HATCH)
   {
-    OpenGl_FrameBuffer* aMainFbos[2] =
-    {
-      myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL,
-      myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL
-    };
-    OpenGl_FrameBuffer* anImmFbos[2] =
-    {
-      myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL,
-      myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL
-    };
-
-    if (!myTransientDrawToFront)
-    {
-      anImmFbos[0] = aMainFbos[0];
-      anImmFbos[1] = aMainFbos[1];
-    }
-    else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
-          || aStereoMode == Graphic3d_StereoMode_QuadBuffer)
+    const Tint hatchstyle = AspectFace_set->Hatch();
+    if (AspectFace_applied == NULL || AspectFace_applied->Hatch() != hatchstyle)
     {
-      anImmFbos[0] = NULL;
-      anImmFbos[1] = NULL;
-    }
-
-  #if !defined(GL_ES_VERSION_2_0)
-    myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
-  #endif
-    redraw1 (theCView, theCUnderLayer, theCOverLayer,
-             aMainFbos[0], Graphic3d_Camera::Projection_MonoLeftEye);
-    myBackBufferRestored = Standard_True;
-    myIsImmediateDrawn   = Standard_False;
-  #if !defined(GL_ES_VERSION_2_0)
-    myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
-  #endif
-    if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aMainFbos[0], aProjectType, anImmFbos[0]))
-    {
-      toSwap = false;
-    }
-    else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
-          && toSwap)
-    {
-      myGlContext->SwapBuffers();
+      myLineAttribs->SetTypeOfHatch (hatchstyle);
     }
+  }
+#endif
 
-  #if !defined(GL_ES_VERSION_2_0)
-    myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK);
-  #endif
-    redraw1 (theCView, theCUnderLayer, theCOverLayer,
-             aMainFbos[1], Graphic3d_Camera::Projection_MonoRightEye);
-    myBackBufferRestored = Standard_True;
-    myIsImmediateDrawn   = Standard_False;
-    if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aMainFbos[1], aProjectType, anImmFbos[1]))
+  // Aspect_POM_None means: do not change current settings
+  if ((AspectFace_set->PolygonOffset().mode & Aspect_POM_None) != Aspect_POM_None)
+  {
+    if (PolygonOffset_applied.mode   != AspectFace_set->PolygonOffset().mode
+     || PolygonOffset_applied.factor != AspectFace_set->PolygonOffset().factor
+     || PolygonOffset_applied.units  != AspectFace_set->PolygonOffset().units)
     {
-      toSwap = false;
+      SetPolygonOffset (AspectFace_set->PolygonOffset().mode,
+                        AspectFace_set->PolygonOffset().factor,
+                        AspectFace_set->PolygonOffset().units);
     }
+  }
 
-    if (anImmFbos[0] != NULL)
-    {
-      bindDefaultFbo (aFrameBuffer);
-      drawStereoPair (theCView);
-    }
+  updateMaterial (TEL_FRONT_MATERIAL);
+  if (AspectFace_set->DistinguishingMode() == TOn)
+  {
+    updateMaterial (TEL_BACK_MATERIAL);
   }
-  else
+
+  if ((NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0)
   {
-    OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL;
-  #if !defined(GL_ES_VERSION_2_0)
-    if (aMainFbo     == NULL
-     && aFrameBuffer == NULL)
+    if (AspectFace_set->DoTextureMap())
     {
-      myGlContext->SetReadDrawBuffer (GL_BACK);
+      EnableTexture (AspectFace_set->TextureRes (myGlContext),
+                     AspectFace_set->TextureParams());
     }
-  #endif
-    redraw1 (theCView, theCUnderLayer, theCOverLayer,
-             aMainFbo != NULL ? aMainFbo : aFrameBuffer, aProjectType);
-    myBackBufferRestored = Standard_True;
-    myIsImmediateDrawn   = Standard_False;
-    if (!redrawImmediate (theCView, theCOverLayer, theCUnderLayer, aMainFbo, aProjectType, aFrameBuffer))
+    else
     {
-      toSwap = false;
+      DisableTexture();
     }
   }
 
-#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE)
-  if (OpenGl_AVIWriter_AllowWriting (theCView.DefWindow.XWindow))
-  {
-    GLint params[4];
-    glGetIntegerv (GL_VIEWPORT, params);
-    int nWidth  = params[2] & ~0x7;
-    int nHeight = params[3] & ~0x7;
-
-    const int nBitsPerPixel = 24;
-    GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8];
+  AspectFace_applied = AspectFace_set;
+  return AspectFace_set;
+}
 
-    glPixelStorei (GL_PACK_ALIGNMENT, 1);
-    glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData);
-    OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel);
-    delete[] aDumpData;
-  }
-#endif
+//=======================================================================
+//function : SetPolygonOffset
+//purpose  :
+//=======================================================================
+void OpenGl_Workspace::SetPolygonOffset (int theMode,
+                                         Standard_ShortReal theFactor,
+                                         Standard_ShortReal theUnits)
+{
+  PolygonOffset_applied.mode   = theMode;
+  PolygonOffset_applied.factor = theFactor;
+  PolygonOffset_applied.units  = theUnits;
 
-  // bind default FBO
-  bindDefaultFbo();
+  TelUpdatePolygonOffsets (PolygonOffset_applied);
+}
 
-  // Swap the buffers
-  if (toSwap)
+// =======================================================================
+// function : AspectMarker
+// purpose  :
+// =======================================================================
+const OpenGl_AspectMarker* OpenGl_Workspace::AspectMarker (const Standard_Boolean theToApply)
+{
+  if (theToApply && (AspectMarker_set != AspectMarker_applied))
   {
-    GetGlContext()->SwapBuffers();
-    if (!myMainSceneFbos[0]->IsValid())
+    if (!AspectMarker_applied || (AspectMarker_set->Scale() != AspectMarker_applied->Scale()))
     {
-      myBackBufferRestored = Standard_False;
+    #if !defined(GL_ES_VERSION_2_0)
+      glPointSize (AspectMarker_set->Scale());
+    #ifdef HAVE_GL2PS
+      gl2psPointSize (AspectMarker_set->Scale());
+    #endif
+    #endif
     }
+    AspectMarker_applied = AspectMarker_set;
   }
-  else
-  {
-    myGlContext->core11fwd->glFlush();
-  }
-
-  // reset render mode state
-  myGlContext->FetchState();
+  return AspectMarker_set;
 }
 
 // =======================================================================
-// function : redraw1
+// function : AspectText
 // purpose  :
 // =======================================================================
-void OpenGl_Workspace::redraw1 (const Graphic3d_CView&               theCView,
-                                const Aspect_CLayer2d&               theCUnderLayer,
-                                const Aspect_CLayer2d&               theCOverLayer,
-                                OpenGl_FrameBuffer*                  theReadDrawFbo,
-                                const Graphic3d_Camera::Projection   theProjection)
+const OpenGl_AspectText* OpenGl_Workspace::AspectText (const Standard_Boolean theWithApply)
 {
-  if (myView.IsNull())
+  if (theWithApply)
   {
-    return;
-  }
-
-  if (theReadDrawFbo != NULL)
-  {
-    theReadDrawFbo->BindBuffer    (myGlContext);
-    theReadDrawFbo->SetupViewport (myGlContext);
-  }
-  else
-  {
-    myGlContext->core11fwd->glViewport (0, 0, myWidth, myHeight);
+    AspectText_applied = AspectText_set;
   }
 
-  // request reset of material
-  NamedStatus |= OPENGL_NS_RESMAT;
-
-  myUseZBuffer    = Standard_True;
-  myUseDepthWrite = Standard_True;
-  GLbitfield toClear = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
-  glDepthFunc (GL_LEQUAL);
-  glDepthMask (GL_TRUE);
-  glEnable (GL_DEPTH_TEST);
-
-#if !defined(GL_ES_VERSION_2_0)
-  glClearDepth (1.0);
-#else
-  glClearDepthf (1.0f);
-#endif
-
-  if (NamedStatus & OPENGL_NS_WHITEBACK)
-  {
-    // set background to white
-    glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
-  }
-  else
-  {
-    glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f);
-  }
-
-  glClear (toClear);
-
-  Handle(OpenGl_Workspace) aWS (this);
-  myView->Render (myPrintContext, aWS, theReadDrawFbo, theProjection, theCView, theCUnderLayer, theCOverLayer, Standard_False);
+  return AspectText_set;
 }
 
 // =======================================================================
-// function : copyBackToFront
+// function : Width
 // purpose  :
 // =======================================================================
-void OpenGl_Workspace::copyBackToFront()
+Standard_Integer OpenGl_Workspace::Width()  const
 {
-#if !defined(GL_ES_VERSION_2_0)
+  return !myView->GlWindow().IsNull() ? myView->GlWindow()->Width() : 0;
+}
 
-  OpenGl_Mat4 aProjectMat;
-  OpenGl_Utils::Ortho2D<Standard_ShortReal> (aProjectMat,
-    0.f, static_cast<GLfloat> (myWidth), 0.f, static_cast<GLfloat> (myHeight));
+// =======================================================================
+// function : Height
+// purpose  :
+// =======================================================================
+Standard_Integer OpenGl_Workspace::Height() const
+{
+  return !myView->GlWindow().IsNull() ? myView->GlWindow()->Height() : 0;
+}
 
-  myGlContext->WorldViewState.Push();
-  myGlContext->ProjectionState.Push();
+// =======================================================================
+// function : UseGLLight
+// purpose  :
+// =======================================================================
+Standard_Boolean OpenGl_Workspace::UseGLLight() const
+{
+  return myView->IsGLLightEnabled();
+}
 
-  myGlContext->WorldViewState.SetIdentity();
-  myGlContext->ProjectionState.SetCurrent (aProjectMat);
+// =======================================================================
+// function : AntiAliasingMode
+// purpose  :
+// =======================================================================
+Standard_Integer OpenGl_Workspace::AntiAliasingMode() const
+{
+  return myView->IsAntialiasingEnabled();
+}
 
-  myGlContext->ApplyProjectionMatrix();
-  myGlContext->ApplyWorldViewMatrix();
+// =======================================================================
+// function : IsCullingEnabled
+// purpose  :
+// =======================================================================
+Standard_Boolean OpenGl_Workspace::IsCullingEnabled() const
+{
+  return myView->IsCullingEnabled();
+}
 
-  DisableFeatures();
+// =======================================================================
+// function : FBOCreate
+// purpose  :
+// =======================================================================
+Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth,
+                                                      const Standard_Integer theHeight)
+{
+  // activate OpenGL context
+  if (!Activate())
+    return NULL;
 
-  switch (myGlContext->DrawBuffer())
+  // create the FBO
+  const Handle(OpenGl_Context)& aCtx = GetGlContext();
+  OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer();
+  if (!aFrameBuffer->Init (aCtx, theWidth, theHeight))
   {
-    case GL_BACK_LEFT:
-    {
-      myGlContext->SetReadBuffer (GL_BACK_LEFT);
-      myGlContext->SetDrawBuffer (GL_FRONT_LEFT);
-      break;
-    }
-    case GL_BACK_RIGHT:
-    {
-      myGlContext->SetReadBuffer (GL_BACK_RIGHT);
-      myGlContext->SetDrawBuffer (GL_FRONT_RIGHT);
-      break;
-    }
-    default:
-    {
-      myGlContext->SetReadBuffer (GL_BACK);
-      myGlContext->SetDrawBuffer (GL_FRONT);
-      break;
-    }
+    aFrameBuffer->Release (aCtx.operator->());
+    delete aFrameBuffer;
+    return NULL;
   }
-
-  glRasterPos2i (0, 0);
-  glCopyPixels  (0, 0, myWidth + 1, myHeight + 1, GL_COLOR);
-  //glCopyPixels  (0, 0, myWidth + 1, myHeight + 1, GL_DEPTH);
-
-  EnableFeatures();
-
-  myGlContext->WorldViewState.Pop();
-  myGlContext->ProjectionState.Pop();
-  myGlContext->ApplyProjectionMatrix();
-
-  // read/write from front buffer now
-  myGlContext->SetReadBuffer (myGlContext->DrawBuffer());
-#endif
-  myIsImmediateDrawn = Standard_False;
+  return (Graphic3d_PtrFrameBuffer )aFrameBuffer;
 }
 
 // =======================================================================
-// function : DisplayCallback
+// function : FBORelease
 // purpose  :
 // =======================================================================
-void OpenGl_Workspace::DisplayCallback (const Graphic3d_CView& theCView,
-                                        Standard_Integer       theReason)
+void OpenGl_Workspace::FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr)
 {
-  if (theCView.GDisplayCB == NULL)
+  // activate OpenGL context
+  if (!Activate()
+   || theFBOPtr == NULL)
   {
     return;
   }
 
-  Aspect_GraphicCallbackStruct aCallData;
-  aCallData.reason    = theReason;
-  aCallData.glContext = myGlContext;
-  aCallData.wsID      = theCView.WsId;
-  aCallData.viewID    = theCView.ViewId;
-  aCallData.IsCoreProfile = (myGlContext->core11 == NULL);
-  theCView.GDisplayCB (theCView.DefWindow.XWindow, theCView.GClientData, &aCallData);
+  // release the object
+  OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer*)theFBOPtr;
+  if (aFrameBuffer != NULL)
+  {
+    aFrameBuffer->Release (GetGlContext().operator->());
+  }
+  delete aFrameBuffer;
 }
 
-// =======================================================================
-// function : RedrawImmediate
-// purpose  :
-// =======================================================================
-void OpenGl_Workspace::RedrawImmediate (const Graphic3d_CView& theCView,
-                                        const Aspect_CLayer2d& theCUnderLayer,
-                                        const Aspect_CLayer2d& theCOverLayer)
+inline bool getDataFormat (const Image_PixMap& theData,
+                           GLenum&             thePixelFormat,
+                           GLenum&             theDataType)
 {
-  const Handle(Graphic3d_Camera)& aCamera      = myView->Camera();
-  Graphic3d_Camera::Projection    aProjectType = aCamera->ProjectionType();
-  OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO;
-  if ( aFrameBuffer == NULL
-   && !myGlContext->DefaultFrameBuffer().IsNull()
-   &&  myGlContext->DefaultFrameBuffer()->IsValid())
+  thePixelFormat = GL_RGB;
+  theDataType    = GL_UNSIGNED_BYTE;
+  switch (theData.Format())
   {
-    aFrameBuffer = myGlContext->DefaultFrameBuffer().operator->();
+  #if !defined(GL_ES_VERSION_2_0)
+    case Image_PixMap::ImgGray:
+      thePixelFormat = GL_DEPTH_COMPONENT;
+      theDataType    = GL_UNSIGNED_BYTE;
+      return true;
+    case Image_PixMap::ImgGrayF:
+      thePixelFormat = GL_DEPTH_COMPONENT;
+      theDataType    = GL_FLOAT;
+      return true;
+    case Image_PixMap::ImgBGR:
+      thePixelFormat = GL_BGR;
+      theDataType    = GL_UNSIGNED_BYTE;
+      return true;
+    case Image_PixMap::ImgBGRA:
+    case Image_PixMap::ImgBGR32:
+      thePixelFormat = GL_BGRA;
+      theDataType    = GL_UNSIGNED_BYTE;
+      return true;
+    case Image_PixMap::ImgBGRF:
+      thePixelFormat = GL_BGR;
+      theDataType    = GL_FLOAT;
+      return true;
+    case Image_PixMap::ImgBGRAF:
+      thePixelFormat = GL_BGRA;
+      theDataType    = GL_FLOAT;
+      return true;
+  #else
+    case Image_PixMap::ImgGray:
+    case Image_PixMap::ImgGrayF:
+    case Image_PixMap::ImgBGR:
+    case Image_PixMap::ImgBGRA:
+    case Image_PixMap::ImgBGR32:
+    case Image_PixMap::ImgBGRF:
+    case Image_PixMap::ImgBGRAF:
+      return false;
+  #endif
+    case Image_PixMap::ImgRGB:
+      thePixelFormat = GL_RGB;
+      theDataType    = GL_UNSIGNED_BYTE;
+      return true;
+    case Image_PixMap::ImgRGBA:
+    case Image_PixMap::ImgRGB32:
+      thePixelFormat = GL_RGBA;
+      theDataType    = GL_UNSIGNED_BYTE;
+      return true;
+    case Image_PixMap::ImgRGBF:
+      thePixelFormat = GL_RGB;
+      theDataType    = GL_FLOAT;
+      return true;
+    case Image_PixMap::ImgRGBAF:
+      thePixelFormat = GL_RGBA;
+      theDataType    = GL_FLOAT;
+      return true;
+    case Image_PixMap::ImgAlpha:
+    case Image_PixMap::ImgAlphaF:
+      return false; // GL_ALPHA is no more supported in core context
+    case Image_PixMap::ImgUNKNOWN:
+      return false;
   }
+  return false;
+}
 
-  const Graphic3d_StereoMode aStereoMode = theCView.RenderParams.StereoMode;
-  if (aProjectType == Graphic3d_Camera::Projection_Stereo)
-  {
-    if (aFrameBuffer != NULL)
-    {
-      // implicitly switch to mono camera for image dump
-      aProjectType = Graphic3d_Camera::Projection_Perspective;
-    }
-    else if (myMainSceneFbos[0]->IsValid()
-         && !myMainSceneFbos[1]->IsValid())
-    {
-      aProjectType = Graphic3d_Camera::Projection_Perspective;
-    }
-  }
+// =======================================================================
+// function : getAligned
+// purpose  :
+// =======================================================================
+inline Standard_Size getAligned (const Standard_Size theNumber,
+                                 const Standard_Size theAlignment)
+{
+  return theNumber + theAlignment - 1 - (theNumber - 1) % theAlignment;
+}
 
-  if (!myTransientDrawToFront
-   || !myBackBufferRestored
-   || (myGlContext->caps->buffersNoSwap && !myMainSceneFbos[0]->IsValid()))
+// =======================================================================
+// function : BufferDump
+// purpose  :
+// =======================================================================
+Standard_Boolean OpenGl_Workspace::BufferDump (OpenGl_FrameBuffer*         theFBOPtr,
+                                               Image_PixMap&               theImage,
+                                               const Graphic3d_BufferType& theBufferType)
+{
+  GLenum aFormat, aType;
+  if (theImage.IsEmpty()
+   || !getDataFormat (theImage, aFormat, aType)
+   || !Activate())
   {
-    Redraw (theCView, theCUnderLayer, theCOverLayer);
-    return;
+    return Standard_False;
   }
-  else if (!Activate())
+#if !defined(GL_ES_VERSION_2_0)
+  GLint aReadBufferPrev = GL_BACK;
+  if (theBufferType == Graphic3d_BT_Depth
+   && aFormat != GL_DEPTH_COMPONENT)
   {
-    return;
+    return Standard_False;
   }
+#endif
 
-  bool toSwap = false;
-  if (aProjectType == Graphic3d_Camera::Projection_Stereo)
+  // bind FBO if used
+  if (theFBOPtr != NULL && theFBOPtr->IsValid())
   {
-    OpenGl_FrameBuffer* aMainFbos[2] =
-    {
-      myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL,
-      myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL
-    };
-    OpenGl_FrameBuffer* anImmFbos[2] =
-    {
-      myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL,
-      myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL
-    };
-    if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
-     || aStereoMode == Graphic3d_StereoMode_QuadBuffer)
-    {
-      anImmFbos[0] = NULL;
-      anImmFbos[1] = NULL;
-    }
-
-    if (myGlContext->arbFBO != NULL)
-    {
-      myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
-    }
-  #if !defined(GL_ES_VERSION_2_0)
-    if (anImmFbos[0] == NULL)
-    {
-      myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
-    }
-  #endif
-    toSwap = redrawImmediate (theCView, theCUnderLayer, theCOverLayer,
-                              aMainFbos[0],
-                              Graphic3d_Camera::Projection_MonoLeftEye,
-                              anImmFbos[0],
-                              Standard_True) || toSwap;
-    if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
-    &&  toSwap
-    && !myGlContext->caps->buffersNoSwap)
-    {
-      myGlContext->SwapBuffers();
-    }
-
-    if (myGlContext->arbFBO != NULL)
-    {
-      myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
-    }
-  #if !defined(GL_ES_VERSION_2_0)
-    if (anImmFbos[1] == NULL)
-    {
-      myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK);
-    }
-  #endif
-    toSwap = redrawImmediate (theCView, theCUnderLayer, theCOverLayer,
-                              aMainFbos[1],
-                              Graphic3d_Camera::Projection_MonoRightEye,
-                              anImmFbos[1],
-                              Standard_True) || toSwap;
-    if (anImmFbos[0] != NULL)
-    {
-      bindDefaultFbo (aFrameBuffer);
-      drawStereoPair (theCView);
-    }
+    theFBOPtr->BindBuffer (GetGlContext());
   }
   else
   {
-    OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL;
   #if !defined(GL_ES_VERSION_2_0)
-    if (aMainFbo == NULL)
-    {
-      myGlContext->SetReadDrawBuffer (GL_BACK);
-    }
+    glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev);
+    GLint aDrawBufferPrev = GL_BACK;
+    glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev);
+    glReadBuffer (aDrawBufferPrev);
   #endif
-    toSwap = redrawImmediate (theCView, theCUnderLayer, theCOverLayer,
-                              aMainFbo,
-                              aProjectType,
-                              aFrameBuffer,
-                              Standard_True) || toSwap;
   }
 
-  // bind default FBO
-  bindDefaultFbo();
+  // setup alignment
+  const GLint anAligment   = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL
+  glPixelStorei (GL_PACK_ALIGNMENT, anAligment);
+  bool isBatchCopy = !theImage.IsTopDown();
 
-  if (toSwap
-  && !myGlContext->caps->buffersNoSwap)
+  const GLint   anExtraBytes       = GLint(theImage.RowExtraBytes());
+  GLint         aPixelsWidth       = GLint(theImage.SizeRowBytes() / theImage.SizePixelBytes());
+  Standard_Size aSizeRowBytesEstim = getAligned (theImage.SizePixelBytes() * aPixelsWidth, anAligment);
+  if (anExtraBytes < anAligment)
   {
-    myGlContext->SwapBuffers();
+    aPixelsWidth = 0;
   }
-  else
+  else if (aSizeRowBytesEstim != theImage.SizeRowBytes())
   {
-    myGlContext->core11fwd->glFlush();
+    aPixelsWidth = 0;
+    isBatchCopy  = false;
   }
-}
-
-// =======================================================================
-// function : redrawImmediate
-// purpose  :
-// =======================================================================
-bool OpenGl_Workspace::redrawImmediate (const Graphic3d_CView& theCView,
-                                        const Aspect_CLayer2d& theCUnderLayer,
-                                        const Aspect_CLayer2d& theCOverLayer,
-                                        OpenGl_FrameBuffer*    theReadFbo,
-                                        const Graphic3d_Camera::Projection theProjection,
-                                        OpenGl_FrameBuffer*    theDrawFbo,
-                                        const Standard_Boolean theIsPartialUpdate)
-{
-  GLboolean toCopyBackToFront = GL_FALSE;
-  if (!myTransientDrawToFront)
-  {
-    myBackBufferRestored = Standard_False;
-  }
-  else if (theReadFbo != NULL
-        && theReadFbo->IsValid()
-        && myGlContext->IsRender())
+#if !defined(GL_ES_VERSION_2_0)
+  glPixelStorei (GL_PACK_ROW_LENGTH, aPixelsWidth);
+#else
+  if (aPixelsWidth != 0)
   {
-    if (!blitBuffers (theReadFbo, theDrawFbo))
-    {
-      return true;
-    }
+    isBatchCopy = false;
   }
-  else if (theDrawFbo == NULL)
+#endif
+
+  if (!isBatchCopy)
   {
-  #if !defined(GL_ES_VERSION_2_0)
-    myGlContext->core11fwd->glGetBooleanv (GL_DOUBLEBUFFER, &toCopyBackToFront);
-  #endif
-    if (toCopyBackToFront)
-    {
-      if (!myView->HasImmediateStructures()
-       && !theIsPartialUpdate)
-      {
-        // prefer Swap Buffers within Redraw in compatibility mode (without FBO)
-        return true;
-      }
-      copyBackToFront();
-    }
-    else
+    // copy row by row
+    for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
     {
-      myBackBufferRestored = Standard_False;
+      // Image_PixMap rows indexation always starts from the upper corner
+      // while order in memory depends on the flag and processed by ChangeRow() method
+      glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow));
     }
   }
   else
   {
-    myBackBufferRestored = Standard_False;
+    glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData());
   }
-  myIsImmediateDrawn = Standard_True;
 
-  Handle(OpenGl_Workspace) aWS (this);
-
-  myUseZBuffer    = Standard_True;
-  myUseDepthWrite = Standard_True;
-  glDepthFunc (GL_LEQUAL);
-  glDepthMask (GL_TRUE);
-  glEnable (GL_DEPTH_TEST);
+  glPixelStorei (GL_PACK_ALIGNMENT,  1);
 #if !defined(GL_ES_VERSION_2_0)
-  glClearDepth (1.0);
-#else
-  glClearDepthf (1.0f);
+  glPixelStorei (GL_PACK_ROW_LENGTH, 0);
 #endif
 
-  myView->Render (myPrintContext, aWS, theDrawFbo, theProjection,
-                  theCView, theCUnderLayer, theCOverLayer, Standard_True);
-  if (!myView->ImmediateStructures().IsEmpty())
+  if (theFBOPtr != NULL && theFBOPtr->IsValid())
   {
-    myUseZBuffer = Standard_False;
-    glDisable (GL_DEPTH_TEST);
+    theFBOPtr->UnbindBuffer (GetGlContext());
   }
-  for (OpenGl_IndexedMapOfStructure::Iterator anIter (myView->ImmediateStructures()); anIter.More(); anIter.Next())
+  else
   {
-    const OpenGl_Structure* aStructure = anIter.Value();
-    if (!aStructure->IsVisible())
-    {
-      continue;
-    }
-
-    aStructure->Render (aWS);
+  #if !defined(GL_ES_VERSION_2_0)
+    glReadBuffer (aReadBufferPrev);
+  #endif
   }
-
-  return !toCopyBackToFront;
+  return Standard_True;
 }
 
-
 // =======================================================================
 // function : CanRender
 // purpose  :