void GR_CortexPrimitive::update( RE_Render *r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p )
{

#if UT_MAJOR_VERSION_INT >= 15

	GU_DetailHandleAutoReadLock handle( p.geometry );
	if ( !handle.isValid() )
	{
		m_scene = 0;
		m_renderable = 0;
		return;
	}
	
	const GU_Detail *detail = handle.getGdp();

#else

	const GU_Detail *detail = &p.geometry;

#endif

	GA_Offset offset = detail->primitiveOffset( m_primId );
	const CortexPrimitive *prim = dynamic_cast<const CortexPrimitive *>( detail->getGEOPrimitive( offset ) );
	if ( !prim )
	{
		m_scene = 0;
		m_renderable = 0;
		return;
	}
	
	m_renderable = IECore::runTimeCast<const IECore::Renderable>( prim->getObject() );
	if ( !m_renderable )
	{
		m_scene = 0;
		return;
	}
	
	IECoreGL::RendererPtr renderer = new IECoreGL::Renderer();
	renderer->setOption( "gl:mode", new IECore::StringData( "deferred" ) );
	renderer->setOption( "gl:drawCoordinateSystems", new IECore::BoolData( true ) );
	renderer->worldBegin();
	
	if ( p.dopts.boundBox() )
	{
		const IECore::VisibleRenderable *visible = IECore::runTimeCast<const IECore::VisibleRenderable>( m_renderable );
		if ( visible )
		{
			IECore::MeshPrimitive::createBox( visible->bound() )->render( renderer.get() );
		}
	}
	else
	{
		m_renderable->render( renderer.get() );
	}
	
	renderer->worldEnd();
	
	m_scene = renderer->scene();
	m_scene->setCamera( 0 ); // houdini will be providing the camera
}
/// Redraws the OpenGL Scene if the procedural is marked as having changed (aka dirty)
IECoreGL::ConstScenePtr SOP_ProceduralHolder::scene()
{
	IECore::ParameterisedProceduralPtr procedural = IECore::runTimeCast<IECore::ParameterisedProcedural>( getParameterised() );
	if ( !procedural )
	{
		return 0;
	}
	
	if ( m_dirty || !m_scene )
	{
		IECorePython::ScopedGILLock gilLock;
		try
		{
			IECoreGL::RendererPtr renderer = new IECoreGL::Renderer();
			renderer->setOption( "gl:mode", new IECore::StringData( "deferred" ) );
			renderer->worldBegin();
			procedural->render( renderer );
			renderer->worldEnd();
			m_scene = renderer->scene();
			m_scene->setCamera( 0 ); // houdini will be providing the camera when we draw the scene
		}
		catch( const std::exception &e )
		{
			std::cerr << e.what() << std::endl;
		}
		catch( ... )
		{
			std::cerr << "Unknown!" << std::endl;
		}

		m_dirty = false;
	}
	
	return m_scene;
}
void GR_CortexPrimitive::update( RE_Render *r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p )
{
	GA_Offset offset = p.geometry.primitiveOffset( m_primId );
	const GU_CortexPrimitive *prim = dynamic_cast<const GU_CortexPrimitive *>( p.geometry.getGEOPrimitive( offset ) );
	if ( !prim )
	{
		m_scene = 0;
		m_renderable = 0;
		return;
	}
	
	m_renderable = IECore::runTimeCast<const IECore::Renderable>( prim->getObject() );
	if ( !m_renderable )
	{
		m_scene = 0;
		return;
	}
	
	IECoreGL::RendererPtr renderer = new IECoreGL::Renderer();
	renderer->setOption( "gl:mode", new IECore::StringData( "deferred" ) );
	renderer->setOption( "gl:drawCoordinateSystems", new IECore::BoolData( true ) );
	renderer->worldBegin();
	renderer->transformBegin();
	
	UT_Matrix4D transform;
	memcpy( transform.data(), r->getUniform( RE_UNIFORM_OBJECT_MATRIX )->getValue(), sizeof(double) * 16 );
	renderer->setTransform( IECore::convert<Imath::M44f>( transform ) );
	
	if ( p.dopts.boundBox() )
	{
		const IECore::VisibleRenderable *visible = IECore::runTimeCast<const IECore::VisibleRenderable>( m_renderable );
		if ( visible )
		{
			IECore::MeshPrimitive::createBox( visible->bound() )->render( renderer );
		}
	}
	else
	{
		m_renderable->render( renderer );
	}
	
	renderer->transformEnd();
	renderer->worldEnd();
	
	m_scene = renderer->scene();
	m_scene->setCamera( 0 ); // houdini will be providing the camera
}
Exemple #4
0
void RenderableGadget::setRenderable( IECore::ConstVisibleRenderablePtr renderable )
{
	if( renderable!=m_renderable )
	{
		m_renderable = renderable;
		m_scene = 0;
		if( m_renderable )
		{
			IECoreGL::RendererPtr renderer = new IECoreGL::Renderer;
			renderer->setOption( "gl:mode", new IECore::StringData( "deferred" ) );
			{
				IECore::WorldBlock world( renderer );
				m_renderable->render( renderer.get() );
			}
			m_scene = renderer->scene();
			m_scene->setCamera( 0 );
			applySelection();
		}
		renderRequestSignal()( this );
	}
}
// Renders an object directly (normally from an opHolder)
void GR_Cortex::renderObject( const IECore::Object *object, const IECoreGL::State *displayState )
{
	// try and cast this to a visible renderable
	IECore::ConstVisibleRenderablePtr renderable = IECore::runTimeCast<const IECore::VisibleRenderable>( object );
	if ( !renderable )
	{
		return;
	}

	// render our object into a buffer
	IECoreGL::RendererPtr renderer = new IECoreGL::Renderer();
	renderer->setOption( "gl:mode", new IECore::StringData( "deferred" ) );
	renderer->worldBegin();
	renderable->render( renderer );
	renderer->worldEnd();
	IECoreGL::ScenePtr scene = renderer->scene();
	scene->setCamera( 0 ); // houdini will be providing the camera
	
	// now render
	scene->render( const_cast<IECoreGL::State *>( displayState ) );
}