diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-16 18:04:21 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-16 18:04:21 -0300 |
| commit | e77b01d4b5504cea08a3f88cf8502897d868a1d3 (patch) | |
| tree | c8e643d234dd26d920cbc563bfa7f740febf1fc7 /web/host.js | |
| parent | d3074636fff0fbcd5fd9b71c0c3b1c1f5c0c1285 (diff) | |
| download | sketchbook-e77b01d4b5504cea08a3f88cf8502897d868a1d3.tar.gz sketchbook-e77b01d4b5504cea08a3f88cf8502897d868a1d3.zip | |
Add glTF scene rendering, resource setup and 9P controls
Diffstat (limited to 'web/host.js')
| -rw-r--r-- | web/host.js | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/web/host.js b/web/host.js index 2c410f7..7559dfc 100644 --- a/web/host.js +++ b/web/host.js @@ -190,7 +190,7 @@ const gpu = { }, pipeline(p, samples, stencil) { - const key = JSON.stringify([p.vertex.hash, p.fragment.hash, p.stride, p.attributes, p.primitive, p.blend, p.write_color, p.stencil, samples, stencil]); + const key = JSON.stringify([p.vertex.hash, p.fragment.hash, p.stride, p.attributes, p.primitive, p.blend, p.write_color, p.stencil, p.depth_test, p.depth_write, samples, stencil]); let pipeline = gpu.pipelines.get(key); if (pipeline) return pipeline; const formats = {float: 'float32', float2: 'float32x2', float3: 'float32x3', float4: 'float32x4', ubyte4_norm: 'unorm8x4'}; @@ -212,7 +212,7 @@ const gpu = { primitive: {topology: dashed(p.primitive)}, multisample: {count: samples}, depthStencil: stencil ? { - format: 'depth24plus-stencil8', depthWriteEnabled: false, depthCompare: 'always', + format: 'depth24plus-stencil8', depthWriteEnabled: p.depth_write ?? false, depthCompare: dashed(p.depth_test ?? 'always'), stencilFront: p.stencil ? face(p.stencil.front) : keep, stencilBack: p.stencil ? face(p.stencil.back) : keep, } : undefined, }); @@ -232,7 +232,7 @@ const gpu = { clearValue: p.clear ? {r: p.clear[0], g: p.clear[1], b: p.clear[2], a: p.clear[3]} : undefined, storeOp: 'store', }; - const depthStencil = p.stencil ? { + const depthStencil = p.stencil || p.depth ? { view: gpu.attachment(entry, 'stencil', 'depth24plus-stencil8', samples).createView(), depthLoadOp: 'clear', depthClearValue: 1, depthStoreOp: 'discard', stencilLoadOp: 'clear', stencilClearValue: 0, stencilStoreOp: 'discard', @@ -247,7 +247,7 @@ const gpu = { const commands = gpu.device.createCommandEncoder(); const pass = commands.beginRenderPass({colorAttachments: [color], depthStencilAttachment: depthStencil}); for (const {d, vertices, vertexUniforms, fragmentUniforms} of draws) { - const pipeline = gpu.pipeline(p.pipelines[d.pipeline], samples, p.stencil); + const pipeline = gpu.pipeline(p.pipelines[d.pipeline], samples, p.stencil || p.depth); pass.setPipeline(pipeline); gpu.bind(pass, pipeline, [gpu.storage(d.vertex_storage), gpu.uniform(vertexUniforms), gpu.storage(d.fragment_storage), gpu.uniform(fragmentUniforms)]); if (vertices) pass.setVertexBuffer(0, vertices.buffer, vertices.offset, vertices.size); @@ -596,7 +596,12 @@ const imports = { available: () => gpu.device ? 1 : gpu.absent(), newBuffer: size => gpu.device ? gpu.newBuffer(size) : 0, freeBuffer(id) { gpu.buffers[id]?.destroy(); gpu.buffers[id] = null; }, - write(id, offset, ptr, len) { if (gpu.buffers[id]) gpu.device.queue.writeBuffer(gpu.buffers[id], offset, bytes(ptr, len).slice()); }, + write(id, offset, ptr, len) { + const buffer = gpu.buffers[id]; + if (!gpu.device || !buffer || offset % 4 || len % 4 || offset + len > buffer.size) return 0; + try { gpu.device.queue.writeBuffer(buffer, offset, bytes(ptr, len).slice()); return 1; } + catch { return 0; } + }, compute(ptr, len) { if (gpu.device) gpu.compute(JSON.parse(string(ptr, len))); }, pass(ptr, len) { if (gpu.device) gpu.pass(JSON.parse(string(ptr, len))); }, download(id, offset, size, key) { if (gpu.buffers[id]) gpu.download(id, offset, size, key); }, |
