void Channel::_drawModel( const Model* scene ) { Window* window = static_cast< Window* >( getWindow( )); VertexBufferState& state = window->getState(); const FrameData& frameData = _getFrameData(); if( frameData.getColorMode() == COLOR_MODEL && scene->hasColors( )) state.setColors( true ); else state.setColors( false ); state.setChannel( this ); // Compute cull matrix const eq::Matrix4f& rotation = frameData.getCameraRotation(); const eq::Matrix4f& modelRotation = frameData.getModelRotation(); eq::Matrix4f position = eq::Matrix4f::IDENTITY; position.set_translation( frameData.getCameraPosition()); const eq::Frustumf& frustum = getFrustum(); const eq::Matrix4f projection = useOrtho() ? frustum.compute_ortho_matrix(): frustum.compute_matrix(); const eq::Matrix4f& view = getHeadTransform(); const eq::Matrix4f model = rotation * position * modelRotation; state.setProjectionModelViewMatrix( projection * view * model ); state.setRange( &getRange().start); const eq::Pipe* pipe = getPipe(); const GLuint program = state.getProgram( pipe ); if( program != VertexBufferState::INVALID ) glUseProgram( program ); scene->cullDraw( state ); state.setChannel( 0 ); if( program != VertexBufferState::INVALID ) glUseProgram( 0 ); const InitData& initData = static_cast<Config*>( getConfig( ))->getInitData(); if( initData.useROI( )) // declare empty region in case nothing is in frustum declareRegion( eq::PixelViewport( )); else declareRegion( getPixelViewport( )); #ifndef NDEBUG outlineViewport(); #endif }
void VertexBufferState::updateRegion( const BoundingBox& box ) { const Vertex corners[8] = { Vertex( box[0][0], box[0][1], box[0][2] ), Vertex( box[1][0], box[0][1], box[0][2] ), Vertex( box[0][0], box[1][1], box[0][2] ), Vertex( box[1][0], box[1][1], box[0][2] ), Vertex( box[0][0], box[0][1], box[1][2] ), Vertex( box[1][0], box[0][1], box[1][2] ), Vertex( box[0][0], box[1][1], box[1][2] ), Vertex( box[1][0], box[1][1], box[1][2] ) }; Vector4f region( std::numeric_limits< float >::max(), std::numeric_limits< float >::max(), -std::numeric_limits< float >::max(), -std::numeric_limits< float >::max( )); for( size_t i = 0; i < 8; ++i ) { const Vertex corner = _pmvMatrix * corners[i]; region[0] = std::min( corner[0], region[0] ); region[1] = std::min( corner[1], region[1] ); region[2] = std::max( corner[0], region[2] ); region[3] = std::max( corner[1], region[3] ); } // transform region of interest from [ -1 -1 1 1 ] to normalized viewport const Vector4f normalized( region[0] * .5f + .5f, region[1] * .5f + .5f, ( region[2] - region[0] ) * .5f, ( region[3] - region[1] ) * .5f ); declareRegion( normalized ); _region[0] = std::min( _region[0], normalized[0] ); _region[1] = std::min( _region[1], normalized[1] ); _region[2] = std::max( _region[2], normalized[2] ); _region[3] = std::max( _region[3], normalized[3] ); }
void Channel::_drawModel( const Model* scene ) { Window* window = static_cast< Window* >( getWindow( )); VertexBufferState& state = window->getState(); const FrameData& frameData = _getFrameData(); if( frameData.getColorMode() == COLOR_MODEL && scene->hasColors( )) state.setColors( true ); else state.setColors( false ); state.setChannel( this ); // Compute cull matrix const eq::Matrix4f& rotation = frameData.getCameraRotation(); const eq::Matrix4f& modelRotation = frameData.getModelRotation(); eq::Matrix4f position = eq::Matrix4f::IDENTITY; position.set_translation( frameData.getCameraPosition()); const eq::Frustumf& frustum = getFrustum(); const eq::Matrix4f projection = useOrtho() ? frustum.compute_ortho_matrix(): frustum.compute_matrix(); const eq::Matrix4f& view = getHeadTransform(); const eq::Matrix4f model = rotation * position * modelRotation; state.setProjectionModelViewMatrix( projection * view * model ); state.setRange( &getRange().start); const eq::Pipe* pipe = getPipe(); const GLuint program = state.getProgram( pipe ); if( program != VertexBufferState::INVALID ) glUseProgram( program ); scene->cullDraw( state ); state.setChannel( 0 ); if( program != VertexBufferState::INVALID ) glUseProgram( 0 ); const InitData& initData = static_cast<Config*>( getConfig( ))->getInitData(); if( !initData.useROI( )) { declareRegion( getPixelViewport( )); return; } #ifndef NDEBUG // region border const eq::PixelViewport& pvp = getPixelViewport(); const eq::PixelViewport& region = getRegion(); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 0.f, pvp.w, 0.f, pvp.h, -1.f, 1.f ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); const eq::View* currentView = getView(); if( currentView && frameData.getCurrentViewID() == currentView->getID( )) glColor3f( 0.f, 0.f, 0.f ); else glColor3f( 1.f, 1.f, 1.f ); glNormal3f( 0.f, 0.f, 1.f ); const eq::Vector4f rect( float( region.x ) + .5f, float( region.y ) + .5f, float( region.getXEnd( )) - .5f, float( region.getYEnd( )) - .5f ); glBegin( GL_LINE_LOOP ); { glVertex3f( rect[0], rect[1], -.99f ); glVertex3f( rect[2], rect[1], -.99f ); glVertex3f( rect[2], rect[3], -.99f ); glVertex3f( rect[0], rect[3], -.99f ); } glEnd(); #endif }