github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/gpu/shaders/scene.h (about) 1 // SPDX-License-Identifier: Apache-2.0 OR MIT OR Unlicense 2 3 // Code auto-generated by piet-gpu-derive 4 5 struct LineSegRef { 6 uint offset; 7 }; 8 9 struct QuadSegRef { 10 uint offset; 11 }; 12 13 struct CubicSegRef { 14 uint offset; 15 }; 16 17 struct FillColorRef { 18 uint offset; 19 }; 20 21 struct FillImageRef { 22 uint offset; 23 }; 24 25 struct SetLineWidthRef { 26 uint offset; 27 }; 28 29 struct TransformRef { 30 uint offset; 31 }; 32 33 struct ClipRef { 34 uint offset; 35 }; 36 37 struct SetFillModeRef { 38 uint offset; 39 }; 40 41 struct ElementRef { 42 uint offset; 43 }; 44 45 struct LineSeg { 46 vec2 p0; 47 vec2 p1; 48 }; 49 50 #define LineSeg_size 16 51 52 LineSegRef LineSeg_index(LineSegRef ref, uint index) { 53 return LineSegRef(ref.offset + index * LineSeg_size); 54 } 55 56 struct QuadSeg { 57 vec2 p0; 58 vec2 p1; 59 vec2 p2; 60 }; 61 62 #define QuadSeg_size 24 63 64 QuadSegRef QuadSeg_index(QuadSegRef ref, uint index) { 65 return QuadSegRef(ref.offset + index * QuadSeg_size); 66 } 67 68 struct CubicSeg { 69 vec2 p0; 70 vec2 p1; 71 vec2 p2; 72 vec2 p3; 73 }; 74 75 #define CubicSeg_size 32 76 77 CubicSegRef CubicSeg_index(CubicSegRef ref, uint index) { 78 return CubicSegRef(ref.offset + index * CubicSeg_size); 79 } 80 81 struct FillColor { 82 uint rgba_color; 83 }; 84 85 #define FillColor_size 4 86 87 FillColorRef FillColor_index(FillColorRef ref, uint index) { 88 return FillColorRef(ref.offset + index * FillColor_size); 89 } 90 91 struct FillImage { 92 uint index; 93 ivec2 offset; 94 }; 95 96 #define FillImage_size 8 97 98 FillImageRef FillImage_index(FillImageRef ref, uint index) { 99 return FillImageRef(ref.offset + index * FillImage_size); 100 } 101 102 struct SetLineWidth { 103 float width; 104 }; 105 106 #define SetLineWidth_size 4 107 108 SetLineWidthRef SetLineWidth_index(SetLineWidthRef ref, uint index) { 109 return SetLineWidthRef(ref.offset + index * SetLineWidth_size); 110 } 111 112 struct Transform { 113 vec4 mat; 114 vec2 translate; 115 }; 116 117 #define Transform_size 24 118 119 TransformRef Transform_index(TransformRef ref, uint index) { 120 return TransformRef(ref.offset + index * Transform_size); 121 } 122 123 struct Clip { 124 vec4 bbox; 125 }; 126 127 #define Clip_size 16 128 129 ClipRef Clip_index(ClipRef ref, uint index) { 130 return ClipRef(ref.offset + index * Clip_size); 131 } 132 133 struct SetFillMode { 134 uint fill_mode; 135 }; 136 137 #define SetFillMode_size 4 138 139 SetFillModeRef SetFillMode_index(SetFillModeRef ref, uint index) { 140 return SetFillModeRef(ref.offset + index * SetFillMode_size); 141 } 142 143 #define Element_Nop 0 144 #define Element_Line 1 145 #define Element_Quad 2 146 #define Element_Cubic 3 147 #define Element_FillColor 4 148 #define Element_SetLineWidth 5 149 #define Element_Transform 6 150 #define Element_BeginClip 7 151 #define Element_EndClip 8 152 #define Element_FillImage 9 153 #define Element_SetFillMode 10 154 #define Element_size 36 155 156 ElementRef Element_index(ElementRef ref, uint index) { 157 return ElementRef(ref.offset + index * Element_size); 158 } 159 160 struct ElementTag { 161 uint tag; 162 uint flags; 163 }; 164 165 LineSeg LineSeg_read(LineSegRef ref) { 166 uint ix = ref.offset >> 2; 167 uint raw0 = scene[ix + 0]; 168 uint raw1 = scene[ix + 1]; 169 uint raw2 = scene[ix + 2]; 170 uint raw3 = scene[ix + 3]; 171 LineSeg s; 172 s.p0 = vec2(uintBitsToFloat(raw0), uintBitsToFloat(raw1)); 173 s.p1 = vec2(uintBitsToFloat(raw2), uintBitsToFloat(raw3)); 174 return s; 175 } 176 177 QuadSeg QuadSeg_read(QuadSegRef ref) { 178 uint ix = ref.offset >> 2; 179 uint raw0 = scene[ix + 0]; 180 uint raw1 = scene[ix + 1]; 181 uint raw2 = scene[ix + 2]; 182 uint raw3 = scene[ix + 3]; 183 uint raw4 = scene[ix + 4]; 184 uint raw5 = scene[ix + 5]; 185 QuadSeg s; 186 s.p0 = vec2(uintBitsToFloat(raw0), uintBitsToFloat(raw1)); 187 s.p1 = vec2(uintBitsToFloat(raw2), uintBitsToFloat(raw3)); 188 s.p2 = vec2(uintBitsToFloat(raw4), uintBitsToFloat(raw5)); 189 return s; 190 } 191 192 CubicSeg CubicSeg_read(CubicSegRef ref) { 193 uint ix = ref.offset >> 2; 194 uint raw0 = scene[ix + 0]; 195 uint raw1 = scene[ix + 1]; 196 uint raw2 = scene[ix + 2]; 197 uint raw3 = scene[ix + 3]; 198 uint raw4 = scene[ix + 4]; 199 uint raw5 = scene[ix + 5]; 200 uint raw6 = scene[ix + 6]; 201 uint raw7 = scene[ix + 7]; 202 CubicSeg s; 203 s.p0 = vec2(uintBitsToFloat(raw0), uintBitsToFloat(raw1)); 204 s.p1 = vec2(uintBitsToFloat(raw2), uintBitsToFloat(raw3)); 205 s.p2 = vec2(uintBitsToFloat(raw4), uintBitsToFloat(raw5)); 206 s.p3 = vec2(uintBitsToFloat(raw6), uintBitsToFloat(raw7)); 207 return s; 208 } 209 210 FillColor FillColor_read(FillColorRef ref) { 211 uint ix = ref.offset >> 2; 212 uint raw0 = scene[ix + 0]; 213 FillColor s; 214 s.rgba_color = raw0; 215 return s; 216 } 217 218 FillImage FillImage_read(FillImageRef ref) { 219 uint ix = ref.offset >> 2; 220 uint raw0 = scene[ix + 0]; 221 uint raw1 = scene[ix + 1]; 222 FillImage s; 223 s.index = raw0; 224 s.offset = ivec2(int(raw1 << 16) >> 16, int(raw1) >> 16); 225 return s; 226 } 227 228 SetLineWidth SetLineWidth_read(SetLineWidthRef ref) { 229 uint ix = ref.offset >> 2; 230 uint raw0 = scene[ix + 0]; 231 SetLineWidth s; 232 s.width = uintBitsToFloat(raw0); 233 return s; 234 } 235 236 Transform Transform_read(TransformRef ref) { 237 uint ix = ref.offset >> 2; 238 uint raw0 = scene[ix + 0]; 239 uint raw1 = scene[ix + 1]; 240 uint raw2 = scene[ix + 2]; 241 uint raw3 = scene[ix + 3]; 242 uint raw4 = scene[ix + 4]; 243 uint raw5 = scene[ix + 5]; 244 Transform s; 245 s.mat = vec4(uintBitsToFloat(raw0), uintBitsToFloat(raw1), uintBitsToFloat(raw2), uintBitsToFloat(raw3)); 246 s.translate = vec2(uintBitsToFloat(raw4), uintBitsToFloat(raw5)); 247 return s; 248 } 249 250 Clip Clip_read(ClipRef ref) { 251 uint ix = ref.offset >> 2; 252 uint raw0 = scene[ix + 0]; 253 uint raw1 = scene[ix + 1]; 254 uint raw2 = scene[ix + 2]; 255 uint raw3 = scene[ix + 3]; 256 Clip s; 257 s.bbox = vec4(uintBitsToFloat(raw0), uintBitsToFloat(raw1), uintBitsToFloat(raw2), uintBitsToFloat(raw3)); 258 return s; 259 } 260 261 SetFillMode SetFillMode_read(SetFillModeRef ref) { 262 uint ix = ref.offset >> 2; 263 uint raw0 = scene[ix + 0]; 264 SetFillMode s; 265 s.fill_mode = raw0; 266 return s; 267 } 268 269 ElementTag Element_tag(ElementRef ref) { 270 uint tag_and_flags = scene[ref.offset >> 2]; 271 return ElementTag(tag_and_flags & 0xffff, tag_and_flags >> 16); 272 } 273 274 LineSeg Element_Line_read(ElementRef ref) { 275 return LineSeg_read(LineSegRef(ref.offset + 4)); 276 } 277 278 QuadSeg Element_Quad_read(ElementRef ref) { 279 return QuadSeg_read(QuadSegRef(ref.offset + 4)); 280 } 281 282 CubicSeg Element_Cubic_read(ElementRef ref) { 283 return CubicSeg_read(CubicSegRef(ref.offset + 4)); 284 } 285 286 FillColor Element_FillColor_read(ElementRef ref) { 287 return FillColor_read(FillColorRef(ref.offset + 4)); 288 } 289 290 SetLineWidth Element_SetLineWidth_read(ElementRef ref) { 291 return SetLineWidth_read(SetLineWidthRef(ref.offset + 4)); 292 } 293 294 Transform Element_Transform_read(ElementRef ref) { 295 return Transform_read(TransformRef(ref.offset + 4)); 296 } 297 298 Clip Element_BeginClip_read(ElementRef ref) { 299 return Clip_read(ClipRef(ref.offset + 4)); 300 } 301 302 Clip Element_EndClip_read(ElementRef ref) { 303 return Clip_read(ClipRef(ref.offset + 4)); 304 } 305 306 FillImage Element_FillImage_read(ElementRef ref) { 307 return FillImage_read(FillImageRef(ref.offset + 4)); 308 } 309 310 SetFillMode Element_SetFillMode_read(ElementRef ref) { 311 return SetFillMode_read(SetFillModeRef(ref.offset + 4)); 312 } 313