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 93bef72f2..94acc7494 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 @@ -17,10 +17,12 @@ import de.bixilon.kutil.latch.AbstractLatch import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader 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 +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontCompressions +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontTextureArray + +class DummyFontTextureArray(context: RenderContext) : FontTextureArray(context, 1024, FontCompressions.NONE) { -class DummyFontTextureArray(context: RenderContext) : FontTextureArray(context, 1024, false) { override fun load(latch: AbstractLatch) { for (texture in textures) { texture.renderData = DummyTextureRenderData diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/texture/DummyTextureManager.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/texture/DummyTextureManager.kt index 2635321e8..d330d5259 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/texture/DummyTextureManager.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/dummy/texture/DummyTextureManager.kt @@ -15,7 +15,7 @@ package de.bixilon.minosoft.gui.rendering.system.dummy.texture import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager -import de.bixilon.minosoft.gui.rendering.system.base.texture.array.FontTextureArray +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontTextureArray class DummyTextureManager(val context: RenderContext) : TextureManager() { override val dynamic = DummyDynamicTextureArray(context) 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 fb40e33f5..8ed32550d 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,9 +13,10 @@ 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.delegate.types.EnumDelegate import de.bixilon.minosoft.config.profile.profiles.rendering.RenderingProfile +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontCompressions class TexturesC(profile: RenderingProfile) { @@ -28,5 +29,5 @@ class TexturesC(profile: RenderingProfile) { * 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) + var fontCompression by EnumDelegate(profile, FontCompressions.COMPRESSED_ALPHA, FontCompressions) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/legacy/LegacyUnicodeFontType.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/legacy/LegacyUnicodeFontType.kt index b0e0792bb..013b9abf1 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/legacy/LegacyUnicodeFontType.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/legacy/LegacyUnicodeFontType.kt @@ -26,7 +26,7 @@ import de.bixilon.minosoft.gui.rendering.font.renderer.properties.FontProperties import de.bixilon.minosoft.gui.rendering.font.types.PostInitFontType import de.bixilon.minosoft.gui.rendering.font.types.factory.FontTypeFactory import de.bixilon.minosoft.gui.rendering.font.types.unicode.UnicodeCodeRenderer -import de.bixilon.minosoft.gui.rendering.system.base.texture.array.FontTextureArray +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontTextureArray import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.file.PNGTexture import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnifontRasterizer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnifontRasterizer.kt index 1afa27a2b..a2fcad88d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnifontRasterizer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/types/unicode/unihex/UnifontRasterizer.kt @@ -16,7 +16,7 @@ package de.bixilon.minosoft.gui.rendering.font.types.unicode.unihex import de.bixilon.minosoft.gui.rendering.font.renderer.code.CodePointRenderer import de.bixilon.minosoft.gui.rendering.font.types.empty.EmptyCodeRenderer import de.bixilon.minosoft.gui.rendering.font.types.unicode.unihex.UnifontTexture.Companion.isPixelSet -import de.bixilon.minosoft.gui.rendering.system.base.texture.array.FontTextureArray +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontTextureArray class UnifontRasterizer( private val array: FontTextureArray, diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/TextureManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/TextureManager.kt index b97b889ba..a87285583 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/TextureManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/TextureManager.kt @@ -20,8 +20,8 @@ import de.bixilon.minosoft.gui.rendering.RenderConstants import de.bixilon.minosoft.gui.rendering.gui.atlas.textures.CodeTexturePart import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader import de.bixilon.minosoft.gui.rendering.system.base.shader.ShaderUniforms -import de.bixilon.minosoft.gui.rendering.system.base.texture.array.FontTextureArray import de.bixilon.minosoft.gui.rendering.system.base.texture.array.StaticTextureArray +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontTextureArray import de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic.DynamicTextureArray import de.bixilon.minosoft.gui.rendering.system.base.texture.skin.SkinManager import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/font/FontCompressions.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/font/FontCompressions.kt new file mode 100644 index 000000000..b2b1c3845 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/font/FontCompressions.kt @@ -0,0 +1,29 @@ +/* + * Minosoft + * Copyright (C) 2020-2023 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. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.system.base.texture.array.font + +import de.bixilon.kutil.enums.ValuesEnum +import de.bixilon.kutil.enums.ValuesEnum.Companion.names + +enum class FontCompressions { + NONE, + ALPHA, + COMPRESSED_ALPHA, + ; + + companion object : ValuesEnum { + override val VALUES = values() + override val NAME_MAP = names() + } +} 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/font/FontTextureArray.kt similarity index 90% rename from src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/FontTextureArray.kt rename to src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/font/FontTextureArray.kt index 2a7f8e94b..62e34bf5c 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/font/FontTextureArray.kt @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.gui.rendering.system.base.texture.array +package de.bixilon.minosoft.gui.rendering.system.base.texture.array.font import de.bixilon.kutil.concurrent.lock.simple.SimpleLock import de.bixilon.kutil.concurrent.pool.DefaultThreadPool @@ -20,12 +20,14 @@ import de.bixilon.kutil.concurrent.pool.runnable.ForcePooledRunnable import de.bixilon.kutil.latch.AbstractLatch import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureStates +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.TextureArray +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.TextureArrayStates import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture abstract class FontTextureArray( val context: RenderContext, val resolution: Int, - val compressed: Boolean, + val compression: FontCompressions, ) : 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 8c4e494c7..cc66879f9 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 @@ -19,9 +19,10 @@ import de.bixilon.kutil.latch.AbstractLatch import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader 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 import de.bixilon.minosoft.gui.rendering.system.base.texture.array.TextureArrayStates +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontCompressions +import de.bixilon.minosoft.gui.rendering.system.base.texture.array.font.FontTextureArray import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture import de.bixilon.minosoft.gui.rendering.system.opengl.OpenGLRenderSystem import de.bixilon.minosoft.gui.rendering.system.opengl.texture.OpenGLTextureUtil.glFormat @@ -31,11 +32,12 @@ import de.bixilon.minosoft.util.logging.Log import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType import org.lwjgl.opengl.GL30.* +import org.lwjgl.opengl.GL33.GL_TEXTURE_SWIZZLE_RGBA import java.nio.ByteBuffer class OpenGLFontTextureArray( context: RenderContext, - compressed: Boolean, + compressed: FontCompressions, ) : FontTextureArray(context, RESOLUTION, compressed) { val index = context.system.unsafeCast().textureBindingIndex++ private var handle = -1 @@ -44,8 +46,14 @@ 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? + val format = when (compression) { + FontCompressions.NONE -> GL_RGBA8 + FontCompressions.ALPHA -> GL_ALPHA8 + FontCompressions.COMPRESSED_ALPHA -> GL_COMPRESSED_ALPHA + } + if (compression != FontCompressions.NONE) { + glTexParameteriv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_RGBA, intArrayOf(GL_ONE, GL_ONE, GL_ONE, GL_ALPHA)) + } glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, format, RESOLUTION, RESOLUTION, textures.size, 0, GL_RGBA, GL_UNSIGNED_BYTE, null as ByteBuffer?) 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 86c742792..7bb485826 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 @@ -22,5 +22,5 @@ class OpenGLTextureManager(val context: RenderContext) : TextureManager() { 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) + override val font = OpenGLFontTextureArray(context, config.fontCompression) }