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