diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d900edda..90b1aad4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ kotlin = "1.9.25" kotlinx-coroutines = "1.5.2" jetbrains-annotations = "23.0.0" -universalcraft = "466" +universalcraft = "494" commonmark = "0.17.1" dom4j = "2.1.1" diff --git a/src/main/kotlin/gg/essential/elementa/components/UIImage.kt b/src/main/kotlin/gg/essential/elementa/components/UIImage.kt index 500cf055..a874a746 100644 --- a/src/main/kotlin/gg/essential/elementa/components/UIImage.kt +++ b/src/main/kotlin/gg/essential/elementa/components/UIImage.kt @@ -7,6 +7,7 @@ import gg.essential.elementa.utils.ResourceCache import gg.essential.elementa.utils.drawTexture import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack +import gg.essential.universal.render.UGpuSampler import gg.essential.universal.utils.ReleasedDynamicTexture import org.lwjgl.opengl.GL11 import java.awt.Color @@ -77,7 +78,7 @@ open class UIImage @JvmOverloads constructor( override fun drawImage(matrixStack: UMatrixStack, x: Double, y: Double, width: Double, height: Double, color: Color) { when { - texture != null -> drawTexture(matrixStack, texture!!, color, x, y, width, height, textureMinFilter.glMode, textureMagFilter.glMode) + texture != null -> drawTexture(matrixStack, texture!!, color, x, y, width, height, textureMinFilter, textureMagFilter) imageFuture.isCompletedExceptionally -> failureImage.drawImageCompat(matrixStack, x, y, width, height, color) else -> loadingImage.drawImageCompat(matrixStack, x, y, width, height, color) } @@ -115,13 +116,13 @@ open class UIImage @JvmOverloads constructor( waiting.poll().applyTexture(texture) } - enum class TextureScalingMode(internal val glMode: Int) { - NEAREST(GL11.GL_NEAREST), - LINEAR(GL11.GL_LINEAR), - NEAREST_MIPMAP_NEAREST(GL11.GL_NEAREST_MIPMAP_NEAREST), - LINEAR_MIPMAP_NEAREST(GL11.GL_LINEAR_MIPMAP_NEAREST), - NEAREST_MIPMAP_LINEAR(GL11.GL_NEAREST_MIPMAP_LINEAR), - LINEAR_MIPMAP_LINEAR(GL11.GL_LINEAR_MIPMAP_LINEAR) + enum class TextureScalingMode(internal val glMode: Int, internal val ucMode: UGpuSampler.FilterMode, internal val useMipmaps: Boolean) { + NEAREST(GL11.GL_NEAREST, UGpuSampler.FilterMode.NEAREST, false), + LINEAR(GL11.GL_LINEAR, UGpuSampler.FilterMode.LINEAR, false), + NEAREST_MIPMAP_NEAREST(GL11.GL_NEAREST_MIPMAP_NEAREST, UGpuSampler.FilterMode.NEAREST, true), + LINEAR_MIPMAP_NEAREST(GL11.GL_LINEAR_MIPMAP_NEAREST, UGpuSampler.FilterMode.LINEAR, true), + NEAREST_MIPMAP_LINEAR(GL11.GL_NEAREST_MIPMAP_LINEAR, UGpuSampler.FilterMode.NEAREST, true), + LINEAR_MIPMAP_LINEAR(GL11.GL_LINEAR_MIPMAP_LINEAR, UGpuSampler.FilterMode.LINEAR, true) } companion object { diff --git a/src/main/kotlin/gg/essential/elementa/components/image/DefaultFailureImage.kt b/src/main/kotlin/gg/essential/elementa/components/image/DefaultFailureImage.kt index c2d849e8..a6f65110 100644 --- a/src/main/kotlin/gg/essential/elementa/components/image/DefaultFailureImage.kt +++ b/src/main/kotlin/gg/essential/elementa/components/image/DefaultFailureImage.kt @@ -1,10 +1,10 @@ package gg.essential.elementa.components.image +import gg.essential.elementa.components.UIImage import gg.essential.elementa.utils.drawTexture import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack import gg.essential.universal.utils.ReleasedDynamicTexture -import org.lwjgl.opengl.GL11 import java.awt.Color import java.awt.image.BufferedImage import javax.imageio.ImageIO @@ -35,8 +35,8 @@ object DefaultFailureImage : ImageProvider { y, width, height, - textureMinFilter = GL11.GL_LINEAR, - textureMagFilter = GL11.GL_LINEAR, + textureMinFilter = UIImage.TextureScalingMode.LINEAR, + textureMagFilter = UIImage.TextureScalingMode.LINEAR, ) } } diff --git a/src/main/kotlin/gg/essential/elementa/components/image/DefaultLoadingImage.kt b/src/main/kotlin/gg/essential/elementa/components/image/DefaultLoadingImage.kt index c0e64420..6cacb376 100644 --- a/src/main/kotlin/gg/essential/elementa/components/image/DefaultLoadingImage.kt +++ b/src/main/kotlin/gg/essential/elementa/components/image/DefaultLoadingImage.kt @@ -1,10 +1,10 @@ package gg.essential.elementa.components.image +import gg.essential.elementa.components.UIImage import gg.essential.elementa.utils.drawTexture import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack import gg.essential.universal.utils.ReleasedDynamicTexture -import org.lwjgl.opengl.GL11 import java.awt.Color import java.awt.image.BufferedImage import javax.imageio.ImageIO @@ -34,8 +34,8 @@ object DefaultLoadingImage : ImageProvider { y, width, height, - textureMinFilter = GL11.GL_LINEAR, - textureMagFilter = GL11.GL_LINEAR, + textureMinFilter = UIImage.TextureScalingMode.LINEAR, + textureMagFilter = UIImage.TextureScalingMode.LINEAR, ) } } diff --git a/src/main/kotlin/gg/essential/elementa/utils/image.kt b/src/main/kotlin/gg/essential/elementa/utils/image.kt index 20bdf693..89cbf712 100644 --- a/src/main/kotlin/gg/essential/elementa/utils/image.kt +++ b/src/main/kotlin/gg/essential/elementa/utils/image.kt @@ -1,8 +1,10 @@ package gg.essential.elementa.utils import gg.essential.elementa.ElementaVersion +import gg.essential.elementa.components.UIImage import gg.essential.universal.UGraphics import gg.essential.universal.UMatrixStack +import gg.essential.universal.render.UGpuSampler import gg.essential.universal.render.URenderPipeline import gg.essential.universal.shader.BlendState import gg.essential.universal.utils.ReleasedDynamicTexture @@ -24,21 +26,16 @@ internal fun drawTexture( y: Double, width: Double, height: Double, - textureMinFilter: Int = GL11.GL_NEAREST, - textureMagFilter: Int = GL11.GL_NEAREST + textureMinFilter: UIImage.TextureScalingMode = UIImage.TextureScalingMode.NEAREST, + textureMagFilter: UIImage.TextureScalingMode = UIImage.TextureScalingMode.NEAREST, ) { matrixStack.push() matrixStack.scale(1f, 1f, 50f) - val glId = texture.dynamicGlId val red = color.red.toFloat() / 255f val green = color.green.toFloat() / 255f val blue = color.blue.toFloat() / 255f val alpha = color.alpha.toFloat() / 255f - UGraphics.configureTexture(glId) { - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, textureMinFilter) - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, textureMagFilter) - } fun drawTexturedQuad(vertexConsumer: UVertexConsumer) { vertexConsumer.pos(matrixStack, x, y + height, 0.0).tex(0.0, 1.0).color(red, green, blue, alpha).endVertex() @@ -48,12 +45,24 @@ internal fun drawTexture( } if (URenderPipeline.isRequired || ElementaVersion.atLeastV9Active) { + val gpuTextureView = texture.gpuTextureView val bufferBuilder = UBufferBuilder.create(UGraphics.DrawMode.QUADS, UGraphics.CommonVertexFormats.POSITION_TEXTURE_COLOR) drawTexturedQuad(bufferBuilder) bufferBuilder.build()?.drawAndClose(if (ElementaVersion.atLeastV10Active) TEXTURED_QUAD_PIPELINE2 else TEXTURED_QUAD_PIPELINE) { - texture(0, glId) + texture(0, gpuTextureView, UGpuSampler( + UGpuSampler.AddressMode.CLAMP_TO_EDGE, + UGpuSampler.AddressMode.CLAMP_TO_EDGE, + textureMinFilter.ucMode, + textureMagFilter.ucMode, + textureMinFilter.useMipmaps, + )) } } else { + val glId = texture.dynamicGlId + UGraphics.configureTexture(glId) { + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, textureMinFilter.glMode) + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, textureMagFilter.glMode) + } @Suppress("DEPRECATION") UGraphics.enableBlend() UGraphics.enableAlpha()