---
id: wiki-2026-0508-webgl-20
title: WebGL 2.0
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [WebGL 2.0, WebGL2, GLES3 Web]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [webgl, graphics, frontend, gpu, opengl-es]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: JavaScript / GLSL ES 3.00
  framework: WebGL 2.0
---

# WebGL 2.0

## 매 한 줄
> **"매 OpenGL ES 3.0 기반 매 browser 그래픽 API"**. 매 WebGL 1.0 (ES 2.0) 대비 매 transform feedback, 매 UBO, 매 instancing, 매 3D / array textures, 매 GLSL ES 3.00 등 매 modern feature 표준화. 매 2026 기준 매 모든 주요 browser default 지원, 매 WebGPU 으로 매 점진 이행 중이지만 매 fallback baseline.

## 매 핵심

### 매 ES 2.0 → ES 3.0 차이
- **GLSL ES 3.00** — `in`/`out`, layout qualifier, integer texture.
- **VAO** — Vertex Array Object 표준 (1.0 은 extension).
- **UBO** — Uniform Buffer Object (binding point 기반 sharing).
- **Instancing** — `drawArraysInstanced` core (1.0 은 ANGLE_instanced_arrays).
- **Transform feedback** — vertex shader 결과 buffer 로 capture.
- **MRT** — Multiple Render Targets.
- **3D / 2D array textures**, sampler objects.

### 매 응용
1. 매 GPGPU compute (transform feedback).
2. 매 Deferred shading (MRT).
3. 매 Volumetric rendering (3D texture).

## 💻 패턴

### Context 획득
```javascript
const gl = canvas.getContext('webgl2');
if (!gl) throw new Error('WebGL2 unsupported');
```

### VAO + instancing
```javascript
const vao = gl.createVertexArray();
gl.bindVertexArray(vao);
// setup attribs...
gl.vertexAttribDivisor(instanceAttribLoc, 1); // 1 per instance
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, instanceCount);
```

### UBO
```glsl
#version 300 es
layout(std140) uniform Camera {
  mat4 view;
  mat4 proj;
};
```
```javascript
const ubo = gl.createBuffer();
gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
gl.bufferData(gl.UNIFORM_BUFFER, 128, gl.DYNAMIC_DRAW);
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
const idx = gl.getUniformBlockIndex(program, 'Camera');
gl.uniformBlockBinding(program, idx, 0);
```

### Transform feedback
```javascript
gl.transformFeedbackVaryings(program, ['v_position'], gl.SEPARATE_ATTRIBS);
gl.linkProgram(program);

const tfBuf = gl.createBuffer();
gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, tfBuf);
gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, byteLen, gl.DYNAMIC_COPY);
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, tfBuf);

gl.enable(gl.RASTERIZER_DISCARD);
gl.beginTransformFeedback(gl.POINTS);
gl.drawArrays(gl.POINTS, 0, count);
gl.endTransformFeedback();
gl.disable(gl.RASTERIZER_DISCARD);
```

### MRT
```javascript
gl.drawBuffers([
  gl.COLOR_ATTACHMENT0, // diffuse
  gl.COLOR_ATTACHMENT1, // normal
  gl.COLOR_ATTACHMENT2, // depth/spec
]);
```

### 3D texture
```javascript
gl.texImage3D(gl.TEXTURE_3D, 0, gl.R8, w, h, d, 0, gl.RED, gl.UNSIGNED_BYTE, data);
```

## 매 결정 기준
| 상황 | API |
|---|---|
| 광범위 호환 / 단순 | WebGL 1 + 매 fallback |
| Modern feature 필요 | WebGL 2 |
| Compute / 매 advanced | WebGPU |
| Library 사용 | Three.js / Babylon.js (auto-detect) |

**기본값**: 매 2026 신규 프로젝트 — WebGPU 가능하면 WebGPU, 아니면 WebGL 2 + WEBGL_multi_draw.

## 🔗 Graph
- 부모: [[WebGL]] · [[OpenGL ES]]
- 변형: [[WebGPU]]
- 응용: [[Three.js]] · [[Babylonjs]] · [[CesiumJS]]
- Adjacent: [[WEBGL_multi_draw]] · [[GLSL]]

## 🤖 LLM 활용
**언제**: 매 boilerplate (VAO/UBO setup), 매 GLSL 변환 (ES 2 → ES 3).
**언제 X**: 매 driver-specific bug — 매 매 platform test 필요.

## ❌ 안티패턴
- **`#version 300 es` 누락**: 매 WebGL2 shader 인데 매 ES 2 syntax.
- **VAO 미사용**: 매 매 draw 마다 attrib 재바인딩 — 매 perf 손실.
- **UBO 정렬 무시**: 매 std140 padding 안 맞춰 매 silent 손상.
- **Loss of context 무시**: 매 GPU reset / 매 tab background — 매 `webglcontextlost` 핸들링 필수.

## 🧪 검증 / 중복
- Verified (Khronos WebGL 2.0 spec, MDN WebGL2RenderingContext).
- 신뢰도 A.

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — VAO/UBO/TF/MRT 패턴 + WebGPU 비교 |
