#include <OpenGl_GlCore11.hxx>
#include <Graphic3d_GraphicDriver.hxx>
+#include <Graphic3d_StructureManager.hxx>
#include <Graphic3d_TextureParams.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
#include <Graphic3d_TransformUtils.hxx>
#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>
{
#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);
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);
}
{
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)
&& !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;
}
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();
// 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
// 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)
// reset render mode state
aCtx->FetchState();
+ aCtx->FrameStats()->FrameEnd (myWorkspace->View(), false);
myWasRedrawnGL = Standard_True;
}
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()
// 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)
{
{
aCtx->core11fwd->glFlush();
}
+ aCtx->FrameStats()->FrameEnd (myWorkspace->View(), true);
myWasRedrawnGL = Standard_True;
}
#if !defined(GL_ES_VERSION_2_0)
aCtx->core11fwd->glGetBooleanv (GL_DOUBLEBUFFER, &toCopyBackToFront);
#endif
- if (toCopyBackToFront)
+ if (toCopyBackToFront
+ && myTransientDrawToFront)
{
if (!HasImmediateStructures()
&& !theIsPartialUpdate)
// ==================================
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
}
#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());
}
#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);
}
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
renderScene (theProjection, theOutputFBO, theOitAccumFbo, theToDrawImmediate);
- myWorkspace->SetEnvironmentTexture (Handle(OpenGl_Texture)());
+ myWorkspace->SetEnvironmentTexture (Handle(OpenGl_TextureSet)());
// ===============================
// Step 4: Trihedron
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
OpenGl_FrameBuffer* theOitAccumFbo,
const Standard_Boolean theToDrawImmediate)
{
+ myZLayers.UpdateCulling (myWorkspace, theToDrawImmediate);
if ( myZLayers.NbStructures() <= 0 )
return;
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);
// 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)
{
// 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)
}
}
+//=======================================================================
+//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 :
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())
{
}
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())
{
}
#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;
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);
}
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
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();
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
{
}
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";
}
{
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;
}
}