From 0ce0f806c5e85cd851a5379f5ceb4d79bf0012b3 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sun, 21 May 2023 20:35:08 +0200 Subject: [PATCH] BakedFace::render test --- .../rendering/models/baked/BakedFaceTest.kt | 79 +++++++++++++++++++ .../models/block/state/baked/BakedFace.kt | 4 +- .../rendering/world/mesh/SingleWorldMesh.kt | 8 +- 3 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/baked/BakedFaceTest.kt diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/baked/BakedFaceTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/baked/BakedFaceTest.kt new file mode 100644 index 000000000..dddce179e --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/models/baked/BakedFaceTest.kt @@ -0,0 +1,79 @@ +/* + * 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.models.baked + +import de.bixilon.kutil.collections.primitive.floats.HeapArrayFloatList +import de.bixilon.kutil.reflection.ReflectionUtil.forceSet +import de.bixilon.minosoft.gui.rendering.models.block.state.baked.BakedFace +import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer +import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes +import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture +import de.bixilon.minosoft.gui.rendering.world.mesh.SingleWorldMesh +import de.bixilon.minosoft.gui.rendering.world.mesh.WorldMesh +import de.bixilon.minosoft.test.IT.OBJENESIS +import de.bixilon.minosoft.util.KUtil.toResourceLocation +import org.testng.Assert.assertEquals +import org.testng.annotations.Test + +@Test(groups = ["models"]) +class BakedFaceTest { + private val texture = "block/test" + + private fun texture(): AbstractTexture { + val manager = BakedModelTestUtil.createTextureManager(texture) + return manager.staticTextures.createTexture(texture.toResourceLocation()) + } + + private fun singleMesh(): SingleWorldMesh { + val mesh = OBJENESIS.newInstance(SingleWorldMesh::class.java) + mesh::quadType.forceSet(PrimitiveTypes.QUAD) + mesh::order.forceSet(SingleWorldMesh.QUAD_ORDER) + + mesh.data = HeapArrayFloatList(1000) + + mesh::initialCacheSize.forceSet(1000) + + return mesh + } + + private fun mesh(): WorldMesh { + val mesh = OBJENESIS.newInstance(WorldMesh::class.java) + mesh::opaqueMesh.forceSet(singleMesh()) + + return mesh + + } + + fun renderFull() { + val face = BakedFace(floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f), floatArrayOf(-1f, -2f, -3f, -4f, -5f, -6f, -7f, -8f), 1.0f, -1, null, texture()) + + val mesh = mesh() + + face.render(floatArrayOf(0.0f, 0.0f, 0.0f), mesh, byteArrayOf(0, 0, 0, 0, 0, 0, 0), null) + + val texture = 0.buffer() + val lightTint = 0xFFFFFF.buffer() + + val data = mesh.opaqueMesh!!.data.toArray() + val expected = floatArrayOf( + 0f, 1f, 2f, -7f, -8f, texture, lightTint, + 9f, 10f, 11f, -1f, -2f, texture, lightTint, + 6f, 7f, 8f, -3f, -4f, texture, lightTint, + 3f, 4f, 5f, -5f, -6f, texture, lightTint, + ) + + + assertEquals(data, expected) + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/BakedFace.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/BakedFace.kt index c42c2ce4a..2c43f7553 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/BakedFace.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/block/state/baked/BakedFace.kt @@ -44,7 +44,7 @@ class BakedFace( fun render(offset: FloatArray, mesh: WorldMesh, light: ByteArray, tints: IntArray?) { val tint = color(tints?.getOrNull(tintIndex) ?: 0) - val tintLight = ((light[cullIndex].toInt() shl 24) or tint).buffer() + val lightTint = ((light[cullIndex].toInt() shl 24) or tint).buffer() val textureId = this.texture.shaderId.buffer() @@ -59,7 +59,7 @@ class BakedFace( uv = floatArrayOf(uv[uvOffset], uv[uvOffset + 1]), texture = this.texture, shaderTextureId = textureId, - tintLight = tintLight, + lightTint = lightTint, ) } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/world/mesh/SingleWorldMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/world/mesh/SingleWorldMesh.kt index e3cc3dcf0..c08ed4990 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/world/mesh/SingleWorldMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/world/mesh/SingleWorldMesh.kt @@ -35,10 +35,10 @@ class SingleWorldMesh(context: RenderContext, initialCacheSize: Int, onDemand: B data.add(position[2]) data.add(transformedUV) data.add(texture.renderData.shaderTextureId.buffer()) - data.add((tintColor or (light shl 24)).buffer()) + data.add(((light shl 24) or tintColor).buffer()) } - fun addVertex(x: Float, y: Float, z: Float, uv: FloatArray, texture: AbstractTexture, shaderTextureId: Float, tintLight: Float) { + fun addVertex(x: Float, y: Float, z: Float, uv: FloatArray, texture: AbstractTexture, shaderTextureId: Float, lightTint: Float) { data.ensureSize(WorldMeshStruct.FLOATS_PER_VERTEX) val transformedUV = texture.renderData.transformUV(uv) data.add(x) @@ -46,7 +46,7 @@ class SingleWorldMesh(context: RenderContext, initialCacheSize: Int, onDemand: B data.add(z) data.add(transformedUV) data.add(shaderTextureId) - data.add(tintLight) + data.add(lightTint) } @@ -54,7 +54,7 @@ class SingleWorldMesh(context: RenderContext, initialCacheSize: Int, onDemand: B val position: Vec3, val uv: Vec2, val indexLayerAnimation: Int, - val tintLight: Int, + val lightTint: Int, ) { companion object : MeshStruct(WorldMeshStruct::class) }