0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[occt.git] / src / OpenGl / OpenGl_View_Redraw.cxx
index 0c4aa80..cdf41b6 100644 (file)
@@ -19,6 +19,7 @@
 #include <OpenGl_GlCore11.hxx>
 
 #include <Graphic3d_GraphicDriver.hxx>
+#include <Graphic3d_StructureManager.hxx>
 #include <Graphic3d_TextureParams.hxx>
 #include <Graphic3d_Texture2Dmanual.hxx>
 #include <Graphic3d_TransformUtils.hxx>
@@ -26,8 +27,8 @@
 
 #include <NCollection_Mat4.hxx>
 
-#include <OpenGl_AspectLine.hxx>
 #include <OpenGl_Context.hxx>
+#include <OpenGl_FrameStats.hxx>
 #include <OpenGl_Matrix.hxx>
 #include <OpenGl_Workspace.hxx>
 #include <OpenGl_View.hxx>
@@ -96,7 +97,8 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
   {
   #if !defined(GL_ES_VERSION_2_0)
     GLint aShadingModelOld = GL_SMOOTH;
-    if (aCtx->core11 != NULL)
+    if (aCtx->core11 != NULL
+     && aCtx->caps->ffpEnable)
     {
       aCtx->core11fwd->glDisable (GL_LIGHTING);
       aCtx->core11fwd->glGetIntegerv (GL_SHADE_MODEL, &aShadingModelOld);
@@ -107,7 +109,8 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
     myBgGradientArray->Render (theWorkspace);
 
   #if !defined(GL_ES_VERSION_2_0)
-    if (aCtx->core11 != NULL)
+    if (aCtx->core11 != NULL
+     && aCtx->caps->ffpEnable)
     {
       aCtx->core11->glShadeModel (aShadingModelOld);
     }
@@ -121,9 +124,9 @@ void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
   {
     aCtx->core11fwd->glDisable (GL_BLEND);
 
-    const OpenGl_AspectFace* anOldAspectFace = theWorkspace->SetAspectFace (myTextureParams);
+    const OpenGl_Aspects* anOldAspectFace = theWorkspace->SetAspects (myTextureParams);
     myBgTextureArray->Render (theWorkspace);
-    theWorkspace->SetAspectFace (anOldAspectFace);
+    theWorkspace->SetAspects (anOldAspectFace);
   }
 
   if (wasUsedZBuffer)
@@ -145,11 +148,9 @@ void OpenGl_View::Redraw()
   && !myCaps->vboDisable
   && !myCaps->keepArrayData)
   {
-    if (myWasRedrawnGL)
-    {
-      myDeviceLostFlag = Standard_True;
-    }
-
+    // caps are shared across all views, thus we need to invalidate all of them
+    // if (myWasRedrawnGL) { myStructureManager->SetDeviceLost(); }
+    myDriver->setDeviceLost();
     myCaps->keepArrayData = Standard_True;
   }
 
@@ -164,6 +165,8 @@ void OpenGl_View::Redraw()
   const Graphic3d_StereoMode   aStereoMode  = myRenderParams.StereoMode;
   Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType();
   Handle(OpenGl_Context)       aCtx         = myWorkspace->GetGlContext();
+  aCtx->FrameStats()->FrameStart (myWorkspace->View(), false);
+  aCtx->SetLineFeather (myRenderParams.LineFeather);
 
   // release pending GL resources
   aCtx->ReleaseDelayed();
@@ -171,15 +174,24 @@ void OpenGl_View::Redraw()
   // fetch OpenGl context state
   aCtx->FetchState();
 
-  OpenGl_FrameBuffer* aFrameBuffer = myFBO.operator->();
+  OpenGl_FrameBuffer* aFrameBuffer = myFBO.get();
   bool toSwap = aCtx->IsRender()
             && !aCtx->caps->buffersNoSwap
             &&  aFrameBuffer == NULL;
 
-  Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width();
-  Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height();
-  Standard_Integer aRendSizeX = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f);
-  Standard_Integer aRendSizeY = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f);
+  const Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width();
+  const Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height();
+  const Standard_Integer aRendSizeX = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f);
+  const Standard_Integer aRendSizeY = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f);
+  if (aSizeX < 1
+   || aSizeY < 1
+   || aRendSizeX < 1
+   || aRendSizeY < 1)
+  {
+    myBackBufferRestored = Standard_False;
+    myIsImmediateDrawn   = Standard_False;
+    return;
+  }
 
   // determine multisampling parameters
   Standard_Integer aNbSamples = !myToDisableMSAA && aSizeX == aRendSizeX
