opengl: properly reset buffer for uploading

This commit is contained in:
Moritz Zwerger 2024-01-16 16:00:34 +01:00
parent 2c80c8047a
commit bb23496b8b
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 7 additions and 5 deletions

View File

@ -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<String>, 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())
}

View File

@ -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)
}

View File

@ -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)
}