Revert "Mesh: Force use FragmentedArrayFloatList"

This reverts commit 0a06695d
This commit is contained in:
Moritz Zwerger 2023-11-04 19:15:33 +01:00
parent 04edd74988
commit 30414c756e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 26 additions and 22 deletions

View File

@ -33,7 +33,7 @@ import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2Util.EMPTY
import de.bixilon.minosoft.util.Initializable
import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList
import de.bixilon.minosoft.util.collections.floats.FloatListUtil
open class GUIMeshElement<T : Element>(
val element: T,
@ -42,7 +42,7 @@ open class GUIMeshElement<T : Element>(
override val context: RenderContext = guiRenderer.context
private val clickCounter = MouseClickCounter()
private var _mesh: GUIMesh? = null
var mesh: GUIMesh = GUIMesh(context, guiRenderer.halfSize, FragmentedArrayFloatList(1000))
var mesh: GUIMesh = GUIMesh(context, guiRenderer.halfSize, FloatListUtil.direct(1000))
override val skipDraw: Boolean
get() = if (element is BaseDrawable) element.skipDraw else false
protected var lastRevision = 0L

View File

@ -28,7 +28,7 @@ import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.debug.DebugHUDElement
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMesh
import de.bixilon.minosoft.gui.rendering.system.base.BlendingFunctions
import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList
import de.bixilon.minosoft.util.collections.floats.BufferedArrayFloatList
class CrosshairHUDElement(guiRenderer: GUIRenderer) : CustomHUDElement(guiRenderer) {
private val profile = guiRenderer.connection.profiles.gui
@ -91,7 +91,7 @@ class CrosshairHUDElement(guiRenderer: GUIRenderer) : CustomHUDElement(guiRender
mesh?.unload()
this.mesh = null
val mesh = GUIMesh(context, guiRenderer.halfSize, FragmentedArrayFloatList(42))
val mesh = GUIMesh(context, guiRenderer.halfSize, BufferedArrayFloatList(42))
val start = (guiRenderer.scaledSize - CROSSHAIR_SIZE) / 2
mesh.addQuad(start, start + CROSSHAIR_SIZE, crosshairAtlasElement, crosshairProfile.color, null)

View File

@ -22,12 +22,11 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderIdenti
import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList
class GUIMesh(
context: RenderContext,
val halfSize: Vec2,
data: FragmentedArrayFloatList,
data: AbstractFloatList,
) : Mesh(context, GUIMeshStruct, initialCacheSize = 40000, clearOnLoad = false, data = data), GUIVertexConsumer {
private val whiteTexture = context.textures.whiteTexture
override val order = context.system.quadOrder

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.particle
import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.gui.rendering.RenderContext
import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer
@ -23,9 +24,8 @@ import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveType
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList
class ParticleMesh(context: RenderContext, data: FragmentedArrayFloatList) : Mesh(context, ParticleMeshStruct, PrimitiveTypes.POINT, -1, clearOnLoad = false, data = data) {
class ParticleMesh(context: RenderContext, data: AbstractFloatList) : Mesh(context, ParticleMeshStruct, PrimitiveTypes.POINT, -1, clearOnLoad = false, data = data) {
fun addVertex(position: Vec3d, scale: Float, texture: Texture, tintColor: RGBColor, uvMin: FloatArray? = null, uvMax: FloatArray? = null, light: Int) {
val minTransformedUV = if (uvMin == null) {

View File

@ -39,7 +39,7 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates.Companion.disconnected
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.chunk.ChunkUtil.isInViewDistance
import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList
import de.bixilon.minosoft.util.collections.floats.BufferedArrayFloatList
class ParticleRenderer(
@ -53,8 +53,8 @@ class ParticleRenderer(
private val translucentShader = renderSystem.createShader(minosoft("particle")) { ParticleShader(it, false) }
// There is no opaque mesh because it is simply not needed (every particle has transparency)
private var transparentMesh = ParticleMesh(context, FragmentedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX))
private var translucentMesh = ParticleMesh(context, FragmentedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX))
private var transparentMesh = ParticleMesh(context, BufferedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX))
private var translucentMesh = ParticleMesh(context, BufferedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX))
private val particlesLock = SimpleLock()
private var particles: MutableList<Particle> = mutableListOf()

View File

@ -15,12 +15,15 @@ package de.bixilon.minosoft.gui.rendering.util.mesh
import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kutil.cast.CastUtil.nullCast
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList
import de.bixilon.minosoft.gui.rendering.RenderContext
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.FloatVertexBuffer
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2Util
import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList
import de.bixilon.minosoft.util.collections.floats.FragmentedArrayFloatList
import de.bixilon.minosoft.util.collections.floats.FloatListUtil
abstract class Mesh(
val context: RenderContext,
@ -28,15 +31,15 @@ abstract class Mesh(
val quadType: PrimitiveTypes = context.system.quadType,
var initialCacheSize: Int = 10000,
val clearOnLoad: Boolean = true,
data: FragmentedArrayFloatList? = null,
data: AbstractFloatList? = null,
val onDemand: Boolean = false,
) : AbstractVertexConsumer {
override val order = context.system.legacyQuadOrder
private var _data: FragmentedArrayFloatList? = data ?: if (onDemand) null else FragmentedArrayFloatList(initialCacheSize)
var data: FragmentedArrayFloatList
private var _data: AbstractFloatList? = data ?: if (onDemand) null else FloatListUtil.direct(initialCacheSize)
var data: AbstractFloatList
get() {
if (_data == null && onDemand) {
_data = FragmentedArrayFloatList(initialCacheSize)
_data = FloatListUtil.direct(initialCacheSize)
}
return _data.unsafeCast()
}
@ -85,14 +88,14 @@ abstract class Mesh(
fun unload() {
when (state) {
MeshStates.LOADED -> buffer.unload()
MeshStates.PREPARING, MeshStates.FINISHED -> _data?.unload()
MeshStates.PREPARING, MeshStates.FINISHED -> _data?.nullCast<DirectArrayFloatList>()?.unload()
else -> throw IllegalStateException("Mesh is already unloaded")
}
state = MeshStates.UNLOADED
}
inline fun addXQuad(start: Vec2, x: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) {
inline fun addXQuad(start: Vec2, x: Float, end: Vec2, uvStart: Vec2 = Vec2Util.EMPTY, uvEnd: Vec2 = Vec2Util.ONE, vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) {
val positions = arrayOf(
Vec3(x, start.x, start.y),
Vec3(x, start.x, end.y),
@ -102,7 +105,7 @@ abstract class Mesh(
addQuad(positions, uvStart, uvEnd, vertexConsumer)
}
inline fun addYQuad(start: Vec2, y: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) {
inline fun addYQuad(start: Vec2, y: Float, end: Vec2, uvStart: Vec2 = Vec2Util.EMPTY, uvEnd: Vec2 = Vec2Util.ONE, vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) {
val positions = arrayOf(
Vec3(start.x, y, end.y),
Vec3(end.x, y, end.y),
@ -112,7 +115,7 @@ abstract class Mesh(
addQuad(positions, uvStart, uvEnd, vertexConsumer)
}
inline fun addZQuad(start: Vec2, z: Float, end: Vec2, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) {
inline fun addZQuad(start: Vec2, z: Float, end: Vec2, uvStart: Vec2 = Vec2Util.EMPTY, uvEnd: Vec2 = Vec2Util.ONE, vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) {
val positions = arrayOf(
Vec3(start.x, start.y, z),
Vec3(start.x, end.y, z),
@ -122,7 +125,7 @@ abstract class Mesh(
addQuad(positions, uvStart, uvEnd, vertexConsumer)
}
inline fun addQuad(positions: Array<Vec3>, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) {
inline fun addQuad(positions: Array<Vec3>, uvStart: Vec2 = Vec2Util.EMPTY, uvEnd: Vec2 = Vec2Util.ONE, vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) {
val texturePositions = arrayOf(
uvStart,
Vec2(uvStart.x, uvEnd.y),

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* 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.
*
@ -19,6 +19,8 @@ import de.bixilon.kutil.math.interpolation.FloatInterpolation.interpolateSine
import de.bixilon.kutil.primitive.FloatUtil.toFloat
object Vec2Util {
val EMPTY = Vec2.EMPTY
val ONE = Vec2(1.0f)
val Vec2.Companion.MIN: Vec2
get() = Vec2(Float.MIN_VALUE, Float.MIN_VALUE)