From bb23496b8b222bdeba14a6b5f39e4eb5956c61d0 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 16 Jan 2024 16:00:34 +0100 Subject: [PATCH] opengl: properly reset buffer for uploading --- .../gui/rendering/font/types/bitmap/BitmapFontType.kt | 4 ++-- .../system/opengl/texture/OpenGLFontTextureArray.kt | 3 ++- .../minosoft/gui/rendering/system/window/BaseWindow.kt | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/bitmap/BitmapFontType.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/bitmap/BitmapFontType.kt index 03aef8dd7..5ea6e31ed 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/bitmap/BitmapFontType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/bitmap/BitmapFontType.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2024 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. * @@ -81,8 +81,8 @@ class BitmapFontType( private fun load(file: ResourceLocation, height: Int, ascent: Int, chars: List, context: RenderContext): BitmapFontType? { if (chars.isEmpty() || height <= 0) return null val texture = PNGTexture(file, 0) - context.textures.font += texture texture.load(context) // force load it, we need to calculate the width of every char + context.textures.font += texture // TODO: convert to font array size and remove empty lines return load(texture, texture.size.y / chars.size, ascent, chars.codePoints()) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLFontTextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLFontTextureArray.kt index 989384463..3eaae313b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLFontTextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLFontTextureArray.kt @@ -60,7 +60,8 @@ class OpenGLFontTextureArray( for (texture in textures) { val renderData = texture.renderData as OpenGLTextureData val buffer = texture.data.buffer - buffer.data.flip() + buffer.data.position(0) + buffer.data.limit(buffer.data.capacity()) glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, renderData.index, buffer.size.x, buffer.size.y, 1, buffer.glFormat, buffer.glType, buffer.data) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/window/BaseWindow.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/window/BaseWindow.kt index deb5ac8eb..9f6348c2a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/window/BaseWindow.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/window/BaseWindow.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2024 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. * @@ -86,7 +86,8 @@ interface BaseWindow { val decoder = PNGDecoder(assetsManager[SystemUtil.ICON]) val data = BufferUtils.createByteBuffer(decoder.width * decoder.height * PNGDecoder.Format.RGBA.numComponents) decoder.decode(data, decoder.width * PNGDecoder.Format.RGBA.numComponents, PNGDecoder.Format.RGBA) - data.flip() + data.position(0) + data.limit(data.capacity()) setIcon(Vec2i(decoder.width, decoder.height), data) }