diff --git a/api/Elementa.api b/api/Elementa.api index e6bce3f1..d7121568 100644 --- a/api/Elementa.api +++ b/api/Elementa.api @@ -2,6 +2,7 @@ public final class gg/essential/elementa/ElementaVersion : java/lang/Enum { public static final field Companion Lgg/essential/elementa/ElementaVersion$Companion; public static final field V0 Lgg/essential/elementa/ElementaVersion; public static final field V1 Lgg/essential/elementa/ElementaVersion; + public static final field V10 Lgg/essential/elementa/ElementaVersion; public static final field V2 Lgg/essential/elementa/ElementaVersion; public static final field V3 Lgg/essential/elementa/ElementaVersion; public static final field V4 Lgg/essential/elementa/ElementaVersion; @@ -9,6 +10,7 @@ public final class gg/essential/elementa/ElementaVersion : java/lang/Enum { public static final field V6 Lgg/essential/elementa/ElementaVersion; public static final field V7 Lgg/essential/elementa/ElementaVersion; public static final field V8 Lgg/essential/elementa/ElementaVersion; + public static final field V9 Lgg/essential/elementa/ElementaVersion; public final fun enableFor (Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; public static fun valueOf (Ljava/lang/String;)Lgg/essential/elementa/ElementaVersion; public static fun values ()[Lgg/essential/elementa/ElementaVersion; diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7b4a8bcc..53a52545 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin = "1.5.10" kotlinx-coroutines = "1.5.2" jetbrains-annotations = "23.0.0" -universalcraft = "389" +universalcraft = "406" commonmark = "0.17.1" dom4j = "2.1.1" diff --git a/src/main/kotlin/gg/essential/elementa/ElementaVersion.kt b/src/main/kotlin/gg/essential/elementa/ElementaVersion.kt index 8df41a71..f87d4214 100644 --- a/src/main/kotlin/gg/essential/elementa/ElementaVersion.kt +++ b/src/main/kotlin/gg/essential/elementa/ElementaVersion.kt @@ -1,10 +1,14 @@ package gg.essential.elementa +import gg.essential.elementa.components.UIText +import gg.essential.elementa.components.UIWrappedText import gg.essential.elementa.components.UpdateFunc import gg.essential.elementa.components.Window import gg.essential.elementa.constraints.SuperConstraint import gg.essential.elementa.constraints.animation.AnimationComponent import gg.essential.elementa.effects.Effect +import gg.essential.universal.render.URenderPipeline +import gg.essential.universal.shader.BlendState /** * Sometimes it is necessary or desirable to introduce breaking behavioral changes to Elementa. In order to maintain @@ -170,8 +174,23 @@ enum class ElementaVersion { * The new constraint tracking will only invalidate constraints which were evaluated, and the [UpdateFunc]s * are tracked intelligently at registration, such that no more full tree traversals should be necessary. */ + @Deprecated(DEPRECATION_MESSAGE) V8, + /** + * All Minecraft versions now use [URenderPipeline] instead of modifying global GL state. + * Additionally, [UIText] and [UIWrappedText] no longer enable (and forget to disable) blending. + */ + @Deprecated(DEPRECATION_MESSAGE) + V9, + + /** + * All components now use [BlendState.ALPHA] instead of [BlendState.NORMAL] and variants. + * This fixes the alpha channel of the render result, allowing it to be correctly composited with other textures. + * See [UniversalCraft#105](https://github.com/EssentialGG/UniversalCraft/pull/105) for more details. + */ + V10, + ; /** @@ -218,8 +237,16 @@ Be sure to read through all the changes between your current version and your ne internal val v6 = V6 @Suppress("DEPRECATION") internal val v7 = V7 + @Suppress("DEPRECATION") internal val v8 = V8 + @Suppress("DEPRECATION") + internal val v9 = V9 + internal val v10 = V10 + internal val atLeastV9Active: Boolean + get() = active >= v9 + internal val atLeastV10Active: Boolean + get() = active >= v10 @PublishedApi internal var active: ElementaVersion = v0 diff --git a/src/main/kotlin/gg/essential/elementa/components/GradientComponent.kt b/src/main/kotlin/gg/essential/elementa/components/GradientComponent.kt index fbf7b381..f25a2be2 100644 --- a/src/main/kotlin/gg/essential/elementa/components/GradientComponent.kt +++ b/src/main/kotlin/gg/essential/elementa/components/GradientComponent.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.components +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.state.BasicState import gg.essential.elementa.state.MappedState import gg.essential.elementa.state.State @@ -127,7 +128,7 @@ open class GradientComponent constructor( endColor: Color, direction: GradientDirection ) { - if (!URenderPipeline.isRequired) { + if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) { @Suppress("DEPRECATION") return drawGradientBlockLegacy(matrixStack, x1, y1, x2, y2, startColor, endColor, direction) } @@ -138,7 +139,7 @@ open class GradientComponent constructor( bufferBuilder.pos(matrixStack, x1, y1, 0.0).color(colors.topLeft).endVertex() bufferBuilder.pos(matrixStack, x1, y2, 0.0).color(colors.bottomLeft).endVertex() bufferBuilder.pos(matrixStack, x2, y2, 0.0).color(colors.bottomRight).endVertex() - bufferBuilder.build()?.drawAndClose(PIPELINE) + bufferBuilder.build()?.drawAndClose(if (ElementaVersion.atLeastV10Active) PIPELINE2 else PIPELINE) } @Deprecated("Stops working in 1.21.5") @@ -168,7 +169,12 @@ open class GradientComponent constructor( } private val PIPELINE = URenderPipeline.builderWithDefaultShader("elementa:gradient_block", UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + @Suppress("DEPRECATION") blendState = BlendState.NORMAL.copy(srcAlpha = BlendState.Param.ONE, dstAlpha = BlendState.Param.ZERO) }.build() + + private val PIPELINE2 = URenderPipeline.builderWithDefaultShader("elementa:gradient_block", UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + blendState = BlendState.ALPHA + }.build() } } \ No newline at end of file diff --git a/src/main/kotlin/gg/essential/elementa/components/UIBlock.kt b/src/main/kotlin/gg/essential/elementa/components/UIBlock.kt index f76c385b..736a486d 100644 --- a/src/main/kotlin/gg/essential/elementa/components/UIBlock.kt +++ b/src/main/kotlin/gg/essential/elementa/components/UIBlock.kt @@ -57,14 +57,14 @@ open class UIBlock(colorConstraint: ColorConstraint = Color.WHITE.toConstraint() drawBlock(UMatrixStack(), color, x1, y1, x2, y2) fun drawBlock(matrixStack: UMatrixStack, color: Color, x1: Double, y1: Double, x2: Double, y2: Double) { - if (!URenderPipeline.isRequired) { + if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) { @Suppress("DEPRECATION") return drawBlockLegacy(matrixStack, color, x1, y1, x2, y2) } val bufferBuilder = UBufferBuilder.create(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR) drawBlock(bufferBuilder, matrixStack, color, x1, y1, x2, y2) - bufferBuilder.build()?.drawAndClose(PIPELINE) + bufferBuilder.build()?.drawAndClose(if (ElementaVersion.atLeastV10Active) PIPELINE2 else PIPELINE) } @Deprecated("Stops working in 1.21.5, see UGraphics.Globals") @@ -133,6 +133,7 @@ open class UIBlock(colorConstraint: ColorConstraint = Color.WHITE.toConstraint() } private val PIPELINE = URenderPipeline.builderWithDefaultShader("elementa:block", UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + @Suppress("DEPRECATION") blendState = BlendState.NORMAL.copy(srcAlpha = BlendState.Param.ONE, dstAlpha = BlendState.Param.ZERO) // At some point MC started enabling its depth test during font rendering but all GUI code is // essentially flat and has depth tests disabled. This can cause stuff rendered in the background of the @@ -141,5 +142,15 @@ open class UIBlock(colorConstraint: ColorConstraint = Color.WHITE.toConstraint() // To work around this, we'll write depth buffer unconditionally in the area where we draw the block. depthTest = URenderPipeline.DepthTest.Always }.build() + + private val PIPELINE2 = URenderPipeline.builderWithDefaultShader("elementa:block", UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + blendState = BlendState.ALPHA + // At some point MC started enabling its depth test during font rendering but all GUI code is + // essentially flat and has depth tests disabled. This can cause stuff rendered in the background of the + // GUI to interfere with text rendered in the foreground because none of the blocks rendered in between + // will actually write to the depth buffer. + // To work around this, we'll write depth buffer unconditionally in the area where we draw the block. + depthTest = URenderPipeline.DepthTest.Always + }.build() } } diff --git a/src/main/kotlin/gg/essential/elementa/components/UICircle.kt b/src/main/kotlin/gg/essential/elementa/components/UICircle.kt index 38660601..9b9a148c 100644 --- a/src/main/kotlin/gg/essential/elementa/components/UICircle.kt +++ b/src/main/kotlin/gg/essential/elementa/components/UICircle.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.components +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.UIComponent import gg.essential.elementa.dsl.toConstraint import gg.essential.elementa.dsl.pixels @@ -77,10 +78,22 @@ class UICircle @JvmOverloads constructor(radius: Float = 0f, color: Color = Colo readElementaShaderSource("rect", "vsh"), readElementaShaderSource("circle", "fsh"), ).apply { + @Suppress("DEPRECATION") blendState = BlendState.NORMAL depthTest = URenderPipeline.DepthTest.Always // see UIBlock.PIPELINE }.build() + private val PIPELINE2 = URenderPipeline.builderWithLegacyShader( + "elementa:circle", + UGraphics.DrawMode.QUADS, + UGraphics.CommonVertexFormats.POSITION_COLOR, + readElementaShaderSource("rect", "vsh"), + readElementaShaderSource("circle", "fsh"), + ).apply { + blendState = BlendState.ALPHA + depthTest = URenderPipeline.DepthTest.Always // see UIBlock.PIPELINE + }.build() + fun initShaders() { if (URenderPipeline.isRequired) return if (::shader.isInitialized) @@ -104,7 +117,7 @@ class UICircle @JvmOverloads constructor(radius: Float = 0f, color: Color = Colo drawCircle(UMatrixStack(), centerX, centerY, radius, color) fun drawCircle(matrixStack: UMatrixStack, centerX: Float, centerY: Float, radius: Float, color: Color) { - if (!URenderPipeline.isRequired) { + if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) { @Suppress("DEPRECATION") return drawCircleLegacy(matrixStack, centerX, centerY, radius, color) } @@ -119,7 +132,7 @@ class UICircle @JvmOverloads constructor(radius: Float = 0f, color: Color = Colo (centerX + radius).toDouble(), (centerY + radius).toDouble() ) - bufferBuilder.build()?.drawAndClose(PIPELINE) { + bufferBuilder.build()?.drawAndClose(if (ElementaVersion.atLeastV10Active) PIPELINE2 else PIPELINE) { uniform("u_Radius", radius) uniform("u_CenterPos", centerX, centerY) } diff --git a/src/main/kotlin/gg/essential/elementa/components/UIRoundedRectangle.kt b/src/main/kotlin/gg/essential/elementa/components/UIRoundedRectangle.kt index 7a9503b0..bd601591 100644 --- a/src/main/kotlin/gg/essential/elementa/components/UIRoundedRectangle.kt +++ b/src/main/kotlin/gg/essential/elementa/components/UIRoundedRectangle.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.components +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.UIComponent import gg.essential.elementa.dsl.pixels import gg.essential.elementa.utils.readElementaShaderSource @@ -48,10 +49,22 @@ open class UIRoundedRectangle(radius: Float) : UIComponent() { readElementaShaderSource("rect", "vsh"), readElementaShaderSource("rounded_rect", "fsh"), ).apply { + @Suppress("DEPRECATION") blendState = BlendState.NORMAL depthTest = URenderPipeline.DepthTest.Always // see UIBlock.PIPELINE }.build() + private val PIPELINE2 = URenderPipeline.builderWithLegacyShader( + "elementa:rounded_rectangle", + UGraphics.DrawMode.QUADS, + UGraphics.CommonVertexFormats.POSITION_COLOR, + readElementaShaderSource("rect", "vsh"), + readElementaShaderSource("rounded_rect", "fsh"), + ).apply { + blendState = BlendState.ALPHA + depthTest = URenderPipeline.DepthTest.Always // see UIBlock.PIPELINE + }.build() + fun initShaders() { if (URenderPipeline.isRequired) return if (::shader.isInitialized) @@ -78,14 +91,14 @@ open class UIRoundedRectangle(radius: Float) : UIComponent() { * Draws a rounded rectangle */ fun drawRoundedRectangle(matrixStack: UMatrixStack, left: Float, top: Float, right: Float, bottom: Float, radius: Float, color: Color) { - if (!URenderPipeline.isRequired) { + if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) { @Suppress("DEPRECATION") return drawRoundedRectangleLegacy(matrixStack, left, top, right, bottom, radius, color) } val bufferBuilder = UBufferBuilder.create(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR) UIBlock.drawBlock(bufferBuilder, matrixStack, color, left.toDouble(), top.toDouble(), right.toDouble(), bottom.toDouble()) - bufferBuilder.build()?.drawAndClose(PIPELINE) { + bufferBuilder.build()?.drawAndClose(if (ElementaVersion.atLeastV10Active) PIPELINE2 else PIPELINE) { uniform("u_Radius", radius) uniform("u_InnerRect", left + radius, top + radius, right - radius, bottom - radius) } diff --git a/src/main/kotlin/gg/essential/elementa/components/UIShape.kt b/src/main/kotlin/gg/essential/elementa/components/UIShape.kt index c3d1f1f2..96a254cf 100644 --- a/src/main/kotlin/gg/essential/elementa/components/UIShape.kt +++ b/src/main/kotlin/gg/essential/elementa/components/UIShape.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.components +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.UIComponent import gg.essential.elementa.dsl.toConstraint import gg.essential.universal.UGraphics @@ -44,7 +45,7 @@ open class UIShape @JvmOverloads constructor(color: Color = Color.WHITE) : UICom val color = this.getColor() if (color.alpha == 0) return super.draw(matrixStack) - if (URenderPipeline.isRequired) { + if (URenderPipeline.isRequired || ElementaVersion.atLeastV9Active) { draw(matrixStack, color) } else { @Suppress("DEPRECATION") @@ -62,7 +63,7 @@ open class UIShape @JvmOverloads constructor(color: Color = Color.WHITE) : UICom .color(color.red, color.green, color.blue, color.alpha) .endVertex() } - bufferBuilder.build()?.drawAndClose(PIPELINE) + bufferBuilder.build()?.drawAndClose(if (ElementaVersion.atLeastV10Active) PIPELINE2 else PIPELINE) } @Deprecated("Stops working in 1.21.5, see UGraphics.Globals") @@ -97,7 +98,11 @@ open class UIShape @JvmOverloads constructor(color: Color = Color.WHITE) : UICom private companion object { private val PIPELINE = URenderPipeline.builderWithDefaultShader("elementa:shape", UGraphics.DrawMode.TRIANGLE_FAN, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + @Suppress("DEPRECATION") blendState = BlendState.NORMAL.copy(srcAlpha = BlendState.Param.ONE, dstAlpha = BlendState.Param.ZERO) }.build() + private val PIPELINE2 = URenderPipeline.builderWithDefaultShader("elementa:shape", UGraphics.DrawMode.TRIANGLE_FAN, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + blendState = BlendState.ALPHA + }.build() } } diff --git a/src/main/kotlin/gg/essential/elementa/components/UIText.kt b/src/main/kotlin/gg/essential/elementa/components/UIText.kt index f04049f5..f6e054f3 100644 --- a/src/main/kotlin/gg/essential/elementa/components/UIText.kt +++ b/src/main/kotlin/gg/essential/elementa/components/UIText.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.components +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.UIComponent import gg.essential.elementa.UIConstraints import gg.essential.elementa.constraints.CenterConstraint @@ -118,7 +119,7 @@ constructor( return super.draw(matrixStack) } - if (!URenderPipeline.isRequired) { + if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) { @Suppress("DEPRECATION") UGraphics.enableBlend() } diff --git a/src/main/kotlin/gg/essential/elementa/components/UIWrappedText.kt b/src/main/kotlin/gg/essential/elementa/components/UIWrappedText.kt index 1165cab5..d23c05e2 100644 --- a/src/main/kotlin/gg/essential/elementa/components/UIWrappedText.kt +++ b/src/main/kotlin/gg/essential/elementa/components/UIWrappedText.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.components +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.UIComponent import gg.essential.elementa.UIConstraints import gg.essential.elementa.constraints.CenterConstraint @@ -152,7 +153,7 @@ open class UIWrappedText @JvmOverloads constructor( return super.draw(matrixStack) } - if (!URenderPipeline.isRequired) { + if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) { @Suppress("DEPRECATION") UGraphics.enableBlend() } diff --git a/src/main/kotlin/gg/essential/elementa/components/inspector/Inspector.kt b/src/main/kotlin/gg/essential/elementa/components/inspector/Inspector.kt index d53eabf5..8316e51c 100644 --- a/src/main/kotlin/gg/essential/elementa/components/inspector/Inspector.kt +++ b/src/main/kotlin/gg/essential/elementa/components/inspector/Inspector.kt @@ -382,7 +382,7 @@ class Inspector @JvmOverloads constructor( UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR, ).apply { - blendState = BlendState.NORMAL + blendState = BlendState.ALPHA depthTest = URenderPipeline.DepthTest.Less }.build() } diff --git a/src/main/kotlin/gg/essential/elementa/font/BasicFontRenderer.kt b/src/main/kotlin/gg/essential/elementa/font/BasicFontRenderer.kt index aeb87647..7512094c 100644 --- a/src/main/kotlin/gg/essential/elementa/font/BasicFontRenderer.kt +++ b/src/main/kotlin/gg/essential/elementa/font/BasicFontRenderer.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.font +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.UIComponent import gg.essential.elementa.constraints.ConstraintType import gg.essential.elementa.constraints.resolution.ConstraintVisitor @@ -148,10 +149,10 @@ class BasicFontRenderer( y: Float, originalPointSize: Float ) { - if (URenderPipeline.isRequired) { + if (URenderPipeline.isRequired || ElementaVersion.atLeastV9Active) { val bufferBuilder = UBufferBuilder.create(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_TEXTURE_COLOR) drawStringNow(bufferBuilder, matrixStack, string, color, x, y, originalPointSize) - bufferBuilder.build()?.drawAndClose(PIPELINE) { + bufferBuilder.build()?.drawAndClose(if (ElementaVersion.atLeastV10Active) PIPELINE2 else PIPELINE) { texture(0, regularFont.getTexture().dynamicGlId) } } else { @@ -274,7 +275,11 @@ class BasicFontRenderer( private companion object { private val PIPELINE = URenderPipeline.builderWithDefaultShader("elementa:basic_font", UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + @Suppress("DEPRECATION") blendState = BlendState.NORMAL.copy(srcAlpha = BlendState.Param.ONE, dstAlpha = BlendState.Param.ZERO) }.build() + private val PIPELINE2 = URenderPipeline.builderWithDefaultShader("elementa:basic_font", UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + blendState = BlendState.ALPHA + }.build() } } \ No newline at end of file diff --git a/src/main/kotlin/gg/essential/elementa/font/FontRenderer.kt b/src/main/kotlin/gg/essential/elementa/font/FontRenderer.kt index d75ca304..321377dc 100644 --- a/src/main/kotlin/gg/essential/elementa/font/FontRenderer.kt +++ b/src/main/kotlin/gg/essential/elementa/font/FontRenderer.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.font +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.UIComponent import gg.essential.elementa.constraints.ConstraintType import gg.essential.elementa.constraints.resolution.ConstraintVisitor @@ -25,7 +26,7 @@ import kotlin.math.max /** * [MSDF](https://github.com/Chlumsky/msdfgen) Font Renderer */ -@Deprecated("Not well maintained. Does not currently support 1.21.5+ at all.") +@Deprecated("Not well maintained. Does not currently support 1.21.5+ or ElementaVersion.V9 at all.") @Suppress("DEPRECATION") class FontRenderer( private val regularFont: Font, @@ -133,6 +134,9 @@ class FontRenderer( shadow: Boolean, shadowColor: Color? ) { + if (ElementaVersion.atLeastV9Active) { + return + } val effectiveSize = originalPointSize * scale * 1.3623059867f val adjustedY = y - effectiveSize / 5 if (shadow) { diff --git a/src/main/kotlin/gg/essential/elementa/utils/LineUtils.kt b/src/main/kotlin/gg/essential/elementa/utils/LineUtils.kt index 87d0b50a..b0262113 100644 --- a/src/main/kotlin/gg/essential/elementa/utils/LineUtils.kt +++ b/src/main/kotlin/gg/essential/elementa/utils/LineUtils.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.utils +import gg.essential.elementa.ElementaVersion import gg.essential.elementa.components.UIPoint import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack @@ -12,8 +13,12 @@ import kotlin.math.sqrt object LineUtils { private val PIPELINE = URenderPipeline.builderWithDefaultShader("elementa:line_strip", UGraphics.DrawMode.TRIANGLE_STRIP, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + @Suppress("DEPRECATION") blendState = BlendState.NORMAL }.build() + private val PIPELINE2 = URenderPipeline.builderWithDefaultShader("elementa:line_strip", UGraphics.DrawMode.TRIANGLE_STRIP, UGraphics.CommonVertexFormats.POSITION_COLOR).apply { + blendState = BlendState.ALPHA + }.build() @Deprecated(UMatrixStack.Compat.DEPRECATED, ReplaceWith("drawLine(UMatrixStack(), x1, y1, x2, y2, color, width)")) @JvmStatic @@ -27,10 +32,10 @@ object LineUtils { @JvmStatic fun drawLineStrip(matrixStack: UMatrixStack, points: List>, color: Color, width: Float) { - if (URenderPipeline.isRequired) { + if (URenderPipeline.isRequired || ElementaVersion.atLeastV9Active) { val bufferBuilder = UBufferBuilder.create(UGraphics.DrawMode.TRIANGLE_STRIP, UGraphics.CommonVertexFormats.POSITION_COLOR) drawLineStrip(bufferBuilder, matrixStack, points, color, width) - bufferBuilder.build()?.drawAndClose(PIPELINE) + bufferBuilder.build()?.drawAndClose(if (ElementaVersion.atLeastV10Active) PIPELINE2 else PIPELINE) } else { @Suppress("DEPRECATION") UGraphics.enableBlend() diff --git a/src/main/kotlin/gg/essential/elementa/utils/image.kt b/src/main/kotlin/gg/essential/elementa/utils/image.kt index 8642792a..20bdf693 100644 --- a/src/main/kotlin/gg/essential/elementa/utils/image.kt +++ b/src/main/kotlin/gg/essential/elementa/utils/image.kt @@ -1,5 +1,6 @@ package gg.essential.elementa.utils +import gg.essential.elementa.ElementaVersion import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack import gg.essential.universal.render.URenderPipeline @@ -46,10 +47,10 @@ internal fun drawTexture( vertexConsumer.pos(matrixStack, x, y, 0.0).tex(0.0, 0.0).color(red, green, blue, alpha).endVertex() } - if (URenderPipeline.isRequired) { + if (URenderPipeline.isRequired || ElementaVersion.atLeastV9Active) { val bufferBuilder = UBufferBuilder.create(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_TEXTURE_COLOR) drawTexturedQuad(bufferBuilder) - bufferBuilder.build()?.drawAndClose(TEXTURED_QUAD_PIPELINE) { + bufferBuilder.build()?.drawAndClose(if (ElementaVersion.atLeastV10Active) TEXTURED_QUAD_PIPELINE2 else TEXTURED_QUAD_PIPELINE) { texture(0, glId) } } else { @@ -72,9 +73,18 @@ private val TEXTURED_QUAD_PIPELINE = URenderPipeline.builderWithDefaultShader( UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_TEXTURE_COLOR, ).apply { + @Suppress("DEPRECATION") blendState = BlendState.NORMAL }.build() +private val TEXTURED_QUAD_PIPELINE2 = URenderPipeline.builderWithDefaultShader( + "elementa:textured_quad", + UGraphics.DrawMode.QUADS, + UGraphics.CommonVertexFormats.POSITION_TEXTURE_COLOR, +).apply { + blendState = BlendState.ALPHA +}.build() + fun decodeBlurHash(blurHash: String?, width: Int, height: Int, punch: Float = 1f): BufferedImage? { if (blurHash == null || blurHash.length < 6) return null