@@ -542,7 +554,10 @@ void OpenGl_View::Redraw()
 
   // reset state for safety
   aCtx->BindProgram (Handle(OpenGl_ShaderProgram)());
-  aCtx->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
+  if (aCtx->caps->ffpEnable)
+  {
+    aCtx->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
+  }
 
   // Swap the buffers
   if (toSwap)
@@ -560,6 +575,7 @@ void OpenGl_View::Redraw()
 
   // reset render mode state
   aCtx->FetchState();
+  aCtx->FrameStats()->FrameEnd (myWorkspace->View(), false);
 
   myWasRedrawnGL = Standard_True;
 }
@@ -584,7 +600,8 @@ void OpenGl_View::RedrawImmediate()
 
   const Graphic3d_StereoMode   aStereoMode  = myRenderParams.StereoMode;
   Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType();
-  OpenGl_FrameBuffer*          aFrameBuffer = myFBO.operator->();
+  OpenGl_FrameBuffer*          aFrameBuffer = myFBO.get();
+  aCtx->FrameStats()->FrameStart (myWorkspace->View(), true);
 
   if ( aFrameBuffer == NULL
    && !aCtx->DefaultFrameBuffer().IsNull()
@@ -712,7 +729,10 @@ void OpenGl_View::RedrawImmediate()
 
   // reset state for safety
   aCtx->BindProgram (Handle(OpenGl_ShaderProgram)());
-  aCtx->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
+  if (aCtx->caps->ffpEnable)
+  {
+    aCtx->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
+  }
 
   if (toSwap && !aCtx->caps->buffersNoSwap)
   {
@@ -722,6 +742,7 @@ void OpenGl_View::RedrawImmediate()
   {
     aCtx->core11fwd->glFlush();
   }
+  aCtx->FrameStats()->FrameEnd (myWorkspace->View(), true);
 
   myWasRedrawnGL = Standard_True;
 }
@@ -801,7 +822,8 @@ bool OpenGl_View::redrawImmediate (const Graphic3d_Camera::Projection theProject
   #if !defined(GL_ES_VERSION_2_0)
     aCtx->core11fwd->glGetBooleanv (GL_DOUBLEBUFFER, &toCopyBackToFront);
   #endif
-    if (toCopyBackToFront)
+    if (toCopyBackToFront
+     && myTransientDrawToFront)
     {
       if (!HasImmediateStructures()
        && !theIsPartialUpdate)
@@ -856,6 +878,9 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
   // ==================================
 
   const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
+  aContext->SetAllowSampleAlphaToCoverage (myRenderParams.ToEnableAlphaToCoverage
+                                        && theOutputFBO != NULL
+                                        && theOutputFBO->NbSamples() != 0);
 
 #if !defined(GL_ES_VERSION_2_0)
   // Disable current clipping planes
@@ -869,14 +894,24 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
   }
 #endif
 
-  // Update states of OpenGl_BVHTreeSelector (frustum culling algorithm).
+  // update states of OpenGl_BVHTreeSelector (frustum culling algorithm);
+  // note that we pass here window dimensions ignoring Graphic3d_RenderingParams::RenderResolutionScale
   myBVHSelector.SetViewVolume (myCamera);
-  myBVHSelector.SetViewportSize (myWindow->Width(), myWindow->Height());
+  myBVHSelector.SetViewportSize (myWindow->Width(), myWindow->Height(), myRenderParams.ResolutionRatio());
+  myBVHSelector.CacheClipPtsProjections();
 
-  const Handle(OpenGl_ShaderManager)& aManager   = aContext->ShaderManager();
-  if (StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()) != myLastLightSourceState)
+  const Handle(OpenGl_ShaderManager)& aManager = aContext->ShaderManager();
+  const Handle(Graphic3d_LightSet)&   aLights  = myShadingModel == Graphic3d_TOSM_UNLIT ? myNoShadingLight : myLights;
+  Standard_Size aLightsRevision = 0;
+  if (!aLights.IsNull())
   {
-    aManager->UpdateLightSourceStateTo (myShadingModel == Graphic3d_TOSM_NONE ? &myNoShadingLight : &myLights);
+    aLightsRevision = aLights->UpdateRevision();
+  }
+  if (StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()) != myLastLightSourceState
+   || aLightsRevision != myLightsRevision)
+  {
+    myLightsRevision = aLightsRevision;
+    aManager->UpdateLightSourceStateTo (aLights);
     myLastLightSourceState = StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index());
   }
 
