mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
gpu, io/router, op: use f32.Affine2D instead of op.TransformOp for transforms
Encode TransformOp as an Affince2D matrix instead and use that in gpu and io transform handling. There are no changes to user facing API and so far only the offset part of the matrix is used. This patch is a step towards full affine transformations. Signed-off-by: Viktor <viktor.ogeman@gmail.com>
This commit is contained in:
+16
-7
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/opconst"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
const QuadSize = 4 * 2 * 3
|
||||
@@ -38,13 +37,23 @@ func DecodeQuad(d []byte) (q Quad) {
|
||||
return
|
||||
}
|
||||
|
||||
func DecodeTransformOp(d []byte) op.TransformOp {
|
||||
bo := binary.LittleEndian
|
||||
func DecodeTransform(d []byte) (t f32.Affine2D) {
|
||||
if opconst.OpType(d[0]) != opconst.TypeTransform {
|
||||
panic("invalid op")
|
||||
}
|
||||
return op.TransformOp{}.Offset(f32.Point{
|
||||
X: math.Float32frombits(bo.Uint32(d[1:])),
|
||||
Y: math.Float32frombits(bo.Uint32(d[5:])),
|
||||
})
|
||||
if len(d) < 1+6*4 {
|
||||
panic("too short buffer")
|
||||
}
|
||||
return decodeAffine2D(d[1:])
|
||||
}
|
||||
|
||||
func decodeAffine2D(data []byte) f32.Affine2D {
|
||||
bo := binary.LittleEndian
|
||||
a := math.Float32frombits(bo.Uint32(data))
|
||||
b := math.Float32frombits(bo.Uint32(data[4*1:]))
|
||||
c := math.Float32frombits(bo.Uint32(data[4*2:]))
|
||||
d := math.Float32frombits(bo.Uint32(data[4*3:]))
|
||||
e := math.Float32frombits(bo.Uint32(data[4*4:]))
|
||||
f := math.Float32frombits(bo.Uint32(data[4*5:]))
|
||||
return f32.NewAffine2D(a, b, c, d, e, f)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user