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
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
)
}
}

View File

@ -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)

View File

@ -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())
}

View File

@ -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)
}