mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
wip HUDRenderer
This commit is contained in:
parent
b7c928f02b
commit
620a49d348
@ -13,21 +13,15 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering
|
package de.bixilon.minosoft.gui.rendering
|
||||||
|
|
||||||
import de.bixilon.minosoft.Minosoft
|
|
||||||
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
|
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
|
||||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
import de.bixilon.minosoft.gui.rendering.block.WorldRenderer
|
|
||||||
import de.bixilon.minosoft.gui.rendering.block.chunk.ChunkBorderRenderer
|
|
||||||
import de.bixilon.minosoft.gui.rendering.block.outline.BlockOutlineRenderer
|
|
||||||
import de.bixilon.minosoft.gui.rendering.entity.EntityHitBoxRenderer
|
|
||||||
import de.bixilon.minosoft.gui.rendering.font.Font
|
import de.bixilon.minosoft.gui.rendering.font.Font
|
||||||
import de.bixilon.minosoft.gui.rendering.font.FontLoader
|
import de.bixilon.minosoft.gui.rendering.font.FontLoader
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.atlas.TextureLike
|
import de.bixilon.minosoft.gui.rendering.gui.hud.HUDRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.atlas.TextureLikeTexture
|
import de.bixilon.minosoft.gui.rendering.gui.hud.atlas.TextureLike
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.hud.atlas.TextureLikeTexture
|
||||||
import de.bixilon.minosoft.gui.rendering.input.key.RenderWindowInputHandler
|
import de.bixilon.minosoft.gui.rendering.input.key.RenderWindowInputHandler
|
||||||
import de.bixilon.minosoft.gui.rendering.modding.events.*
|
import de.bixilon.minosoft.gui.rendering.modding.events.*
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
|
||||||
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.IntegratedBufferTypes
|
import de.bixilon.minosoft.gui.rendering.system.base.IntegratedBufferTypes
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.PolygonModes
|
import de.bixilon.minosoft.gui.rendering.system.base.PolygonModes
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
|
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
|
||||||
@ -104,7 +98,7 @@ class RenderWindow(
|
|||||||
})
|
})
|
||||||
|
|
||||||
// order dependent (from back to front)
|
// order dependent (from back to front)
|
||||||
registerRenderer(SkyRenderer)
|
/* registerRenderer(SkyRenderer)
|
||||||
registerRenderer(WorldRenderer)
|
registerRenderer(WorldRenderer)
|
||||||
registerRenderer(BlockOutlineRenderer)
|
registerRenderer(BlockOutlineRenderer)
|
||||||
if (Minosoft.config.config.game.graphics.particles.enabled) {
|
if (Minosoft.config.config.game.graphics.particles.enabled) {
|
||||||
@ -115,7 +109,8 @@ class RenderWindow(
|
|||||||
}
|
}
|
||||||
if (Minosoft.config.config.game.world.chunkBorders.enabled) {
|
if (Minosoft.config.config.game.world.chunkBorders.enabled) {
|
||||||
registerRenderer(ChunkBorderRenderer)
|
registerRenderer(ChunkBorderRenderer)
|
||||||
}
|
}*/
|
||||||
|
registerRenderer(HUDRenderer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun init(latch: CountUpAndDownLatch) {
|
fun init(latch: CountUpAndDownLatch) {
|
||||||
|
@ -51,7 +51,7 @@ class ChunkSectionArrayMesh(renderWindow: RenderWindow) : Mesh(renderWindow, Sec
|
|||||||
|
|
||||||
data class SectionArrayMeshStruct(
|
data class SectionArrayMeshStruct(
|
||||||
val position: Vec3,
|
val position: Vec3,
|
||||||
val uvCoordinates: Vec2,
|
val uv: Vec2,
|
||||||
val textureLayer: Int,
|
val textureLayer: Int,
|
||||||
val animationId: Int,
|
val animationId: Int,
|
||||||
val tintColor: RGBColor,
|
val tintColor: RGBColor,
|
||||||
|
@ -13,8 +13,12 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.font
|
package de.bixilon.minosoft.gui.rendering.font
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.text.ChatColors
|
||||||
|
import de.bixilon.minosoft.data.text.TextStyle
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.mesh.FontVertexConsumer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
||||||
import glm_.vec2.Vec2
|
import glm_.vec2.Vec2
|
||||||
|
import glm_.vec2.Vec2i
|
||||||
|
|
||||||
class CharData(
|
class CharData(
|
||||||
val char: Char,
|
val char: Char,
|
||||||
@ -23,8 +27,13 @@ class CharData(
|
|||||||
var uvStart: Vec2,
|
var uvStart: Vec2,
|
||||||
var uvEnd: Vec2,
|
var uvEnd: Vec2,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun postInit() {
|
fun postInit() {
|
||||||
uvStart = uvStart * texture.textureArrayUV
|
uvStart = uvStart * texture.textureArrayUV
|
||||||
uvEnd = uvEnd * texture.textureArrayUV
|
uvEnd = uvEnd * texture.textureArrayUV
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun render(position: Vec2i, style: TextStyle, vertexConsumer: FontVertexConsumer) {
|
||||||
|
vertexConsumer.addQuad(position, position + Vec2i(width, Font.CHAR_HEIGHT), texture, uvStart, uvEnd, style.color ?: ChatColors.WHITE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.gui.rendering.gui.hud
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.Minosoft
|
||||||
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
|
import de.bixilon.minosoft.data.text.ChatColors
|
||||||
|
import de.bixilon.minosoft.data.text.PreChatFormattingCodes
|
||||||
|
import de.bixilon.minosoft.data.text.TextComponent
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
|
import de.bixilon.minosoft.gui.rendering.Renderer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RendererBuilder
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIMesh
|
||||||
|
import de.bixilon.minosoft.gui.rendering.modding.events.ResizeWindowEvent
|
||||||
|
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
||||||
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
|
import glm_.glm
|
||||||
|
import glm_.mat4x4.Mat4
|
||||||
|
import glm_.vec2.Vec2i
|
||||||
|
|
||||||
|
class HUDRenderer(
|
||||||
|
val connection: PlayConnection,
|
||||||
|
val renderWindow: RenderWindow,
|
||||||
|
) : Renderer {
|
||||||
|
private val shader = renderWindow.renderSystem.createShader("minosoft:hud".toResourceLocation())
|
||||||
|
private lateinit var mesh: GUIMesh
|
||||||
|
var scaledSize: Vec2i = renderWindow.window.size
|
||||||
|
private var matrix: Mat4 = Mat4()
|
||||||
|
|
||||||
|
override fun init() {
|
||||||
|
connection.registerEvent(CallbackEventInvoker.of<ResizeWindowEvent> {
|
||||||
|
scaledSize = it.size / Minosoft.config.config.game.hud.scale
|
||||||
|
matrix = glm.ortho(0.0f, scaledSize.x.toFloat(), scaledSize.y.toFloat(), 0.0f)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun postInit() {
|
||||||
|
shader.load()
|
||||||
|
renderWindow.textureManager.staticTextures.use(shader)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun draw() {
|
||||||
|
renderWindow.renderSystem.reset()
|
||||||
|
if (this::mesh.isInitialized) {
|
||||||
|
mesh.unload()
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh = GUIMesh(renderWindow, matrix)
|
||||||
|
val style = TextComponent("", ChatColors.BLUE, ChatColors.RED, formatting = mutableSetOf(PreChatFormattingCodes.BOLD, PreChatFormattingCodes.SHADOWED, PreChatFormattingCodes.UNDERLINED))
|
||||||
|
renderWindow.font['M']?.render(Vec2i(100, 100), style, mesh)
|
||||||
|
renderWindow.font['o']?.render(Vec2i(108, 100), style, mesh)
|
||||||
|
renderWindow.font['r']?.render(Vec2i(116, 100), style, mesh)
|
||||||
|
|
||||||
|
mesh.load()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
shader.use()
|
||||||
|
mesh.draw()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : RendererBuilder<HUDRenderer> {
|
||||||
|
override val RESOURCE_LOCATION = ResourceLocation("minosoft:hud_renderer")
|
||||||
|
|
||||||
|
override fun build(connection: PlayConnection, renderWindow: RenderWindow): HUDRenderer {
|
||||||
|
return HUDRenderer(connection, renderWindow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@
|
|||||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.hud.atlas
|
package de.bixilon.minosoft.gui.rendering.gui.hud.atlas
|
||||||
|
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
||||||
import glm_.vec2.Vec2
|
import glm_.vec2.Vec2
|
@ -24,7 +24,7 @@
|
|||||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.hud.atlas
|
package de.bixilon.minosoft.gui.rendering.gui.hud.atlas
|
||||||
|
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
||||||
import glm_.vec2.Vec2
|
import glm_.vec2.Vec2
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.gui.rendering.gui.mesh
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
||||||
|
import glm_.vec2.Vec2
|
||||||
|
import glm_.vec2.Vec2i
|
||||||
|
|
||||||
|
interface FontVertexConsumer {
|
||||||
|
|
||||||
|
fun addVertex(position: Vec2i, texture: AbstractTexture, uv: Vec2, tint: RGBColor)
|
||||||
|
|
||||||
|
fun addQuad(start: Vec2i, end: Vec2i, texture: AbstractTexture, uvStart: Vec2, uvEnd: Vec2, tint: RGBColor)
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2021 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.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.gui.rendering.gui.mesh
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||||
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct
|
||||||
|
import glm_.mat4x4.Mat4
|
||||||
|
import glm_.vec2.Vec2
|
||||||
|
import glm_.vec2.Vec2i
|
||||||
|
import glm_.vec3.Vec3
|
||||||
|
import glm_.vec4.Vec4
|
||||||
|
|
||||||
|
class GUIMesh(
|
||||||
|
renderWindow: RenderWindow,
|
||||||
|
val matrix: Mat4,
|
||||||
|
) : Mesh(renderWindow, HUDMeshStruct), FontVertexConsumer {
|
||||||
|
|
||||||
|
override fun addVertex(position: Vec2i, texture: AbstractTexture, uv: Vec2, tint: RGBColor) {
|
||||||
|
val outPosition = matrix * Vec4(position, 1.0f, 1.0f)
|
||||||
|
data.addAll(floatArrayOf(
|
||||||
|
outPosition.x,
|
||||||
|
outPosition.y,
|
||||||
|
0.95f,
|
||||||
|
uv.x,
|
||||||
|
uv.y,
|
||||||
|
Float.fromBits(texture.renderData?.layer ?: RenderConstants.DEBUG_TEXTURE_ID),
|
||||||
|
Float.fromBits(tint.rgba),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addQuad(start: Vec2i, end: Vec2i, texture: AbstractTexture, uvStart: Vec2, uvEnd: Vec2, tint: RGBColor) {
|
||||||
|
val positions = arrayOf(
|
||||||
|
start,
|
||||||
|
Vec2i(end.x, start.y),
|
||||||
|
end,
|
||||||
|
Vec2i(start.x, end.y),
|
||||||
|
)
|
||||||
|
val texturePositions = arrayOf(
|
||||||
|
Vec2(uvEnd.x, uvStart.y),
|
||||||
|
uvStart,
|
||||||
|
Vec2(uvStart.x, uvEnd.y),
|
||||||
|
uvEnd,
|
||||||
|
)
|
||||||
|
|
||||||
|
for ((vertexIndex, textureIndex) in QUAD_DRAW_ODER) {
|
||||||
|
addVertex(positions[vertexIndex], texture, texturePositions[textureIndex], tint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class HUDMeshStruct(
|
||||||
|
val position: Vec3,
|
||||||
|
val uv: Vec2,
|
||||||
|
val textureLayer: Int,
|
||||||
|
val tintColor: RGBColor,
|
||||||
|
) {
|
||||||
|
companion object : MeshStruct(HUDMeshStruct::class)
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ import de.bixilon.minosoft.gui.rendering.modding.events.CameraMatrixChangeEvent
|
|||||||
import de.bixilon.minosoft.gui.rendering.system.base.BlendingFunctions
|
import de.bixilon.minosoft.gui.rendering.system.base.BlendingFunctions
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.DepthFunctions
|
import de.bixilon.minosoft.gui.rendering.system.base.DepthFunctions
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh
|
||||||
import de.bixilon.minosoft.gui.rendering.util.mesh.SimpleTextureMesh
|
import de.bixilon.minosoft.gui.rendering.util.mesh.SimpleTextureMesh
|
||||||
import de.bixilon.minosoft.modding.event.events.TimeChangeEvent
|
import de.bixilon.minosoft.modding.event.events.TimeChangeEvent
|
||||||
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
||||||
@ -94,14 +95,14 @@ class SkyRenderer(
|
|||||||
skySunMesh = SimpleTextureMesh(renderWindow)
|
skySunMesh = SimpleTextureMesh(renderWindow)
|
||||||
|
|
||||||
|
|
||||||
skySunMesh.addQuad(
|
Mesh.addQuad(
|
||||||
start = Vec3(-0.15f, 1.0f, -0.15f),
|
start = Vec3(-0.15f, 1.0f, -0.15f),
|
||||||
end = Vec3(+0.15f, 1.0f, +0.15f),
|
end = Vec3(+0.15f, 1.0f, +0.15f),
|
||||||
vertexConsumer = { position, textureCoordinate ->
|
vertexConsumer = { position, uv ->
|
||||||
skySunMesh.addVertex(
|
skySunMesh.addVertex(
|
||||||
position = position,
|
position = position,
|
||||||
texture = sunTexture,
|
texture = sunTexture,
|
||||||
textureCoordinates = textureCoordinate,
|
uv = uv,
|
||||||
tintColor = ChatColors.WHITE.with(alpha = 1.0f - connection.world.rainGradient), // ToDo: Depends on time
|
tintColor = ChatColors.WHITE.with(alpha = 1.0f - connection.world.rainGradient), // ToDo: Depends on time
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -61,25 +61,6 @@ abstract class Mesh(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addQuad(start: Vec3, end: Vec3, textureStart: Vec2 = Vec2(0.0f, 0.0f), textureEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, textureCoordinate: Vec2) -> Unit) {
|
|
||||||
val positions = arrayOf(
|
|
||||||
start,
|
|
||||||
Vec3(start.x, start.y, end.z),
|
|
||||||
end,
|
|
||||||
Vec3(end.x, end.y, start.z),
|
|
||||||
)
|
|
||||||
val texturePositions = arrayOf(
|
|
||||||
Vec2(textureEnd.x, textureStart.y),
|
|
||||||
textureStart,
|
|
||||||
Vec2(textureStart.x, textureEnd.y),
|
|
||||||
textureEnd,
|
|
||||||
)
|
|
||||||
|
|
||||||
for ((vertexIndex, textureIndex) in QUAD_DRAW_ODER) {
|
|
||||||
vertexConsumer.invoke(positions[vertexIndex], texturePositions[textureIndex])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class MeshStates {
|
enum class MeshStates {
|
||||||
PREPARING,
|
PREPARING,
|
||||||
LOADED,
|
LOADED,
|
||||||
@ -95,5 +76,25 @@ abstract class Mesh(
|
|||||||
1 to 0,
|
1 to 0,
|
||||||
0 to 1,
|
0 to 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
fun addQuad(start: Vec3, end: Vec3, uvStart: Vec2 = Vec2(0.0f, 0.0f), uvEnd: Vec2 = Vec2(1.0f, 1.0f), vertexConsumer: (position: Vec3, uv: Vec2) -> Unit) {
|
||||||
|
val positions = arrayOf(
|
||||||
|
start,
|
||||||
|
Vec3(start.x, start.y, end.z),
|
||||||
|
end,
|
||||||
|
Vec3(end.x, end.y, start.z),
|
||||||
|
)
|
||||||
|
val texturePositions = arrayOf(
|
||||||
|
Vec2(uvEnd.x, uvStart.y),
|
||||||
|
uvStart,
|
||||||
|
Vec2(uvStart.x, uvEnd.y),
|
||||||
|
uvEnd,
|
||||||
|
)
|
||||||
|
|
||||||
|
for ((vertexIndex, textureIndex) in QUAD_DRAW_ODER) {
|
||||||
|
vertexConsumer.invoke(positions[vertexIndex], texturePositions[textureIndex])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import glm_.vec3.Vec3
|
|||||||
|
|
||||||
open class SimpleTextureMesh(renderWindow: RenderWindow) : Mesh(renderWindow, SimpleTextureMeshStruct, initialCacheSize = 2 * 3 * SimpleTextureMeshStruct.FLOATS_PER_VERTEX) {
|
open class SimpleTextureMesh(renderWindow: RenderWindow) : Mesh(renderWindow, SimpleTextureMeshStruct, initialCacheSize = 2 * 3 * SimpleTextureMeshStruct.FLOATS_PER_VERTEX) {
|
||||||
|
|
||||||
fun addVertex(position: Vec3, texture: AbstractTexture, textureCoordinates: Vec2, tintColor: RGBColor) {
|
fun addVertex(position: Vec3, texture: AbstractTexture, uv: Vec2, tintColor: RGBColor) {
|
||||||
val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) {
|
val textureLayer = if (RenderConstants.FORCE_DEBUG_TEXTURE) {
|
||||||
RenderConstants.DEBUG_TEXTURE_ID
|
RenderConstants.DEBUG_TEXTURE_ID
|
||||||
} else {
|
} else {
|
||||||
@ -34,8 +34,8 @@ open class SimpleTextureMesh(renderWindow: RenderWindow) : Mesh(renderWindow, Si
|
|||||||
position.x,
|
position.x,
|
||||||
position.y,
|
position.y,
|
||||||
position.z,
|
position.z,
|
||||||
textureCoordinates.x,
|
uv.x,
|
||||||
textureCoordinates.y,
|
uv.y,
|
||||||
Float.fromBits(textureLayer),
|
Float.fromBits(textureLayer),
|
||||||
Float.fromBits(tintColor.rgba),
|
Float.fromBits(tintColor.rgba),
|
||||||
))
|
))
|
||||||
@ -44,7 +44,7 @@ open class SimpleTextureMesh(renderWindow: RenderWindow) : Mesh(renderWindow, Si
|
|||||||
|
|
||||||
data class SimpleTextureMeshStruct(
|
data class SimpleTextureMeshStruct(
|
||||||
val position: Vec3,
|
val position: Vec3,
|
||||||
val uvCoordinates: Vec2,
|
val uv: Vec2,
|
||||||
val textureLayer: Int,
|
val textureLayer: Int,
|
||||||
val animationId: Int,
|
val animationId: Int,
|
||||||
) {
|
) {
|
||||||
|
@ -24,6 +24,8 @@ in vec4 finTintColor;
|
|||||||
void main() {
|
void main() {
|
||||||
vec4 texelColor = getTexture(finTextureIndex, finTextureCoordinates);
|
vec4 texelColor = getTexture(finTextureIndex, finTextureCoordinates);
|
||||||
|
|
||||||
|
//texelColor = vec4(1.0f, 0.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
if (finTintColor.a == 1.0f && texelColor.a == 0) {
|
if (finTintColor.a == 1.0f && texelColor.a == 0) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout (location = 0) in vec3 vinPosition;
|
layout (location = 0) in vec3 vinPosition;
|
||||||
layout (location = 1) in vec2 vinUVCoordinates;
|
layout (location = 1) in vec2 vinUV;
|
||||||
layout (location = 2) in uint vinRextureLayer;
|
layout (location = 2) in uint vinTextureLayer;
|
||||||
layout (location = 3) in uint vinTintColor;
|
layout (location = 3) in uint vinTintColor;
|
||||||
|
|
||||||
flat out uint finTextureIndex;
|
flat out uint finTextureIndex;
|
||||||
@ -26,7 +26,7 @@ out vec4 finTintColor;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(vinPosition.xyz, 1.0f);
|
gl_Position = vec4(vinPosition.xyz, 1.0f);
|
||||||
finTextureCoordinates = vec3(vinUVCoordinates, vinRextureLayer & 0xFFFFFFu);
|
finTextureCoordinates = vec3(vinUV, vinTextureLayer & 0xFFFFFFu);
|
||||||
finTextureIndex = vinRextureLayer >> 24u;
|
finTextureIndex = vinTextureLayer >> 24u;
|
||||||
finTintColor = getRGBAColor(vinTintColor);
|
finTintColor = getRGBAColor(vinTintColor);
|
||||||
}
|
}
|
||||||
|
@ -14,18 +14,18 @@
|
|||||||
|
|
||||||
uniform sampler2DArray uTextures[7];
|
uniform sampler2DArray uTextures[7];
|
||||||
|
|
||||||
vec4 getTexture(uint textureId, vec3 textureCoordinates) { // ToDo: This method is just stupid and workarounds a opengl crash with mesa drivers
|
vec4 getTexture(uint textureId, vec3 uv) { // ToDo: This method is just stupid and workarounds a opengl crash with mesa drivers
|
||||||
#ifdef __NVIDIA
|
#ifdef __NVIDIA
|
||||||
return texture(uTextures[textureId], textureCoordinates);
|
return texture(uTextures[textureId], uv);
|
||||||
#else
|
#else
|
||||||
switch (textureId) {
|
switch (textureId) {
|
||||||
case 1u: return texture(uTextures[1], textureCoordinates);
|
case 1u: return texture(uTextures[1], uv);
|
||||||
case 2u: return texture(uTextures[2], textureCoordinates);
|
case 2u: return texture(uTextures[2], uv);
|
||||||
case 3u: return texture(uTextures[3], textureCoordinates);
|
case 3u: return texture(uTextures[3], uv);
|
||||||
case 4u: return texture(uTextures[4], textureCoordinates);
|
case 4u: return texture(uTextures[4], uv);
|
||||||
case 5u: return texture(uTextures[5], textureCoordinates);
|
case 5u: return texture(uTextures[5], uv);
|
||||||
case 6u: return texture(uTextures[6], textureCoordinates);
|
case 6u: return texture(uTextures[6], uv);
|
||||||
}
|
}
|
||||||
return texture(uTextures[0], textureCoordinates);
|
return texture(uTextures[0], uv);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout (location = 0) in vec3 vinPosition;
|
layout (location = 0) in vec3 vinPosition;
|
||||||
layout (location = 1) in vec2 vinUVCoordinates;
|
layout (location = 1) in vec2 vinUV;
|
||||||
layout (location = 2) in uint vinTextureLayer;
|
layout (location = 2) in uint vinTextureLayer;
|
||||||
layout (location = 3) in uint vinTintColor;
|
layout (location = 3) in uint vinTintColor;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ uniform mat4 uSkyViewProjectionMatrix;
|
|||||||
void main() {
|
void main() {
|
||||||
gl_Position = (uSkyViewProjectionMatrix * vec4(vinPosition, 1.0f)).xyww - vec4(0.0f, 0.0f, 0.000001f, 0.0f);// prevent face fighting
|
gl_Position = (uSkyViewProjectionMatrix * vec4(vinPosition, 1.0f)).xyww - vec4(0.0f, 0.0f, 0.000001f, 0.0f);// prevent face fighting
|
||||||
|
|
||||||
finTextureCoordinates = vec3(vinUVCoordinates, vinTextureLayer & 0xFFFFFFu);
|
finTextureCoordinates = vec3(vinUV, vinTextureLayer & 0xFFFFFFu);
|
||||||
finTextureIndex = vinTextureLayer >> 24u;
|
finTextureIndex = vinTextureLayer >> 24u;
|
||||||
finTintColor = getRGBAColor(vinTintColor);
|
finTintColor = getRGBAColor(vinTintColor);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout (location = 0) in vec3 vinPosition;
|
layout (location = 0) in vec3 vinPosition;
|
||||||
layout (location = 1) in vec2 vinUVCoordinates;
|
layout (location = 1) in vec2 vinUV;
|
||||||
layout (location = 2) in uint vinTextureLayer;
|
layout (location = 2) in uint vinTextureLayer;
|
||||||
|
|
||||||
layout (location = 3) in int vinAnimationIndex;
|
layout (location = 3) in int vinAnimationIndex;
|
||||||
@ -45,7 +45,7 @@ void work() {
|
|||||||
if (vinAnimationIndex == -1) {
|
if (vinAnimationIndex == -1) {
|
||||||
finTextureIndex1 = vinTextureLayer >> 24u;
|
finTextureIndex1 = vinTextureLayer >> 24u;
|
||||||
|
|
||||||
finTextureCoordinates1 = vec3(vinUVCoordinates, (vinTextureLayer & 0xFFFFFFu));
|
finTextureCoordinates1 = vec3(vinUV, (vinTextureLayer & 0xFFFFFFu));
|
||||||
|
|
||||||
finInterpolation = 0.0f;
|
finInterpolation = 0.0f;
|
||||||
return;
|
return;
|
||||||
@ -57,10 +57,10 @@ void work() {
|
|||||||
uint interpolation = data.z;
|
uint interpolation = data.z;
|
||||||
|
|
||||||
finTextureIndex1 = firstTexture >> 24u;
|
finTextureIndex1 = firstTexture >> 24u;
|
||||||
finTextureCoordinates1 = vec3(vinUVCoordinates, firstTexture & 0xFFFFFFu);
|
finTextureCoordinates1 = vec3(vinUV, firstTexture & 0xFFFFFFu);
|
||||||
|
|
||||||
finTextureIndex2 = secondTexture >> 24u;
|
finTextureIndex2 = secondTexture >> 24u;
|
||||||
finTextureCoordinates2 = vec3(vinUVCoordinates, secondTexture & 0xFFFFFFu);
|
finTextureCoordinates2 = vec3(vinUV, secondTexture & 0xFFFFFFu);
|
||||||
|
|
||||||
finInterpolation = interpolation / 100.0f;
|
finInterpolation = interpolation / 100.0f;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user