From d0f46afc2845c36db23033ae137c69131d92f153 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Fri, 27 Jun 2025 02:38:39 +0200 Subject: [PATCH] Actually use a value of 40 for BufferType.VERTICES, and continue porting effort Signed-off-by: Username404-59 --- .../snowygui/gui/elements/ClickBox.kt | 6 ++--- .../snowygui/gui/feature/ButtonImpl.kt | 3 +-- .../fr/username404/snowygui/utils/FontUtil.kt | 7 +++++- .../snowygui/utils/RenderingUtil.kt | 23 ++++++++++++++----- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index f8f3129..f91fa74 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -1,6 +1,5 @@ package fr.username404.snowygui.gui.elements -import com.mojang.blaze3d.systems.RenderSystem.teardownOverlayColor import fr.username404.snowygui.Snowy.Companion.MissingComponent import fr.username404.snowygui.config.Configuration 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.renderer.RenderPipelines import net.minecraft.network.chat.Component +import net.minecraft.util.ARGB import org.jetbrains.annotations.ApiStatus import java.util.TreeSet import kotlin.collections.LinkedHashSet @@ -45,7 +45,7 @@ class ClickBox( override val color: Int get() = this@ClickBox.color override fun render(guiGraphics: GuiGraphics?) { prepareDraw() - colorShader(); defaultRectFunc(); teardownOverlayColor() + colorShader(); defaultRectFunc(); endDraw() } init { height = 8 } @@ -123,7 +123,7 @@ class ClickBox( this, Component.nullToEmpty(name.string), (x + 5).toInt(), (y + 2).toInt(), - Colors.TRANSPARENT.hexValue, false + ARGB.opaque(Colors.TRANSPARENT.hexValue), false ) } } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index fcfcd77..e4d4e84 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -1,6 +1,5 @@ package fr.username404.snowygui.gui.feature -import com.mojang.blaze3d.systems.RenderSystem.teardownOverlayColor import fr.username404.snowygui.ClickGui import fr.username404.snowygui.Snowy 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?) { prepareDraw() - colorShader(); defaultRectFunc(); teardownOverlayColor() + colorShader(); defaultRectFunc(); endDraw() if (guiGraphics != null) { FontUtil.drawScaled(guiGraphics, title, x + 1, y + 1, 0.75F) diff --git a/common/src/main/kotlin/fr/username404/snowygui/utils/FontUtil.kt b/common/src/main/kotlin/fr/username404/snowygui/utils/FontUtil.kt index 90d6642..126249d 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/utils/FontUtil.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/utils/FontUtil.kt @@ -3,13 +3,18 @@ package fr.username404.snowygui.utils import net.minecraft.client.Minecraft import fr.username404.snowygui.gui.feature.Colors import net.minecraft.client.gui.GuiGraphics +import net.minecraft.util.ARGB import org.joml.Matrix3x2f object FontUtil { fun drawScaled(guiGraphics: GuiGraphics, text: String, x: Double, y: Double, scaleFactor: Float, color: Colors = Colors.BLACK) { val stack = guiGraphics.pose() 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 stack.scale(factorToOriginal, factorToOriginal, Matrix3x2f()) } diff --git a/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt b/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt index 2e7610f..62ef766 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt @@ -1,6 +1,5 @@ package fr.username404.snowygui.utils -import com.mojang.blaze3d.buffers.GpuBuffer import com.mojang.blaze3d.opengl.GlCommandEncoder import com.mojang.blaze3d.opengl.GlStateManager import com.mojang.blaze3d.pipeline.RenderPipeline @@ -14,6 +13,9 @@ import fr.username404.snowygui.gui.feature.Colors import fr.username404.snowygui.gui.hextoRGB import net.minecraft.client.Minecraft 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.OptionalInt @@ -22,16 +24,13 @@ object RenderingUtil { fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer = hextoRGB(color).run { setColor(get(0), get(1), get(2), opacity) } - fun colorShader() { - RenderSystem.setupOverlayColor(Minecraft.getInstance().mainRenderTarget.colorTextureView) - } + fun colorShader() {} fun prepareDraw() { colorShader() GlStateManager._enableBlend() } fun endDraw() { GlStateManager._disableBlend() - RenderSystem.teardownOverlayColor() } fun drawRectangle( x: Double, y: Double, height: Int, width: Int, @@ -45,6 +44,13 @@ object RenderingUtil { 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( name: String? = "Dynamic vertex buffer", renderPipeline: RenderPipeline, @@ -66,7 +72,7 @@ object RenderingUtil { ).use { renderPass -> encoder.inRenderPass = false; RenderSystem.getDevice().createBuffer( - { name }, GpuBuffer.USAGE_VERTEX + GpuBuffer.USAGE_MAP_WRITE, meshData.vertexBuffer() + { name }, 40, meshData.vertexBuffer() ).use { buffer -> val autoStorageIndexBuffer = RenderSystem.getSequentialBuffer(mode) renderPass.setPipeline(renderPipeline) @@ -75,6 +81,11 @@ object RenderingUtil { autoStorageIndexBuffer.getBuffer(meshData.drawState().indexCount()), autoStorageIndexBuffer.type() ) + // RenderSystem.bindDefaultUniforms(renderPass) + renderPass.setUniform( + "DynamicTransforms", + gpuSlice + ) uniformAndSamplerConsumer?.invoke(renderPass) renderPass.drawIndexed(0, 0, meshData.drawState().indexCount(), 1) }