1package vulkan
2
3import (
4 "image"
5
6 "github.com/bnema/neferwl/internal/ports"
7)
8
9// sceneSize is the size of a scene in scene-physical pixels: the target's,
10// swapped when the output transform t rotates by 90 or 270 degrees.
11func (r *Renderer) sceneSize(t ports.BufferTransform) (int, int) {
12 return t.Size(r.width, r.height)
13}
14
15// orient maps draws built in scene space to the target, in place and without
16// allocating: the target holds the scene transformed by t, like a client
17// buffer holds its surface under wl_surface.set_buffer_transform. Each rect
18// goes through t.RectToBuffer (integer rects stay integer under these eight
19// isometries, so the rounding is exact) and each source map is composed with
20// the affine target-to-scene map, the inverse transform. The vertex shader's
21// target size (misc[2:4]) stays the target's.
22//
23// Pixel centres map to pixel centres under these isometries, so a draw
24// flagged flagExact still reads texelFetch(floor(src)) on the right texel.
25//
26// It runs once per frame, after damage clipping, and before any consumer of
27// the target: HDR composition (hdrOwn is target-sized and recordHDR reads the
28// already-oriented target) and the capture and Pixels paths stay unchanged.
29func (r *Renderer) orient(ds []draw, t ports.BufferTransform) {
30 if t == 0 {
31 return
32 }
33 sw, sh := r.sceneSize(t)
34 inv := t.Invert()
35 tw, th := float64(r.width), float64(r.height)
36 // scene = f0 + x*fx + y*fy for a target point (x, y).
37 f0x, f0y := inv.ToBuffer(0, 0, tw, th)
38 fxx, fxy := inv.ToBuffer(1, 0, tw, th)
39 fyx, fyy := inv.ToBuffer(0, 1, tw, th)
40 fxx, fxy = fxx-f0x, fxy-f0y
41 fyx, fyy = fyx-f0x, fyy-f0y
42 for i := range ds {
43 pc := &ds[i].pc
44 rect := t.RectToBuffer(image.Rect(int(pc.rect[0]), int(pc.rect[1]), int(pc.rect[2]), int(pc.rect[3])), sw, sh)
45 pc.rect = [4]int32{int32(rect.Min.X), int32(rect.Min.Y), int32(rect.Max.X), int32(rect.Max.Y)}
46 if pc.misc[0] == modeSolid {
47 continue
48 }
49 m0x, m0y := float64(pc.mapv[0]), float64(pc.mapv[1])
50 mxx, mxy := float64(pc.mapv[2]), float64(pc.mapv[3])
51 myx, myy := float64(pc.mapy[0]), float64(pc.mapy[1])
52 pc.mapv = [4]float32{
53 float32(m0x + f0x*mxx + f0y*myx),
54 float32(m0y + f0x*mxy + f0y*myy),
55 float32(fxx*mxx + fxy*myx),
56 float32(fxx*mxy + fxy*myy),
57 }
58 pc.mapy[0] = float32(fyx*mxx + fyy*myx)
59 pc.mapy[1] = float32(fyx*mxy + fyy*myy)
60 }
61}