Skip to content
Merged
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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
17 changes: 9 additions & 8 deletions src/main/kotlin/gg/essential/elementa/components/UIImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
)
}
}
25 changes: 17 additions & 8 deletions src/main/kotlin/gg/essential/elementa/utils/image.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Loading