P0.3: flip the quad color on a real iOS-Simulator tap, driven by sx
Prove the input path end-to-end. Poll platform events in the frame loop and, on a mouse_down (UIKit touchesBegan, mapped to an Event in uikit.sx), toggle the centered quad between orange and green. The toggle marks the vertex buffer dirty; the next frame re-uploads the active color palette before drawing. Flip on the press only — a tap also delivers mouse_up (touchesEnded), so toggling on both would net to no visible change. goldens/p0_input_before.png (orange quad) and goldens/p0_input_after.png (green quad) bracket a real tap injected at the device-screen center (201,437 pt) via `idb ui tap` on the booted iOS 26.0 simulator.
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_shader : ShaderHandle = 0;
|
||||||
g_quad_vbuf : BufferHandle = 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 };
|
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 +
|
// Vertex layout matches QUAD_MSL's `Vertex`: packed_float2 pos +
|
||||||
// packed_float4 color = 24 bytes. `packed_*` avoids the 16-byte alignment
|
// packed_float4 color = 24 bytes. `packed_*` avoids the 16-byte alignment
|
||||||
// padding a plain `float4` would force. 6 vertices = 2 triangles.
|
// padding a plain `float4` would force. 6 vertices = 2 triangles. Two
|
||||||
QUAD_VERTS : [36]f32 = .[
|
// 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,
|
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,
|
-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
|
// Pass-through shader: the vertex stage emits NDC positions directly (no
|
||||||
// projection), the fragment stage returns the interpolated vertex color.
|
// projection), the fragment stage returns the interpolated vertex color.
|
||||||
// Entry-point names vmain / fmain are what MetalGPU.create_shader looks up.
|
// Entry-point names vmain / fmain are what MetalGPU.create_shader looks up.
|
||||||
@@ -82,6 +102,14 @@ frame :: () {
|
|||||||
g_viewport_h = fc.viewport_h;
|
g_viewport_h = fc.viewport_h;
|
||||||
|
|
||||||
for g_plat.poll_events(): (*ev) {
|
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 {
|
inline if OS != .ios {
|
||||||
if ev == {
|
if ev == {
|
||||||
case .key_up: (e) {
|
case .key_up: (e) {
|
||||||
@@ -112,7 +140,11 @@ frame :: () {
|
|||||||
if g_quad_vbuf == 0 {
|
if g_quad_vbuf == 0 {
|
||||||
g_quad_vbuf = g_metal_gpu.create_buffer(size_of([36]f32));
|
g_quad_vbuf = g_metal_gpu.create_buffer(size_of([36]f32));
|
||||||
if g_quad_vbuf == 0 { return; }
|
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; }
|
if !g_metal_gpu.begin_frame(BG_CLEAR) { return; }
|
||||||
|
|||||||
Reference in New Issue
Block a user