public static bool redraw() { IntPtr backBufView = WebGPUNative.wgpuSwapChainGetCurrentTextureView(SwapChain); // create textureView WGPURenderPassColorAttachmentDescriptor colorDesc = new WGPURenderPassColorAttachmentDescriptor { attachment = backBufView, loadOp = WGPULoadOp.WGPULoadOp_Clear, storeOp = WGPUStoreOp.WGPUStoreOp_Store, clearColor = new WGPUColor { r = 0.3f, g = 0.3f, b = 0.3f, a = 1.0f } }; WGPURenderPassDescriptor renderPass = new WGPURenderPassDescriptor { colorAttachmentCount = 1, colorAttachments = &colorDesc }; IntPtr encoder = WebGPUNative.wgpuDeviceCreateCommandEncoder(Device, null); // create encoder IntPtr pass = WebGPUNative.wgpuCommandEncoderBeginRenderPass(encoder, &renderPass); // update the rotation rotDeg += 0.1f; fixed(void *data = &rotDeg) { WebGPUNative.wgpuQueueWriteBuffer(Queue, uRotBuf, 0, data, sizeof(float)); } // draw the triangle (comment these five lines to simply clear the screen) WebGPUNative.wgpuRenderPassEncoderSetPipeline(pass, pipeline); WebGPUNative.wgpuRenderPassEncoderSetBindGroup(pass, 0, bindGroup, 0, null); WebGPUNative.wgpuRenderPassEncoderSetVertexBuffer(pass, 0, vertBuf, 0, 0); WebGPUNative.wgpuRenderPassEncoderSetIndexBufferWithFormat(pass, indxBuf, WGPUIndexFormat.WGPUIndexFormat_Uint16, 0, 0); WebGPUNative.wgpuRenderPassEncoderDrawIndexed(pass, 3, 1, 0, 0, 0); WebGPUNative.wgpuRenderPassEncoderEndPass(pass); WebGPUNative.wgpuRenderPassEncoderRelease(pass); // release pass IntPtr commands = WebGPUNative.wgpuCommandEncoderFinish(encoder, null); // create commands WebGPUNative.wgpuCommandEncoderRelease(encoder); // release encoder WebGPUNative.wgpuQueueSubmit(Queue, 1, &commands); WebGPUNative.wgpuCommandBufferRelease(commands); // release commands // TODO EMSCRIPTEN: wgpuSwapChainPresent is unsupported in Emscripten, so what do we do? WebGPUNative.wgpuSwapChainPresent(SwapChain); WebGPUNative.wgpuTextureViewRelease(backBufView); // release textureView return(true); }