Skip to content

Phase 4 Step 6: Canvas WebGL context #47

@thomasnemer

Description

@thomasnemer

Parent: #41

Goal

Implement the Canvas WebGL context (WebGLRenderingContext) so that JavaScript can use GPU-accelerated 3D graphics on <canvas> elements.

Prerequisites

  • Step 5 (Canvas 2D context — reuse canvas element infrastructure)

Implementation

  • Expose WebGLRenderingContext (WebGL 1.0) in Boa JS engine
  • Map WebGL API calls to wgpu equivalents
  • GLSL ES to WGSL shader translation via naga (already a transitive dep of wgpu)
  • Shader management: createShader, shaderSource, compileShader, createProgram, linkProgram
  • Buffer management: createBuffer, bindBuffer, bufferData
  • Texture management: createTexture, bindTexture, texImage2D
  • Framebuffer management: createFramebuffer, bindFramebuffer, framebufferTexture2D
  • Draw calls: drawArrays, drawElements
  • Uniforms and attributes: getUniformLocation, uniformNf/i, vertexAttribPointer, enableVertexAttribArray
  • Render to same offscreen texture as 2D context
  • WebGL 2.0 deferred to Phase 5+

Tests

  • Shader compilation and linking tests (GLSL ES → WGSL)
  • Buffer creation and data upload tests
  • Texture creation and sampling tests
  • Draw call output validation tests
  • Context switching between 2D and WebGL on same canvas

Acceptance Criteria

  • WebGL 1.0 API is functional in JS
  • GLSL ES shaders translate to WGSL and compile correctly
  • Basic WebGL programs (triangle, textured quad) render correctly
  • WebGL canvas displays in the page using shared offscreen texture

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions