ImmediateMode usage

Hopefully a pretty simple one...

How do you use AIS_InteractiveContext ImmediateMode drawing?

I guessed it was something like this:

 _context->BeginImmediateDraw();
for(//something)
{
   Handle(AIS_InteractiveObject) a = //object
   _context->ImmediateAdd(a);
}
_context->EndImmediateDraw();
_context->RedrawImmediate(_viewer);

...but quite frankly it doesn't do anything!

Can you advise how best to use this feature?
Can you also advise if the AIS objects are transient - or permanent residents which must be cleared inbetween refreshes?

cheers

Mat

gkv311 n's picture

The methods AIS_InteractiveContext::BeginImmediateDraw() and AIS_InteractiveContext::EndImmediateDraw() are rather artifacts of a legacy immediate rendering implementation that performed, well, immediate rendering in the place. The revised design is more involving.

Instead of immediate rendering, it now splits rendering of V3d_View content into two parts - rendering of a main scene, which might be cached into offscreen image buffer and rendering something on top multiple times without redrawing main scene (which is cached in form of a bitmap).

Basically speaking, this is done by assigning presentation to a Z-Layer (Graphic3d_ZLayerId) with Graphic3d_ZLayerSettings::IsImmediate() flag set ON. Within default configuration, this includes Graphic3d_ZLayerId_Topmost and Graphic3d_ZLayerId_TopOSD.

So, how this could be actually used? The most straightforward scenario is dynamic highlighting of interactive object (e.g. while move mouse), which is already done automatically. Implementations of custom AIS objects may put highlighted presentation into transient list of immediate presentations via PrsMgr_PresentationManager::AddToImmediateList() within SelectMgr_EntityOwner::HilightWithColor() like in this sample.

Otherwise, you may put entire AIS object to immediate Z-layer via AIS_InteractiveContext::SetZLayer() method (e.g. by assigning Graphic3d_ZLayerId_Topmost layer or similar), so that it will be not cached within mains scene bitmap and instead redrawn within each viewer update. But moving the object to immediate layer will not improve performance per se...

Next thing to do is to perform V3d_View::InvalidateImmediate() while changing the object in the immediate layer (for instance, while animating the object), performing V3d_View::Invalidate() while changing objects within main scene, and redrawing immediate layers by calling V3d_View::RedrawImmediate(). When using AIS_ViewController::FlushViewEvents()/AIS_ViewController::HandleViewEvents(), then AIS_ViewController will rely on V3d_View::IsInvalidated()/V3d_View::IsInvalidatedImmediate() flags to decide if V3d_View::Redraw() should be called or V3d_View::RedrawImmediate() will be enough. And then you might need to looks into performance counters / debug the code to ensure that your rendering cycle actually follows your intentions and if it brings any performance boost...

Doesn't sound that simple, right ;)? I guess that it is better to dig into immediate rendering workflow when you experience performance issues and see that caching main view scene bitmap may actually help.