Skip to content

Commit b6711cd

Browse files
committed
Misc: Use URenderPipeline on all Minecraft versions
1 parent a8e824f commit b6711cd

File tree

13 files changed

+39
-11
lines changed

13 files changed

+39
-11
lines changed

api/Elementa.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public final class gg/essential/elementa/ElementaVersion : java/lang/Enum {
99
public static final field V6 Lgg/essential/elementa/ElementaVersion;
1010
public static final field V7 Lgg/essential/elementa/ElementaVersion;
1111
public static final field V8 Lgg/essential/elementa/ElementaVersion;
12+
public static final field V9 Lgg/essential/elementa/ElementaVersion;
1213
public final fun enableFor (Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
1314
public static fun valueOf (Ljava/lang/String;)Lgg/essential/elementa/ElementaVersion;
1415
public static fun values ()[Lgg/essential/elementa/ElementaVersion;

src/main/kotlin/gg/essential/elementa/ElementaVersion.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package gg.essential.elementa
22

3+
import gg.essential.elementa.components.UIText
4+
import gg.essential.elementa.components.UIWrappedText
35
import gg.essential.elementa.components.UpdateFunc
46
import gg.essential.elementa.components.Window
57
import gg.essential.elementa.constraints.SuperConstraint
68
import gg.essential.elementa.constraints.animation.AnimationComponent
79
import gg.essential.elementa.effects.Effect
10+
import gg.essential.universal.render.URenderPipeline
811

912
/**
1013
* Sometimes it is necessary or desirable to introduce breaking behavioral changes to Elementa. In order to maintain
@@ -170,8 +173,15 @@ enum class ElementaVersion {
170173
* The new constraint tracking will only invalidate constraints which were evaluated, and the [UpdateFunc]s
171174
* are tracked intelligently at registration, such that no more full tree traversals should be necessary.
172175
*/
176+
@Deprecated(DEPRECATION_MESSAGE)
173177
V8,
174178

179+
/**
180+
* All Minecraft versions now use [URenderPipeline] instead of modifying global GL state.
181+
* Additionally, [UIText] and [UIWrappedText] no longer enable (and forget to disable) blending.
182+
*/
183+
V9,
184+
175185
;
176186

177187
/**
@@ -218,8 +228,12 @@ Be sure to read through all the changes between your current version and your ne
218228
internal val v6 = V6
219229
@Suppress("DEPRECATION")
220230
internal val v7 = V7
231+
@Suppress("DEPRECATION")
221232
internal val v8 = V8
233+
internal val v9 = V9
222234

235+
internal val atLeastV9Active: Boolean
236+
get() = active >= v9
223237

224238
@PublishedApi
225239
internal var active: ElementaVersion = v0

src/main/kotlin/gg/essential/elementa/components/GradientComponent.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gg.essential.elementa.components
22

3+
import gg.essential.elementa.ElementaVersion
34
import gg.essential.elementa.state.BasicState
45
import gg.essential.elementa.state.MappedState
56
import gg.essential.elementa.state.State
@@ -127,7 +128,7 @@ open class GradientComponent constructor(
127128
endColor: Color,
128129
direction: GradientDirection
129130
) {
130-
if (!URenderPipeline.isRequired) {
131+
if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) {
131132
@Suppress("DEPRECATION")
132133
return drawGradientBlockLegacy(matrixStack, x1, y1, x2, y2, startColor, endColor, direction)
133134
}

src/main/kotlin/gg/essential/elementa/components/UIBlock.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ open class UIBlock(colorConstraint: ColorConstraint = Color.WHITE.toConstraint()
5757
drawBlock(UMatrixStack(), color, x1, y1, x2, y2)
5858

5959
fun drawBlock(matrixStack: UMatrixStack, color: Color, x1: Double, y1: Double, x2: Double, y2: Double) {
60-
if (!URenderPipeline.isRequired) {
60+
if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) {
6161
@Suppress("DEPRECATION")
6262
return drawBlockLegacy(matrixStack, color, x1, y1, x2, y2)
6363
}

src/main/kotlin/gg/essential/elementa/components/UICircle.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gg.essential.elementa.components
22

3+
import gg.essential.elementa.ElementaVersion
34
import gg.essential.elementa.UIComponent
45
import gg.essential.elementa.dsl.toConstraint
56
import gg.essential.elementa.dsl.pixels
@@ -104,7 +105,7 @@ class UICircle @JvmOverloads constructor(radius: Float = 0f, color: Color = Colo
104105
drawCircle(UMatrixStack(), centerX, centerY, radius, color)
105106

106107
fun drawCircle(matrixStack: UMatrixStack, centerX: Float, centerY: Float, radius: Float, color: Color) {
107-
if (!URenderPipeline.isRequired) {
108+
if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) {
108109
@Suppress("DEPRECATION")
109110
return drawCircleLegacy(matrixStack, centerX, centerY, radius, color)
110111
}

src/main/kotlin/gg/essential/elementa/components/UIRoundedRectangle.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gg.essential.elementa.components
22

3+
import gg.essential.elementa.ElementaVersion
34
import gg.essential.elementa.UIComponent
45
import gg.essential.elementa.dsl.pixels
56
import gg.essential.elementa.utils.readElementaShaderSource
@@ -78,7 +79,7 @@ open class UIRoundedRectangle(radius: Float) : UIComponent() {
7879
* Draws a rounded rectangle
7980
*/
8081
fun drawRoundedRectangle(matrixStack: UMatrixStack, left: Float, top: Float, right: Float, bottom: Float, radius: Float, color: Color) {
81-
if (!URenderPipeline.isRequired) {
82+
if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) {
8283
@Suppress("DEPRECATION")
8384
return drawRoundedRectangleLegacy(matrixStack, left, top, right, bottom, radius, color)
8485
}

src/main/kotlin/gg/essential/elementa/components/UIShape.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gg.essential.elementa.components
22

3+
import gg.essential.elementa.ElementaVersion
34
import gg.essential.elementa.UIComponent
45
import gg.essential.elementa.dsl.toConstraint
56
import gg.essential.universal.UGraphics
@@ -44,7 +45,7 @@ open class UIShape @JvmOverloads constructor(color: Color = Color.WHITE) : UICom
4445
val color = this.getColor()
4546
if (color.alpha == 0) return super.draw(matrixStack)
4647

47-
if (URenderPipeline.isRequired) {
48+
if (URenderPipeline.isRequired || ElementaVersion.atLeastV9Active) {
4849
draw(matrixStack, color)
4950
} else {
5051
@Suppress("DEPRECATION")

src/main/kotlin/gg/essential/elementa/components/UIText.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gg.essential.elementa.components
22

3+
import gg.essential.elementa.ElementaVersion
34
import gg.essential.elementa.UIComponent
45
import gg.essential.elementa.UIConstraints
56
import gg.essential.elementa.constraints.CenterConstraint
@@ -118,7 +119,7 @@ constructor(
118119
return super.draw(matrixStack)
119120
}
120121

121-
if (!URenderPipeline.isRequired) {
122+
if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) {
122123
@Suppress("DEPRECATION")
123124
UGraphics.enableBlend()
124125
}

src/main/kotlin/gg/essential/elementa/components/UIWrappedText.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gg.essential.elementa.components
22

3+
import gg.essential.elementa.ElementaVersion
34
import gg.essential.elementa.UIComponent
45
import gg.essential.elementa.UIConstraints
56
import gg.essential.elementa.constraints.CenterConstraint
@@ -152,7 +153,7 @@ open class UIWrappedText @JvmOverloads constructor(
152153
return super.draw(matrixStack)
153154
}
154155

155-
if (!URenderPipeline.isRequired) {
156+
if (!URenderPipeline.isRequired && !ElementaVersion.atLeastV9Active) {
156157
@Suppress("DEPRECATION")
157158
UGraphics.enableBlend()
158159
}

src/main/kotlin/gg/essential/elementa/font/BasicFontRenderer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gg.essential.elementa.font
22

3+
import gg.essential.elementa.ElementaVersion
34
import gg.essential.elementa.UIComponent
45
import gg.essential.elementa.constraints.ConstraintType
56
import gg.essential.elementa.constraints.resolution.ConstraintVisitor
@@ -148,7 +149,7 @@ class BasicFontRenderer(
148149
y: Float,
149150
originalPointSize: Float
150151
) {
151-
if (URenderPipeline.isRequired) {
152+
if (URenderPipeline.isRequired || ElementaVersion.atLeastV9Active) {
152153
val bufferBuilder = UBufferBuilder.create(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_TEXTURE_COLOR)
153154
drawStringNow(bufferBuilder, matrixStack, string, color, x, y, originalPointSize)
154155
bufferBuilder.build()?.drawAndClose(PIPELINE) {

0 commit comments

Comments
 (0)