1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

0024637: Visualization - clean up implementation of rendering in immediate mode

Remove unused flag "DoubleBuf".
Remove Visual3d_TransientManager "class" (functionality moved to PrsMgr_PresentationManager).
Remove unused "Add" immediate mode.

V3d_View class - remove methods ::TransientManagerBeginDraw(), ::TransientManagerClearDraw(), ::TransientManagerBeginAddDraw().
Add method ::RedrawImmediate() to redraw only immediate presentations.

OpenGl_GraphicDriver - add methods ::DisplayImmediateStructure(), ::EraseImmediateStructure(), ::RedrawImmediate().
OpenGl_View - manage list of immediate structures.
OpenGl_Workspace - automate rendering workflow of immediate + persistent layers.

Merge PrsMgr_PresentationManager3d class into PrsMgr_PresentationManager.
Mark PrsMgr_PresentationManager3d as alias to PrsMgr_PresentationManager to simplify porting.

Prs3d_Presentation - remove unused field myStruct.
Prs3d_PresentationShadow - shadow link to existing presentation with custom attributes.
Graphic3d_Structure::Highlight() - do not register undisplayed structure in structure manager.

AIS_InteractiveContext, AIS_LocalContext add flag to prevent view update into methods
::MoveTo(), ::HilightNextDetected(), ::HilightPreviousDetected()
to allow update of customized immediate structures before redraw but after ::MoveTo().

Remove unused method AIS_InteractiveContext::Drag().

StdSelect_ViewerSelector3d do not user immediate mode in methods
::DisplayAreas(), ::ClearAreas(), ::ClearSensitive(), ::DisplaySensitive(),

GridEcho - update value in StdSelect_ViewerSelector3d::Pick() instead of V3d_View::Compute().
Do not use global variable for GridEcho vertex.
Redraw immediate mode not within GridEcho but at AIS_InteractiveContext, AIS_LocalContext layer.

V3d_View::ToPixMap() - disable autoupdate during FitAll.
Avoid Redraw() into FBO without ImmediateModeDrawToFront flag.

PrsMgr_PresentationManager stores list of temporary immediate presentations,
automatically cleared within BeginImmediateMode() call.
Methods with ambiguous names have been renamed
(new names now consistent with pre-existed method names in AIS_LocalContext class):
- BeginDraw -> BeginImmediateDraw
- EndDraw -> EndImmediateDraw
Remove now useless Remove() method (and ImmediateRemove() in AIS).

Visual3d_View now stores map of displayed immediate presentations.

ViewerTest_EventManager - eliminate double redraw in selection methods.

Fix warning
This commit is contained in:
kgv
2014-03-20 13:54:12 +04:00
committed by bugmaster
parent 01ca42b2c1
commit 679ecdeeac
60 changed files with 2773 additions and 3216 deletions

View File

@@ -26,11 +26,12 @@
#include <OpenGl_AspectMarker.hxx>
#include <OpenGl_AspectText.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_Element.hxx>
#include <OpenGl_FrameBuffer.hxx>
#include <OpenGl_Structure.hxx>
#include <OpenGl_Texture.hxx>
#include <OpenGl_View.hxx>
#include <OpenGl_Workspace.hxx>
#include <OpenGl_Element.hxx>
#include <Graphic3d_TextureParams.hxx>
@@ -145,14 +146,13 @@ OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
NamedStatus (0),
HighlightColor (&THE_WHITE_COLOR),
//
myIsTransientOpen (Standard_False),
myRetainMode (Standard_False),
myTransientDrawToFront (Standard_True),
myBackBufferRestored (Standard_False),
myIsImmediateDrawn (Standard_False),
myUseTransparency (Standard_False),
myUseZBuffer (Standard_False),
myUseDepthTest (Standard_True),
myUseGLLight (Standard_True),
myBackBufferRestored (Standard_False),
//
AspectLine_set (&myDefaultAspectLine),
AspectLine_applied (NULL),
@@ -571,10 +571,11 @@ void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView,
if (!theCView.IsRaytracing || myComputeInitStatus == OpenGl_CLIS_FAIL)
{
#endif
Redraw1 (theCView, theCUnderLayer, theCOverLayer, toSwap);
if (aFrameBuffer == NULL || !myTransientDrawToFront)
const Standard_Boolean isImmediate = !myView->ImmediateStructures().IsEmpty();
redraw1 (theCView, theCUnderLayer, theCOverLayer, isImmediate ? 0 : toSwap);
if (isImmediate)
{
RedrawImmediatMode();
RedrawImmediate (theCView, theCUnderLayer, theCOverLayer, Standard_True);
}
theCView.WasRedrawnGL = Standard_True;
@@ -598,7 +599,7 @@ void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView,
glViewport (aViewPortBack[0], aViewPortBack[1], aViewPortBack[2], aViewPortBack[3]);
}
#if (defined(_WIN32) || defined(__WIN32__)) && defined(HAVE_VIDEOCAPTURE)
#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE)
if (OpenGl_AVIWriter_AllowWriting (theCView.DefWindow.XWindow))
{
GLint params[4];
@@ -619,3 +620,210 @@ void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView,
// reset render mode state
aGlCtx->FetchState();
}
// =======================================================================
// function : redraw1
// purpose :
// =======================================================================
void OpenGl_Workspace::redraw1 (const Graphic3d_CView& theCView,
const Aspect_CLayer2d& theCUnderLayer,
const Aspect_CLayer2d& theCOverLayer,
const int theToSwap)
{
if (myDisplay.IsNull() || myView.IsNull())
{
return;
}
// request reset of material
NamedStatus |= OPENGL_NS_RESMAT;
// GL_DITHER on/off pour le background
if (myBackDither)
{
glEnable (GL_DITHER);
}
else
{
glDisable (GL_DITHER);
}
GLbitfield toClear = GL_COLOR_BUFFER_BIT;
if (myUseZBuffer)
{
glDepthFunc (GL_LEQUAL);
glDepthMask (GL_TRUE);
if (myUseDepthTest)
{
glEnable (GL_DEPTH_TEST);
}
else
{
glDisable (GL_DEPTH_TEST);
}
glClearDepth (1.0);
toClear |= GL_DEPTH_BUFFER_BIT;
}
else
{
glDisable (GL_DEPTH_TEST);
}
if (NamedStatus & OPENGL_NS_WHITEBACK)
{
// set background to white
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
toClear |= GL_DEPTH_BUFFER_BIT;
}
else
{
glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f);
}
glClear (toClear);
Handle(OpenGl_Workspace) aWS (this);
myView->Render (myPrintContext, aWS, theCView, theCUnderLayer, theCOverLayer);
// swap the buffers
if (theToSwap)
{
GetGlContext()->SwapBuffers();
myBackBufferRestored = Standard_False;
myIsImmediateDrawn = Standard_False;
}
else
{
glFlush();
myBackBufferRestored = Standard_True;
myIsImmediateDrawn = Standard_False;
}
}
// =======================================================================
// function : copyBackToFront
// purpose :
// =======================================================================
void OpenGl_Workspace::copyBackToFront()
{
glMatrixMode (GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D (0.0, (GLdouble )myWidth, 0.0, (GLdouble )myHeight);
glMatrixMode (GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
DisableFeatures();
glDrawBuffer (GL_FRONT);
glReadBuffer (GL_BACK);
glRasterPos2i (0, 0);
glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_COLOR);
EnableFeatures();
glMatrixMode (GL_PROJECTION);
glPopMatrix();
glMatrixMode (GL_MODELVIEW);
glPopMatrix();
glDrawBuffer (GL_BACK);
myIsImmediateDrawn = Standard_False;
}
// =======================================================================
// function : DisplayCallback
// purpose :
// =======================================================================
void OpenGl_Workspace::DisplayCallback (const Graphic3d_CView& theCView,
Standard_Integer theReason)
{
if (theCView.GDisplayCB == NULL)
{
return;
}
Aspect_GraphicCallbackStruct aCallData;
aCallData.reason = theReason;
aCallData.glContext = GetGlContext();
aCallData.wsID = theCView.WsId;
aCallData.viewID = theCView.ViewId;
theCView.GDisplayCB (theCView.DefWindow.XWindow, theCView.GClientData, &aCallData);
}
// =======================================================================
// function : RedrawImmediate
// purpose :
// =======================================================================
void OpenGl_Workspace::RedrawImmediate (const Graphic3d_CView& theCView,
const Aspect_CLayer2d& theCUnderLayer,
const Aspect_CLayer2d& theCOverLayer,
const Standard_Boolean theToForce)
{
if (!Activate())
{
return;
}
GLboolean isDoubleBuffer = GL_FALSE;
glGetBooleanv (GL_DOUBLEBUFFER, &isDoubleBuffer);
if (myView->ImmediateStructures().IsEmpty())
{
if (theToForce
|| !myIsImmediateDrawn)
{
myIsImmediateDrawn = Standard_False;
return;
}
if (myBackBufferRestored
&& isDoubleBuffer)
{
copyBackToFront();
}
else
{
Redraw (theCView, theCUnderLayer, theCOverLayer);
}
return;
}
if (isDoubleBuffer && myTransientDrawToFront)
{
if (!myBackBufferRestored)
{
Redraw (theCView, theCUnderLayer, theCOverLayer);
return;
}
copyBackToFront();
MakeFrontBufCurrent();
}
else
{
myBackBufferRestored = Standard_False;
}
myIsImmediateDrawn = Standard_True;
NamedStatus |= OPENGL_NS_IMMEDIATE;
///glDisable (GL_LIGHTING);
glDisable (GL_DEPTH_TEST);
Handle(OpenGl_Workspace) aWS (this);
for (OpenGl_SequenceOfStructure::Iterator anIter (myView->ImmediateStructures());
anIter.More(); anIter.Next())
{
const OpenGl_Structure* aStructure = anIter.Value();
aStructure->Render (aWS);
}
NamedStatus &= ~OPENGL_NS_IMMEDIATE;
if (isDoubleBuffer && myTransientDrawToFront)
{
glFlush();
MakeBackBufCurrent();
}
}