@@ -910,7 +945,8 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
 
 #if !defined(GL_ES_VERSION_2_0)
   // Switch off lighting by default
-  if (aContext->core11 != NULL)
+  if (aContext->core11 != NULL
+   && aContext->caps->ffpEnable)
   {
     glDisable(GL_LIGHTING);
   }
@@ -953,7 +989,7 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
   if (aContext->core11 != NULL)
   {
     aContext->core11->glShadeModel (myShadingModel == Graphic3d_TOSM_FACET
-                                 || myShadingModel == Graphic3d_TOSM_NONE ? GL_FLAT : GL_SMOOTH);
+                                 || myShadingModel == Graphic3d_TOSM_UNLIT ? GL_FLAT : GL_SMOOTH);
   }
 #endif
 
@@ -975,7 +1011,7 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
 
   renderScene (theProjection, theOutputFBO, theOitAccumFbo, theToDrawImmediate);
 
-  myWorkspace->SetEnvironmentTexture (Handle(OpenGl_Texture)());
+  myWorkspace->SetEnvironmentTexture (Handle(OpenGl_TextureSet)());
 
   // ===============================
   //      Step 4: Trihedron
@@ -1003,10 +1039,21 @@ void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
         glDisable (GL_CULL_FACE);
     }
   }
+  else
+  {
+    renderFrameStats();
+  }
+
+  myWorkspace->ResetAppliedAspect();
+  aContext->SetAllowSampleAlphaToCoverage (false);
+  aContext->SetSampleAlphaToCoverage (false);
 
   // reset FFP state for safety
   aContext->BindProgram (Handle(OpenGl_ShaderProgram)());
-  aContext->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
+  if (aContext->caps->ffpEnable)
+  {
+    aContext->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
+  }
 
   // ==============================================================
   //      Step 6: Keep shader manager informed about last View
@@ -1036,6 +1083,7 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
                                  OpenGl_FrameBuffer*          theOitAccumFbo,
                                  const Standard_Boolean       theToDrawImmediate)
 {
+  myZLayers.UpdateCulling (myWorkspace, theToDrawImmediate);
   if ( myZLayers.NbStructures() <= 0 )
     return;
 
@@ -1047,22 +1095,18 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
 
   if (!toRenderGL)
   {
-    toRenderGL = !initRaytraceResources (aCtx) ||
-      !updateRaytraceGeometry (OpenGl_GUM_CHECK, myId, aCtx);
+    const Standard_Integer aSizeX = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeX() : myWindow->Width();
+    const Standard_Integer aSizeY = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeY() : myWindow->Height();
+
+    toRenderGL = !initRaytraceResources (aSizeX, aSizeY, aCtx)
+              || !updateRaytraceGeometry (OpenGl_GUM_CHECK, myId, aCtx);
 
     toRenderGL |= !myIsRaytraceDataValid; // if no ray-trace data use OpenGL
 
     if (!toRenderGL)
     {
-      const Standard_Integer aSizeX = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeX() : myWindow->Width();
-      const Standard_Integer aSizeY = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeY() : myWindow->Height();
       myOpenGlFBO ->InitLazy (aCtx, aSizeX, aSizeY, myFboColorFormat, myFboDepthFormat, 0);
 
-      if (myRaytraceFilter.IsNull())
-        myRaytraceFilter = new OpenGl_RaytraceFilter;
-
-      myRaytraceFilter->SetPrevRenderFilter (myWorkspace->GetRenderFilter());
-
       if (theReadDrawFbo != NULL)
         theReadDrawFbo->UnbindBuffer (aCtx);
 
@@ -1072,7 +1116,8 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
         // Render bottom OSD layer
         myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Bottom, theReadDrawFbo, theOitAccumFbo);
 
-        myWorkspace->SetRenderFilter (myRaytraceFilter);
+        const Standard_Integer aPrevFilter = myWorkspace->RenderFilter() & ~(Standard_Integer )(OpenGl_RenderFilter_NonRaytraceableOnly);
+        myWorkspace->SetRenderFilter (aPrevFilter | OpenGl_RenderFilter_NonRaytraceableOnly);
         {
           if (theReadDrawFbo != NULL)
           {
@@ -1086,7 +1131,7 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
           // Render non-polygonal elements in default layer
           myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Default, theReadDrawFbo, theOitAccumFbo);
         }
-        myWorkspace->SetRenderFilter (myRaytraceFilter->PrevRenderFilter());
+        myWorkspace->SetRenderFilter (aPrevFilter);
       }
 
       if (theReadDrawFbo != NULL)
@@ -1133,6 +1178,20 @@ void OpenGl_View::renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace)
   }
 }
 
