Commit 47758422 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

RealTimeSelectionListener modified so as to add the possibility to update the...

RealTimeSelectionListener modified so as to add the possibility to update the selection z-buffer during the selection action, on mouse pressed/release/moved events, instead of just when entering the selection mode.
parent 47067482
......@@ -1246,7 +1246,7 @@ void GLViewer::updateSelection( SelectionTool &tool )
// Initializes the selection context.
tool.setDepthBuffer( m_SelectionDepthBuffer );
tool.setDepthBuffer( m_SelectionDepthTexture );
tool.selectBackFacingGeometry( m_View.isCullingEnabled? GL_FALSE : GL_TRUE );
tool.preSelectionUpdate();
......@@ -1312,16 +1312,22 @@ void GLViewer::updateSelectionZBuffer()
// Recovers the depth buffer matching the current view for depth test during selection.
m_SelectionDepthBuffer.Create( GL_DEPTH_COMPONENT, width(), height(), GL_DEPTH_COMPONENT, GL_INT, NULL );
m_SelectionDepthBuffer.SetFiltering( GL_LINEAR );
m_SelectionDepthBuffer.SetBaseAndMaxLevels( 0 );
m_SelectionDepthBuffer.SetCompareMode( GL_COMPARE_R_TO_TEXTURE );
m_SelectionDepthBuffer.SetCompareFunc( GL_LEQUAL );
m_SelectionDepthBuffer.SetDepthTextureMode( GL_INTENSITY );
std::cout << "Selection ZBuffer updated" << std::endl;
if( !m_SelectionDepthTexture.IsInstantiated() )
{
std::cout << " [Re-allocated!]" << std::endl;
m_SelectionDepthTexture.Create( GL_DEPTH_COMPONENT, width(), height(), GL_DEPTH_COMPONENT, GL_INT, NULL );
m_SelectionDepthTexture.SetFiltering( GL_LINEAR );
m_SelectionDepthTexture.SetBaseAndMaxLevels( 0 );
m_SelectionDepthTexture.SetCompareMode( GL_COMPARE_R_TO_TEXTURE );
m_SelectionDepthTexture.SetCompareFunc( GL_LEQUAL );
m_SelectionDepthTexture.SetDepthTextureMode( GL_INTENSITY );
m_SelectionDepthBuffer.Create( width(), height() );
m_SelectionDepthBuffer.Attach( GL_DEPTH_ATTACHMENT, m_SelectionDepthTexture );
}
GPU::FrameBuffer fbuffer( width(), height() );
fbuffer.Attach( GL_DEPTH_ATTACHMENT, m_SelectionDepthBuffer );
fbuffer.Bind();
m_SelectionDepthBuffer.Bind();
glClear( GL_DEPTH_BUFFER_BIT );
......@@ -1356,7 +1362,7 @@ void GLViewer::updateSelectionZBuffer()
releaseScene();
fbuffer.Unbind();
m_SelectionDepthBuffer.Unbind();
}
......@@ -1668,6 +1674,8 @@ void GLViewer::mousePressEvent( QMouseEvent *evt )
else
{
makeCurrent();
if( m_SelectionZBufferUpdateMode & SelectionZBufferUpdateMode::ON_MOUSE_PRESSED )
updateSelectionZBuffer();
m_SelectionCurrentTool->mousePressEvent( evt );
}
}
......@@ -1683,6 +1691,8 @@ void GLViewer::mouseReleaseEvent( QMouseEvent *evt )
if( isSelectionEnabled() )
{
makeCurrent();
if( m_SelectionZBufferUpdateMode & SelectionZBufferUpdateMode::ON_MOUSE_RELEASED )
updateSelectionZBuffer();
m_SelectionCurrentTool->mouseReleaseEvent( evt );
updateSelectionMode( evt->modifiers() );
}
......@@ -1730,6 +1740,8 @@ void GLViewer::mouseMoveEvent( QMouseEvent *evt )
if( isSelectionEnabled() )
{
makeCurrent();
if( evt->buttons() != Qt::MouseButton::NoButton && (m_SelectionZBufferUpdateMode & SelectionZBufferUpdateMode::ON_MOUSE_MOVED) )
updateSelectionZBuffer();
m_SelectionCurrentTool->mouseMoveEvent( evt );
update();
}
......@@ -2525,11 +2537,12 @@ void GLViewer::setSelectionEnabled( bool enabled )
if( enabled )
{
setSelectionEntity( m_SelectionCurrentTool->entityToSelect() );
for( DisplayableMap::iterator d=m_Displayables.begin(); d!=m_Displayables.end(); ++d )
{
if( d->first->GetDisplayOptions() )
d->first->GetDisplayOptions()->setDisabled( true );
setSelectionEntity( m_SelectionCurrentTool->entityToSelect() );
}
updateSelectionZBuffer();
......@@ -2539,6 +2552,7 @@ void GLViewer::setSelectionEnabled( bool enabled )
else
{
// Releases the selection depth buffer.
m_SelectionDepthTexture.Release();
m_SelectionDepthBuffer.Release();
m_SelectionCurrentTool->postSelectionUpdate();
......@@ -2572,6 +2586,7 @@ void GLViewer::setSelectionEntity( SelectableEntity entity )
makeCurrent();
m_SelectionCurrentTool->setEntityToSelect( entity );
m_SelectionZBufferUpdateMode = ON_SELECTION_ENABLED;
for( DisplayableMap::iterator d=m_Displayables.begin(); d!=m_Displayables.end(); ++d )
{
......@@ -2581,6 +2596,10 @@ void GLViewer::setSelectionEntity( SelectableEntity entity )
{
d->second.currentSelectionMgr = mngr;
d->second.currentSelectionMgr->onRecompilingSelectionShader( m_SelectionCurrentTool );
if( mngr->isRealTimeSelectionEnabled() )
m_SelectionZBufferUpdateMode = SelectionZBufferUpdateMode( m_SelectionZBufferUpdateMode | mngr->realTimeListener()->zBufferUpdateMode() );
break;
}
}
......
......@@ -145,7 +145,9 @@ protected:
GPU::Shader m_PickingShader;
GPU::Shader m_ZBufferShader;
GPU::Texture2D m_SelectionDepthBuffer;
GPU::Texture2D m_SelectionDepthTexture;
GPU::FrameBuffer m_SelectionDepthBuffer;
SelectionZBufferUpdateMode m_SelectionZBufferUpdateMode;
DisplayableInfo *m_BelowCursor;
......
......@@ -125,12 +125,28 @@ public:
class SelectionToolDisk;
enum SelectionZBufferUpdateMode
{
ON_SELECTION_ENABLED = 0x00,
ON_MOUSE_PRESSED = 0x01,
ON_MOUSE_MOVED = 0x02,
ON_MOUSE_RELEASED = 0x04,
};
class RealTimeSelectionListener
{
SelectionZBufferUpdateMode m_ZBufferUpdateMode;
public:
inline RealTimeSelectionListener() : m_ZBufferUpdateMode(ON_SELECTION_ENABLED) {}
virtual void texelSelectionTriggered ( SelectionToolDisk *brush, GPU::Texture2D &selectionTexture ) {}
virtual void vertexSelectionTriggered( SelectionToolDisk *brush, GPU::Texture2D &selectionTexture ) {}
virtual void faceSelectionTriggered ( SelectionToolDisk *brush, GPU::Texture2D &selectionTexture ) {}
inline SelectionZBufferUpdateMode zBufferUpdateMode() const { return m_ZBufferUpdateMode; }
inline void setZBufferUpdateMode( SelectionZBufferUpdateMode mode ) { m_ZBufferUpdateMode = mode; }
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment