ram: improve more with using primitive float arrays

This commit is contained in:
Bixilon 2021-03-14 17:15:20 +01:00
parent 2eb44713e7
commit 28d9f9bbdc
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 18 additions and 27 deletions

View File

@ -346,5 +346,10 @@
<artifactId>moshi-kotlin</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>commons-primitives</groupId>
<artifactId>commons-primitives</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>

View File

@ -28,6 +28,7 @@ class SectionArrayMesh : Mesh() {
var highestBlockHeight = 0
fun addVertex(position: Vec3, textureCoordinates: Vec2, texture: Texture, tintColor: RGBColor?, lightLevel: Int = 14) {
val data = data!!
data.add(position.x)
data.add(position.y)
data.add(position.z)

View File

@ -235,13 +235,10 @@ class WorldRenderer(
val index = getSectionIndex(highestBlockHeight)
mesh.lowestBlockHeight = lowestBlockHeight
mesh.highestBlockHeight = highestBlockHeight
mesh.preLoad()
renderWindow.renderQueue.add {
val sectionMap = allChunkSections.getOrPut(chunkPosition, { ConcurrentHashMap() })

View File

@ -16,11 +16,12 @@ package de.bixilon.minosoft.gui.rendering.hud
import de.bixilon.minosoft.data.text.RGBColor
import glm_.vec2.Vec2
import glm_.vec3.Vec3
import org.apache.commons.collections.primitives.ArrayFloatList
class HUDCacheMesh {
private val data: MutableList<Float> = mutableListOf()
private val data = ArrayFloatList()
val cache: List<Float>
val cache: ArrayFloatList
get() = data
fun addVertex(position: Vec3, textureCoordinates: Vec2, textureLayer: Int, tintColor: RGBColor? = null) {
@ -38,14 +39,10 @@ class HUDCacheMesh {
}
val size: Int
get() = data.size
get() = data.size()
fun isEmpty(): Boolean {
return data.isEmpty()
}
fun isNotEmpty(): Boolean {
return data.isNotEmpty()
return data.isEmpty
}
fun clear() {

View File

@ -36,7 +36,7 @@ class HUDMesh : Mesh() {
}
fun addCacheMesh(cacheMesh: HUDCacheMesh) {
data.addAll(cacheMesh.cache)
data!!.addAll(cacheMesh.cache)
}

View File

@ -180,7 +180,6 @@ class HUDRenderer(val connection: Connection, val renderWindow: RenderWindow) :
tempMesh.addCacheMesh(hudElement.layout.cache)
}
currentHUDMesh.unload(false)
tempMesh.preLoad()
tempMesh.load()
currentHUDMesh = tempMesh
}

View File

@ -13,44 +13,37 @@
package de.bixilon.minosoft.gui.rendering.util
import org.apache.commons.collections.primitives.ArrayFloatList
import org.lwjgl.opengl.GL11.GL_TRIANGLES
import org.lwjgl.opengl.GL11.glDrawArrays
import org.lwjgl.opengl.GL30.*
abstract class Mesh {
protected val data: MutableList<Float> = mutableListOf()
protected var data: ArrayFloatList? = ArrayFloatList()
private var vao: Int = -1
private var vbo: Int = -1
var trianglesCount: Int = -1
private set
private var rawData: FloatArray? = null
var state = MeshStates.PREPARING
private set
open fun preLoad() {
check(state == MeshStates.PREPARING) { "Mesh already loaded: $state" }
rawData = data.toFloatArray()
data.clear()
state = MeshStates.PRE_LOADED
}
abstract fun load()
protected fun initializeBuffers(floatsPerVertex: Int) {
check(state == MeshStates.PRE_LOADED) { "Mesh not pre loaded: $state" }
check(state == MeshStates.PREPARING) { "Mesh already loaded: $state" }
trianglesCount = rawData!!.size / floatsPerVertex
trianglesCount = data!!.size() / floatsPerVertex
vao = glGenVertexArrays()
vbo = glGenBuffers()
glBindVertexArray(vao)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, rawData!!, GL_STATIC_DRAW)
glBufferData(GL_ARRAY_BUFFER, data!!.toArray(), GL_STATIC_DRAW)
state = MeshStates.LOADED
rawData = null
data = null
}
protected fun unbind() {
@ -78,7 +71,6 @@ abstract class Mesh {
enum class MeshStates {
PREPARING,
PRE_LOADED,
LOADED,
UNLOADED,
}