-
Notifications
You must be signed in to change notification settings - Fork 15
fix: Use URenderPipeline for ColorPicker #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -232,7 +234,7 @@ class ColorPicker(initial: Color, allowAlpha: Boolean) : UIContainer() { | |
|
|
||
| } | ||
|
|
||
| graphics.drawDirect() | ||
| graphics.build()?.drawAndClose(pipeline) | ||
| cleanupDraw() | ||
| } | ||
|
|
||
|
|
@@ -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()) { | ||
|
|
@@ -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) | ||
| }.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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.