
Thu, 04/17/2025 - 00:06
Forums:
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
Sat, 04/19/2025 - 11:21
The methods
AIS_InteractiveContext::BeginImmediateDraw()
andAIS_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
) withGraphic3d_ZLayerSettings::IsImmediate()
flag set ON. Within default configuration, this includesGraphic3d_ZLayerId_Topmost
andGraphic3d_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()
withinSelectMgr_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 assigningGraphic3d_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), performingV3d_View::Invalidate()
while changing objects within main scene, and redrawing immediate layers by callingV3d_View::RedrawImmediate()
. When usingAIS_ViewController::FlushViewEvents()
/AIS_ViewController::HandleViewEvents()
, thenAIS_ViewController
will rely onV3d_View::IsInvalidated()
/V3d_View::IsInvalidatedImmediate()
flags to decide ifV3d_View::Redraw()
should be called orV3d_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.