// =======================================================================
void OpenGl_Context::DisableFeatures() const
{
-#if !defined(GL_ES_VERSION_2_0)
- glPixelTransferi (GL_MAP_COLOR, GL_FALSE);
-#endif
-
- /*
- * Disable stuff that's likely to slow down glDrawPixels.
- * (Omit as much of this as possible, when you know in advance
- * that the OpenGL state will already be set correctly.)
- */
+ // Disable stuff that's likely to slow down glDrawPixels.
glDisable(GL_DITHER);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
- glDisable(GL_TEXTURE_2D);
glDisable(GL_STENCIL_TEST);
#if !defined(GL_ES_VERSION_2_0)
+ if (core11 == NULL)
+ {
+ return;
+ }
+
+ glDisable(GL_TEXTURE_1D);
+ glDisable(GL_TEXTURE_2D);
+
glDisable(GL_LIGHTING);
glDisable(GL_ALPHA_TEST);
glDisable(GL_FOG);
glDisable(GL_LOGIC_OP);
- glDisable(GL_TEXTURE_1D);
glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
glPixelTransferi(GL_RED_SCALE, 1);
glPixelTransferi(GL_ALPHA_SCALE, 1);
glPixelTransferi(GL_ALPHA_BIAS, 0);
- /*
- * Disable extensions that could slow down glDrawPixels.
- * (Actually, you should check for the presence of the proper
- * extension before making these calls. I've omitted that
- * code for simplicity.)
- */
-
if ((myGlVerMajor >= 1) && (myGlVerMinor >= 2))
{
-#ifdef GL_EXT_convolution
if (CheckExtension ("GL_CONVOLUTION_1D_EXT"))
glDisable(GL_CONVOLUTION_1D_EXT);
if (CheckExtension ("GL_SEPARABLE_2D_EXT"))
glDisable(GL_SEPARABLE_2D_EXT);
-#endif
-#ifdef GL_EXT_histogram
if (CheckExtension ("GL_SEPARABLE_2D_EXT"))
glDisable(GL_HISTOGRAM_EXT);
if (CheckExtension ("GL_MINMAX_EXT"))
glDisable(GL_MINMAX_EXT);
-#endif
-#ifdef GL_EXT_texture3D
if (CheckExtension ("GL_TEXTURE_3D_EXT"))
glDisable(GL_TEXTURE_3D_EXT);
-#endif
}
#endif
}
#include <OpenGl_Structure.hxx>
#include <OpenGl_ArbFBO.hxx>
+namespace
+{
+ //! Format Frame Buffer format for logging messages.
+ static TCollection_AsciiString printFboFormat (const Handle(OpenGl_FrameBuffer)& theFbo)
+ {
+ return TCollection_AsciiString() + theFbo->GetInitVPSizeX() + "x" + theFbo->GetInitVPSizeY() + "@" + theFbo->NbSamples();
+ }
+
+ //! Return TRUE if Frame Buffer initialized has failed with the same parameters.
+ static bool checkWasFailedFbo (const Handle(OpenGl_FrameBuffer)& theFboToCheck,
+ Standard_Integer theSizeX,
+ Standard_Integer theSizeY,
+ Standard_Integer theNbSamples)
+ {
+ return !theFboToCheck->IsValid()
+ && theFboToCheck->GetInitVPSizeX() == theSizeX
+ && theFboToCheck->GetInitVPSizeY() == theSizeY
+ && theFboToCheck->NbSamples() == theNbSamples;
+ }
+
+ //! Return TRUE if Frame Buffer initialized has failed with the same parameters.
+ static bool checkWasFailedFbo (const Handle(OpenGl_FrameBuffer)& theFboToCheck,
+ const Handle(OpenGl_FrameBuffer)& theFboRef)
+ {
+ return checkWasFailedFbo (theFboToCheck, theFboRef->GetVPSizeX(), theFboRef->GetVPSizeY(), theFboRef->NbSamples());
+ }
+}
+
//=======================================================================
//function : drawBackground
//purpose :
// for further blitting and rendering immediate presentations on top
if (aCtx->core20fwd != NULL)
{
- myMainSceneFbos[0]->Init (aCtx, aRendSizeX, aRendSizeY, myFboColorFormat, myFboDepthFormat, aNbSamples);
+ const bool wasFailedMain0 = checkWasFailedFbo (myMainSceneFbos[0], aRendSizeX, aRendSizeY, aNbSamples);
+ if (!myMainSceneFbos[0]->Init (aCtx, aRendSizeX, aRendSizeY, myFboColorFormat, myFboDepthFormat, aNbSamples)
+ && !wasFailedMain0)
+ {
+ TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Main FBO "
+ + printFboFormat (myMainSceneFbos[0]) + " initialization has failed";
+ aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
+ }
}
}
if (myMainSceneFbos[0]->IsValid() && (toInitImmediateFbo || myImmediateSceneFbos[0]->IsValid()))
{
- myImmediateSceneFbos[0]->InitLazy (aCtx, *myMainSceneFbos[0]);
+ const bool wasFailedImm0 = checkWasFailedFbo (myImmediateSceneFbos[0], myMainSceneFbos[0]);
+ if (!myImmediateSceneFbos[0]->InitLazy (aCtx, *myMainSceneFbos[0])
+ && !wasFailedImm0)
+ {
+ TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Immediate FBO "
+ + printFboFormat (myImmediateSceneFbos[0]) + " initialization has failed";
+ aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
+ }
}
}
else
if (aProjectType == Graphic3d_Camera::Projection_Stereo
&& myMainSceneFbos[0]->IsValid())
{
- myMainSceneFbos[1]->InitLazy (aCtx, *myMainSceneFbos[0]);
+ const bool wasFailedMain1 = checkWasFailedFbo (myMainSceneFbos[1], myMainSceneFbos[0]);
+ if (!myMainSceneFbos[1]->InitLazy (aCtx, *myMainSceneFbos[0])
+ && !wasFailedMain1)
+ {
+ TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Main FBO (second) "
+ + printFboFormat (myMainSceneFbos[1]) + " initialization has failed";
+ aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
+ }
if (!myMainSceneFbos[1]->IsValid())
{
// no enough memory?
}
else if (!aCtx->HasStereoBuffers() || aStereoMode != Graphic3d_StereoMode_QuadBuffer)
{
- myImmediateSceneFbos[0]->InitLazy (aCtx, *myMainSceneFbos[0]);
- myImmediateSceneFbos[1]->InitLazy (aCtx, *myMainSceneFbos[0]);
+ const bool wasFailedImm0 = checkWasFailedFbo (myImmediateSceneFbos[0], myMainSceneFbos[0]);
+ const bool wasFailedImm1 = checkWasFailedFbo (myImmediateSceneFbos[1], myMainSceneFbos[0]);
+ if (!myImmediateSceneFbos[0]->InitLazy (aCtx, *myMainSceneFbos[0])
+ && !wasFailedImm0)
+ {
+ TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Immediate FBO (first) "
+ + printFboFormat (myImmediateSceneFbos[0]) + " initialization has failed";
+ aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
+ }
+ if (!myImmediateSceneFbos[1]->InitLazy (aCtx, *myMainSceneFbos[0])
+ && !wasFailedImm1)
+ {
+ TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Error! Immediate FBO (first) "
+ + printFboFormat (myImmediateSceneFbos[1]) + " initialization has failed";
+ aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
+ }
if (!myImmediateSceneFbos[0]->IsValid()
|| !myImmediateSceneFbos[1]->IsValid())
{
// prefer Swap Buffers within Redraw in compatibility mode (without FBO)
return true;
}
- copyBackToFront();
+ if (!copyBackToFront())
+ {
+ toCopyBackToFront = GL_FALSE;
+ myBackBufferRestored = Standard_False;
+ }
}
else
{
// function : copyBackToFront
// purpose :
// =======================================================================
-void OpenGl_View::copyBackToFront()
+bool OpenGl_View::copyBackToFront()
{
+ myIsImmediateDrawn = Standard_False;
#if !defined(GL_ES_VERSION_2_0)
+ const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
+ if (aCtx->core11 == NULL)
+ {
+ return false;
+ }
OpenGl_Mat4 aProjectMat;
Graphic3d_TransformUtils::Ortho2D (aProjectMat,
0.0f, static_cast<GLfloat> (myWindow->Width()),
0.0f, static_cast<GLfloat> (myWindow->Height()));
- const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
-
aCtx->WorldViewState.Push();
aCtx->ProjectionState.Push();
}
}
- glRasterPos2i (0, 0);
- glCopyPixels (0, 0, myWindow->Width() + 1, myWindow->Height() + 1, GL_COLOR);
- //glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_DEPTH);
+ aCtx->core11->glRasterPos2i (0, 0);
+ aCtx->core11->glCopyPixels (0, 0, myWindow->Width() + 1, myWindow->Height() + 1, GL_COLOR);
+ //aCtx->core11->glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_DEPTH);
aCtx->EnableFeatures();
// read/write from front buffer now
aCtx->SetReadBuffer (aCtx->DrawBuffer());
+ return true;
+#else
+ return false;
#endif
- myIsImmediateDrawn = Standard_False;
}
// =======================================================================