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:
Elias Naur
2021-07-19 14:26:11 +02:00
parent e6c31a02fd
commit 318ddd0644
+11 -7
View File
@@ -1679,18 +1679,14 @@ func encodeOp(viewport image.Point, absOff f32.Point, enc *encoder, texOps *[]te
case materialTexture:
// Add fill command. Its offset is resolved and filled in renderMaterials.
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
// except for their integer offsets can share a transformed image.
intx, fracx := math.Modf(float64(ox))
inty, fracy := math.Modf(float64(oy))
t := f32.NewAffine2D(sx, hx, float32(fracx), hy, sy, float32(fracy))
t := op.state.t.Offset(absOff)
t, off := separateTransform(t)
*texOps = append(*texOps, textureOp{
sceneIdx: idx,
img: op.state.image,
off: image.Pt(int(intx), int(inty)),
off: off,
key: textureKey{
transform: t,
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 {
var tr rectangle
for i, c := range r {