Actually use a value of 40 for BufferType.VERTICES, and continue porting effort

Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404-59 2025-06-27 02:38:39 +02:00
parent 04873a7a64
commit d0f46afc28
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
4 changed files with 27 additions and 12 deletions

View File

@ -1,6 +1,5 @@
package fr.username404.snowygui.gui.elements package fr.username404.snowygui.gui.elements
import com.mojang.blaze3d.systems.RenderSystem.teardownOverlayColor
import fr.username404.snowygui.Snowy.Companion.MissingComponent import fr.username404.snowygui.Snowy.Companion.MissingComponent
import fr.username404.snowygui.config.Configuration import fr.username404.snowygui.config.Configuration
import fr.username404.snowygui.gui.ColoredElement import fr.username404.snowygui.gui.ColoredElement
@ -16,6 +15,7 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.renderer.RenderPipelines import net.minecraft.client.renderer.RenderPipelines
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.util.ARGB
import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.ApiStatus
import java.util.TreeSet import java.util.TreeSet
import kotlin.collections.LinkedHashSet import kotlin.collections.LinkedHashSet
@ -45,7 +45,7 @@ class ClickBox(
override val color: Int get() = this@ClickBox.color override val color: Int get() = this@ClickBox.color
override fun render(guiGraphics: GuiGraphics?) { override fun render(guiGraphics: GuiGraphics?) {
prepareDraw() prepareDraw()
colorShader(); defaultRectFunc(); teardownOverlayColor() colorShader(); defaultRectFunc();
endDraw() endDraw()
} }
init { height = 8 } init { height = 8 }
@ -123,7 +123,7 @@ class ClickBox(
this, this,
Component.nullToEmpty(name.string), Component.nullToEmpty(name.string),
(x + 5).toInt(), (y + 2).toInt(), (x + 5).toInt(), (y + 2).toInt(),
Colors.TRANSPARENT.hexValue, false ARGB.opaque(Colors.TRANSPARENT.hexValue), false
) )
} }
} }

View File

