diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index d8be6d4bd7c..516a16e053a 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -17,6 +17,11 @@ https://docs.godotengine.org/en/latest/tutorials/optimization/using_servers.html + + + If [code]false[/code], disables rendering completely, but the engine logic is still being processed. You can call [method force_draw] to draw a frame even with rendering disabled. + + diff --git a/main/main.cpp b/main/main.cpp index 94dd895a264..878a1d47988 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1312,6 +1312,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { } rendering_server->init(); + rendering_server->set_render_loop_enabled(!disable_render_loop); OS::get_singleton()->initialize_joypads(); @@ -2203,7 +2204,7 @@ bool Main::iteration() { RenderingServer::get_singleton()->sync(); //sync if still drawing from previous frames. - if (DisplayServer::get_singleton()->can_any_window_draw() && !disable_render_loop) { + if (DisplayServer::get_singleton()->can_any_window_draw() && RenderingServer::get_singleton()->is_render_loop_enabled()) { if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) { if (RenderingServer::get_singleton()->has_changed()) { RenderingServer::get_singleton()->draw(true, scaled_step); // flush visual commands diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 4f12ec5b025..7edab1418d5 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -1895,6 +1895,10 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("has_os_feature", "feature"), &RenderingServer::has_os_feature); ClassDB::bind_method(D_METHOD("set_debug_generate_wireframes", "generate"), &RenderingServer::set_debug_generate_wireframes); + ClassDB::bind_method(D_METHOD("is_render_loop_enabled"), &RenderingServer::is_render_loop_enabled); + ClassDB::bind_method(D_METHOD("set_render_loop_enabled", "enabled"), &RenderingServer::set_render_loop_enabled); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_loop_enabled"), "set_render_loop_enabled", "is_render_loop_enabled"); + BIND_CONSTANT(NO_INDEX_ARRAY); BIND_CONSTANT(ARRAY_WEIGHTS_SIZE); BIND_CONSTANT(CANVAS_ITEM_Z_MIN); @@ -2286,6 +2290,14 @@ RID RenderingServer::instance_create2(RID p_base, RID p_scenario) { return instance; } +bool RenderingServer::is_render_loop_enabled() const { + return render_loop_enabled; +} + +void RenderingServer::set_render_loop_enabled(bool p_enabled) { + render_loop_enabled = p_enabled; +} + RenderingServer::RenderingServer() { //ERR_FAIL_COND(singleton); singleton = this; diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 3ce63585a87..56a83256302 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -47,6 +47,7 @@ class RenderingServer : public Object { static RenderingServer *singleton; int mm_policy; + bool render_loop_enabled = true; void _camera_set_orthogonal(RID p_camera, float p_size, float p_z_near, float p_z_far); void _canvas_item_add_style_box(RID p_item, const Rect2 &p_rect, const Rect2 &p_source, RID p_texture, const Vector &p_margins, const Color &p_modulate = Color(1, 1, 1)); @@ -1229,6 +1230,9 @@ public: virtual bool is_low_end() const = 0; + bool is_render_loop_enabled() const; + void set_render_loop_enabled(bool p_enabled); + RenderingServer(); virtual ~RenderingServer(); };