mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-05-06 10:36:12 +03:00
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
202 lines
6.7 KiB
C++
Executable File
202 lines
6.7 KiB
C++
Executable File
// Created on: 2013-11-11
|
|
// Created by: Anastasia BORISOVA
|
|
// Copyright (c) 2013-2014 OPEN CASCADE SAS
|
|
//
|
|
// This file is part of Open CASCADE Technology software library.
|
|
//
|
|
// This library is free software; you can redistribute it and/or modify it under
|
|
// the terms of the GNU Lesser General Public License version 2.1 as published
|
|
// by the Free Software Foundation, with special exception defined in the file
|
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
|
// distribution for complete text of the license and disclaimer of any warranty.
|
|
//
|
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
|
// commercial license or contractual agreement.
|
|
|
|
#include <OpenGl_Flipper.hxx>
|
|
|
|
#include <OpenGl_Context.hxx>
|
|
#include <OpenGl_ShaderManager.hxx>
|
|
#include <OpenGl_Vec.hxx>
|
|
#include <OpenGl_Workspace.hxx>
|
|
|
|
#include <gp_Ax2.hxx>
|
|
|
|
// =======================================================================
|
|
// function : Constructor
|
|
// purpose :
|
|
// =======================================================================
|
|
OpenGl_Flipper::OpenGl_Flipper (const gp_Ax2& theReferenceSystem)
|
|
: OpenGl_Element(),
|
|
myReferenceOrigin ((Standard_ShortReal )theReferenceSystem.Location().X(),
|
|
(Standard_ShortReal )theReferenceSystem.Location().Y(),
|
|
(Standard_ShortReal )theReferenceSystem.Location().Z(),
|
|
1.0f),
|
|
myReferenceX ((Standard_ShortReal )theReferenceSystem.XDirection().X(),
|
|
(Standard_ShortReal )theReferenceSystem.XDirection().Y(),
|
|
(Standard_ShortReal )theReferenceSystem.XDirection().Z(),
|
|
1.0f),
|
|
myReferenceY ((Standard_ShortReal )theReferenceSystem.YDirection().X(),
|
|
(Standard_ShortReal )theReferenceSystem.YDirection().Y(),
|
|
(Standard_ShortReal )theReferenceSystem.YDirection().Z(),
|
|
1.0f),
|
|
myReferenceZ ((Standard_ShortReal )theReferenceSystem.Axis().Direction().X(),
|
|
(Standard_ShortReal )theReferenceSystem.Axis().Direction().Y(),
|
|
(Standard_ShortReal )theReferenceSystem.Axis().Direction().Z(),
|
|
1.0f),
|
|
myIsEnabled (Standard_True)
|
|
{
|
|
//
|
|
}
|
|
|
|
// =======================================================================
|
|
// function : Release
|
|
// purpose :
|
|
// =======================================================================
|
|
void OpenGl_Flipper::Release (const Handle(OpenGl_Context)& )
|
|
{
|
|
//
|
|
}
|
|
|
|
// =======================================================================
|
|
// function : Render
|
|
// purpose :
|
|
// =======================================================================
|
|
void OpenGl_Flipper::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
|
|
{
|
|
// Check if rendering is to be in immediate mode
|
|
const Standard_Boolean isImmediate = (theWorkspace->NamedStatus & OPENGL_NS_IMMEDIATE) != 0;
|
|
const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
|
|
GLint aCurrMode = GL_MODELVIEW;
|
|
glGetIntegerv (GL_MATRIX_MODE, &aCurrMode);
|
|
|
|
if (!myIsEnabled)
|
|
{
|
|
// Restore transformation
|
|
if (isImmediate)
|
|
{
|
|
if (aCurrMode != GL_MODELVIEW)
|
|
{
|
|
glMatrixMode (GL_MODELVIEW);
|
|
}
|
|
|
|
glPopMatrix();
|
|
|
|
if (aCurrMode != GL_MODELVIEW)
|
|
{
|
|
glMatrixMode (aCurrMode);
|
|
}
|
|
|
|
Tmatrix3 aModelWorldState = { { 1.f, 0.f, 0.f, 0.f },
|
|
{ 0.f, 1.f, 0.f, 0.f },
|
|
{ 0.f, 0.f, 1.f, 0.f },
|
|
{ 0.f, 0.f, 0.f, 1.f } };
|
|
|
|
aContext->ShaderManager()->RevertModelWorldStateTo (&aModelWorldState);
|
|
}
|
|
else
|
|
{
|
|
// Update current model-view matrix in the top of the stack
|
|
// replacing it with StructureMatrixT*ViewMatrix from the workspace.
|
|
theWorkspace->UpdateModelViewMatrix();
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (isImmediate)
|
|
{
|
|
|
|
if (!aContext->ShaderManager()->IsEmpty())
|
|
{
|
|
Tmatrix3 aWorldView;
|
|
glGetFloatv (GL_MODELVIEW_MATRIX, *aWorldView);
|
|
|
|
Tmatrix3 aProjection;
|
|
glGetFloatv (GL_PROJECTION_MATRIX, *aProjection);
|
|
|
|
aContext->ShaderManager()->UpdateWorldViewStateTo (&aWorldView);
|
|
aContext->ShaderManager()->UpdateProjectionStateTo (&aProjection);
|
|
}
|
|
|
|
if (aCurrMode != GL_MODELVIEW)
|
|
{
|
|
glMatrixMode (GL_MODELVIEW);
|
|
}
|
|
|
|
glPushMatrix();
|
|
|
|
if (aCurrMode != GL_MODELVIEW)
|
|
{
|
|
glMatrixMode (aCurrMode);
|
|
}
|
|
}
|
|
|
|
OpenGl_Mat4 aMatrixMV;
|
|
glGetFloatv (GL_MODELVIEW_MATRIX, aMatrixMV.ChangeData());
|
|
|
|
const OpenGl_Vec4 aMVReferenceOrigin = aMatrixMV * myReferenceOrigin;
|
|
const OpenGl_Vec4 aMVReferenceX = aMatrixMV * OpenGl_Vec4 (myReferenceX.xyz() + myReferenceOrigin.xyz(), 1.0f);
|
|
const OpenGl_Vec4 aMVReferenceY = aMatrixMV * OpenGl_Vec4 (myReferenceY.xyz() + myReferenceOrigin.xyz(), 1.0f);
|
|
const OpenGl_Vec4 aMVReferenceZ = aMatrixMV * OpenGl_Vec4 (myReferenceZ.xyz() + myReferenceOrigin.xyz(), 1.0f);
|
|
|
|
const OpenGl_Vec4 aDirX = aMVReferenceX - aMVReferenceOrigin;
|
|
const OpenGl_Vec4 aDirY = aMVReferenceY - aMVReferenceOrigin;
|
|
const OpenGl_Vec4 aDirZ = aMVReferenceZ - aMVReferenceOrigin;
|
|
|
|
Standard_Boolean isReversedX = aDirX.xyz().Dot (OpenGl_Vec3::DX()) < 0.0f;
|
|
Standard_Boolean isReversedY = aDirY.xyz().Dot (OpenGl_Vec3::DY()) < 0.0f;
|
|
Standard_Boolean isReversedZ = aDirZ.xyz().Dot (OpenGl_Vec3::DZ()) < 0.0f;
|
|
|
|
// compute flipping (rotational transform)
|
|
OpenGl_Mat4 aTransform;
|
|
if ((isReversedX || isReversedY) && !isReversedZ)
|
|
{
|
|
// invert by Z axis: left, up vectors mirrored
|
|
aTransform.SetColumn (0, -aTransform.GetColumn (0).xyz());
|
|
aTransform.SetColumn (1, -aTransform.GetColumn (1).xyz());
|
|
}
|
|
else if (isReversedY && isReversedZ)
|
|
{
|
|
// rotate by X axis: up, forward vectors mirrored
|
|
aTransform.SetColumn (1, -aTransform.GetColumn (1).xyz());
|
|
aTransform.SetColumn (2, -aTransform.GetColumn (2).xyz());
|
|
}
|
|
else if (isReversedZ)
|
|
{
|
|
// rotate by Y axis: left, forward vectors mirrored
|
|
aTransform.SetColumn (0, -aTransform.GetColumn (0).xyz());
|
|
aTransform.SetColumn (2, -aTransform.GetColumn (2).xyz());
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
|
|
// do rotation in origin around reference system "forward" direction
|
|
OpenGl_Mat4 aRefAxes;
|
|
OpenGl_Mat4 aRefInv;
|
|
aRefAxes.SetColumn (0, myReferenceX.xyz());
|
|
aRefAxes.SetColumn (1, myReferenceY.xyz());
|
|
aRefAxes.SetColumn (2, myReferenceZ.xyz());
|
|
aRefAxes.SetColumn (3, myReferenceOrigin.xyz());
|
|
aRefAxes.Inverted (aRefInv);
|
|
|
|
aTransform = aRefAxes * aTransform * aRefInv;
|
|
|
|
// transform model-view matrix
|
|
aMatrixMV = aMatrixMV * aTransform;
|
|
|
|
// load transformed model-view matrix
|
|
if (aCurrMode != GL_MODELVIEW)
|
|
{
|
|
glMatrixMode (GL_MODELVIEW);
|
|
}
|
|
|
|
glLoadMatrixf ((GLfloat*) aMatrixMV);
|
|
|
|
if (aCurrMode != GL_MODELVIEW)
|
|
{
|
|
glMatrixMode (aCurrMode);
|
|
}
|
|
}
|