improve opengl font compression, make it configurable

This commit is contained in:
Moritz Zwerger 2023-12-06 14:00:50 +01:00
parent 3fde8031c4
commit d4682fe0dc
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
10 changed files with 57 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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,

View File

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

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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<FontCompressions> {
override val VALUES = values()
override val NAME_MAP = names()
}
}

View File

@ -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<Texture> = mutableSetOf()
private val lock = SimpleLock()

View File

@ -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<OpenGLRenderSystem>().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?)

View File

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