mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
Add ability to call code on rendering thread
As more users use compute in Godot 4, the way they do is most likely incompatible when running on separate threads and will start erroring soon as we improve the thread safety of the render thread. To properly run code on the render thread, this function was added. Use like this: ```GDScript func initialize_compute_code(): .... func update_compute_code(custom_data): ... func _ready(): RenderingServer.call_on_render_thread( initialize_compute_code ) func _process(): RenderingServer.call_on_render_thread( update_compute_code.bind(with_data) ) ```
This commit is contained in:
parent
202e4b2c1e
commit
c7fb6cea3d
5 changed files with 28 additions and 0 deletions
|
@ -386,6 +386,12 @@ void RenderingServerDefault::draw(bool p_swap_buffers, double frame_step) {
|
|||
}
|
||||
}
|
||||
|
||||
void RenderingServerDefault::_call_on_render_thread(const Callable &p_callable) {
|
||||
Variant ret;
|
||||
Callable::CallError ce;
|
||||
p_callable.callp(nullptr, 0, ret, ce);
|
||||
}
|
||||
|
||||
RenderingServerDefault::RenderingServerDefault(bool p_create_thread) :
|
||||
command_queue(p_create_thread) {
|
||||
RenderingServer::init();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue