Pixel-perfect rendering, 2024 take

This commit is contained in:
Fingercomp 2024-08-26 19:42:44 +07:00
parent 811d8e0a09
commit 27f7db8b46
No known key found for this signature in database
GPG Key ID: BBC71CEE45D86E37

View File

@ -133,7 +133,7 @@ class Graphics(private var width: Int, private var height: Int, private var scal
currentFramebuffer = 0
foreground = RGBAColorNorm(1, 1, 1, alpha)
spriteRect = Rect2D(0, 1f, 1f, -1f)
_rect(0, 0, width / scalingFactor, height / scalingFactor, fixUV = false)
_rect(0, 0, width / scalingFactor, height / scalingFactor)
flush(mainTexture = offscreenTexture)
}
@ -141,7 +141,7 @@ class Graphics(private var width: Int, private var height: Int, private var scal
flush()
foreground = RGBAColorNorm(1, 1, 1, alpha)
spriteRect = Rect2D(0, 1f, 1f, -1f)
_rect(bounds.x, bounds.y, bounds.w, bounds.h, fixUV = false)
_rect(bounds.x, bounds.y, bounds.w, bounds.h)
flush(mainTexture = viewport.textureColor)
}
@ -149,7 +149,7 @@ class Graphics(private var width: Int, private var height: Int, private var scal
flush()
foreground = RGBAColorNorm(1, 1, 1, alpha)
spriteRect = Rect2D(0, 1f, 1f, -1f)
_rect(bounds.x, bounds.y, bounds.w, bounds.h, fixUV = false)
_rect(bounds.x, bounds.y, bounds.w, bounds.h)
flush(mainTexture = viewport.texture)
}
@ -302,7 +302,7 @@ class Graphics(private var width: Int, private var height: Int, private var scal
{
sprite = name
foreground = color
_rect(x, y, width, height, fixUV = true, animation)
_rect(x, y, width, height, animation)
}
def rect(r: Rect2D, color: Color): Unit = {
@ -324,7 +324,6 @@ class Graphics(private var width: Int, private var height: Int, private var scal
}
private def _rect(x: Float, y: Float, width: Float, height: Float,
fixUV: Boolean = true,
animation: Option[Animation] = None): Unit = {
val spriteRect = animation match {
case None => this.spriteRect
@ -348,11 +347,9 @@ class Graphics(private var width: Int, private var height: Int, private var scal
this.spriteRect.copy(y = this.spriteRect.y + curFrame * size.height, h = size.height)
}
val uvTransform = Transform2D.translate(spriteRect.x, spriteRect.y) >>
(if (fixUV)
Transform2D.scale(spriteRect.w - 0.25f / 1024, spriteRect.h - 0.25f / 1024)
else
Transform2D.scale(spriteRect.w, spriteRect.h))
val uvTransform =
Transform2D.translate(spriteRect.x, spriteRect.y) >>
Transform2D.scale(spriteRect.w, spriteRect.h)
val transform =
stack.head.transform >>