From 59fe64020a068922f521c794af512ccf4537b1d3 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Fri, 9 Apr 2021 14:09:47 +0200 Subject: [PATCH] move debug texture to render constants --- .../bixilon/minosoft/gui/rendering/RenderConstants.kt | 5 +++++ .../de/bixilon/minosoft/gui/rendering/RenderWindow.kt | 2 +- .../minosoft/gui/rendering/chunk/SectionArrayMesh.kt | 2 +- .../chunk/models/renderable/ElementRenderer.kt | 10 ++++++++-- .../bixilon/minosoft/gui/rendering/font/FontLoader.kt | 4 ++-- .../minosoft/gui/rendering/textures/TextureArray.kt | 2 -- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt index d5ecbbc7f..0329b0f18 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt @@ -13,6 +13,7 @@ package de.bixilon.minosoft.gui.rendering +import de.bixilon.minosoft.data.mappings.ResourceLocation import de.bixilon.minosoft.data.text.RGBColor object RenderConstants { @@ -57,4 +58,8 @@ object RenderConstants { const val RENDER_HUD = true const val FORCE_DEBUG_TEXTURE = false + + + val DEBUG_TEXTURE_RESOURCE_LOCATION = ResourceLocation("minosoft:textures/debug.png") + const val DEBUG_TEXTURE_ID = 0 // always add the debug texture to the texture array first to ensure the id is 0 } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt index d71e8a5fe..b44f0ba05 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt @@ -238,7 +238,7 @@ class RenderWindow( glEnable(GL_CULL_FACE) - textures.allTextures.add(Texture(TextureArray.DEBUG_TEXTURE)) + textures.allTextures.add(Texture(RenderConstants.DEBUG_TEXTURE_RESOURCE_LOCATION)) font.load(connection.assetsManager) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/SectionArrayMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/SectionArrayMesh.kt index b19356b54..5ce34cacc 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/SectionArrayMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/SectionArrayMesh.kt @@ -36,7 +36,7 @@ class SectionArrayMesh : Mesh(initialCacheSize = 100000) { val lightColor = RGBColor((color.red * lightFactor).toInt(), (color.green * lightFactor).toInt(), (color.blue * lightFactor).toInt()) val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) { - 0 + RenderConstants.DEBUG_TEXTURE_ID } else { (texture.arrayId shl 24) or texture.arrayLayer } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/models/renderable/ElementRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/models/renderable/ElementRenderer.kt index fec0ca955..a20e8ee34 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/models/renderable/ElementRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/models/renderable/ElementRenderer.kt @@ -33,7 +33,13 @@ import de.bixilon.minosoft.gui.rendering.util.VecUtil.rotate import glm_.vec3.Vec3 import glm_.vec3.Vec3i -class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boolean, rescale: Boolean, private val directionMapping: HashBiMap) { +class ElementRenderer( + parent: BlockModelElement, + val rotation: Vec3, + uvLock: Boolean, + rescale: Boolean, + private val directionMapping: HashBiMap, +) { val faceBorderSize: Array = arrayOfNulls(Directions.DIRECTIONS.size) private val faces: MutableMap = mutableMapOf() private var transformedPositions: Array = parent.transformedPositions.clone() @@ -68,7 +74,7 @@ class ElementRenderer(parent: BlockModelElement, val rotation: Vec3, uvLock: Boo val face = faces[realDirection] ?: return // Not our face val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[realDirection.ordinal] - val texture = textureMapping[face.textureName] ?: TODO("Unknown texture used ${face.textureName}") + val texture = textureMapping[face.textureName] ?: TODO("Unknown texture used ${face.textureName}") // ToDo: can be replaced with RenderConstants.DEBUG_TEXTURE_ID? val lightLevel = lightAccessor.getLightLevel(blockPosition + face.cullFace?.let { directionMapping[it] }) // ToDo: rotate cullface diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontLoader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontLoader.kt index e211847fa..e2d38f2e7 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontLoader.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontLoader.kt @@ -18,8 +18,8 @@ import com.google.gson.JsonObject import de.bixilon.minosoft.data.assets.AssetsManager import de.bixilon.minosoft.data.mappings.ResourceLocation import de.bixilon.minosoft.data.text.RGBColor +import de.bixilon.minosoft.gui.rendering.RenderConstants import de.bixilon.minosoft.gui.rendering.textures.Texture -import de.bixilon.minosoft.gui.rendering.textures.TextureArray import java.io.InputStream object FontLoader { @@ -97,7 +97,7 @@ object FontLoader { if (i % 256 == 0) { currentAtlasTexture = if (MISSING_UNICODE_PAGES.contains(i / UNICODE_CHARS_PER_PAGE)) { // ToDo: Why is this texture missing in minecraft? - Texture(TextureArray.DEBUG_TEXTURE) + Texture(RenderConstants.DEBUG_TEXTURE_RESOURCE_LOCATION) } else { // new page (texture) Texture(Texture.getResourceTextureIdentifier(template.namespace, template.path.format("%02x".format(i / 256)))) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt index b56e0682a..c290ae8b5 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt @@ -145,8 +145,6 @@ class TextureArray(val allTextures: MutableList) { val TEXTURE_RESOLUTION_ID_MAP = arrayOf(16, 32, 64, 128, 256, 512, 1024) // A 12x12 texture will be saved in texture id 0 (in 0 are only 16x16 textures). Animated textures get split const val TEXTURE_MAX_RESOLUTION = 1024 - val DEBUG_TEXTURE = ResourceLocation("minosoft:textures/debug.png") - private const val INTS_PER_ANIMATED_TEXTURE = 4 }