@@ -68,15 +68,6 @@ VoxelEngine::VoxelEngine(Config config) {
68
68
ZN_PRINT_VERBOSE (format (" Size of SaveBlockDataTask: {}" , sizeof (SaveBlockDataTask)));
69
69
ZN_PRINT_VERBOSE (format (" Size of MeshBlockTask: {}" , sizeof (MeshBlockTask)));
70
70
71
- if (RenderingServer::get_singleton () == nullptr ) {
72
- // Sadly, that happens. This is a problem in GDExtension...
73
- ZN_PRINT_ERROR (" RenderingServer singleton is null when creating VoxelEngine!" );
74
- // RenderingServer can also be null with `tests=yes`.
75
- // TODO There is no hook to integrate modules to Godot's test framework, update this when it gets improved
76
- } else {
77
- _gpu_task_runner.start ();
78
- }
79
-
80
71
set_main_thread_time_budget_usec (config.main_thread_budget_usec );
81
72
}
82
73
@@ -91,6 +82,24 @@ VoxelEngine::~VoxelEngine() {
91
82
_gpu_task_runner.stop ();
92
83
}
93
84
85
+ void VoxelEngine::try_initialize_gpu_features () {
86
+ // RenderingServer can be null with `tests=yes`.
87
+ // TODO There is no hook to integrate modules to Godot's test framework, update this when it gets improved
88
+ RenderingServer *rs = RenderingServer::get_singleton ();
89
+ if (rs != nullptr ) {
90
+ // TODO Enhancement: threaded graphics resource building should be initialized better.
91
+ // Pick this from the current renderer + user option (at time of writing, Godot 4 has only one
92
+ // renderer and has not figured out how such option would be exposed). Could use
93
+ // `can_create_resources_async` but this is internal. AFAIK `is_low_end` will be `true` only for OpenGL
94
+ // backends, which are the only ones not supporting async resource creation.
95
+ _threaded_graphics_resource_building_enabled = (rs->is_low_end () == false );
96
+ }
97
+
98
+ if (_gpu_task_runner.is_running () == false ) {
99
+ _gpu_task_runner.start ();
100
+ }
101
+ }
102
+
94
103
void VoxelEngine::wait_and_clear_all_tasks (bool warn) {
95
104
_general_thread_pool.wait_for_all_tasks ();
96
105
@@ -216,10 +225,6 @@ void VoxelEngine::set_main_thread_time_budget_usec(unsigned int usec) {
216
225
_main_thread_time_budget_usec = usec;
217
226
}
218
227
219
- void VoxelEngine::set_threaded_graphics_resource_building_enabled (bool enable) {
220
- _threaded_graphics_resource_building_enabled = enable;
221
- }
222
-
223
228
bool VoxelEngine::is_threaded_graphics_resource_building_enabled () const {
224
229
return _threaded_graphics_resource_building_enabled;
225
230
}
0 commit comments