From c9b80df18d37195524245bcbd9b99eb6fbde0e9c Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Sat, 23 May 2026 17:33:25 +0200 Subject: [PATCH] three fixes that allow web (js) to work for cogentcore --- wgpu/adapter_js.go | 2 -- wgpu/pipeline_js.go | 8 ++++++-- wgpu/to_js.go | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/wgpu/adapter_js.go b/wgpu/adapter_js.go index b671d5b..fb44398 100644 --- a/wgpu/adapter_js.go +++ b/wgpu/adapter_js.go @@ -9,8 +9,6 @@ import ( ) func (g *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) { - fmt.Println(pointerToJS(descriptor)) - descriptor.toJS() promise := g.jsValue.Call("requestDevice", pointerToJS(descriptor)) device, ok := jsx.Await(promise) diff --git a/wgpu/pipeline_js.go b/wgpu/pipeline_js.go index 0790956..b46a71b 100644 --- a/wgpu/pipeline_js.go +++ b/wgpu/pipeline_js.go @@ -109,7 +109,7 @@ func (g StencilFaceState) toJS() any { // https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate type DepthStencilState struct { Format TextureFormat - DepthWriteEnabled bool + DepthWriteEnabled OptionalBool DepthCompare CompareFunction StencilFront StencilFaceState StencilBack StencilFaceState @@ -123,7 +123,11 @@ type DepthStencilState struct { func (g DepthStencilState) toJS() any { result := make(map[string]any) result["format"] = enumToJS(g.Format) - result["depthWriteEnabled"] = g.DepthWriteEnabled + if g.DepthWriteEnabled == OptionalBoolTrue { + result["depthWriteEnabled"] = true + } else if g.DepthWriteEnabled == OptionalBoolFalse { + result["depthWriteEnabled"] = false + } result["depthCompare"] = enumToJS(g.DepthCompare) result["stencilFront"] = g.StencilFront.toJS() result["stencilBack"] = g.StencilBack.toJS() diff --git a/wgpu/to_js.go b/wgpu/to_js.go index c724c43..2530466 100644 --- a/wgpu/to_js.go +++ b/wgpu/to_js.go @@ -193,17 +193,23 @@ func (g *RenderPassColorAttachment) toJS() any { } func (g *RenderPassDepthStencilAttachment) toJS() any { - return map[string]any{ + result := map[string]any{ "view": pointerToJS(g.View), - "depthLoadOp": enumToJS(g.DepthLoadOp), - "depthStoreOp": enumToJS(g.DepthStoreOp), "depthClearValue": g.DepthClearValue, - "depthReadOnly": g.DepthReadOnly, - "stencilLoadOp": enumToJS(g.StencilLoadOp), - "stencilStoreOp": enumToJS(g.StencilStoreOp), "stencilClearValue": g.StencilClearValue, + "depthReadOnly": g.DepthReadOnly, "stencilReadOnly": g.StencilReadOnly, } + // https://www.w3.org/TR/webgpu/#abstract-opdef-gpurenderpassdepthstencilattachment-gpurenderpassdepthstencilattachment-valid-usage + if !g.DepthReadOnly { + result["depthLoadOp"] = enumToJS(g.DepthLoadOp) + result["depthStoreOp"] = enumToJS(g.DepthStoreOp) + } + if !g.StencilReadOnly { + result["stencilLoadOp"] = enumToJS(g.StencilLoadOp) + result["stencilStoreOp"] = enumToJS(g.StencilStoreOp) + } + return result } func (g *RenderPipelineDescriptor) toJS() any {