mirror of
https://github.com/italicsjenga/vello.git
synced 2024-10-17 23:11:30 +11:00
f53d00e6bc
Actually handle transforms in RenderCtx (was implemented in renderer but not actually plumbed through). This also requires maintaining a state stack, which will also be required for clipping. This PR also starts work on encoding clipping, including tracking bounding boxes. WIP, none of this is tested yet.
522 lines
12 KiB
C
522 lines
12 KiB
C
// Code auto-generated by piet-gpu-derive
|
|
|
|
struct CmdCircleRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdLineRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdStrokeRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdFillRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdFillMaskRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdBeginClipRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdEndClipRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdSolidRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdSolidMaskRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdJumpRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct SegmentRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct SegChunkRef {
|
|
uint offset;
|
|
};
|
|
|
|
struct CmdCircle {
|
|
vec2 center;
|
|
float radius;
|
|
uint rgba_color;
|
|
};
|
|
|
|
#define CmdCircle_size 16
|
|
|
|
CmdCircleRef CmdCircle_index(CmdCircleRef ref, uint index) {
|
|
return CmdCircleRef(ref.offset + index * CmdCircle_size);
|
|
}
|
|
|
|
struct CmdLine {
|
|
vec2 start;
|
|
vec2 end;
|
|
};
|
|
|
|
#define CmdLine_size 16
|
|
|
|
CmdLineRef CmdLine_index(CmdLineRef ref, uint index) {
|
|
return CmdLineRef(ref.offset + index * CmdLine_size);
|
|
}
|
|
|
|
struct CmdStroke {
|
|
uint tile_ref;
|
|
float half_width;
|
|
uint rgba_color;
|
|
};
|
|
|
|
#define CmdStroke_size 12
|
|
|
|
CmdStrokeRef CmdStroke_index(CmdStrokeRef ref, uint index) {
|
|
return CmdStrokeRef(ref.offset + index * CmdStroke_size);
|
|
}
|
|
|
|
struct CmdFill {
|
|
uint tile_ref;
|
|
int backdrop;
|
|
uint rgba_color;
|
|
};
|
|
|
|
#define CmdFill_size 12
|
|
|
|
CmdFillRef CmdFill_index(CmdFillRef ref, uint index) {
|
|
return CmdFillRef(ref.offset + index * CmdFill_size);
|
|
}
|
|
|
|
struct CmdFillMask {
|
|
uint tile_ref;
|
|
int backdrop;
|
|
float mask;
|
|
};
|
|
|
|
#define CmdFillMask_size 12
|
|
|
|
CmdFillMaskRef CmdFillMask_index(CmdFillMaskRef ref, uint index) {
|
|
return CmdFillMaskRef(ref.offset + index * CmdFillMask_size);
|
|
}
|
|
|
|
struct CmdBeginClip {
|
|
uint tile_ref;
|
|
int backdrop;
|
|
};
|
|
|
|
#define CmdBeginClip_size 8
|
|
|
|
CmdBeginClipRef CmdBeginClip_index(CmdBeginClipRef ref, uint index) {
|
|
return CmdBeginClipRef(ref.offset + index * CmdBeginClip_size);
|
|
}
|
|
|
|
struct CmdEndClip {
|
|
float alpha;
|
|
};
|
|
|
|
#define CmdEndClip_size 4
|
|
|
|
CmdEndClipRef CmdEndClip_index(CmdEndClipRef ref, uint index) {
|
|
return CmdEndClipRef(ref.offset + index * CmdEndClip_size);
|
|
}
|
|
|
|
struct CmdSolid {
|
|
uint rgba_color;
|
|
};
|
|
|
|
#define CmdSolid_size 4
|
|
|
|
CmdSolidRef CmdSolid_index(CmdSolidRef ref, uint index) {
|
|
return CmdSolidRef(ref.offset + index * CmdSolid_size);
|
|
}
|
|
|
|
struct CmdSolidMask {
|
|
float mask;
|
|
};
|
|
|
|
#define CmdSolidMask_size 4
|
|
|
|
CmdSolidMaskRef CmdSolidMask_index(CmdSolidMaskRef ref, uint index) {
|
|
return CmdSolidMaskRef(ref.offset + index * CmdSolidMask_size);
|
|
}
|
|
|
|
struct CmdJump {
|
|
uint new_ref;
|
|
};
|
|
|
|
#define CmdJump_size 4
|
|
|
|
CmdJumpRef CmdJump_index(CmdJumpRef ref, uint index) {
|
|
return CmdJumpRef(ref.offset + index * CmdJump_size);
|
|
}
|
|
|
|
#define Cmd_End 0
|
|
#define Cmd_Circle 1
|
|
#define Cmd_Line 2
|
|
#define Cmd_Fill 3
|
|
#define Cmd_FillMask 4
|
|
#define Cmd_FillMaskInv 5
|
|
#define Cmd_BeginClip 6
|
|
#define Cmd_EndClip 7
|
|
#define Cmd_Stroke 8
|
|
#define Cmd_Solid 9
|
|
#define Cmd_SolidMask 10
|
|
#define Cmd_Jump 11
|
|
#define Cmd_size 20
|
|
|
|
CmdRef Cmd_index(CmdRef ref, uint index) {
|
|
return CmdRef(ref.offset + index * Cmd_size);
|
|
}
|
|
|
|
struct Segment {
|
|
vec2 start;
|
|
vec2 end;
|
|
float y_edge;
|
|
};
|
|
|
|
#define Segment_size 20
|
|
|
|
SegmentRef Segment_index(SegmentRef ref, uint index) {
|
|
return SegmentRef(ref.offset + index * Segment_size);
|
|
}
|
|
|
|
struct SegChunk {
|
|
uint n;
|
|
SegChunkRef next;
|
|
SegmentRef segs;
|
|
};
|
|
|
|
#define SegChunk_size 12
|
|
|
|
SegChunkRef SegChunk_index(SegChunkRef ref, uint index) {
|
|
return SegChunkRef(ref.offset + index * SegChunk_size);
|
|
}
|
|
|
|
CmdCircle CmdCircle_read(CmdCircleRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
uint raw1 = ptcl[ix + 1];
|
|
uint raw2 = ptcl[ix + 2];
|
|
uint raw3 = ptcl[ix + 3];
|
|
CmdCircle s;
|
|
s.center = vec2(uintBitsToFloat(raw0), uintBitsToFloat(raw1));
|
|
s.radius = uintBitsToFloat(raw2);
|
|
s.rgba_color = raw3;
|
|
return s;
|
|
}
|
|
|
|
void CmdCircle_write(CmdCircleRef ref, CmdCircle s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = floatBitsToUint(s.center.x);
|
|
ptcl[ix + 1] = floatBitsToUint(s.center.y);
|
|
ptcl[ix + 2] = floatBitsToUint(s.radius);
|
|
ptcl[ix + 3] = s.rgba_color;
|
|
}
|
|
|
|
CmdLine CmdLine_read(CmdLineRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
uint raw1 = ptcl[ix + 1];
|
|
uint raw2 = ptcl[ix + 2];
|
|
uint raw3 = ptcl[ix + 3];
|
|
CmdLine s;
|
|
s.start = vec2(uintBitsToFloat(raw0), uintBitsToFloat(raw1));
|
|
s.end = vec2(uintBitsToFloat(raw2), uintBitsToFloat(raw3));
|
|
return s;
|
|
}
|
|
|
|
void CmdLine_write(CmdLineRef ref, CmdLine s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = floatBitsToUint(s.start.x);
|
|
ptcl[ix + 1] = floatBitsToUint(s.start.y);
|
|
ptcl[ix + 2] = floatBitsToUint(s.end.x);
|
|
ptcl[ix + 3] = floatBitsToUint(s.end.y);
|
|
}
|
|
|
|
CmdStroke CmdStroke_read(CmdStrokeRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
uint raw1 = ptcl[ix + 1];
|
|
uint raw2 = ptcl[ix + 2];
|
|
CmdStroke s;
|
|
s.tile_ref = raw0;
|
|
s.half_width = uintBitsToFloat(raw1);
|
|
s.rgba_color = raw2;
|
|
return s;
|
|
}
|
|
|
|
void CmdStroke_write(CmdStrokeRef ref, CmdStroke s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = s.tile_ref;
|
|
ptcl[ix + 1] = floatBitsToUint(s.half_width);
|
|
ptcl[ix + 2] = s.rgba_color;
|
|
}
|
|
|
|
CmdFill CmdFill_read(CmdFillRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
uint raw1 = ptcl[ix + 1];
|
|
uint raw2 = ptcl[ix + 2];
|
|
CmdFill s;
|
|
s.tile_ref = raw0;
|
|
s.backdrop = int(raw1);
|
|
s.rgba_color = raw2;
|
|
return s;
|
|
}
|
|
|
|
void CmdFill_write(CmdFillRef ref, CmdFill s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = s.tile_ref;
|
|
ptcl[ix + 1] = uint(s.backdrop);
|
|
ptcl[ix + 2] = s.rgba_color;
|
|
}
|
|
|
|
CmdFillMask CmdFillMask_read(CmdFillMaskRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
uint raw1 = ptcl[ix + 1];
|
|
uint raw2 = ptcl[ix + 2];
|
|
CmdFillMask s;
|
|
s.tile_ref = raw0;
|
|
s.backdrop = int(raw1);
|
|
s.mask = uintBitsToFloat(raw2);
|
|
return s;
|
|
}
|
|
|
|
void CmdFillMask_write(CmdFillMaskRef ref, CmdFillMask s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = s.tile_ref;
|
|
ptcl[ix + 1] = uint(s.backdrop);
|
|
ptcl[ix + 2] = floatBitsToUint(s.mask);
|
|
}
|
|
|
|
CmdBeginClip CmdBeginClip_read(CmdBeginClipRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
uint raw1 = ptcl[ix + 1];
|
|
CmdBeginClip s;
|
|
s.tile_ref = raw0;
|
|
s.backdrop = int(raw1);
|
|
return s;
|
|
}
|
|
|
|
void CmdBeginClip_write(CmdBeginClipRef ref, CmdBeginClip s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = s.tile_ref;
|
|
ptcl[ix + 1] = uint(s.backdrop);
|
|
}
|
|
|
|
CmdEndClip CmdEndClip_read(CmdEndClipRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
CmdEndClip s;
|
|
s.alpha = uintBitsToFloat(raw0);
|
|
return s;
|
|
}
|
|
|
|
void CmdEndClip_write(CmdEndClipRef ref, CmdEndClip s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = floatBitsToUint(s.alpha);
|
|
}
|
|
|
|
CmdSolid CmdSolid_read(CmdSolidRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
CmdSolid s;
|
|
s.rgba_color = raw0;
|
|
return s;
|
|
}
|
|
|
|
void CmdSolid_write(CmdSolidRef ref, CmdSolid s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = s.rgba_color;
|
|
}
|
|
|
|
CmdSolidMask CmdSolidMask_read(CmdSolidMaskRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
CmdSolidMask s;
|
|
s.mask = uintBitsToFloat(raw0);
|
|
return s;
|
|
}
|
|
|
|
void CmdSolidMask_write(CmdSolidMaskRef ref, CmdSolidMask s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = floatBitsToUint(s.mask);
|
|
}
|
|
|
|
CmdJump CmdJump_read(CmdJumpRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
CmdJump s;
|
|
s.new_ref = raw0;
|
|
return s;
|
|
}
|
|
|
|
void CmdJump_write(CmdJumpRef ref, CmdJump s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = s.new_ref;
|
|
}
|
|
|
|
uint Cmd_tag(CmdRef ref) {
|
|
return ptcl[ref.offset >> 2];
|
|
}
|
|
|
|
CmdCircle Cmd_Circle_read(CmdRef ref) {
|
|
return CmdCircle_read(CmdCircleRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdLine Cmd_Line_read(CmdRef ref) {
|
|
return CmdLine_read(CmdLineRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdFill Cmd_Fill_read(CmdRef ref) {
|
|
return CmdFill_read(CmdFillRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdFillMask Cmd_FillMask_read(CmdRef ref) {
|
|
return CmdFillMask_read(CmdFillMaskRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdFillMask Cmd_FillMaskInv_read(CmdRef ref) {
|
|
return CmdFillMask_read(CmdFillMaskRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdBeginClip Cmd_BeginClip_read(CmdRef ref) {
|
|
return CmdBeginClip_read(CmdBeginClipRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdEndClip Cmd_EndClip_read(CmdRef ref) {
|
|
return CmdEndClip_read(CmdEndClipRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdStroke Cmd_Stroke_read(CmdRef ref) {
|
|
return CmdStroke_read(CmdStrokeRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdSolid Cmd_Solid_read(CmdRef ref) {
|
|
return CmdSolid_read(CmdSolidRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdSolidMask Cmd_SolidMask_read(CmdRef ref) {
|
|
return CmdSolidMask_read(CmdSolidMaskRef(ref.offset + 4));
|
|
}
|
|
|
|
CmdJump Cmd_Jump_read(CmdRef ref) {
|
|
return CmdJump_read(CmdJumpRef(ref.offset + 4));
|
|
}
|
|
|
|
void Cmd_End_write(CmdRef ref) {
|
|
ptcl[ref.offset >> 2] = Cmd_End;
|
|
}
|
|
|
|
void Cmd_Circle_write(CmdRef ref, CmdCircle s) {
|
|
ptcl[ref.offset >> 2] = Cmd_Circle;
|
|
CmdCircle_write(CmdCircleRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_Line_write(CmdRef ref, CmdLine s) {
|
|
ptcl[ref.offset >> 2] = Cmd_Line;
|
|
CmdLine_write(CmdLineRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_Fill_write(CmdRef ref, CmdFill s) {
|
|
ptcl[ref.offset >> 2] = Cmd_Fill;
|
|
CmdFill_write(CmdFillRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_FillMask_write(CmdRef ref, CmdFillMask s) {
|
|
ptcl[ref.offset >> 2] = Cmd_FillMask;
|
|
CmdFillMask_write(CmdFillMaskRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_FillMaskInv_write(CmdRef ref, CmdFillMask s) {
|
|
ptcl[ref.offset >> 2] = Cmd_FillMaskInv;
|
|
CmdFillMask_write(CmdFillMaskRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_BeginClip_write(CmdRef ref, CmdBeginClip s) {
|
|
ptcl[ref.offset >> 2] = Cmd_BeginClip;
|
|
CmdBeginClip_write(CmdBeginClipRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_EndClip_write(CmdRef ref, CmdEndClip s) {
|
|
ptcl[ref.offset >> 2] = Cmd_EndClip;
|
|
CmdEndClip_write(CmdEndClipRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_Stroke_write(CmdRef ref, CmdStroke s) {
|
|
ptcl[ref.offset >> 2] = Cmd_Stroke;
|
|
CmdStroke_write(CmdStrokeRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_Solid_write(CmdRef ref, CmdSolid s) {
|
|
ptcl[ref.offset >> 2] = Cmd_Solid;
|
|
CmdSolid_write(CmdSolidRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_SolidMask_write(CmdRef ref, CmdSolidMask s) {
|
|
ptcl[ref.offset >> 2] = Cmd_SolidMask;
|
|
CmdSolidMask_write(CmdSolidMaskRef(ref.offset + 4), s);
|
|
}
|
|
|
|
void Cmd_Jump_write(CmdRef ref, CmdJump s) {
|
|
ptcl[ref.offset >> 2] = Cmd_Jump;
|
|
CmdJump_write(CmdJumpRef(ref.offset + 4), s);
|
|
}
|
|
|
|
Segment Segment_read(SegmentRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
uint raw1 = ptcl[ix + 1];
|
|
uint raw2 = ptcl[ix + 2];
|
|
uint raw3 = ptcl[ix + 3];
|
|
uint raw4 = ptcl[ix + 4];
|
|
Segment s;
|
|
s.start = vec2(uintBitsToFloat(raw0), uintBitsToFloat(raw1));
|
|
s.end = vec2(uintBitsToFloat(raw2), uintBitsToFloat(raw3));
|
|
s.y_edge = uintBitsToFloat(raw4);
|
|
return s;
|
|
}
|
|
|
|
void Segment_write(SegmentRef ref, Segment s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = floatBitsToUint(s.start.x);
|
|
ptcl[ix + 1] = floatBitsToUint(s.start.y);
|
|
ptcl[ix + 2] = floatBitsToUint(s.end.x);
|
|
ptcl[ix + 3] = floatBitsToUint(s.end.y);
|
|
ptcl[ix + 4] = floatBitsToUint(s.y_edge);
|
|
}
|
|
|
|
SegChunk SegChunk_read(SegChunkRef ref) {
|
|
uint ix = ref.offset >> 2;
|
|
uint raw0 = ptcl[ix + 0];
|
|
uint raw1 = ptcl[ix + 1];
|
|
uint raw2 = ptcl[ix + 2];
|
|
SegChunk s;
|
|
s.n = raw0;
|
|
s.next = SegChunkRef(raw1);
|
|
s.segs = SegmentRef(raw2);
|
|
return s;
|
|
}
|
|
|
|
void SegChunk_write(SegChunkRef ref, SegChunk s) {
|
|
uint ix = ref.offset >> 2;
|
|
ptcl[ix + 0] = s.n;
|
|
ptcl[ix + 1] = s.next.offset;
|
|
ptcl[ix + 2] = s.segs.offset;
|
|
}
|
|
|