@ -1,6 +1,5 @@
package fr.username404.snowygui.gui.feature package fr.username404.snowygui.gui.feature
import com.mojang.blaze3d.systems.RenderSystem.teardownOverlayColor
import fr.username404.snowygui.ClickGui import fr.username404.snowygui.ClickGui
import fr.username404.snowygui.Snowy import fr.username404.snowygui.Snowy
import fr.username404.snowygui.config.Configuration import fr.username404.snowygui.config.Configuration
@ -88,7 +87,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
} }
final override fun render(guiGraphics: GuiGraphics?) { final override fun render(guiGraphics: GuiGraphics?) {
prepareDraw() prepareDraw()
colorShader(); defaultRectFunc(); teardownOverlayColor() colorShader(); defaultRectFunc();
endDraw() endDraw()
if (guiGraphics != null) { if (guiGraphics != null) {
FontUtil.drawScaled(guiGraphics, title, x + 1, y + 1, 0.75F) FontUtil.drawScaled(guiGraphics, title, x + 1, y + 1, 0.75F)

View File

@ -3,13 +3,18 @@ package fr.username404.snowygui.utils
import net.minecraft.client.Minecraft import net.minecraft.client.Minecraft
import fr.username404.snowygui.gui.feature.Colors import fr.username404.snowygui.gui.feature.Colors
import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.GuiGraphics
import net.minecraft.util.ARGB
import org.joml.Matrix3x2f import org.joml.Matrix3x2f
object FontUtil { object FontUtil {
fun drawScaled(guiGraphics: GuiGraphics, text: String, x: Double, y: Double, scaleFactor: Float, color: Colors = Colors.BLACK) { fun drawScaled(guiGraphics: GuiGraphics, text: String, x: Double, y: Double, scaleFactor: Float, color: Colors = Colors.BLACK) {
val stack = guiGraphics.pose() val stack = guiGraphics.pose()
stack.scale(scaleFactor, scaleFactor, Matrix3x2f()) stack.scale(scaleFactor, scaleFactor, Matrix3x2f())
guiGraphics.drawString(Minecraft.getInstance().font, text, (x / scaleFactor).toInt(), (y / scaleFactor).toInt(), color.hexValue, false) guiGraphics.drawString(
Minecraft.getInstance().font, text,
(x / scaleFactor).toInt(), (y / scaleFactor).toInt(),
ARGB.opaque(color.hexValue), false
)
val factorToOriginal = 1F / scaleFactor val factorToOriginal = 1F / scaleFactor
stack.scale(factorToOriginal, factorToOriginal, Matrix3x2f()) stack.scale(factorToOriginal, factorToOriginal, Matrix3x2f())
} }

View File

@ -1,6 +1,5 @@
package fr.username404.snowygui.utils package fr.username404.snowygui.utils
import com.mojang.blaze3d.buffers.GpuBuffer
import com.mojang.blaze3d.opengl.GlCommandEncoder import com.mojang.blaze3d.opengl.GlCommandEncoder
import com.mojang.blaze3d.opengl.GlStateManager import com.mojang.blaze3d.opengl.GlStateManager
import com.mojang.blaze3d.pipeline.RenderPipeline import com.mojang.blaze3d.pipeline.RenderPipeline
@ -14,6 +13,9 @@ import fr.username404.snowygui.gui.feature.Colors
import fr.username404.snowygui.gui.hextoRGB import fr.username404.snowygui.gui.hextoRGB
import net.minecraft.client.Minecraft import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.RenderPipelines import net.minecraft.client.renderer.RenderPipelines
import org.joml.Matrix4f
import org.joml.Vector3f
import org.joml.Vector4f
import java.util.OptionalDouble import java.util.OptionalDouble
import java.util.OptionalInt import java.util.OptionalInt
@ -22,16 +24,13 @@ object RenderingUtil {
fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer = hextoRGB(color).run { fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer = hextoRGB(color).run {
setColor(get(0), get(1), get(2), opacity) setColor(get(0), get(1), get(2), opacity)
} }
fun colorShader() { fun colorShader() {}
RenderSystem.setupOverlayColor(Minecraft.getInstance().mainRenderTarget.colorTextureView)
}
fun prepareDraw() { fun prepareDraw() {
colorShader() colorShader()
GlStateManager._enableBlend() GlStateManager._enableBlend()
} }
fun endDraw() { fun endDraw() {
GlStateManager._disableBlend() GlStateManager._disableBlend()
RenderSystem.teardownOverlayColor()
} }
fun drawRectangle( fun drawRectangle(
x: Double, y: Double, height: Int, width: Int, x: Double, y: Double, height: Int, width: Int,
@ -45,6 +44,13 @@ object RenderingUtil {
addVertex(x, y, 0.0F).colorIt() addVertex(x, y, 0.0F).colorIt()
} }
val gpuSlice = RenderSystem.getDynamicUniforms().writeTransform(
RenderSystem.getModelViewMatrix(),
Vector4f(1F, 1F, 1F, 1F), // Alternative to old setShaderColor
Vector3f(),
Matrix4f(),
0.0F
)
fun renderBufferWithPipeline( fun renderBufferWithPipeline(
name: String? = "Dynamic vertex buffer", name: String? = "Dynamic vertex buffer",
renderPipeline: RenderPipeline, renderPipeline: RenderPipeline,
@ -66,7 +72,7 @@ object RenderingUtil {
).use { renderPass -> ).use { renderPass ->
encoder.inRenderPass = false; encoder.inRenderPass = false;
RenderSystem.getDevice().createBuffer( RenderSystem.getDevice().createBuffer(
{ name }, GpuBuffer.USAGE_VERTEX + GpuBuffer.USAGE_MAP_WRITE, meshData.vertexBuffer() { name }, 40, meshData.vertexBuffer()
).use { buffer -> ).use { buffer ->
val autoStorageIndexBuffer = RenderSystem.getSequentialBuffer(mode) val autoStorageIndexBuffer = RenderSystem.getSequentialBuffer(mode)
renderPass.setPipeline(renderPipeline) renderPass.setPipeline(renderPipeline)
@ -75,6 +81,11 @@ object RenderingUtil {
autoStorageIndexBuffer.getBuffer(meshData.drawState().indexCount()), autoStorageIndexBuffer.getBuffer(meshData.drawState().indexCount()),
autoStorageIndexBuffer.type() autoStorageIndexBuffer.type()
) )
// RenderSystem.bindDefaultUniforms(renderPass)
renderPass.setUniform(
"DynamicTransforms",
gpuSlice
)
uniformAndSamplerConsumer?.invoke(renderPass) uniformAndSamplerConsumer?.invoke(renderPass)
renderPass.drawIndexed(0, 0, meshData.drawState().indexCount(), 1) renderPass.drawIndexed(0, 0, meshData.drawState().indexCount(), 1)
} }