From 803cdcc552bd57fb7294b5aaa2d2595ade13029b Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 5 Dec 2023 23:28:31 +0100 Subject: [PATCH] option to disable compressed font textures That can workaround issues on some gpus --- .../system/dummy/texture/DummyFontTextureArray.kt | 2 +- .../profile/profiles/rendering/textures/TexturesC.kt | 7 +++++++ .../system/base/texture/array/FontTextureArray.kt | 1 + .../system/opengl/texture/OpenGLFontTextureArray.kt | 6 ++++-- .../system/opengl/texture/OpenGLTextureManager.kt | 8 ++++---- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/texture/DummyFontTextureArray.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/texture/DummyFontTextureArray.kt index 9203ec687..93bef72f2 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/texture/DummyFontTextureArray.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/texture/DummyFontTextureArray.kt @@ -20,7 +20,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureStates import de.bixilon.minosoft.gui.rendering.system.base.texture.array.FontTextureArray import de.bixilon.minosoft.gui.rendering.system.base.texture.array.TextureArrayProperties -class DummyFontTextureArray(context: RenderContext) : FontTextureArray(context, 1024) { +class DummyFontTextureArray(context: RenderContext) : FontTextureArray(context, 1024, false) { override fun load(latch: AbstractLatch) { for (texture in textures) { texture.renderData = DummyTextureRenderData diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/textures/TexturesC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/textures/TexturesC.kt index 8ada1c9e9..fb40e33f5 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/textures/TexturesC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/textures/TexturesC.kt @@ -13,6 +13,7 @@ package de.bixilon.minosoft.config.profile.profiles.rendering.textures +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate import de.bixilon.minosoft.config.profile.delegate.primitive.IntDelegate import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfile @@ -22,4 +23,10 @@ class TexturesC(profile: RenderingProfile) { * Weather to use mipmaps for all static textures */ var mipmaps by IntDelegate(profile, 4, arrayOf(0..4)) + + /** + * Font texture can be compressed on the gpu which massively reduces vram usage. + * It may not work with all drivers well, so disable it when font is just black. + */ + var compressedFont by BooleanDelegate(profile, true) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/FontTextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/FontTextureArray.kt index 4e7df0e4c..2a7f8e94b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/FontTextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/FontTextureArray.kt @@ -25,6 +25,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture abstract class FontTextureArray( val context: RenderContext, val resolution: Int, + val compressed: Boolean, ) : TextureArray { protected val textures: MutableSet = mutableSetOf() private val lock = SimpleLock() 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 d0ac45728..8c4e494c7 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 @@ -35,7 +35,8 @@ import java.nio.ByteBuffer class OpenGLFontTextureArray( context: RenderContext, -) : FontTextureArray(context, RESOLUTION) { + compressed: Boolean, +) : FontTextureArray(context, RESOLUTION, compressed) { val index = context.system.unsafeCast().textureBindingIndex++ private var handle = -1 private var textureIndex = 0 @@ -43,9 +44,10 @@ class OpenGLFontTextureArray( override fun upload(latch: AbstractLatch?) { this.handle = OpenGLTextureUtil.createTextureArray(0) + val format = if (compressed) GL_COMPRESSED_LUMINANCE_ALPHA else GL_RGBA8 // glTexParameteriv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_RGBA, intArrayOf(GL_LUMINANCE, GL_LUMINANCE, GL_LUMINANCE, GL_LUMINANCE)) // TODO: not working? - glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_COMPRESSED_LUMINANCE_ALPHA, RESOLUTION, RESOLUTION, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?) + glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, format, RESOLUTION, RESOLUTION, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?) for (texture in textures) { val renderData = texture.renderData as OpenGLTextureData diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLTextureManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLTextureManager.kt index 84d2fb861..86c742792 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLTextureManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/texture/OpenGLTextureManager.kt @@ -19,8 +19,8 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager import de.bixilon.minosoft.gui.rendering.system.opengl.texture.dynamic.OpenGLDynamicTextureArray class OpenGLTextureManager(val context: RenderContext) : TextureManager() { - private val mipmaps = context.connection.profiles.rendering.textures.mipmaps - override val static = OpenGLTextureArray(context, true, mipmaps) - override val dynamic = OpenGLDynamicTextureArray(context, context.system.unsafeCast(), resolution = 64, mipmaps = mipmaps) - override val font = OpenGLFontTextureArray(context) + private val config = context.connection.profiles.rendering.textures + override val static = OpenGLTextureArray(context, true, config.mipmaps) + override val dynamic = OpenGLDynamicTextureArray(context, context.system.unsafeCast(), resolution = 64, mipmaps = config.mipmaps) + override val font = OpenGLFontTextureArray(context, config.compressedFont) }