+//=======================================================================
+//function : renderFrameStats
+//purpose  :
+//=======================================================================
+void OpenGl_View::renderFrameStats()
+{
+  if (myRenderParams.ToShowStats
+   && myRenderParams.CollectedStats != Graphic3d_RenderingParams::PerfCounters_NONE)
+  {
+    myFrameStatsPrs.Update (myWorkspace);
+    myFrameStatsPrs.Render (myWorkspace);
+  }
+}
+
 // =======================================================================
 // function : Invalidate
 // purpose  :
@@ -1154,7 +1213,7 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
   const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
 
   // Specify clipping planes in view transformation space
-  aContext->ChangeClipping().Reset (aContext, myClipPlanes);
+  aContext->ChangeClipping().Reset (myClipPlanes);
   if (!myClipPlanes.IsNull()
    && !myClipPlanes->IsEmpty())
   {
@@ -1162,12 +1221,12 @@ void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
   }
 
   renderStructs (theProjection, theReadDrawFbo, theOitAccumFbo, theToDrawImmediate);
-  myWorkspace->DisableTexture();
+  aContext->BindTextures (Handle(OpenGl_TextureSet)());
 
   // Apply restored view matrix.
   aContext->ApplyWorldViewMatrix();
 
-  aContext->ChangeClipping().Reset (aContext, Handle(Graphic3d_SequenceOfHClipPlane)());
+  aContext->ChangeClipping().Reset (Handle(Graphic3d_SequenceOfHClipPlane)());
   if (!myClipPlanes.IsNull()
    && !myClipPlanes->IsEmpty())
   {
@@ -1376,7 +1435,7 @@ bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer*    theReadFbo,
     }
   #endif
 
-    myWorkspace->DisableTexture();
+    aCtx->BindTextures (Handle(OpenGl_TextureSet)());
 
     const Graphic3d_TypeOfTextureFilter aFilter = (aDrawSizeX == aReadSizeX && aDrawSizeY == aReadSizeY) ? Graphic3d_TOTF_NEAREST : Graphic3d_TOTF_BILINEAR;
     const GLint aFilterGl = aFilter == Graphic3d_TOTF_NEAREST ? GL_NEAREST : GL_LINEAR;
@@ -1386,18 +1445,19 @@ bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer*    theReadFbo,
     if (aVerts->IsValid()
      && aManager->BindFboBlitProgram())
     {
-      theReadFbo->ColorTexture()->Bind (aCtx, GL_TEXTURE0 + 0);
-      if (theReadFbo->ColorTexture()->GetParams()->Filter() != aFilter)
+      aCtx->SetSampleAlphaToCoverage (false);
+      theReadFbo->ColorTexture()->Bind (aCtx, Graphic3d_TextureUnit_0);
+      if (theReadFbo->ColorTexture()->Sampler()->Parameters()->Filter() != aFilter)
       {
-        theReadFbo->ColorTexture()->GetParams()->SetFilter (aFilter);
+        theReadFbo->ColorTexture()->Sampler()->Parameters()->SetFilter (aFilter);
         aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterGl);
         aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilterGl);
       }
 
-      theReadFbo->DepthStencilTexture()->Bind (aCtx, GL_TEXTURE0 + 1);
-      if (theReadFbo->DepthStencilTexture()->GetParams()->Filter() != aFilter)
+      theReadFbo->DepthStencilTexture()->Bind (aCtx, Graphic3d_TextureUnit_1);
+      if (theReadFbo->DepthStencilTexture()->Sampler()->Parameters()->Filter() != aFilter)
       {
-        theReadFbo->DepthStencilTexture()->GetParams()->SetFilter (aFilter);
+        theReadFbo->DepthStencilTexture()->Sampler()->Parameters()->SetFilter (aFilter);
         aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterGl);
         aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilterGl);
       }
@@ -1407,8 +1467,8 @@ bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer*    theReadFbo,
       aCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
 
       aVerts->UnbindVertexAttrib (aCtx, Graphic3d_TOA_POS);
