mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
wip: RenderSystem buffer creation
This commit is contained in:
parent
875d75c2bc
commit
4a8ef1adce
@ -81,7 +81,7 @@ class WorldRenderer(
|
|||||||
private fun prepareSections(chunkPosition: Vec2i, sections: Map<Int, ChunkSection>): ChunkSectionMeshCollection {
|
private fun prepareSections(chunkPosition: Vec2i, sections: Map<Int, ChunkSection>): ChunkSectionMeshCollection {
|
||||||
check(sections.isNotEmpty()) { "Illegal argument!" }
|
check(sections.isNotEmpty()) { "Illegal argument!" }
|
||||||
queuedChunks.remove(chunkPosition)
|
queuedChunks.remove(chunkPosition)
|
||||||
val meshCollection = ChunkSectionMeshCollection()
|
val meshCollection = ChunkSectionMeshCollection(renderWindow)
|
||||||
|
|
||||||
for ((sectionHeight, section) in sections) {
|
for ((sectionHeight, section) in sections) {
|
||||||
for ((index, blockState) in section.blocks.withIndex()) {
|
for ((index, blockState) in section.blocks.withIndex()) {
|
||||||
|
@ -39,7 +39,7 @@ class ChunkBorderRenderer(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastMesh?.unload(false)
|
lastMesh?.unload(false)
|
||||||
val mesh = LineMesh()
|
val mesh = LineMesh(renderWindow)
|
||||||
|
|
||||||
val dimension = renderWindow.connection.world.dimension ?: return
|
val dimension = renderWindow.connection.world.dimension ?: return
|
||||||
val basePosition = chunkPosition * Vec2i(ProtocolDefinition.SECTION_WIDTH_X, ProtocolDefinition.SECTION_WIDTH_Z)
|
val basePosition = chunkPosition * Vec2i(ProtocolDefinition.SECTION_WIDTH_X, ProtocolDefinition.SECTION_WIDTH_Z)
|
||||||
|
@ -16,13 +16,14 @@ package de.bixilon.minosoft.gui.rendering.block.mesh
|
|||||||
import de.bixilon.minosoft.data.text.ChatColors
|
import de.bixilon.minosoft.data.text.ChatColors
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
||||||
import glm_.vec2.Vec2
|
import glm_.vec2.Vec2
|
||||||
import glm_.vec3.Vec3
|
import glm_.vec3.Vec3
|
||||||
|
|
||||||
class ChunkSectionArrayMesh : Mesh(SectionArrayMeshStruct::class, initialCacheSize = 100000) {
|
class ChunkSectionArrayMesh(renderWindow: RenderWindow) : Mesh(renderWindow, SectionArrayMeshStruct::class, initialCacheSize = 100000) {
|
||||||
|
|
||||||
fun addVertex(position: Vec3, textureCoordinates: Vec2, texture: Texture, tintColor: RGBColor?, light: Int) {
|
fun addVertex(position: Vec3, textureCoordinates: Vec2, texture: Texture, tintColor: RGBColor?, light: Int) {
|
||||||
val color = tintColor ?: ChatColors.WHITE
|
val color = tintColor ?: ChatColors.WHITE
|
||||||
@ -32,7 +33,8 @@ class ChunkSectionArrayMesh : Mesh(SectionArrayMeshStruct::class, initialCacheSi
|
|||||||
} else {
|
} else {
|
||||||
(texture.arrayId shl 24) or texture.arrayLayer
|
(texture.arrayId shl 24) or texture.arrayLayer
|
||||||
}
|
}
|
||||||
data.addAll(floatArrayOf(
|
data.addAll(
|
||||||
|
floatArrayOf(
|
||||||
position.x,
|
position.x,
|
||||||
position.y,
|
position.y,
|
||||||
position.z,
|
position.z,
|
||||||
@ -46,12 +48,6 @@ class ChunkSectionArrayMesh : Mesh(SectionArrayMeshStruct::class, initialCacheSi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val MAX_LIGHT_LEVEL = 17
|
|
||||||
private const val MAX_LIGHT_LEVEL_FLOAT = MAX_LIGHT_LEVEL.toFloat() // Level 0 and 15 kind of does not exist here.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
data class SectionArrayMeshStruct(
|
data class SectionArrayMeshStruct(
|
||||||
val position: Vec3,
|
val position: Vec3,
|
||||||
val uvCoordinates: Vec2,
|
val uvCoordinates: Vec2,
|
||||||
|
@ -13,9 +13,12 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.block.mesh
|
package de.bixilon.minosoft.gui.rendering.block.mesh
|
||||||
|
|
||||||
data class ChunkSectionMeshCollection(
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
val opaqueSectionArrayMesh: ChunkSectionArrayMesh = ChunkSectionArrayMesh(),
|
|
||||||
var transparentSectionArrayMesh: ChunkSectionArrayMesh? = ChunkSectionArrayMesh(),
|
class ChunkSectionMeshCollection(
|
||||||
|
renderWindow: RenderWindow,
|
||||||
|
val opaqueSectionArrayMesh: ChunkSectionArrayMesh = ChunkSectionArrayMesh(renderWindow),
|
||||||
|
var transparentSectionArrayMesh: ChunkSectionArrayMesh? = ChunkSectionArrayMesh(renderWindow),
|
||||||
) {
|
) {
|
||||||
var lowestBlockHeight = 0
|
var lowestBlockHeight = 0
|
||||||
var highestBlockHeight = 0
|
var highestBlockHeight = 0
|
||||||
|
@ -85,7 +85,7 @@ class BlockOutlineRenderer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentMesh?.unload()
|
currentMesh?.unload()
|
||||||
currentMesh = LineMesh()
|
currentMesh = LineMesh(renderWindow)
|
||||||
|
|
||||||
val blockOffset = raycastHit.blockPosition.toVec3d + raycastHit.blockPosition.getWorldOffset(raycastHit.blockState.block)
|
val blockOffset = raycastHit.blockPosition.toVec3d + raycastHit.blockPosition.getWorldOffset(raycastHit.blockState.block)
|
||||||
|
|
||||||
|
@ -17,13 +17,15 @@ import de.bixilon.minosoft.Minosoft
|
|||||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||||
import de.bixilon.minosoft.data.registries.AABB
|
import de.bixilon.minosoft.data.registries.AABB
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.LineMesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.LineMesh
|
||||||
import glm_.vec3.Vec3
|
import glm_.vec3.Vec3
|
||||||
|
|
||||||
class EntityHitBoxMesh(
|
class EntityHitBoxMesh(
|
||||||
|
renderWindow: RenderWindow,
|
||||||
val entity: Entity,
|
val entity: Entity,
|
||||||
val aabb: AABB,
|
val aabb: AABB,
|
||||||
) : LineMesh() {
|
) : LineMesh(renderWindow) {
|
||||||
var needsUpdate = true
|
var needsUpdate = true
|
||||||
var visible = false
|
var visible = false
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class EntityHitBoxRenderer(
|
|||||||
if (entity.isInvisible && !Minosoft.config.config.game.entities.hitBox.renderInvisibleEntities) {
|
if (entity.isInvisible && !Minosoft.config.config.game.entities.hitBox.renderInvisibleEntities) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val mesh = EntityHitBoxMesh(entity, aabb)
|
val mesh = EntityHitBoxMesh(renderWindow, entity, aabb)
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
mesh.load()
|
mesh.load()
|
||||||
|
@ -13,9 +13,10 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.hud
|
package de.bixilon.minosoft.gui.rendering.hud
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.SimpleTextureMesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.SimpleTextureMesh
|
||||||
|
|
||||||
class HUDMesh : SimpleTextureMesh() {
|
class HUDMesh(renderWindow: RenderWindow) : SimpleTextureMesh(renderWindow) {
|
||||||
|
|
||||||
fun addCacheMesh(cacheMesh: HUDCacheMesh) {
|
fun addCacheMesh(cacheMesh: HUDCacheMesh) {
|
||||||
data.addAll(cacheMesh.cache)
|
data.addAll(cacheMesh.cache)
|
||||||
|
@ -44,7 +44,7 @@ class HUDRenderer(val connection: PlayConnection, val renderWindow: RenderWindow
|
|||||||
lateinit var hudAtlasElements: Map<ResourceLocation, HUDAtlasElement>
|
lateinit var hudAtlasElements: Map<ResourceLocation, HUDAtlasElement>
|
||||||
var orthographicMatrix: Mat4 = Mat4()
|
var orthographicMatrix: Mat4 = Mat4()
|
||||||
private set
|
private set
|
||||||
var currentHUDMesh: HUDMesh = HUDMesh()
|
var currentHUDMesh: HUDMesh = HUDMesh(renderWindow)
|
||||||
|
|
||||||
private var hudEnabled = true
|
private var hudEnabled = true
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ class HUDRenderer(val connection: PlayConnection, val renderWindow: RenderWindow
|
|||||||
}
|
}
|
||||||
renderWindow.renderSystem.reset()
|
renderWindow.renderSystem.reset()
|
||||||
var needsUpdate = false
|
var needsUpdate = false
|
||||||
val tempMesh = HUDMesh()
|
val tempMesh = HUDMesh(renderWindow)
|
||||||
|
|
||||||
for ((_, hudElement) in enabledHUDElement.values) {
|
for ((_, hudElement) in enabledHUDElement.values) {
|
||||||
hudElement.draw()
|
hudElement.draw()
|
||||||
|
@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.particle
|
|||||||
|
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
@ -23,7 +24,7 @@ import glm_.vec2.Vec2
|
|||||||
import glm_.vec3.Vec3
|
import glm_.vec3.Vec3
|
||||||
import glm_.vec3.Vec3d
|
import glm_.vec3.Vec3d
|
||||||
|
|
||||||
class ParticleMesh : Mesh(ParticleMeshStruct::class, PrimitiveTypes.POINT) {
|
class ParticleMesh(renderWindow: RenderWindow) : Mesh(renderWindow, ParticleMeshStruct::class, PrimitiveTypes.POINT) {
|
||||||
|
|
||||||
fun addVertex(position: Vec3d, scale: Float, texture: Texture, tintColor: RGBColor, uvMin: Vec2 = Vec2(0, 0), uvMax: Vec2 = Vec2(1, 1)) {
|
fun addVertex(position: Vec3d, scale: Float, texture: Texture, tintColor: RGBColor, uvMin: Vec2 = Vec2(0, 0), uvMax: Vec2 = Vec2(1, 1)) {
|
||||||
val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) {
|
val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) {
|
||||||
|
@ -36,8 +36,8 @@ class ParticleRenderer(
|
|||||||
val renderWindow: RenderWindow,
|
val renderWindow: RenderWindow,
|
||||||
) : Renderer {
|
) : Renderer {
|
||||||
private val particleShader: Shader = renderWindow.renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "particle"))
|
private val particleShader: Shader = renderWindow.renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "particle"))
|
||||||
private var particleMesh = ParticleMesh()
|
private var particleMesh = ParticleMesh(renderWindow)
|
||||||
private var transparentParticleMesh = ParticleMesh()
|
private var transparentParticleMesh = ParticleMesh(renderWindow)
|
||||||
|
|
||||||
private var particles: MutableSet<Particle> = synchronizedSetOf()
|
private var particles: MutableSet<Particle> = synchronizedSetOf()
|
||||||
|
|
||||||
@ -80,8 +80,8 @@ class ParticleRenderer(
|
|||||||
override fun update() {
|
override fun update() {
|
||||||
particleMesh.unload()
|
particleMesh.unload()
|
||||||
transparentParticleMesh.unload()
|
transparentParticleMesh.unload()
|
||||||
particleMesh = ParticleMesh()
|
particleMesh = ParticleMesh(renderWindow)
|
||||||
transparentParticleMesh = ParticleMesh()
|
transparentParticleMesh = ParticleMesh(renderWindow)
|
||||||
|
|
||||||
|
|
||||||
for (particle in particles.toSynchronizedSet()) {
|
for (particle in particles.toSynchronizedSet()) {
|
||||||
|
@ -42,8 +42,8 @@ class SkyRenderer(
|
|||||||
) : Renderer {
|
) : Renderer {
|
||||||
private val skyboxShader = renderWindow.renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "sky/skybox"))
|
private val skyboxShader = renderWindow.renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "sky/skybox"))
|
||||||
private val skySunShader = renderWindow.renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "sky/sun"))
|
private val skySunShader = renderWindow.renderSystem.createShader(ResourceLocation(ProtocolDefinition.MINOSOFT_NAMESPACE, "sky/sun"))
|
||||||
private val skyboxMesh = SkyboxMesh()
|
private val skyboxMesh = SkyboxMesh(renderWindow)
|
||||||
private var skySunMesh = SimpleTextureMesh()
|
private var skySunMesh = SimpleTextureMesh(renderWindow)
|
||||||
private lateinit var sunTexture: Texture
|
private lateinit var sunTexture: Texture
|
||||||
private var recalculateSunNextFrame: Boolean = true
|
private var recalculateSunNextFrame: Boolean = true
|
||||||
var baseColor = RenderConstants.DEFAULT_SKY_COLOR
|
var baseColor = RenderConstants.DEFAULT_SKY_COLOR
|
||||||
@ -91,7 +91,7 @@ class SkyRenderer(
|
|||||||
setSunMatrix(renderWindow.inputHandler.camera.projectionMatrix * renderWindow.inputHandler.camera.viewMatrix.toMat3().toMat4())
|
setSunMatrix(renderWindow.inputHandler.camera.projectionMatrix * renderWindow.inputHandler.camera.viewMatrix.toMat3().toMat4())
|
||||||
skySunMesh.unload()
|
skySunMesh.unload()
|
||||||
|
|
||||||
skySunMesh = SimpleTextureMesh()
|
skySunMesh = SimpleTextureMesh(renderWindow)
|
||||||
|
|
||||||
|
|
||||||
skySunMesh.addQuad(
|
skySunMesh.addQuad(
|
||||||
|
@ -13,19 +13,21 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.sky
|
package de.bixilon.minosoft.gui.rendering.sky
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.PositionOnlyMeshStruct
|
import de.bixilon.minosoft.gui.rendering.util.mesh.PositionOnlyMeshStruct
|
||||||
|
|
||||||
class SkyboxMesh : Mesh(PositionOnlyMeshStruct::class, initialCacheSize = 6 * 2 * 3 * PositionOnlyMeshStruct.FLOATS_PER_VERTEX) {
|
class SkyboxMesh(renderWindow: RenderWindow) : Mesh(renderWindow, PositionOnlyMeshStruct::class, initialCacheSize = 6 * 2 * 3 * PositionOnlyMeshStruct.FLOATS_PER_VERTEX) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
data.addAll(floatArrayOf(
|
data.addAll(
|
||||||
-1.0f, +1.0f, -1.0f,
|
floatArrayOf(
|
||||||
-1.0f, -1.0f, -1.0f,
|
-1.0f, +1.0f, -1.0f,
|
||||||
+1.0f, -1.0f, -1.0f,
|
-1.0f, -1.0f, -1.0f,
|
||||||
+1.0f, -1.0f, -1.0f,
|
+1.0f, -1.0f, -1.0f,
|
||||||
+1.0f, +1.0f, -1.0f,
|
+1.0f, -1.0f, -1.0f,
|
||||||
-1.0f, +1.0f, -1.0f,
|
+1.0f, +1.0f, -1.0f,
|
||||||
|
-1.0f, +1.0f, -1.0f,
|
||||||
|
|
||||||
-1.0f, -1.0f, +1.0f,
|
-1.0f, -1.0f, +1.0f,
|
||||||
-1.0f, -1.0f, -1.0f,
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
@ -14,9 +14,14 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.system.base
|
package de.bixilon.minosoft.gui.rendering.system.base
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.FloatUniformBuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.IntUniformBuffer
|
||||||
|
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.system.base.shader.Shader
|
import de.bixilon.minosoft.gui.rendering.system.base.shader.Shader
|
||||||
import glm_.vec2.Vec2i
|
import glm_.vec2.Vec2i
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
interface RenderSystem {
|
interface RenderSystem {
|
||||||
val shaders: MutableSet<Shader>
|
val shaders: MutableSet<Shader>
|
||||||
@ -65,4 +70,8 @@ interface RenderSystem {
|
|||||||
|
|
||||||
|
|
||||||
fun createShader(resourceLocation: ResourceLocation): Shader
|
fun createShader(resourceLocation: ResourceLocation): Shader
|
||||||
|
|
||||||
|
fun createVertexBuffer(structure: KClass<*>, data: FloatArray, primitiveType: PrimitiveTypes = PrimitiveTypes.TRIANGLE): FloatVertexBuffer
|
||||||
|
fun createIntUniformBuffer(bindingIndex: Int = 0, data: IntArray = IntArray(0)): IntUniformBuffer
|
||||||
|
fun createFloatUniformBuffer(bindingIndex: Int = 0, data: FloatArray = FloatArray(0)): FloatUniformBuffer
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.system.base.buffer
|
package de.bixilon.minosoft.gui.rendering.system.base.buffer
|
||||||
|
|
||||||
interface FloatBuffer {
|
interface FloatBuffer {
|
||||||
val data: FloatArray
|
var data: FloatArray
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.system.base.buffer
|
package de.bixilon.minosoft.gui.rendering.system.base.buffer
|
||||||
|
|
||||||
interface IntBuffer {
|
interface IntBuffer {
|
||||||
val data: IntArray
|
var data: IntArray
|
||||||
}
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.FloatBuffer
|
||||||
|
|
||||||
|
interface FloatUniformBuffer : UniformBuffer, FloatBuffer
|
@ -0,0 +1,5 @@
|
|||||||
|
package de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.IntBuffer
|
||||||
|
|
||||||
|
interface IntUniformBuffer : UniformBuffer, IntBuffer
|
@ -0,0 +1,6 @@
|
|||||||
|
package de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.FloatBuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.RenderBuffer
|
||||||
|
|
||||||
|
interface FloatVertexBuffer : FloatBuffer, RenderBuffer, VertexBuffer
|
@ -3,6 +3,7 @@ package de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
interface VertexBuffer {
|
interface VertexBuffer {
|
||||||
|
val vertices: Int
|
||||||
val primitiveType: PrimitiveTypes
|
val primitiveType: PrimitiveTypes
|
||||||
val structure: KClass<*>
|
val structure: KClass<*>
|
||||||
|
|
||||||
|
@ -17,7 +17,14 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
|
|||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
|
import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.*
|
import de.bixilon.minosoft.gui.rendering.system.base.*
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.FloatUniformBuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.IntUniformBuffer
|
||||||
|
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.system.base.shader.Shader
|
import de.bixilon.minosoft.gui.rendering.system.base.shader.Shader
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform.FloatOpenGLUniformBuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform.IntOpenGLUniformBuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.vertex.FloatOpenGLVertexBuffer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.vendor.*
|
import de.bixilon.minosoft.gui.rendering.system.opengl.vendor.*
|
||||||
import de.bixilon.minosoft.modding.event.CallbackEventInvoker
|
import de.bixilon.minosoft.modding.event.CallbackEventInvoker
|
||||||
import de.bixilon.minosoft.util.KUtil.synchronizedSetOf
|
import de.bixilon.minosoft.util.KUtil.synchronizedSetOf
|
||||||
@ -26,6 +33,7 @@ import org.lwjgl.BufferUtils
|
|||||||
import org.lwjgl.opengl.GL
|
import org.lwjgl.opengl.GL
|
||||||
import org.lwjgl.opengl.GL20.*
|
import org.lwjgl.opengl.GL20.*
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
class OpenGLRenderSystem(
|
class OpenGLRenderSystem(
|
||||||
private val renderWindow: RenderWindow,
|
private val renderWindow: RenderWindow,
|
||||||
@ -165,6 +173,18 @@ class OpenGLRenderSystem(
|
|||||||
return OpenGLShader(renderWindow, resourceLocation)
|
return OpenGLShader(renderWindow, resourceLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun createVertexBuffer(structure: KClass<*>, data: FloatArray, primitiveType: PrimitiveTypes): FloatVertexBuffer {
|
||||||
|
return FloatOpenGLVertexBuffer(structure, data, primitiveType)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createFloatUniformBuffer(bindingIndex: Int, data: FloatArray): FloatUniformBuffer {
|
||||||
|
return FloatOpenGLUniformBuffer(bindingIndex, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createIntUniformBuffer(bindingIndex: Int, data: IntArray): IntUniformBuffer {
|
||||||
|
return IntOpenGLUniformBuffer(bindingIndex, data)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val RenderingCapabilities.gl: Int
|
private val RenderingCapabilities.gl: Int
|
||||||
get() {
|
get() {
|
||||||
|
@ -7,8 +7,11 @@ import org.lwjgl.opengl.GL15.glBufferData
|
|||||||
import org.lwjgl.opengl.GL15.glBufferSubData
|
import org.lwjgl.opengl.GL15.glBufferSubData
|
||||||
|
|
||||||
open class FloatOpenGLBuffer(protected var _data: FloatArray?) : OpenGLRenderBuffer(RenderBufferTypes.ARRAY_BUFFER), FloatBuffer {
|
open class FloatOpenGLBuffer(protected var _data: FloatArray?) : OpenGLRenderBuffer(RenderBufferTypes.ARRAY_BUFFER), FloatBuffer {
|
||||||
override val data: FloatArray
|
override var data: FloatArray
|
||||||
get() = _data!!
|
get() = _data!!
|
||||||
|
set(value) {
|
||||||
|
_data = value
|
||||||
|
}
|
||||||
override val drawTypes: RenderBufferDrawTypes = RenderBufferDrawTypes.STATIC
|
override val drawTypes: RenderBufferDrawTypes = RenderBufferDrawTypes.STATIC
|
||||||
|
|
||||||
override fun initialUpload() {
|
override fun initialUpload() {
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform
|
package de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform
|
||||||
|
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.FloatBuffer
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.FloatUniformBuffer
|
||||||
import org.lwjgl.opengl.GL15.glBufferData
|
import org.lwjgl.opengl.GL15.glBufferData
|
||||||
import org.lwjgl.opengl.GL15.glBufferSubData
|
import org.lwjgl.opengl.GL15.glBufferSubData
|
||||||
|
|
||||||
class FloatOpenGLUniformBuffer(bindingIndex: Int = 0, override var data: FloatArray = FloatArray(0)) : OpenGLUniformBuffer(bindingIndex), FloatBuffer {
|
class FloatOpenGLUniformBuffer(bindingIndex: Int = 0, override var data: FloatArray = FloatArray(0)) : OpenGLUniformBuffer(bindingIndex), FloatUniformBuffer {
|
||||||
override val size: Int
|
override val size: Int
|
||||||
get() = data.size
|
get() = data.size
|
||||||
|
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform
|
package de.bixilon.minosoft.gui.rendering.system.opengl.buffer.uniform
|
||||||
|
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.IntBuffer
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.IntUniformBuffer
|
||||||
import org.lwjgl.opengl.GL15.glBufferData
|
import org.lwjgl.opengl.GL15.glBufferData
|
||||||
import org.lwjgl.opengl.GL15.glBufferSubData
|
import org.lwjgl.opengl.GL15.glBufferSubData
|
||||||
|
|
||||||
class IntOpenGLUniformBuffer(bindingIndex: Int = 0, override var data: IntArray = IntArray(0)) : OpenGLUniformBuffer(bindingIndex), IntBuffer {
|
class IntOpenGLUniformBuffer(bindingIndex: Int = 0, override var data: IntArray = IntArray(0)) : OpenGLUniformBuffer(bindingIndex), IntUniformBuffer {
|
||||||
override val size: Int
|
override val size: Int
|
||||||
get() = data.size
|
get() = data.size
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.system.opengl.buffer.vertex
|
package de.bixilon.minosoft.gui.rendering.system.opengl.buffer.vertex
|
||||||
|
|
||||||
|
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.system.base.buffer.vertex.PrimitiveTypes
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.VertexBuffer
|
|
||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.FloatOpenGLBuffer
|
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.FloatOpenGLBuffer
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct.Companion.BYTES
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct.Companion.BYTES
|
||||||
@ -16,8 +16,8 @@ import kotlin.reflect.KClass
|
|||||||
import kotlin.reflect.full.companionObjectInstance
|
import kotlin.reflect.full.companionObjectInstance
|
||||||
import kotlin.reflect.full.primaryConstructor
|
import kotlin.reflect.full.primaryConstructor
|
||||||
|
|
||||||
class FloatOpenGLVertexBuffer(override val structure: KClass<*>, data: FloatArray, override val primitiveType: PrimitiveTypes = PrimitiveTypes.TRIANGLE) : FloatOpenGLBuffer(data), VertexBuffer {
|
class FloatOpenGLVertexBuffer(override val structure: KClass<*>, data: FloatArray, override val primitiveType: PrimitiveTypes = PrimitiveTypes.TRIANGLE) : FloatOpenGLBuffer(data), FloatVertexBuffer {
|
||||||
var vertices = -1
|
override var vertices = -1
|
||||||
private set
|
private set
|
||||||
private var vao = -1
|
private var vao = -1
|
||||||
|
|
||||||
|
@ -15,17 +15,20 @@ package de.bixilon.minosoft.gui.rendering.util.mesh
|
|||||||
|
|
||||||
import de.bixilon.minosoft.data.text.ChatColors
|
import de.bixilon.minosoft.data.text.ChatColors
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import glm_.vec3.Vec3
|
import glm_.vec3.Vec3
|
||||||
|
|
||||||
open class GenericColorMesh : Mesh(GenericColorMeshStruct::class) {
|
open class GenericColorMesh(renderWindow: RenderWindow) : Mesh(renderWindow, GenericColorMeshStruct::class) {
|
||||||
|
|
||||||
fun addVertex(position: Vec3, color: RGBColor?) {
|
fun addVertex(position: Vec3, color: RGBColor?) {
|
||||||
data.addAll(floatArrayOf(
|
data.addAll(
|
||||||
position.x,
|
floatArrayOf(
|
||||||
position.y,
|
position.x,
|
||||||
position.z,
|
position.y,
|
||||||
Float.fromBits((color ?: ChatColors.WHITE).rgba)
|
position.z,
|
||||||
))
|
Float.fromBits((color ?: ChatColors.WHITE).rgba)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
data class GenericColorMeshStruct(
|
data class GenericColorMeshStruct(
|
||||||
|
@ -16,13 +16,14 @@ package de.bixilon.minosoft.gui.rendering.util.mesh
|
|||||||
import de.bixilon.minosoft.data.registries.AABB
|
import de.bixilon.minosoft.data.registries.AABB
|
||||||
import de.bixilon.minosoft.data.registries.VoxelShape
|
import de.bixilon.minosoft.data.registries.VoxelShape
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
import de.bixilon.minosoft.gui.rendering.util.VecUtil.EMPTY
|
||||||
import de.bixilon.minosoft.util.BitByte.isBit
|
import de.bixilon.minosoft.util.BitByte.isBit
|
||||||
import de.bixilon.minosoft.util.MMath.positiveNegative
|
import de.bixilon.minosoft.util.MMath.positiveNegative
|
||||||
import glm_.vec3.Vec3
|
import glm_.vec3.Vec3
|
||||||
import glm_.vec3.Vec3d
|
import glm_.vec3.Vec3d
|
||||||
|
|
||||||
open class LineMesh : GenericColorMesh() {
|
open class LineMesh(renderWindow: RenderWindow) : GenericColorMesh(renderWindow) {
|
||||||
|
|
||||||
fun drawLine(start: Vec3, end: Vec3, lineWidth: Float, color: RGBColor) {
|
fun drawLine(start: Vec3, end: Vec3, lineWidth: Float, color: RGBColor) {
|
||||||
val direction = (end - start).normalize()
|
val direction = (end - start).normalize()
|
||||||
|
@ -13,14 +13,16 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.util.mesh
|
package de.bixilon.minosoft.gui.rendering.util.mesh
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
|
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.system.base.buffer.vertex.PrimitiveTypes
|
||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.vertex.FloatOpenGLVertexBuffer
|
|
||||||
import de.bixilon.minosoft.util.collections.ArrayFloatList
|
import de.bixilon.minosoft.util.collections.ArrayFloatList
|
||||||
import glm_.vec2.Vec2
|
import glm_.vec2.Vec2
|
||||||
import glm_.vec3.Vec3
|
import glm_.vec3.Vec3
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
abstract class Mesh(
|
abstract class Mesh(
|
||||||
|
val renderWindow: RenderWindow,
|
||||||
private val struct: KClass<*>,
|
private val struct: KClass<*>,
|
||||||
private val primitiveType: PrimitiveTypes = PrimitiveTypes.TRIANGLE,
|
private val primitiveType: PrimitiveTypes = PrimitiveTypes.TRIANGLE,
|
||||||
initialCacheSize: Int = 10000,
|
initialCacheSize: Int = 10000,
|
||||||
@ -32,7 +34,7 @@ abstract class Mesh(
|
|||||||
_data = value
|
_data = value
|
||||||
}
|
}
|
||||||
|
|
||||||
protected lateinit var buffer: FloatOpenGLVertexBuffer
|
protected lateinit var buffer: FloatVertexBuffer
|
||||||
|
|
||||||
var vertices: Int = -1
|
var vertices: Int = -1
|
||||||
protected set
|
protected set
|
||||||
@ -42,7 +44,7 @@ abstract class Mesh(
|
|||||||
|
|
||||||
|
|
||||||
fun load() {
|
fun load() {
|
||||||
buffer = FloatOpenGLVertexBuffer(struct, data.toArray(), primitiveType)
|
buffer = renderWindow.renderSystem.createVertexBuffer(struct, data.toArray(), primitiveType)
|
||||||
buffer.init()
|
buffer.init()
|
||||||
vertices = buffer.vertices
|
vertices = buffer.vertices
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,12 @@ package de.bixilon.minosoft.gui.rendering.util.mesh
|
|||||||
|
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||||
import glm_.vec2.Vec2
|
import glm_.vec2.Vec2
|
||||||
import glm_.vec3.Vec3
|
import glm_.vec3.Vec3
|
||||||
|
|
||||||
open class SimpleTextureMesh : Mesh(SimpleTextureMeshStruct::class, initialCacheSize = 2 * 3 * SimpleTextureMeshStruct.FLOATS_PER_VERTEX) {
|
open class SimpleTextureMesh(renderWindow: RenderWindow) : Mesh(renderWindow, SimpleTextureMeshStruct::class, initialCacheSize = 2 * 3 * SimpleTextureMeshStruct.FLOATS_PER_VERTEX) {
|
||||||
|
|
||||||
fun addVertex(position: Vec3, texture: Texture, textureCoordinates: Vec2, tintColor: RGBColor) {
|
fun addVertex(position: Vec3, texture: Texture, textureCoordinates: Vec2, tintColor: RGBColor) {
|
||||||
val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) {
|
val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) {
|
||||||
@ -28,8 +29,9 @@ open class SimpleTextureMesh : Mesh(SimpleTextureMeshStruct::class, initialCache
|
|||||||
(texture.arrayId shl 24) or texture.arrayLayer
|
(texture.arrayId shl 24) or texture.arrayLayer
|
||||||
}
|
}
|
||||||
|
|
||||||
data.addAll(floatArrayOf(
|
data.addAll(
|
||||||
position.x,
|
floatArrayOf(
|
||||||
|
position.x,
|
||||||
position.y,
|
position.y,
|
||||||
position.z,
|
position.z,
|
||||||
textureCoordinates.x,
|
textureCoordinates.x,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user