Merge branch 'flow/m3te/P0.3' into m3te-plan
This commit is contained in:
BIN
goldens/p0_input_after.png
Normal file
BIN
goldens/p0_input_after.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
BIN
goldens/p0_input_before.png
Normal file
BIN
goldens/p0_input_before.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
38
main.sx
38
main.sx
@@ -32,12 +32,23 @@ g_metal_gpu : *MetalGPU = null;
|
||||
g_quad_shader : ShaderHandle = 0;
|
||||
g_quad_vbuf : BufferHandle = 0;
|
||||
|
||||
// ── Input-path proof (P0.3) ──────────────────────────────────────────────
|
||||
// A tap toggles the quad between two distinct colors, proving a real touch
|
||||
// reaches sx and changes the rendered frame. UIKit touchesBegan is mapped to
|
||||
// a `mouse_down` Event in uikit.sx; the frame loop's poll flips
|
||||
// `g_quad_flipped` and marks `g_quad_dirty`, which re-uploads the matching
|
||||
// vertex colors before the next draw.
|
||||
g_quad_flipped : bool = false;
|
||||
g_quad_dirty : bool = true;
|
||||
|
||||
BG_CLEAR :: ClearColor.{ r = 0.10, g = 0.20, b = 0.55, a = 1.0 };
|
||||
|
||||
// Vertex layout matches QUAD_MSL's `Vertex`: packed_float2 pos +
|
||||
// packed_float4 color = 24 bytes. `packed_*` avoids the 16-byte alignment
|
||||
// padding a plain `float4` would force. 6 vertices = 2 triangles.
|
||||
QUAD_VERTS : [36]f32 = .[
|
||||
// padding a plain `float4` would force. 6 vertices = 2 triangles. Two
|
||||
// arrays share the same geometry and differ only in color so the buffer
|
||||
// re-upload is a flat memcpy of the active palette.
|
||||
QUAD_VERTS_ORANGE : [36]f32 = .[
|
||||
-0.5, 0.5, 1.0, 0.6, 0.0, 1.0,
|
||||
0.5, 0.5, 1.0, 0.6, 0.0, 1.0,
|
||||
-0.5, -0.5, 1.0, 0.6, 0.0, 1.0,
|
||||
@@ -46,6 +57,15 @@ QUAD_VERTS : [36]f32 = .[
|
||||
-0.5, -0.5, 1.0, 0.6, 0.0, 1.0,
|
||||
];
|
||||
|
||||
QUAD_VERTS_GREEN : [36]f32 = .[
|
||||
-0.5, 0.5, 0.15, 0.85, 0.35, 1.0,
|
||||
0.5, 0.5, 0.15, 0.85, 0.35, 1.0,
|
||||
-0.5, -0.5, 0.15, 0.85, 0.35, 1.0,
|
||||
0.5, 0.5, 0.15, 0.85, 0.35, 1.0,
|
||||
0.5, -0.5, 0.15, 0.85, 0.35, 1.0,
|
||||
-0.5, -0.5, 0.15, 0.85, 0.35, 1.0,
|
||||
];
|
||||
|
||||
// Pass-through shader: the vertex stage emits NDC positions directly (no
|
||||
// projection), the fragment stage returns the interpolated vertex color.
|
||||
// Entry-point names vmain / fmain are what MetalGPU.create_shader looks up.
|
||||
@@ -82,6 +102,14 @@ frame :: () {
|
||||
g_viewport_h = fc.viewport_h;
|
||||
|
||||
for g_plat.poll_events(): (*ev) {
|
||||
if ev == {
|
||||
// Flip on the press only. A tap also produces mouse_up
|
||||
// (touchesEnded); toggling on both would net to no change.
|
||||
case .mouse_down: {
|
||||
g_quad_flipped = !g_quad_flipped;
|
||||
g_quad_dirty = true;
|
||||
}
|
||||
}
|
||||
inline if OS != .ios {
|
||||
if ev == {
|
||||
case .key_up: (e) {
|
||||
@@ -112,7 +140,11 @@ frame :: () {
|
||||
if g_quad_vbuf == 0 {
|
||||
g_quad_vbuf = g_metal_gpu.create_buffer(size_of([36]f32));
|
||||
if g_quad_vbuf == 0 { return; }
|
||||
g_metal_gpu.update_buffer(g_quad_vbuf, xx @QUAD_VERTS, size_of([36]f32));
|
||||
}
|
||||
if g_quad_dirty {
|
||||
verts := if g_quad_flipped then @QUAD_VERTS_GREEN else @QUAD_VERTS_ORANGE;
|
||||
g_metal_gpu.update_buffer(g_quad_vbuf, xx verts, size_of([36]f32));
|
||||
g_quad_dirty = false;
|
||||
}
|
||||
|
||||
if !g_metal_gpu.begin_frame(BG_CLEAR) { return; }
|
||||
|
||||
Reference in New Issue
Block a user