1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
19 #include <OpenGl_GlCore11.hxx>
21 #include <Graphic3d_GraphicDriver.hxx>
22 #include <Graphic3d_StructureManager.hxx>
23 #include <Graphic3d_TextureParams.hxx>
24 #include <Graphic3d_Texture2Dmanual.hxx>
25 #include <Graphic3d_TransformUtils.hxx>
26 #include <Image_AlienPixMap.hxx>
28 #include <NCollection_Mat4.hxx>
30 #include <OpenGl_Context.hxx>
31 #include <OpenGl_FrameStats.hxx>
32 #include <OpenGl_Matrix.hxx>
33 #include <OpenGl_Workspace.hxx>
34 #include <OpenGl_View.hxx>
35 #include <OpenGl_GraduatedTrihedron.hxx>
36 #include <OpenGl_PrimitiveArray.hxx>
37 #include <OpenGl_ShaderManager.hxx>
38 #include <OpenGl_ShaderProgram.hxx>
39 #include <OpenGl_Structure.hxx>
40 #include <OpenGl_ArbFBO.hxx>
44 //! Format Frame Buffer format for logging messages.
45 static TCollection_AsciiString printFboFormat (const Handle(OpenGl_FrameBuffer)& theFbo)
47 return TCollection_AsciiString() + theFbo->GetInitVPSizeX() + "x" + theFbo->GetInitVPSizeY() + "@" + theFbo->NbSamples();
50 //! Return TRUE if Frame Buffer initialized has failed with the same parameters.
51 static bool checkWasFailedFbo (const Handle(OpenGl_FrameBuffer)& theFboToCheck,
52 Standard_Integer theSizeX,
53 Standard_Integer theSizeY,
54 Standard_Integer theNbSamples)
56 return !theFboToCheck->IsValid()
57 && theFboToCheck->GetInitVPSizeX() == theSizeX
58 && theFboToCheck->GetInitVPSizeY() == theSizeY
59 && theFboToCheck->NbSamples() == theNbSamples;
62 //! Return TRUE if Frame Buffer initialized has failed with the same parameters.
63 static bool checkWasFailedFbo (const Handle(OpenGl_FrameBuffer)& theFboToCheck,
64 const Handle(OpenGl_FrameBuffer)& theFboRef)
66 return checkWasFailedFbo (theFboToCheck, theFboRef->GetVPSizeX(), theFboRef->GetVPSizeY(), theFboRef->NbSamples());
70 //=======================================================================
71 //function : drawBackground
73 //=======================================================================
74 void OpenGl_View::drawBackground (const Handle(OpenGl_Workspace)& theWorkspace)
76 const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
77 const Standard_Boolean wasUsedZBuffer = theWorkspace->SetUseZBuffer (Standard_False);
80 aCtx->core11fwd->glDisable (GL_DEPTH_TEST);
83 if (myBackgroundType == Graphic3d_TOB_CUBEMAP)
85 Graphic3d_Camera aCamera (theWorkspace->View()->Camera());
86 aCamera.SetZRange (0.01, 1.0); // is needed to avoid perspective camera exception
87 aCamera.SetProjectionType (Graphic3d_Camera::Projection_Perspective);
89 aCtx->ProjectionState.Push();
90 aCtx->ProjectionState.SetCurrent (aCamera.ProjectionMatrixF());
92 myCubeMapParams->Aspect()->ShaderProgram()->PushVariableInt ("uZCoeff", myBackgroundCubeMap->ZIsInverted() ? -1 : 1);
93 myCubeMapParams->Aspect()->ShaderProgram()->PushVariableInt ("uYCoeff", myBackgroundCubeMap->IsTopDown() ? 1 : -1);
94 const OpenGl_Aspects* anOldAspectFace = theWorkspace->SetAspects (myCubeMapParams);
96 myBackgrounds[Graphic3d_TOB_CUBEMAP]->Render (theWorkspace);
98 aCtx->ProjectionState.Pop();
99 aCtx->ApplyProjectionMatrix();
100 theWorkspace->SetAspects (anOldAspectFace);
102 else if (myBackgroundType == Graphic3d_TOB_GRADIENT
103 || myBackgroundType == Graphic3d_TOB_TEXTURE)
105 // Drawing background gradient if:
106 // - gradient fill type is not Aspect_GFM_NONE and
107 // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode
108 if (myBackgrounds[Graphic3d_TOB_GRADIENT]->IsDefined()
109 && (!myTextureParams->Aspect()->ToMapTexture()
110 || myBackgrounds[Graphic3d_TOB_TEXTURE]->TextureFillMethod() == Aspect_FM_CENTERED
111 || myBackgrounds[Graphic3d_TOB_TEXTURE]->TextureFillMethod() == Aspect_FM_NONE))
113 #if !defined(GL_ES_VERSION_2_0)
114 GLint aShadingModelOld = GL_SMOOTH;
115 if (aCtx->core11 != NULL
116 && aCtx->caps->ffpEnable)
118 aCtx->core11fwd->glDisable (GL_LIGHTING);
119 aCtx->core11fwd->glGetIntegerv (GL_SHADE_MODEL, &aShadingModelOld);
120 aCtx->core11->glShadeModel (GL_SMOOTH);
124 myBackgrounds[Graphic3d_TOB_GRADIENT]->Render(theWorkspace);
126 #if !defined(GL_ES_VERSION_2_0)
127 if (aCtx->core11 != NULL
128 && aCtx->caps->ffpEnable)
130 aCtx->core11->glShadeModel (aShadingModelOld);
135 // Drawing background image if it is defined
136 // (texture is defined and fill type is not Aspect_FM_NONE)
137 if (myBackgrounds[Graphic3d_TOB_TEXTURE]->IsDefined()
138 && myTextureParams->Aspect()->ToMapTexture())
140 aCtx->core11fwd->glDisable (GL_BLEND);
142 const OpenGl_Aspects* anOldAspectFace = theWorkspace->SetAspects (myTextureParams);
143 myBackgrounds[Graphic3d_TOB_TEXTURE]->Render (theWorkspace);
144 theWorkspace->SetAspects (anOldAspectFace);
150 theWorkspace->SetUseZBuffer (Standard_True);
151 aCtx->core11fwd->glEnable (GL_DEPTH_TEST);
155 //=======================================================================
158 //=======================================================================
159 void OpenGl_View::Redraw()
161 const Standard_Boolean wasDisabledMSAA = myToDisableMSAA;
162 const Standard_Boolean hadFboBlit = myHasFboBlit;
163 if (myRenderParams.Method == Graphic3d_RM_RAYTRACING
164 && !myCaps->vboDisable
165 && !myCaps->keepArrayData)
167 // caps are shared across all views, thus we need to invalidate all of them
168 // if (myWasRedrawnGL) { myStructureManager->SetDeviceLost(); }
169 myDriver->setDeviceLost();
170 myCaps->keepArrayData = Standard_True;
173 if (!myWorkspace->Activate())
178 myWindow->SetSwapInterval();
181 const Graphic3d_StereoMode aStereoMode = myRenderParams.StereoMode;
182 Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType();
183 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
184 aCtx->FrameStats()->FrameStart (myWorkspace->View(), false);
185 aCtx->SetLineFeather (myRenderParams.LineFeather);
187 // release pending GL resources
188 aCtx->ReleaseDelayed();
190 // fetch OpenGl context state
193 OpenGl_FrameBuffer* aFrameBuffer = myFBO.get();
194 bool toSwap = aCtx->IsRender()
195 && !aCtx->caps->buffersNoSwap
196 && aFrameBuffer == NULL;
198 const Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width();
199 const Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height();
200 const Standard_Integer aRendSizeX = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f);
201 const Standard_Integer aRendSizeY = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f);
207 myBackBufferRestored = Standard_False;
208 myIsImmediateDrawn = Standard_False;
212 // determine multisampling parameters
213 Standard_Integer aNbSamples = !myToDisableMSAA && aSizeX == aRendSizeX
214 ? Max (Min (myRenderParams.NbMsaaSamples, aCtx->MaxMsaaSamples()), 0)
218 aNbSamples = OpenGl_Context::GetPowerOfTwo (aNbSamples, aCtx->MaxMsaaSamples());
221 bool toUseOit = myRenderParams.TransparencyMethod == Graphic3d_RTM_BLEND_OIT
222 && checkOitCompatibility (aCtx, aNbSamples > 0);
224 const bool toInitImmediateFbo = myTransientDrawToFront
225 && (!aCtx->caps->useSystemBuffer || (toUseOit && HasImmediateStructures()));
227 if ( aFrameBuffer == NULL
228 && !aCtx->DefaultFrameBuffer().IsNull()
229 && aCtx->DefaultFrameBuffer()->IsValid())
231 aFrameBuffer = aCtx->DefaultFrameBuffer().operator->();
235 && (myTransientDrawToFront
236 || aProjectType == Graphic3d_Camera::Projection_Stereo
239 || aSizeX != aRendSizeX))
241 if (myMainSceneFbos[0]->GetVPSizeX() != aRendSizeX
242 || myMainSceneFbos[0]->GetVPSizeY() != aRendSizeY
243 || myMainSceneFbos[0]->NbSamples() != aNbSamples)
245 if (!myTransientDrawToFront)
247 myImmediateSceneFbos[0]->Release (aCtx.operator->());
248 myImmediateSceneFbos[1]->Release (aCtx.operator->());
249 myImmediateSceneFbos[0]->ChangeViewport (0, 0);
250 myImmediateSceneFbos[1]->ChangeViewport (0, 0);
253 // prepare FBOs containing main scene
254 // for further blitting and rendering immediate presentations on top
255 if (aCtx->core20fwd != NULL)
257 const bool wasFailedMain0 = checkWasFailedFbo (myMainSceneFbos[0], aRendSizeX, aRendSizeY, aNbSamples);
258 if (!myMainSceneFbos[0]->Init (aCtx, aRendSizeX, aRendSizeY, myFboColorFormat, myFboDepthFormat, aNbSamples)
261 TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Main FBO "
262 + printFboFormat (myMainSceneFbos[0]) + " initialization has failed";
263 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
267 if (myMainSceneFbos[0]->IsValid() && (toInitImmediateFbo || myImmediateSceneFbos[0]->IsValid()))
269 const bool wasFailedImm0 = checkWasFailedFbo (myImmediateSceneFbos[0], myMainSceneFbos[0]);
270 if (!myImmediateSceneFbos[0]->InitLazy (aCtx, *myMainSceneFbos[0])
273 TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Immediate FBO "
274 + printFboFormat (myImmediateSceneFbos[0]) + " initialization has failed";
275 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
281 myMainSceneFbos [0]->Release (aCtx.operator->());
282 myMainSceneFbos [1]->Release (aCtx.operator->());
283 myImmediateSceneFbos[0]->Release (aCtx.operator->());
284 myImmediateSceneFbos[1]->Release (aCtx.operator->());
285 myMainSceneFbos [0]->ChangeViewport (0, 0);
286 myMainSceneFbos [1]->ChangeViewport (0, 0);
287 myImmediateSceneFbos[0]->ChangeViewport (0, 0);
288 myImmediateSceneFbos[1]->ChangeViewport (0, 0);
291 if (aProjectType == Graphic3d_Camera::Projection_Stereo
292 && myMainSceneFbos[0]->IsValid())
294 const bool wasFailedMain1 = checkWasFailedFbo (myMainSceneFbos[1], myMainSceneFbos[0]);
295 if (!myMainSceneFbos[1]->InitLazy (aCtx, *myMainSceneFbos[0])
298 TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Main FBO (second) "
299 + printFboFormat (myMainSceneFbos[1]) + " initialization has failed";
300 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
302 if (!myMainSceneFbos[1]->IsValid())
305 aProjectType = Graphic3d_Camera::Projection_Perspective;
307 else if (!myTransientDrawToFront)
311 else if (!aCtx->HasStereoBuffers() || aStereoMode != Graphic3d_StereoMode_QuadBuffer)
313 const bool wasFailedImm0 = checkWasFailedFbo (myImmediateSceneFbos[0], myMainSceneFbos[0]);
314 const bool wasFailedImm1 = checkWasFailedFbo (myImmediateSceneFbos[1], myMainSceneFbos[0]);
315 if (!myImmediateSceneFbos[0]->InitLazy (aCtx, *myMainSceneFbos[0])
318 TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Immediate FBO (first) "
319 + printFboFormat (myImmediateSceneFbos[0]) + " initialization has failed";
320 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
322 if (!myImmediateSceneFbos[1]->InitLazy (aCtx, *myMainSceneFbos[0])
325 TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Immediate FBO (first) "
326 + printFboFormat (myImmediateSceneFbos[1]) + " initialization has failed";
327 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
329 if (!myImmediateSceneFbos[0]->IsValid()
330 || !myImmediateSceneFbos[1]->IsValid())
332 aProjectType = Graphic3d_Camera::Projection_Perspective;
337 // create color and coverage accumulation buffers required for OIT algorithm
340 Standard_Integer anFboIt = 0;
341 for (; anFboIt < 2; ++anFboIt)
343 Handle(OpenGl_FrameBuffer)& aMainSceneFbo = myMainSceneFbos [anFboIt];
344 Handle(OpenGl_FrameBuffer)& aMainSceneFboOit = myMainSceneFbosOit [anFboIt];
345 Handle(OpenGl_FrameBuffer)& anImmediateSceneFbo = myImmediateSceneFbos [anFboIt];
346 Handle(OpenGl_FrameBuffer)& anImmediateSceneFboOit = myImmediateSceneFbosOit[anFboIt];
347 if (aMainSceneFbo->IsValid()
348 && (aMainSceneFboOit->GetVPSizeX() != aRendSizeX
349 || aMainSceneFboOit->GetVPSizeY() != aRendSizeY
350 || aMainSceneFboOit->NbSamples() != aNbSamples))
352 Standard_Integer aColorConfig = 0;
353 for (;;) // seemly responding to driver limitation (GL_FRAMEBUFFER_UNSUPPORTED)
355 if (myFboOitColorConfig.IsEmpty())
357 if (!chooseOitColorConfiguration (aCtx, aColorConfig++, myFboOitColorConfig))
362 if (aMainSceneFboOit->Init (aCtx, aRendSizeX, aRendSizeY, myFboOitColorConfig, aMainSceneFbo->DepthStencilTexture(), aNbSamples))
366 myFboOitColorConfig.Clear();
368 if (!aMainSceneFboOit->IsValid())
373 else if (!aMainSceneFbo->IsValid())
375 aMainSceneFboOit->Release (aCtx.operator->());
376 aMainSceneFboOit->ChangeViewport (0, 0);
379 if (anImmediateSceneFbo->IsValid()
380 && (anImmediateSceneFboOit->GetVPSizeX() != aRendSizeX
381 || anImmediateSceneFboOit->GetVPSizeY() != aRendSizeY
382 || anImmediateSceneFboOit->NbSamples() != aNbSamples))
384 if (!anImmediateSceneFboOit->Init (aCtx, aRendSizeX, aRendSizeY, myFboOitColorConfig,
385 anImmediateSceneFbo->DepthStencilTexture(), aNbSamples))
390 else if (!anImmediateSceneFbo->IsValid())
392 anImmediateSceneFboOit->Release (aCtx.operator->());
393 anImmediateSceneFboOit->ChangeViewport (0, 0);
396 if (anFboIt == 0) // only the first OIT framebuffer is mandatory
398 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
399 "Initialization of float texture framebuffer for use with\n"
400 " blended order-independent transparency rendering algorithm has failed.\n"
401 " Blended order-independent transparency will not be available.\n");
404 myToDisableOITMSAA = Standard_True;
408 myToDisableOIT = Standard_True;
413 if (!toUseOit && myMainSceneFbosOit[0]->IsValid())
415 myMainSceneFbosOit [0]->Release (aCtx.operator->());
416 myMainSceneFbosOit [1]->Release (aCtx.operator->());
417 myImmediateSceneFbosOit[0]->Release (aCtx.operator->());
418 myImmediateSceneFbosOit[1]->Release (aCtx.operator->());
419 myMainSceneFbosOit [0]->ChangeViewport (0, 0);
420 myMainSceneFbosOit [1]->ChangeViewport (0, 0);
421 myImmediateSceneFbosOit[0]->ChangeViewport (0, 0);
422 myImmediateSceneFbosOit[1]->ChangeViewport (0, 0);
425 if (aProjectType == Graphic3d_Camera::Projection_Stereo)
427 OpenGl_FrameBuffer* aMainFbos[2] =
429 myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL,
430 myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL
432 OpenGl_FrameBuffer* aMainFbosOit[2] =
434 myMainSceneFbosOit[0]->IsValid() ? myMainSceneFbosOit[0].operator->() : NULL,
435 myMainSceneFbosOit[1]->IsValid() ? myMainSceneFbosOit[1].operator->() :
436 myMainSceneFbosOit[0]->IsValid() ? myMainSceneFbosOit[0].operator->() : NULL
439 OpenGl_FrameBuffer* anImmFbos[2] =
441 myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL,
442 myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL
444 OpenGl_FrameBuffer* anImmFbosOit[2] =
446 myImmediateSceneFbosOit[0]->IsValid() ? myImmediateSceneFbosOit[0].operator->() : NULL,
447 myImmediateSceneFbosOit[1]->IsValid() ? myImmediateSceneFbosOit[1].operator->() :
448 myImmediateSceneFbosOit[0]->IsValid() ? myImmediateSceneFbosOit[0].operator->() : NULL
451 if (!myTransientDrawToFront)
453 anImmFbos [0] = aMainFbos [0];
454 anImmFbos [1] = aMainFbos [1];
455 anImmFbosOit[0] = aMainFbosOit[0];
456 anImmFbosOit[1] = aMainFbosOit[1];
458 else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
459 || aStereoMode == Graphic3d_StereoMode_QuadBuffer)
461 anImmFbos [0] = NULL;
462 anImmFbos [1] = NULL;
463 anImmFbosOit[0] = NULL;
464 anImmFbosOit[1] = NULL;
467 #if !defined(GL_ES_VERSION_2_0)
468 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
470 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
471 aMainFbos[0] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
473 redraw (Graphic3d_Camera::Projection_MonoLeftEye, aMainFbos[0], aMainFbosOit[0]);
474 myBackBufferRestored = Standard_True;
475 myIsImmediateDrawn = Standard_False;
476 #if !defined(GL_ES_VERSION_2_0)
477 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
479 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
480 anImmFbos[0] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
481 if (!redrawImmediate (Graphic3d_Camera::Projection_MonoLeftEye, aMainFbos[0], anImmFbos[0], anImmFbosOit[0]))
485 else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip && toSwap)
490 #if !defined(GL_ES_VERSION_2_0)
491 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK);
493 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
494 aMainFbos[1] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
496 redraw (Graphic3d_Camera::Projection_MonoRightEye, aMainFbos[1], aMainFbosOit[1]);
497 myBackBufferRestored = Standard_True;
498 myIsImmediateDrawn = Standard_False;
499 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
500 anImmFbos[1] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
501 if (!redrawImmediate (Graphic3d_Camera::Projection_MonoRightEye, aMainFbos[1], anImmFbos[1], anImmFbosOit[1]))
506 if (anImmFbos[0] != NULL)
508 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(), 1.0f);
509 drawStereoPair (aFrameBuffer);
514 OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : aFrameBuffer;
515 OpenGl_FrameBuffer* aMainFboOit = myMainSceneFbosOit[0]->IsValid() ? myMainSceneFbosOit[0].operator->() : NULL;
516 OpenGl_FrameBuffer* anImmFbo = aFrameBuffer;
517 OpenGl_FrameBuffer* anImmFboOit = NULL;
518 if (!myTransientDrawToFront)
521 anImmFboOit = aMainFboOit;
523 else if (myImmediateSceneFbos[0]->IsValid())
525 anImmFbo = myImmediateSceneFbos[0].operator->();
526 anImmFboOit = myImmediateSceneFbosOit[0]->IsValid() ? myImmediateSceneFbosOit[0].operator->() : NULL;
529 #if !defined(GL_ES_VERSION_2_0)
530 if (aMainFbo == NULL)
532 aCtx->SetReadDrawBuffer (GL_BACK);
535 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
536 aMainFbo != aFrameBuffer ? myRenderParams.RenderResolutionScale : 1.0f);
538 redraw (aProjectType, aMainFbo, aMainFboOit);
539 myBackBufferRestored = Standard_True;
540 myIsImmediateDrawn = Standard_False;
541 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
542 anImmFbo != aFrameBuffer ? myRenderParams.RenderResolutionScale : 1.0f);
543 if (!redrawImmediate (aProjectType, aMainFbo, anImmFbo, anImmFboOit))
549 && anImmFbo != aFrameBuffer)
551 blitBuffers (anImmFbo, aFrameBuffer, myToFlipOutput);
555 if (myRenderParams.Method == Graphic3d_RM_RAYTRACING
556 && myRenderParams.IsGlobalIlluminationEnabled)
564 if (wasDisabledMSAA != myToDisableMSAA
565 || hadFboBlit != myHasFboBlit)
571 // reset state for safety
572 aCtx->BindProgram (Handle(OpenGl_ShaderProgram)());
573 if (aCtx->caps->ffpEnable)
575 aCtx->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
582 if (!myMainSceneFbos[0]->IsValid())
584 myBackBufferRestored = Standard_False;
589 aCtx->core11fwd->glFlush();
592 // reset render mode state
594 aCtx->FrameStats()->FrameEnd (myWorkspace->View(), false);
596 myWasRedrawnGL = Standard_True;
599 // =======================================================================
600 // function : RedrawImmediate
602 // =======================================================================
603 void OpenGl_View::RedrawImmediate()
605 if (!myWorkspace->Activate())
608 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
609 if (!myTransientDrawToFront
610 || !myBackBufferRestored
611 || (aCtx->caps->buffersNoSwap && !myMainSceneFbos[0]->IsValid()))
617 const Graphic3d_StereoMode aStereoMode = myRenderParams.StereoMode;
618 Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType();
619 OpenGl_FrameBuffer* aFrameBuffer = myFBO.get();
620 aCtx->FrameStats()->FrameStart (myWorkspace->View(), true);
622 if ( aFrameBuffer == NULL
623 && !aCtx->DefaultFrameBuffer().IsNull()
624 && aCtx->DefaultFrameBuffer()->IsValid())
626 aFrameBuffer = aCtx->DefaultFrameBuffer().operator->();
629 if (aProjectType == Graphic3d_Camera::Projection_Stereo)
631 if (myMainSceneFbos[0]->IsValid()
632 && !myMainSceneFbos[1]->IsValid())
634 aProjectType = Graphic3d_Camera::Projection_Perspective;
639 if (aProjectType == Graphic3d_Camera::Projection_Stereo)
641 OpenGl_FrameBuffer* aMainFbos[2] =
643 myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL,
644 myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL
646 OpenGl_FrameBuffer* anImmFbos[2] =
648 myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL,
649 myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL
651 OpenGl_FrameBuffer* anImmFbosOit[2] =
653 myImmediateSceneFbosOit[0]->IsValid() ? myImmediateSceneFbosOit[0].operator->() : NULL,
654 myImmediateSceneFbosOit[1]->IsValid() ? myImmediateSceneFbosOit[1].operator->() :
655 myImmediateSceneFbosOit[0]->IsValid() ? myImmediateSceneFbosOit[0].operator->() : NULL
657 if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
658 || aStereoMode == Graphic3d_StereoMode_QuadBuffer)
662 anImmFbosOit[0] = NULL;
663 anImmFbosOit[1] = NULL;
666 if (aCtx->arbFBO != NULL)
668 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
670 #if !defined(GL_ES_VERSION_2_0)
671 if (anImmFbos[0] == NULL)
673 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
677 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
678 anImmFbos[0] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
679 toSwap = redrawImmediate (Graphic3d_Camera::Projection_MonoLeftEye,
683 Standard_True) || toSwap;
684 if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip
686 && !aCtx->caps->buffersNoSwap)
691 if (aCtx->arbFBO != NULL)
693 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
695 #if !defined(GL_ES_VERSION_2_0)
696 if (anImmFbos[1] == NULL)
698 aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK);
701 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
702 anImmFbos[1] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
703 toSwap = redrawImmediate (Graphic3d_Camera::Projection_MonoRightEye,
707 Standard_True) || toSwap;
708 if (anImmFbos[0] != NULL)
710 drawStereoPair (aFrameBuffer);
715 OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL;
716 OpenGl_FrameBuffer* anImmFbo = aFrameBuffer;
717 OpenGl_FrameBuffer* anImmFboOit = NULL;
718 if (myImmediateSceneFbos[0]->IsValid())
720 anImmFbo = myImmediateSceneFbos[0].operator->();
721 anImmFboOit = myImmediateSceneFbosOit[0]->IsValid() ? myImmediateSceneFbosOit[0].operator->() : NULL;
723 #if !defined(GL_ES_VERSION_2_0)
724 if (aMainFbo == NULL)
726 aCtx->SetReadDrawBuffer (GL_BACK);
729 aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
730 anImmFbo != aFrameBuffer ? myRenderParams.RenderResolutionScale : 1.0f);
731 toSwap = redrawImmediate (aProjectType,
735 Standard_True) || toSwap;
737 && anImmFbo != aFrameBuffer)
739 blitBuffers (anImmFbo, aFrameBuffer, myToFlipOutput);
746 // reset state for safety
747 aCtx->BindProgram (Handle(OpenGl_ShaderProgram)());
748 if (aCtx->caps->ffpEnable)
750 aCtx->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
753 if (toSwap && !aCtx->caps->buffersNoSwap)
759 aCtx->core11fwd->glFlush();
761 aCtx->FrameStats()->FrameEnd (myWorkspace->View(), true);
763 myWasRedrawnGL = Standard_True;
766 // =======================================================================
769 // =======================================================================
770 void OpenGl_View::redraw (const Graphic3d_Camera::Projection theProjection,
771 OpenGl_FrameBuffer* theReadDrawFbo,
772 OpenGl_FrameBuffer* theOitAccumFbo)
774 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
775 if (theReadDrawFbo != NULL)
777 theReadDrawFbo->BindBuffer (aCtx);
778 theReadDrawFbo->SetupViewport (aCtx);
782 const Standard_Integer aViewport[4] = { 0, 0, myWindow->Width(), myWindow->Height() };
783 aCtx->ResizeViewport (aViewport);
786 // request reset of material
787 aCtx->ShaderManager()->UpdateMaterialState();
789 myWorkspace->UseZBuffer() = Standard_True;
790 myWorkspace->UseDepthWrite() = Standard_True;
791 GLbitfield toClear = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
792 glDepthFunc (GL_LEQUAL);
793 glDepthMask (GL_TRUE);
794 glEnable (GL_DEPTH_TEST);
796 #if !defined(GL_ES_VERSION_2_0)
799 glClearDepthf (1.0f);
802 const OpenGl_Vec4& aBgColor = myBgColor;
803 glClearColor (aBgColor.r(), aBgColor.g(), aBgColor.b(), 0.0f);
807 render (theProjection, theReadDrawFbo, theOitAccumFbo, Standard_False);
810 // =======================================================================
811 // function : redrawMonoImmediate
813 // =======================================================================
814 bool OpenGl_View::redrawImmediate (const Graphic3d_Camera::Projection theProjection,
815 OpenGl_FrameBuffer* theReadFbo,
816 OpenGl_FrameBuffer* theDrawFbo,
817 OpenGl_FrameBuffer* theOitAccumFbo,
818 const Standard_Boolean theIsPartialUpdate)
820 const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
821 GLboolean toCopyBackToFront = GL_FALSE;
822 if (theDrawFbo == theReadFbo
823 && theDrawFbo != NULL)
825 myBackBufferRestored = Standard_False;
827 else if (theReadFbo != NULL
828 && theReadFbo->IsValid()
831 if (!blitBuffers (theReadFbo, theDrawFbo))
836 else if (theDrawFbo == NULL)
838 #if !defined(GL_ES_VERSION_2_0)
839 aCtx->core11fwd->glGetBooleanv (GL_DOUBLEBUFFER, &toCopyBackToFront);
841 if (toCopyBackToFront
842 && myTransientDrawToFront)
844 if (!HasImmediateStructures()
845 && !theIsPartialUpdate)
847 // prefer Swap Buffers within Redraw in compatibility mode (without FBO)
850 if (!copyBackToFront())
852 toCopyBackToFront = GL_FALSE;
853 myBackBufferRestored = Standard_False;
858 toCopyBackToFront = GL_FALSE;
859 myBackBufferRestored = Standard_False;
864 myBackBufferRestored = Standard_False;
866 myIsImmediateDrawn = Standard_True;
868 myWorkspace->UseZBuffer() = Standard_True;
869 myWorkspace->UseDepthWrite() = Standard_True;
870 glDepthFunc (GL_LEQUAL);
871 glDepthMask (GL_TRUE);
872 glEnable (GL_DEPTH_TEST);
873 #if !defined(GL_ES_VERSION_2_0)
876 glClearDepthf (1.0f);
879 render (theProjection, theDrawFbo, theOitAccumFbo, Standard_True);
881 return !toCopyBackToFront;
884 //=======================================================================
887 //=======================================================================
888 void OpenGl_View::render (Graphic3d_Camera::Projection theProjection,
889 OpenGl_FrameBuffer* theOutputFBO,
890 OpenGl_FrameBuffer* theOitAccumFbo,
891 const Standard_Boolean theToDrawImmediate)
893 // ==================================
894 // Step 1: Prepare for render
895 // ==================================
897 const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
898 aContext->SetAllowSampleAlphaToCoverage (myRenderParams.ToEnableAlphaToCoverage
899 && theOutputFBO != NULL
900 && theOutputFBO->NbSamples() != 0);
902 #if !defined(GL_ES_VERSION_2_0)
903 // Disable current clipping planes
904 if (aContext->core11 != NULL)
906 const Standard_Integer aMaxPlanes = aContext->MaxClipPlanes();
907 for (Standard_Integer aClipPlaneId = GL_CLIP_PLANE0; aClipPlaneId < GL_CLIP_PLANE0 + aMaxPlanes; ++aClipPlaneId)
909 aContext->core11fwd->glDisable (aClipPlaneId);
914 // update states of OpenGl_BVHTreeSelector (frustum culling algorithm);
915 // note that we pass here window dimensions ignoring Graphic3d_RenderingParams::RenderResolutionScale
916 myBVHSelector.SetViewVolume (myCamera);
917 myBVHSelector.SetViewportSize (myWindow->Width(), myWindow->Height(), myRenderParams.ResolutionRatio());
918 myBVHSelector.CacheClipPtsProjections();
920 const Handle(OpenGl_ShaderManager)& aManager = aContext->ShaderManager();
921 const Handle(Graphic3d_LightSet)& aLights = myShadingModel == Graphic3d_TOSM_UNLIT ? myNoShadingLight : myLights;
922 Standard_Size aLightsRevision = 0;
923 if (!aLights.IsNull())
925 aLightsRevision = aLights->UpdateRevision();
927 if (StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()) != myLastLightSourceState
928 || aLightsRevision != myLightsRevision)
930 myLightsRevision = aLightsRevision;
931 aManager->UpdateLightSourceStateTo (aLights);
932 myLastLightSourceState = StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index());
935 // Update matrices if camera has changed.
936 Graphic3d_WorldViewProjState aWVPState = myCamera->WorldViewProjState();
937 if (myWorldViewProjState != aWVPState)
940 myWorldViewProjState = aWVPState;
943 myLocalOrigin.SetCoord (0.0, 0.0, 0.0);
944 aContext->ProjectionState.SetCurrent (myCamera->ProjectionMatrixF());
945 aContext->WorldViewState .SetCurrent (myCamera->OrientationMatrixF());
946 aContext->ApplyProjectionMatrix();
947 aContext->ApplyWorldViewMatrix();
948 if (aManager->ModelWorldState().Index() == 0)
950 aContext->ShaderManager()->UpdateModelWorldStateTo (OpenGl_Mat4());
953 // ====================================
954 // Step 2: Redraw background
955 // ====================================
958 if (!theToDrawImmediate)
960 drawBackground (myWorkspace);
963 #if !defined(GL_ES_VERSION_2_0)
964 // Switch off lighting by default
965 if (aContext->core11 != NULL
966 && aContext->caps->ffpEnable)
968 glDisable(GL_LIGHTING);
972 // =================================
973 // Step 3: Redraw main plane
974 // =================================
976 // Setup face culling
977 GLboolean isCullFace = GL_FALSE;
978 if (myBackfacing != Graphic3d_TOBM_AUTOMATIC)
980 isCullFace = glIsEnabled (GL_CULL_FACE);
981 if (myBackfacing == Graphic3d_TOBM_DISABLE)
983 glEnable (GL_CULL_FACE);
984 glCullFace (GL_BACK);
987 glDisable (GL_CULL_FACE);
990 #if !defined(GL_ES_VERSION_2_0)
991 // if the view is scaled normal vectors are scaled to unit
992 // length for correct displaying of shaded objects
993 const gp_Pnt anAxialScale = myCamera->AxialScale();
994 if (anAxialScale.X() != 1.F ||
995 anAxialScale.Y() != 1.F ||
996 anAxialScale.Z() != 1.F)
998 aContext->SetGlNormalizeEnabled (Standard_True);
1002 aContext->SetGlNormalizeEnabled (Standard_False);
1005 // Apply InteriorShadingMethod
1006 if (aContext->core11 != NULL)
1008 aContext->core11->glShadeModel (myShadingModel == Graphic3d_TOSM_FACET
1009 || myShadingModel == Graphic3d_TOSM_UNLIT ? GL_FLAT : GL_SMOOTH);
1013 aManager->SetShadingModel (myShadingModel);
1016 if (theProjection == Graphic3d_Camera::Projection_MonoLeftEye)
1018 aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoLeftF());
1019 aContext->ApplyProjectionMatrix();
1021 else if (theProjection == Graphic3d_Camera::Projection_MonoRightEye)
1023 aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoRightF());
1024 aContext->ApplyProjectionMatrix();
1027 myWorkspace->SetEnvironmentTexture (myTextureEnv);
1029 renderScene (theProjection, theOutputFBO, theOitAccumFbo, theToDrawImmediate);
1031 myWorkspace->SetEnvironmentTexture (Handle(OpenGl_TextureSet)());
1033 // ===============================
1034 // Step 4: Trihedron
1035 // ===============================
1037 // Resetting GL parameters according to the default aspects
1038 // in order to synchronize GL state with the graphic driver state
1039 // before drawing auxiliary stuff (trihedrons, overlayer)
1040 myWorkspace->ResetAppliedAspect();
1043 if (!theToDrawImmediate)
1045 renderTrihedron (myWorkspace);
1047 // Restore face culling
1048 if (myBackfacing != Graphic3d_TOBM_AUTOMATIC)
1052 glEnable (GL_CULL_FACE);
1053 glCullFace (GL_BACK);
1056 glDisable (GL_CULL_FACE);
1064 myWorkspace->ResetAppliedAspect();
1065 aContext->SetAllowSampleAlphaToCoverage (false);
1066 aContext->SetSampleAlphaToCoverage (false);
1068 // reset FFP state for safety
1069 aContext->BindProgram (Handle(OpenGl_ShaderProgram)());
1070 if (aContext->caps->ffpEnable)
1072 aContext->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
1075 // ==============================================================
1076 // Step 6: Keep shader manager informed about last View
1077 // ==============================================================
1079 if (!aManager.IsNull())
1081 aManager->SetLastView (this);
1085 // =======================================================================
1086 // function : InvalidateBVHData
1088 // =======================================================================
1089 void OpenGl_View::InvalidateBVHData (const Graphic3d_ZLayerId theLayerId)
1091 myZLayers.InvalidateBVHData (theLayerId);
1094 //=======================================================================
1095 //function : renderStructs
1097 //=======================================================================
1098 void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
1099 OpenGl_FrameBuffer* theReadDrawFbo,
1100 OpenGl_FrameBuffer* theOitAccumFbo,
1101 const Standard_Boolean theToDrawImmediate)
1103 myZLayers.UpdateCulling (myWorkspace, theToDrawImmediate);
1104 if ( myZLayers.NbStructures() <= 0 )
1107 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
1108 Standard_Boolean toRenderGL = theToDrawImmediate ||
1109 myRenderParams.Method != Graphic3d_RM_RAYTRACING ||
1110 myRaytraceInitStatus == OpenGl_RT_FAIL ||
1115 const Standard_Integer aSizeX = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeX() : myWindow->Width();
1116 const Standard_Integer aSizeY = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeY() : myWindow->Height();
1118 toRenderGL = !initRaytraceResources (aSizeX, aSizeY, aCtx)
1119 || !updateRaytraceGeometry (OpenGl_GUM_CHECK, myId, aCtx);
1121 toRenderGL |= !myIsRaytraceDataValid; // if no ray-trace data use OpenGL
1125 myOpenGlFBO ->InitLazy (aCtx, aSizeX, aSizeY, myFboColorFormat, myFboDepthFormat, 0);
1127 if (theReadDrawFbo != NULL)
1128 theReadDrawFbo->UnbindBuffer (aCtx);
1130 // Prepare preliminary OpenGL output
1131 if (aCtx->arbFBOBlit != NULL)
1133 // Render bottom OSD layer
1134 myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Bottom, theReadDrawFbo, theOitAccumFbo);
1136 const Standard_Integer aPrevFilter = myWorkspace->RenderFilter() & ~(Standard_Integer )(OpenGl_RenderFilter_NonRaytraceableOnly);
1137 myWorkspace->SetRenderFilter (aPrevFilter | OpenGl_RenderFilter_NonRaytraceableOnly);
1139 if (theReadDrawFbo != NULL)
1141 theReadDrawFbo->BindDrawBuffer (aCtx);
1145 aCtx->arbFBO->glBindFramebuffer (GL_DRAW_FRAMEBUFFER, 0);
1148 // Render non-polygonal elements in default layer
1149 myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_RayTracable, theReadDrawFbo, theOitAccumFbo);
1151 myWorkspace->SetRenderFilter (aPrevFilter);
1154 if (theReadDrawFbo != NULL)
1156 theReadDrawFbo->BindBuffer (aCtx);
1160 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, 0);
1163 // Reset OpenGl aspects state to default to avoid enabling of
1164 // backface culling which is not supported in ray-tracing.
1165 myWorkspace->ResetAppliedAspect();
1167 // Ray-tracing polygonal primitive arrays
1168 raytrace (aSizeX, aSizeY, theProjection, theReadDrawFbo, aCtx);
1170 // Render upper (top and topmost) OpenGL layers
1171 myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Upper, theReadDrawFbo, theOitAccumFbo);
1175 // Redraw 3D scene using OpenGL in standard
1176 // mode or in case of ray-tracing failure
1179 myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_All, theReadDrawFbo, theOitAccumFbo);
1181 // Set flag that scene was redrawn by standard pipeline
1182 myWasRedrawnGL = Standard_True;
1186 //=======================================================================
1187 //function : renderTrihedron
1189 //=======================================================================
1190 void OpenGl_View::renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace)
1192 if (myToShowGradTrihedron)
1194 myGraduatedTrihedron.Render (theWorkspace);
1198 //=======================================================================
1199 //function : renderFrameStats
1201 //=======================================================================
1202 void OpenGl_View::renderFrameStats()
1204 if (myRenderParams.ToShowStats
1205 && myRenderParams.CollectedStats != Graphic3d_RenderingParams::PerfCounters_NONE)
1207 myFrameStatsPrs.Update (myWorkspace);
1208 myFrameStatsPrs.Render (myWorkspace);
1212 // =======================================================================
1213 // function : Invalidate
1215 // =======================================================================
1216 void OpenGl_View::Invalidate()
1218 myBackBufferRestored = Standard_False;
1221 //=======================================================================
1222 //function : renderScene
1224 //=======================================================================
1225 void OpenGl_View::renderScene (Graphic3d_Camera::Projection theProjection,
1226 OpenGl_FrameBuffer* theReadDrawFbo,
1227 OpenGl_FrameBuffer* theOitAccumFbo,
1228 const Standard_Boolean theToDrawImmediate)
1230 const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
1232 // Specify clipping planes in view transformation space
1233 aContext->ChangeClipping().Reset (myClipPlanes);
1234 if (!myClipPlanes.IsNull()
1235 && !myClipPlanes->IsEmpty())
1237 aContext->ShaderManager()->UpdateClippingState();
1240 renderStructs (theProjection, theReadDrawFbo, theOitAccumFbo, theToDrawImmediate);
1241 aContext->BindTextures (Handle(OpenGl_TextureSet)());
1243 // Apply restored view matrix.
1244 aContext->ApplyWorldViewMatrix();
1246 aContext->ChangeClipping().Reset (Handle(Graphic3d_SequenceOfHClipPlane)());
1247 if (!myClipPlanes.IsNull()
1248 && !myClipPlanes->IsEmpty())
1250 aContext->ShaderManager()->RevertClippingState();
1254 // =======================================================================
1255 // function : bindDefaultFbo
1257 // =======================================================================
1258 void OpenGl_View::bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo)
1260 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
1261 OpenGl_FrameBuffer* anFbo = (theCustomFbo != NULL && theCustomFbo->IsValid())
1263 : (!aCtx->DefaultFrameBuffer().IsNull()
1264 && aCtx->DefaultFrameBuffer()->IsValid()
1265 ? aCtx->DefaultFrameBuffer().operator->()
1269 anFbo->BindBuffer (aCtx);
1270 anFbo->SetupViewport (aCtx);
1274 #if !defined(GL_ES_VERSION_2_0)
1275 aCtx->SetReadDrawBuffer (GL_BACK);
1277 if (aCtx->arbFBO != NULL)
1279 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1282 const Standard_Integer aViewport[4] = { 0, 0, myWindow->Width(), myWindow->Height() };
1283 aCtx->ResizeViewport (aViewport);
1287 // =======================================================================
1288 // function : initBlitQuad
1290 // =======================================================================
1291 OpenGl_VertexBuffer* OpenGl_View::initBlitQuad (const Standard_Boolean theToFlip)
1293 OpenGl_VertexBuffer* aVerts = NULL;
1296 aVerts = &myFullScreenQuad;
1297 if (!aVerts->IsValid())
1299 OpenGl_Vec4 aQuad[4] =
1301 OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 0.0f),
1302 OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 1.0f),
1303 OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 0.0f),
1304 OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 1.0f)
1306 aVerts->Init (myWorkspace->GetGlContext(), 4, 4, aQuad[0].GetData());
1311 aVerts = &myFullScreenQuadFlip;
1312 if (!aVerts->IsValid())
1314 OpenGl_Vec4 aQuad[4] =
1316 OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 1.0f),
1317 OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 0.0f),
1318 OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
1319 OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 0.0f)
1321 aVerts->Init (myWorkspace->GetGlContext(), 4, 4, aQuad[0].GetData());
1327 // =======================================================================
1328 // function : blitBuffers
1330 // =======================================================================
1331 bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer* theReadFbo,
1332 OpenGl_FrameBuffer* theDrawFbo,
1333 const Standard_Boolean theToFlip)
1335 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
1336 const Standard_Integer aReadSizeX = theReadFbo != NULL ? theReadFbo->GetVPSizeX() : myWindow->Width();
1337 const Standard_Integer aReadSizeY = theReadFbo != NULL ? theReadFbo->GetVPSizeY() : myWindow->Height();
1338 const Standard_Integer aDrawSizeX = theDrawFbo != NULL ? theDrawFbo->GetVPSizeX() : myWindow->Width();
1339 const Standard_Integer aDrawSizeY = theDrawFbo != NULL ? theDrawFbo->GetVPSizeY() : myWindow->Height();
1340 if (theReadFbo == NULL || aCtx->IsFeedback())
1344 else if (theReadFbo == theDrawFbo)
1349 // clear destination before blitting
1350 if (theDrawFbo != NULL
1351 && theDrawFbo->IsValid())
1353 theDrawFbo->BindBuffer (aCtx);
1357 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1359 const Standard_Integer aViewport[4] = { 0, 0, aDrawSizeX, aDrawSizeY };
1360 aCtx->ResizeViewport (aViewport);
1362 #if !defined(GL_ES_VERSION_2_0)
1363 aCtx->core20fwd->glClearDepth (1.0);
1365 aCtx->core20fwd->glClearDepthf (1.0f);
1367 aCtx->core20fwd->glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1369 if (aCtx->arbFBOBlit != NULL
1370 && theReadFbo->NbSamples() != 0)
1372 GLbitfield aCopyMask = 0;
1373 theReadFbo->BindReadBuffer (aCtx);
1374 if (theDrawFbo != NULL
1375 && theDrawFbo->IsValid())
1377 theDrawFbo->BindDrawBuffer (aCtx);
1378 if (theDrawFbo->HasColor()
1379 && theReadFbo->HasColor())
1381 aCopyMask |= GL_COLOR_BUFFER_BIT;
1383 if (theDrawFbo->HasDepth()
1384 && theReadFbo->HasDepth())
1386 aCopyMask |= GL_DEPTH_BUFFER_BIT;
1391 if (theReadFbo->HasColor())
1393 aCopyMask |= GL_COLOR_BUFFER_BIT;
1395 if (theReadFbo->HasDepth())
1397 aCopyMask |= GL_DEPTH_BUFFER_BIT;
1399 aCtx->arbFBO->glBindFramebuffer (GL_DRAW_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1402 // we don't copy stencil buffer here... does it matter for performance?
1403 aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, aReadSizeX, aReadSizeY,
1404 0, 0, aDrawSizeX, aDrawSizeY,
1405 aCopyMask, GL_NEAREST);
1406 const int anErr = ::glGetError();
1407 if (anErr != GL_NO_ERROR)
1409 // glBlitFramebuffer() might fail in several cases:
1410 // - Both FBOs have MSAA and they are samples number does not match.
1411 // OCCT checks that this does not happen,
1412 // however some graphics drivers provide an option for overriding MSAA.
1413 // In this case window MSAA might be non-zero (and application can not check it)
1414 // and might not match MSAA of our offscreen FBOs.
1415 // - Pixel formats of FBOs do not match.
1416 // This also might happen with window has pixel format,
1417 // e.g. Mesa fails blitting RGBA8 -> RGB8 while other drivers support this conversion.
1418 TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "FBO blitting has failed [Error #" + anErr + "]\n"
1419 + " Please check your graphics driver settings or try updating driver.";
1420 if (theReadFbo->NbSamples() != 0)
1422 myToDisableMSAA = true;
1423 aMsg += "\n MSAA settings should not be overridden by driver!";
1425 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
1426 GL_DEBUG_TYPE_ERROR,
1428 GL_DEBUG_SEVERITY_HIGH,
1432 if (theDrawFbo != NULL
1433 && theDrawFbo->IsValid())
1435 theDrawFbo->BindBuffer (aCtx);
1439 aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
1444 aCtx->core20fwd->glDepthFunc (GL_ALWAYS);
1445 aCtx->core20fwd->glDepthMask (GL_TRUE);
1446 aCtx->core20fwd->glEnable (GL_DEPTH_TEST);
1447 #if defined(GL_ES_VERSION_2_0)
1448 if (!aCtx->IsGlGreaterEqual (3, 0)
1449 && !aCtx->extFragDepth)
1451 aCtx->core20fwd->glDisable (GL_DEPTH_TEST);
1455 aCtx->BindTextures (Handle(OpenGl_TextureSet)());
1457 const Graphic3d_TypeOfTextureFilter aFilter = (aDrawSizeX == aReadSizeX && aDrawSizeY == aReadSizeY) ? Graphic3d_TOTF_NEAREST : Graphic3d_TOTF_BILINEAR;
1458 const GLint aFilterGl = aFilter == Graphic3d_TOTF_NEAREST ? GL_NEAREST : GL_LINEAR;
1460 OpenGl_VertexBuffer* aVerts = initBlitQuad (theToFlip);
1461 const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager();
1462 if (aVerts->IsValid()
1463 && aManager->BindFboBlitProgram())
1465 aCtx->SetSampleAlphaToCoverage (false);
1466 theReadFbo->ColorTexture()->Bind (aCtx, Graphic3d_TextureUnit_0);
1467 if (theReadFbo->ColorTexture()->Sampler()->Parameters()->Filter() != aFilter)
1469 theReadFbo->ColorTexture()->Sampler()->Parameters()->SetFilter (aFilter);
1470 aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterGl);
1471 aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilterGl);
1474 theReadFbo->DepthStencilTexture()->Bind (aCtx, Graphic3d_TextureUnit_1);
1475 if (theReadFbo->DepthStencilTexture()->Sampler()->Parameters()->Filter() != aFilter)
1477 theReadFbo->DepthStencilTexture()->Sampler()->Parameters()->SetFilter (aFilter);
1478 aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterGl);
1479 aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilterGl);
1482 aVerts->BindVertexAttrib (aCtx, Graphic3d_TOA_POS);
1484 aCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
1486 aVerts->UnbindVertexAttrib (aCtx, Graphic3d_TOA_POS);
1487 theReadFbo->DepthStencilTexture()->Unbind (aCtx, Graphic3d_TextureUnit_1);
1488 theReadFbo->ColorTexture() ->Unbind (aCtx, Graphic3d_TextureUnit_0);
1489 aCtx->BindProgram (NULL);
1493 TCollection_ExtendedString aMsg = TCollection_ExtendedString()
1494 + "Error! FBO blitting has failed";
1495 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
1496 GL_DEBUG_TYPE_ERROR,
1498 GL_DEBUG_SEVERITY_HIGH,
1500 myHasFboBlit = Standard_False;
1501 theReadFbo->Release (aCtx.operator->());
1508 // =======================================================================
1509 // function : drawStereoPair
1511 // =======================================================================
1512 void OpenGl_View::drawStereoPair (OpenGl_FrameBuffer* theDrawFbo)
1514 const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
1515 bindDefaultFbo (theDrawFbo);
1516 OpenGl_FrameBuffer* aPair[2] =
1518 myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL,
1519 myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL
1521 if (aPair[0] == NULL
1523 || !myTransientDrawToFront)
1525 aPair[0] = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL;
1526 aPair[1] = myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL;
1529 if (aPair[0] == NULL
1530 || aPair[1] == NULL)
1535 if (aPair[0]->NbSamples() != 0)
1537 // resolve MSAA buffers before drawing
1538 if (!myOpenGlFBO ->InitLazy (aCtx, aPair[0]->GetVPSizeX(), aPair[0]->GetVPSizeY(), myFboColorFormat, myFboDepthFormat, 0)
1539 || !myOpenGlFBO2->InitLazy (aCtx, aPair[0]->GetVPSizeX(), aPair[0]->GetVPSizeY(), myFboColorFormat, 0, 0))
1541 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
1542 GL_DEBUG_TYPE_ERROR,
1544 GL_DEBUG_SEVERITY_HIGH,
1545 "Error! Unable to allocate FBO for blitting stereo pair");
1546 bindDefaultFbo (theDrawFbo);
1550 if (!blitBuffers (aPair[0], myOpenGlFBO .operator->(), Standard_False)
1551 || !blitBuffers (aPair[1], myOpenGlFBO2.operator->(), Standard_False))
1553 bindDefaultFbo (theDrawFbo);
1557 aPair[0] = myOpenGlFBO .operator->();
1558 aPair[1] = myOpenGlFBO2.operator->();
1559 bindDefaultFbo (theDrawFbo);
1564 Standard_Integer left;
1565 Standard_Integer top;
1566 Standard_Integer right;
1567 Standard_Integer bottom;
1568 Standard_Integer dx() { return right - left; }
1569 Standard_Integer dy() { return bottom - top; }
1572 myWindow->PlatformWindow()->Position (aGeom.left, aGeom.top, aGeom.right, aGeom.bottom);
1574 Standard_Boolean toReverse = myRenderParams.ToReverseStereo;
1575 const Standard_Boolean isOddY = (aGeom.top + aGeom.dy()) % 2 == 1;
1576 const Standard_Boolean isOddX = aGeom.left % 2 == 1;
1578 && (myRenderParams.StereoMode == Graphic3d_StereoMode_RowInterlaced
1579 || myRenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard))
1581 toReverse = !toReverse;
1584 && (myRenderParams.StereoMode == Graphic3d_StereoMode_ColumnInterlaced
1585 || myRenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard))
1587 toReverse = !toReverse;
1592 std::swap (aPair[0], aPair[1]);
1595 aCtx->core20fwd->glDepthFunc (GL_ALWAYS);
1596 aCtx->core20fwd->glDepthMask (GL_TRUE);
1597 aCtx->core20fwd->glEnable (GL_DEPTH_TEST);
1599 aCtx->BindTextures (Handle(OpenGl_TextureSet)());
1600 OpenGl_VertexBuffer* aVerts = initBlitQuad (myToFlipOutput);
1602 const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager();
1603 if (aVerts->IsValid()
1604 && aManager->BindStereoProgram (myRenderParams.StereoMode))
1606 if (myRenderParams.StereoMode == Graphic3d_StereoMode_Anaglyph)
1608 OpenGl_Mat4 aFilterL, aFilterR;
1609 aFilterL.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
1610 aFilterR.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
1611 switch (myRenderParams.AnaglyphFilter)
1613 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple:
1615 aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
1616 aFilterR.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
1617 aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
1620 case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized:
1622 aFilterL.SetRow (0, Graphic3d_Vec4 ( 0.4154f, 0.4710f, 0.16666667f, 0.0f));
1623 aFilterL.SetRow (1, Graphic3d_Vec4 (-0.0458f, -0.0484f, -0.0257f, 0.0f));
1624 aFilterL.SetRow (2, Graphic3d_Vec4 (-0.0547f, -0.0615f, 0.0128f, 0.0f));
1625 aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f));
1626 aFilterR.SetRow (0, Graphic3d_Vec4 (-0.01090909f, -0.03636364f, -0.00606061f, 0.0f));
1627 aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.37560000f, 0.73333333f, 0.01111111f, 0.0f));
1628 aFilterR.SetRow (2, Graphic3d_Vec4 (-0.06510000f, -0.12870000f, 1.29710000f, 0.0f));
1629 aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f));
1632 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple:
1634 aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
1635 aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
1636 aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
1639 case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized:
1641 aFilterL.SetRow (0, Graphic3d_Vec4 ( 1.062f, -0.205f, 0.299f, 0.0f));
1642 aFilterL.SetRow (1, Graphic3d_Vec4 (-0.026f, 0.908f, 0.068f, 0.0f));
1643 aFilterL.SetRow (2, Graphic3d_Vec4 (-0.038f, -0.173f, 0.022f, 0.0f));
1644 aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f));
1645 aFilterR.SetRow (0, Graphic3d_Vec4 (-0.016f, -0.123f, -0.017f, 0.0f));
1646 aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.006f, 0.062f, -0.017f, 0.0f));
1647 aFilterR.SetRow (2, Graphic3d_Vec4 ( 0.094f, 0.185f, 0.911f, 0.0f));
1648 aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f));
1651 case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple:
1653 aFilterR.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f));
1654 aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f));
1655 aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f));
1658 case Graphic3d_RenderingParams::Anaglyph_UserDefined:
1660 aFilterL = myRenderParams.AnaglyphLeft;
1661 aFilterR = myRenderParams.AnaglyphRight;
1665 aCtx->ActiveProgram()->SetUniform (aCtx, "uMultL", aFilterL);
1666 aCtx->ActiveProgram()->SetUniform (aCtx, "uMultR", aFilterR);
1669 aPair[0]->ColorTexture()->Bind (aCtx, Graphic3d_TextureUnit_0);
1670 aPair[1]->ColorTexture()->Bind (aCtx, Graphic3d_TextureUnit_1);
1671 aVerts->BindVertexAttrib (aCtx, 0);
1673 aCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
1675 aVerts->UnbindVertexAttrib (aCtx, 0);
1676 aPair[1]->ColorTexture()->Unbind (aCtx, Graphic3d_TextureUnit_1);
1677 aPair[0]->ColorTexture()->Unbind (aCtx, Graphic3d_TextureUnit_0);
1681 TCollection_ExtendedString aMsg = TCollection_ExtendedString()
1682 + "Error! Anaglyph has failed";
1683 aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
1684 GL_DEBUG_TYPE_ERROR,
1686 GL_DEBUG_SEVERITY_HIGH,
1691 // =======================================================================
1692 // function : copyBackToFront
1694 // =======================================================================
1695 bool OpenGl_View::copyBackToFront()
1697 myIsImmediateDrawn = Standard_False;
1698 #if !defined(GL_ES_VERSION_2_0)
1699 const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
1700 if (aCtx->core11 == NULL)
1705 OpenGl_Mat4 aProjectMat;
1706 Graphic3d_TransformUtils::Ortho2D (aProjectMat,
1707 0.0f, static_cast<GLfloat> (myWindow->Width()),
1708 0.0f, static_cast<GLfloat> (myWindow->Height()));
1710 aCtx->WorldViewState.Push();
1711 aCtx->ProjectionState.Push();
1713 aCtx->WorldViewState.SetIdentity();
1714 aCtx->ProjectionState.SetCurrent (aProjectMat);
1716 aCtx->ApplyProjectionMatrix();
1717 aCtx->ApplyWorldViewMatrix();
1719 // synchronize FFP state before copying pixels
1720 aCtx->BindProgram (Handle(OpenGl_ShaderProgram)());
1721 aCtx->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
1722 aCtx->DisableFeatures();
1724 switch (aCtx->DrawBuffer())
1728 aCtx->SetReadBuffer (GL_BACK_LEFT);
1729 aCtx->SetDrawBuffer (GL_FRONT_LEFT);
1734 aCtx->SetReadBuffer (GL_BACK_RIGHT);
1735 aCtx->SetDrawBuffer (GL_FRONT_RIGHT);
1740 aCtx->SetReadBuffer (GL_BACK);
1741 aCtx->SetDrawBuffer (GL_FRONT);
1746 aCtx->core11->glRasterPos2i (0, 0);
1747 aCtx->core11->glCopyPixels (0, 0, myWindow->Width() + 1, myWindow->Height() + 1, GL_COLOR);
1748 //aCtx->core11->glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_DEPTH);
1750 aCtx->EnableFeatures();
1752 aCtx->WorldViewState.Pop();
1753 aCtx->ProjectionState.Pop();
1754 aCtx->ApplyProjectionMatrix();
1756 // read/write from front buffer now
1757 aCtx->SetReadBuffer (aCtx->DrawBuffer());
1764 // =======================================================================
1765 // function : checkOitCompatibility
1767 // =======================================================================
1768 Standard_Boolean OpenGl_View::checkOitCompatibility (const Handle(OpenGl_Context)& theGlContext,
1769 const Standard_Boolean theMSAA)
1771 // determine if OIT is supported by current OpenGl context
1772 Standard_Boolean& aToDisableOIT = theMSAA ? myToDisableMSAA : myToDisableOIT;
1775 return Standard_False;
1778 TCollection_ExtendedString aCompatibilityMsg;
1779 if (theGlContext->hasFloatBuffer == OpenGl_FeatureNotAvailable
1780 && theGlContext->hasHalfFloatBuffer == OpenGl_FeatureNotAvailable)
1782 aCompatibilityMsg += "OpenGL context does not support floating-point RGBA color buffer format.\n";
1784 if (theMSAA && theGlContext->hasSampleVariables == OpenGl_FeatureNotAvailable)
1786 aCompatibilityMsg += "Current version of GLSL does not support built-in sample variables.\n";
1788 if (theGlContext->hasDrawBuffers == OpenGl_FeatureNotAvailable)
1790 aCompatibilityMsg += "OpenGL context does not support multiple draw buffers.\n";
1792 if (aCompatibilityMsg.IsEmpty())
1794 return Standard_True;
1797 aCompatibilityMsg += " Blended order-independent transparency will not be available.\n";
1798 theGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
1799 GL_DEBUG_TYPE_ERROR,
1801 GL_DEBUG_SEVERITY_HIGH,
1804 aToDisableOIT = Standard_True;
1805 return Standard_False;
1808 // =======================================================================
1809 // function : chooseOitColorConfiguration
1811 // =======================================================================
1812 bool OpenGl_View::chooseOitColorConfiguration (const Handle(OpenGl_Context)& theGlContext,
1813 const Standard_Integer theConfigIndex,
1814 OpenGl_ColorFormats& theFormats)
1817 switch (theConfigIndex)
1819 case 0: // choose best applicable color format combination
1821 theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
1822 theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_R16F : GL_R32F);
1825 case 1: // choose non-optimal applicable color format combination
1827 theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
1828 theFormats.Append (theGlContext->hasHalfFloatBuffer != OpenGl_FeatureNotAvailable ? GL_RGBA16F : GL_RGBA32F);
1832 return false; // color combination does not exist