Overview
Every backend maintains a per-pixel uint32_t object-ID buffer alongside color and depth. Picking reads this buffer to identify the object at a given screen coordinate.
Object IDs
| Value | Meaning |
|---|---|
0 | Background (no object) |
1+ | Application-defined object ID |
Multiple meshes may share the same ID if the application treats them as one selectable entity.
Backend Contract
Every backend must:
- Allocate an object-ID buffer during
framebuffer_create - Clear it to
0duringframe_begin - Write
draw_call->object_idfor every rasterized pixel duringdraw - Implement
pick_read_id(device, fb, x, y) → uint32_t - Implement
pick_read_depth(device, fb, x, y) → float
Result Struct
typedef struct MopPickResult {
bool hit; /* true if object_id != 0 at (x,y) */
uint32_t object_id; /* valid only when hit == true */
float depth; /* [0,1] normalized depth */
} MopPickResult;
Usage
mop_viewport_render(viewport);
MopPickResult r = mop_viewport_pick(viewport, mouse_x, mouse_y);
if (r.hit) {
select_object(r.object_id);
}
Picking reads the most recently rendered frame. Render before picking.