mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
gpu: [compute] add function for separating integer offsets from transforms
Refactor only; separateTransform is needed in the following change. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+11
-7
@@ -1679,18 +1679,14 @@ func encodeOp(viewport image.Point, absOff f32.Point, enc *encoder, texOps *[]te
|
|||||||
case materialTexture:
|
case materialTexture:
|
||||||
// Add fill command. Its offset is resolved and filled in renderMaterials.
|
// Add fill command. Its offset is resolved and filled in renderMaterials.
|
||||||
idx := enc.fillImage(0)
|
idx := enc.fillImage(0)
|
||||||
sx, hx, ox, hy, sy, oy := op.state.t.Elems()
|
|
||||||
ox += absOff.X
|
|
||||||
oy += absOff.Y
|
|
||||||
// Separate integer offset from transformation. TextureOps that have identical transforms
|
// Separate integer offset from transformation. TextureOps that have identical transforms
|
||||||
// except for their integer offsets can share a transformed image.
|
// except for their integer offsets can share a transformed image.
|
||||||
intx, fracx := math.Modf(float64(ox))
|
t := op.state.t.Offset(absOff)
|
||||||
inty, fracy := math.Modf(float64(oy))
|
t, off := separateTransform(t)
|
||||||
t := f32.NewAffine2D(sx, hx, float32(fracx), hy, sy, float32(fracy))
|
|
||||||
*texOps = append(*texOps, textureOp{
|
*texOps = append(*texOps, textureOp{
|
||||||
sceneIdx: idx,
|
sceneIdx: idx,
|
||||||
img: op.state.image,
|
img: op.state.image,
|
||||||
off: image.Pt(int(intx), int(inty)),
|
off: off,
|
||||||
key: textureKey{
|
key: textureKey{
|
||||||
transform: t,
|
transform: t,
|
||||||
handle: op.state.image.handle,
|
handle: op.state.image.handle,
|
||||||
@@ -1729,6 +1725,14 @@ func transformBounds(t f32.Affine2D, bounds f32.Rectangle) rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func separateTransform(t f32.Affine2D) (f32.Affine2D, image.Point) {
|
||||||
|
sx, hx, ox, hy, sy, oy := t.Elems()
|
||||||
|
intx, fracx := math.Modf(float64(ox))
|
||||||
|
inty, fracy := math.Modf(float64(oy))
|
||||||
|
t = f32.NewAffine2D(sx, hx, float32(fracx), hy, sy, float32(fracy))
|
||||||
|
return t, image.Pt(int(intx), int(inty))
|
||||||
|
}
|
||||||
|
|
||||||
func transformRect(t f32.Affine2D, r rectangle) rectangle {
|
func transformRect(t f32.Affine2D, r rectangle) rectangle {
|
||||||
var tr rectangle
|
var tr rectangle
|
||||||
for i, c := range r {
|
for i, c := range r {
|
||||||
|
|||||||
Reference in New Issue
Block a user