Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[versions]
kotlin = "1.5.10"
jetbrains-annotations = "23.0.0"
universalcraft = "355"
elementa = "659"
universalcraft = "415"
elementa = "710"
nightconfig = "3.6.0"

[libraries]
Expand Down
22 changes: 14 additions & 8 deletions src/main/kotlin/gg/essential/vigilance/gui/settings/ColorPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import gg.essential.elementa.state.toConstraint
import gg.essential.universal.UGraphics
import gg.essential.universal.UMatrixStack
import gg.essential.universal.USound
import gg.essential.universal.render.URenderPipeline
import gg.essential.universal.shader.BlendState
import gg.essential.universal.vertex.UBufferBuilder
import gg.essential.vigilance.gui.VigilancePalette
import gg.essential.vigilance.utils.onLeftClick
import java.awt.Color
Expand Down Expand Up @@ -204,8 +207,7 @@ class ColorPicker(initial: Color, allowAlpha: Boolean) : UIContainer() {
val bottom = component.getBottom().toDouble()

setupDraw()
val graphics = UGraphics.getFromTessellator()
graphics.beginWithDefaultShader(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR)
val graphics = UBufferBuilder.create(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR)

val height = bottom - top

Expand All @@ -232,7 +234,7 @@ class ColorPicker(initial: Color, allowAlpha: Boolean) : UIContainer() {

}

graphics.drawDirect()
graphics.build()?.drawAndClose(pipeline)
cleanupDraw()
}

Expand All @@ -247,9 +249,7 @@ class ColorPicker(initial: Color, allowAlpha: Boolean) : UIContainer() {
val height = component.getHeight().toDouble()

setupDraw()
val graphics = UGraphics.getFromTessellator()

graphics.beginWithDefaultShader(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR)
val graphics = UBufferBuilder.create(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR)

var first = true
for ((i, color) in hueColorList.withIndex()) {
Expand All @@ -265,24 +265,30 @@ class ColorPicker(initial: Color, allowAlpha: Boolean) : UIContainer() {
first = false
}

graphics.drawDirect()
graphics.build()?.drawAndClose(pipeline)
cleanupDraw()
}

private val pipeline = URenderPipeline.builderWithDefaultShader("vigilance:color_picker", UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR).apply {
blendState = BlendState.ALPHA.copy(dstAlpha = BlendState.Param.ZERO)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI the blend function used by the original code is just plain wrong. Setting dstAlpha to 0 doesn't make sense.

}.build()

private fun setupDraw() {
// NO-OP on 1.21.5+
UGraphics.enableBlend()
UGraphics.disableAlpha()
UGraphics.tryBlendFuncSeparate(770, 771, 1, 0)
Comment on lines +277 to 280
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI URenderPipeline overrides blend and alpha states on all versions.

UGraphics.shadeModel(7425)
}

private fun cleanupDraw() {
// NO-OP on 1.21.5+
UGraphics.shadeModel(7424)
UGraphics.disableBlend()
UGraphics.enableAlpha()
}

private fun drawVertex(graphics: UGraphics, matrixStack: UMatrixStack, x: Double, y: Double, color: Color) {
private fun drawVertex(graphics: UBufferBuilder, matrixStack: UMatrixStack, x: Double, y: Double, color: Color) {
graphics
.pos(matrixStack, x, y, 0.0)
.color(color.red.toFloat() / 255f, color.green.toFloat() / 255f, color.blue.toFloat() / 255f, 1f)
Expand Down