From 6fca18a47500874bc3a660b30c4f6828cc3d045b Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Sun, 9 Mar 2025 22:45:51 +0100 Subject: [PATCH] optimize render loop a bit --- .../data/registries/shapes/aabb/AABB.kt | 1 + .../de/bixilon/minosoft/gui/RenderLoop.kt | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/data/registries/shapes/aabb/AABB.kt b/src/main/java/de/bixilon/minosoft/data/registries/shapes/aabb/AABB.kt index 685283893..5aade89a9 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/shapes/aabb/AABB.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/shapes/aabb/AABB.kt @@ -253,6 +253,7 @@ class AABB { operator fun contains(position: Vec3i): Boolean { return position.x in getRange(min.x, max.x) && position.y in getRange(min.y, max.y) && position.z in getRange(min.z, max.z) } + operator fun contains(position: BlockPosition): Boolean { return position.x in getRange(min.x, max.x) && position.y in getRange(min.y, max.y) && position.z in getRange(min.z, max.z) } diff --git a/src/main/java/de/bixilon/minosoft/gui/RenderLoop.kt b/src/main/java/de/bixilon/minosoft/gui/RenderLoop.kt index b731c1353..bffe33701 100644 --- a/src/main/java/de/bixilon/minosoft/gui/RenderLoop.kt +++ b/src/main/java/de/bixilon/minosoft/gui/RenderLoop.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -62,12 +62,20 @@ class RenderLoop( if (context.state == RenderingStates.QUITTING || context.session.established || !context.state.active) { break } - context.renderStats.startFrame() + context.framebuffer.clear() context.system.framebuffer = null context.system.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER) + + context.window.pollEvents() + + context.input.draw(deltaFrameTime) + context.camera.draw() + + context.system.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER) + context.light.updateAsync() // ToDo: do async context.light.update() @@ -89,18 +97,19 @@ class RenderLoop( context.system.reset() // Reset to enable depth mask, etc again + // handle opengl context tasks, but limit it per frame + context.queue.workTimeLimited(RenderConstants.MAXIMUM_QUEUE_TIME_PER_FRAME) + context.renderStats.endDraw() - context.window.pollEvents() context.window.swapBuffers() - context.window.pollEvents() - context.input.draw(deltaFrameTime) - context.camera.draw() + // glClear waits for any unfinished operation, so it might swill wait for the buffer swap and makes frame times really long. + context.framebuffer.clear() + context.system.framebuffer = null + context.system.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER) - // handle opengl context tasks, but limit it per frame - context.queue.workTimeLimited(RenderConstants.MAXIMUM_QUEUE_TIME_PER_FRAME) if (context.state == RenderingStates.SLOW && slowRendering) { Thread.sleep(100L)