mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
vertex operations: improve performance
This commit is contained in:
parent
cf81d90394
commit
07ab08ccb0
@ -30,19 +30,16 @@ class ParticleMesh(renderWindow: RenderWindow, data: DirectArrayFloatList) : Mes
|
||||
fun addVertex(position: Vec3d, scale: Float, texture: AbstractTexture, tintColor: RGBColor, uvMin: Vec2 = Vec2(0.0f, 0.0f), uvMax: Vec2 = Vec2(1.0f, 1.0f)) {
|
||||
val minTransformedUV = texture.renderData?.transformUV(uvMin) ?: uvMin
|
||||
val maxTransformedUV = texture.renderData?.transformUV(uvMax) ?: uvMax
|
||||
data.addAll(
|
||||
floatArrayOf(
|
||||
position.x.toFloat(), // ToDo: Use doubles
|
||||
position.y.toFloat(),
|
||||
position.z.toFloat(),
|
||||
minTransformedUV.x,
|
||||
minTransformedUV.y,
|
||||
maxTransformedUV.x,
|
||||
maxTransformedUV.y,
|
||||
Float.fromBits(texture.renderData?.shaderTextureId ?: RenderConstants.DEBUG_TEXTURE_ID),
|
||||
scale,
|
||||
Float.fromBits(tintColor.rgba),
|
||||
))
|
||||
data.add(position.x.toFloat())
|
||||
data.add(position.y.toFloat())
|
||||
data.add(position.z.toFloat())
|
||||
data.add(minTransformedUV.x)
|
||||
data.add(minTransformedUV.y)
|
||||
data.add(maxTransformedUV.x)
|
||||
data.add(maxTransformedUV.y)
|
||||
data.add(Float.fromBits(texture.renderData?.shaderTextureId ?: RenderConstants.DEBUG_TEXTURE_ID))
|
||||
data.add(scale)
|
||||
data.add(Float.fromBits(tintColor.rgba))
|
||||
}
|
||||
|
||||
|
||||
|
@ -143,9 +143,7 @@ class ParticleRenderer(
|
||||
particlesLock.unlock()
|
||||
}
|
||||
|
||||
operator fun plusAssign(particle: Particle) {
|
||||
add(particle)
|
||||
}
|
||||
operator fun plusAssign(particle: Particle) = add(particle)
|
||||
|
||||
override fun prepareDraw() {
|
||||
transparentMesh.unload()
|
||||
@ -153,7 +151,6 @@ class ParticleRenderer(
|
||||
|
||||
val toRemove: MutableSet<Particle> = mutableSetOf()
|
||||
|
||||
|
||||
transparentMesh.data.clear()
|
||||
translucentMesh.data.clear()
|
||||
transparentMesh = ParticleMesh(renderWindow, transparentMesh.data)
|
||||
@ -171,6 +168,7 @@ class ParticleRenderer(
|
||||
particle.addVertex(transparentMesh, translucentMesh, time)
|
||||
}
|
||||
particlesLock.release()
|
||||
|
||||
if (toRemove.isNotEmpty()) {
|
||||
particlesLock.lock()
|
||||
particles -= toRemove
|
||||
|
@ -76,7 +76,6 @@ abstract class Particle(
|
||||
}
|
||||
field = value
|
||||
|
||||
|
||||
val x = ((aabb.min.x + aabb.max.x) - spacing.x) / 2.0
|
||||
val z = ((aabb.min.z + aabb.max.z) - spacing.z) / 2.0
|
||||
|
||||
|
@ -369,10 +369,12 @@ object VecUtil {
|
||||
delta <= 0.0 -> return start
|
||||
delta >= 1.0 -> return end
|
||||
}
|
||||
val startArray = start.array
|
||||
val endArray = end.array
|
||||
return Vec3d(
|
||||
lerp(delta, start.x, end.x),
|
||||
lerp(delta, start.y, end.y),
|
||||
lerp(delta, start.z, end.z),
|
||||
lerp(delta, startArray[0], endArray[0]),
|
||||
lerp(delta, startArray[1], endArray[1]),
|
||||
lerp(delta, startArray[2], endArray[2]),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ abstract class Mesh(
|
||||
val reversedOrder = order.reversedArray()
|
||||
private var _data: DirectArrayFloatList? = data ?: DirectArrayFloatList(initialCacheSize)
|
||||
var data: DirectArrayFloatList
|
||||
get() = _data!!
|
||||
get() = _data as DirectArrayFloatList
|
||||
set(value) {
|
||||
_data = value
|
||||
}
|
||||
|
@ -26,15 +26,13 @@ class SingleWorldMesh(renderWindow: RenderWindow, initialCacheSize: Int) : Mesh(
|
||||
|
||||
fun addVertex(position: FloatArray, uv: Vec2, texture: AbstractTexture, tintColor: Int, light: Int) {
|
||||
val transformedUV = texture.renderData?.transformUV(uv) ?: uv
|
||||
data.addAll(floatArrayOf(
|
||||
position[0],
|
||||
position[1],
|
||||
position[2],
|
||||
transformedUV.x,
|
||||
transformedUV.y,
|
||||
Float.fromBits(texture.renderData?.shaderTextureId ?: RenderConstants.DEBUG_TEXTURE_ID),
|
||||
Float.fromBits(tintColor or (light shl 24)),
|
||||
))
|
||||
data.add(position[0])
|
||||
data.add(position[1])
|
||||
data.add(position[2])
|
||||
data.add(transformedUV.x)
|
||||
data.add(transformedUV.y)
|
||||
data.add(Float.fromBits(texture.renderData?.shaderTextureId ?: RenderConstants.DEBUG_TEXTURE_ID))
|
||||
data.add(Float.fromBits(tintColor or (light shl 24)))
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,8 +24,8 @@ class DirectArrayFloatList(
|
||||
) : AbstractFloatList() {
|
||||
var buffer: FloatBuffer = memAllocFloat(initialSize)
|
||||
private set
|
||||
override val limit: Int
|
||||
get() = buffer.capacity()
|
||||
override var limit: Int = buffer.limit()
|
||||
private set
|
||||
override val size: Int
|
||||
get() = buffer.position()
|
||||
override val isEmpty: Boolean
|
||||
@ -58,6 +58,7 @@ class DirectArrayFloatList(
|
||||
}
|
||||
val oldBuffer = buffer
|
||||
buffer = memAllocFloat(newSize)
|
||||
limit = newSize
|
||||
if (FLOAT_PUT_METHOD == null) { // Java < 16
|
||||
for (i in 0 until oldBuffer.position()) {
|
||||
buffer.put(oldBuffer.get(i))
|
||||
@ -139,6 +140,7 @@ class DirectArrayFloatList(
|
||||
finished = true
|
||||
val oldBuffer = buffer
|
||||
buffer = memAllocFloat(oldBuffer.position())
|
||||
limit = buffer.limit()
|
||||
if (FLOAT_PUT_METHOD == null) { // Java < 16
|
||||
for (i in 0 until oldBuffer.position()) {
|
||||
buffer.put(oldBuffer.get(i))
|
||||
|
Loading…
x
Reference in New Issue
Block a user