WebGL
0 lines- Shaders
- GLSL ES 1.0 strings
- Draw call
- gl.drawArrays(TRIANGLES)
- Geometry
- Your own vertex array
WebGL · WebGPU · Three.js
One cottage drawn three ways: raw WebGL, raw WebGPU and Three.js. Drag any view to orbit. All three follow the same camera, so you can compare the output and the code behind it.
The same job at three levels. WebGL and WebGPU hand you raw GPU objects. Three.js hands you a scene graph and does the GPU work for you.
| WebGL | WebGPU | Three.js | |
|---|---|---|---|
| Core objects | WebGLProgram, WebGLShader, WebGLBuffer, WebGLTexture, WebGLFramebuffer |
GPUDevice, GPUQueue, GPUBuffer, GPUTexture, GPUShaderModule, GPURenderPipeline, GPUBindGroup, GPUCommandEncoder |
Scene, PerspectiveCamera, WebGLRenderer, Mesh, BufferGeometry, Material, Light |
| Drawing primitives | POINTS, LINES, LINE_STRIP, LINE_LOOP, TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN |
point-list, line-list, line-strip, triangle-list, triangle-strip (no fans or loops) |
Mesh, Line, LineSegments, Points, Sprite, plus ready-made shapes like BoxGeometry and SphereGeometry |
| Shader language | GLSL ES, compiled at runtime from a string | WGSL, compiled from a string into a shader module | Built-in materials. ShaderMaterial for your own GLSL |
| Setup | canvas.getContext('webgl') returns immediately |
requestAdapter() then requestDevice(), both async |
new WebGLRenderer({ canvas }). Recent releases also ship a WebGPU renderer |
| GPU state | One global state machine: bind this, enable that | Baked into an immutable render pipeline | Properties on materials and meshes |
| Uniforms | uniformMatrix4fv for each uniform |
One uniform buffer plus a bind group | Filled in for you from camera, lights and transforms |
| Submitting a draw | gl.drawArrays() |
Command encoder, render pass, draw(), queue.submit() |
renderer.render(scene, camera) |
| Depth and MSAA | Context flags and gl.enable(DEPTH_TEST) |
You create the depth and multisample textures | antialias: true. Depth testing is on by default |
| Clip-space depth | −1 to 1 | 0 to 1 | Handled for you |