-      theReadFbo->DepthStencilTexture()->Unbind (aCtx, GL_TEXTURE0 + 1);
-      theReadFbo->ColorTexture()       ->Unbind (aCtx, GL_TEXTURE0 + 0);
+      theReadFbo->DepthStencilTexture()->Unbind (aCtx, Graphic3d_TextureUnit_1);
+      theReadFbo->ColorTexture()       ->Unbind (aCtx, Graphic3d_TextureUnit_0);
       aCtx->BindProgram (NULL);
     }
     else
@@ -1519,7 +1579,7 @@ void OpenGl_View::drawStereoPair (OpenGl_FrameBuffer* theDrawFbo)
   aCtx->core20fwd->glDepthMask (GL_TRUE);
   aCtx->core20fwd->glEnable (GL_DEPTH_TEST);
 
-  myWorkspace->DisableTexture();
+  aCtx->BindTextures (Handle(OpenGl_TextureSet)());
   OpenGl_VertexBuffer* aVerts = initBlitQuad (myToFlipOutput);
 
   const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager();
@@ -1589,15 +1649,15 @@ void OpenGl_View::drawStereoPair (OpenGl_FrameBuffer* theDrawFbo)
       aCtx->ActiveProgram()->SetUniform (aCtx, "uMultR", aFilterR);
     }
 
-    aPair[0]->ColorTexture()->Bind (aCtx, GL_TEXTURE0 + 0);
-    aPair[1]->ColorTexture()->Bind (aCtx, GL_TEXTURE0 + 1);
+    aPair[0]->ColorTexture()->Bind (aCtx, Graphic3d_TextureUnit_0);
+    aPair[1]->ColorTexture()->Bind (aCtx, Graphic3d_TextureUnit_1);
     aVerts->BindVertexAttrib (aCtx, 0);
 
     aCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
 
     aVerts->UnbindVertexAttrib (aCtx, 0);
-    aPair[1]->ColorTexture()->Unbind (aCtx, GL_TEXTURE0 + 1);
-    aPair[0]->ColorTexture()->Unbind (aCtx, GL_TEXTURE0 + 0);
+    aPair[1]->ColorTexture()->Unbind (aCtx, Graphic3d_TextureUnit_1);
+    aPair[0]->ColorTexture()->Unbind (aCtx, Graphic3d_TextureUnit_0);
   }
   else
   {
@@ -1699,16 +1759,16 @@ Standard_Boolean OpenGl_View::checkOitCompatibility (const Handle(OpenGl_Context
   }
 
   TCollection_ExtendedString aCompatibilityMsg;
-  if (!theGlContext->hasFloatBuffer
-   && !theGlContext->hasHalfFloatBuffer)
+  if (theGlContext->hasFloatBuffer     == OpenGl_FeatureNotAvailable
+   && theGlContext->hasHalfFloatBuffer == OpenGl_FeatureNotAvailable)
   {
     aCompatibilityMsg += "OpenGL context does not support floating-point RGBA color buffer format.\n";
   }
-  if (theMSAA && !theGlContext->hasSampleVariables)
+  if (theMSAA && theGlContext->hasSampleVariables == OpenGl_FeatureNotAvailable)
   {
     aCompatibilityMsg += "Current version of GLSL does not support built-in sample variables.\n";
   }
-  if (!theGlContext->hasDrawBuffers)
+  if (theGlContext->hasDrawBuffers == OpenGl_FeatureNotAvailable)
   {
     aCompatibilityMsg += "OpenGL context does not support multiple draw buffers.\n";
   }
@@ -1741,14 +1801,14 @@ bool OpenGl_View::chooseOitColorConfiguration (const Handle(OpenGl_Context)& the
   {
     case 0: // choose best applicable color format combination
     {
-      theFormats.Append (theGlContext->hasHalfFloatBuffer ? GL_RGBA16F : GL_RGBA32F);
-      theFormats.Append (theGlContext->hasHalfFloatBuffer ? GL_R16F    : GL_R32F);
+      theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
+      theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_R16F    : GL_R32F);
       return true;
     }
     case 1: // choose non-optimal applicable color format combination
     {
-      theFormats.Append (theGlContext->hasHalfFloatBuffer ? GL_RGBA16F : GL_RGBA32F);
-      theFormats.Append (theGlContext->hasHalfFloatBuffer ? GL_RGBA16F : GL_RGBA32F);
+      theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
+      theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
       return true;
     }
   }