- Naphtalene
- Posts: 4
- Joined:
thread safety of IRenderer
Hi,
I need a way to block input events that are over a GUI View. i've seen that thread :
viewtopic.php?t=698
my question is, is it safe to operate on IRenderer on the main thread:
while render thread is operating on the same IRenderer in this way :
I need a way to block input events that are over a GUI View. i've seen that thread :
viewtopic.php?t=698
my question is, is it safe to operate on IRenderer on the main thread:
Code: Select all
Ptr<IView> current_view;
IRenderer* uiRenderer = current_view->GetRenderer();
Visual* root = VisualTreeHelper::GetRoot(uiRenderer->GetContent());
HitTestResult hit = VisualTreeHelper::HitTest(root, Point(mousePosX, mousePosY));
if (hit.visualHit != 0)
{
// block event
}
Code: Select all
current_view->GetRenderer()->UpdateRenderTree();
current_view->GetRenderer()->RenderOffscreen();
...
current_view->GetRenderer()->Render();
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: thread safety of IRenderer
That post is quite old and the API changed a bit in newer versions. The IView provides access to the Content so you don't need to interact with the IRenderer object for that:
Code: Select all
Ptr<IView> current_view;
Visual* root = VisualTreeHelper::GetRoot(current_view->GetContent());
HitTestResult hit = VisualTreeHelper::HitTest(root, Point(mousePosX, mousePosY));
if (hit.visualHit != 0)
{
// block event
}
- Naphtalene
- Posts: 4
- Joined:
Re: thread safety of IRenderer
Alright i will do it this way, Thank you very much !
- Naphtalene
- Posts: 4
- Joined:
Re: thread safety of IRenderer
Turns out
and
Code: Select all
Ptr<IView> current_view;
current_view->GetContent(); // returns a FrameworkElement*
Code: Select all
VisualTreeHelper::GetRoot(const Visual* ) //takes a Visual*
Last edited by Naphtalene on 16 Aug 2021, 19:07, edited 3 times in total.
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: thread safety of IRenderer
Yes, a FrameworkElement inherits from Visual, so you can pass the element to the GetRoot() function.
If you have compiler errors make sure to include <NsGui/FrameworkElement.h> in your code (or just the NoesisPCH.h we provide in our SDK if you are using precompiled headers).
If you have compiler errors make sure to include <NsGui/FrameworkElement.h> in your code (or just the NoesisPCH.h we provide in our SDK if you are using precompiled headers).
Re: thread safety of IRenderer
Just a clarification for future readers: all functions in the interface IRenderer must always be invoked from the render thread (in case you are using a separate thread for rendering)
Who is online
Users browsing this forum: No registered users and 55 guests