# core/graphic (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/core/graphic/

그래픽.

## GeometryKey extends Object

기하 캐시 열쇠. (Component.writeGeometryKey 가 그리기 입력을 적는 곳)
- add 로 적은 값을 지난번에 적은 값과 차례대로 === 로 견준다. 하나라도 다르거나 수가 다르면 바뀐 것으로 본다.
- 견주며 바로 덮어 적으므로 프레임마다 배열을 새로 만들지 않는다.

예제: 그리기 입력을 적고 바뀌었는지 보기

```js
import { GeometryKey } from "./build/vanilla.js";

const geometryKey = new GeometryKey();
geometryKey.begin();
geometryKey.add(10);
geometryKey.add("#ff0000");
console.log(geometryKey.end());
geometryKey.begin();
geometryKey.add(10);
geometryKey.add("#ff0000");
console.log(geometryKey.end());
geometryKey.begin();
geometryKey.add(12);
geometryKey.add("#ff0000");
console.log(geometryKey.end());
```

- `constructor()` (constructor, since 0.4.0): 생성.
- `begin()` (method, since 0.4.0): 적기 시작. (Graphic 이 writeGeometryKey 앞에 부른다)
- `add(value)` (method, since 0.4.0): 값 하나 적기. (숫자, 문자열, 참거짓, 객체 참조, null)
  - `value` *: 그리기가 읽는 값. (객체는 참조로 견주므로, 안의 값이 바뀔 수 있는 Color 같은 것은 칸을 따로 적는다)
- `end()` (method, since 0.4.0): 적기 끝. (지난번과 같으면 true)
  - returns boolean: 이번에 적은 값이 지난번과 모두 같으면 참. (처음 적은 때는 거짓)

## Graphic extends Object

그래픽.
- Canvas 의 WebGL2 렌더링 컨텍스트를 통해 출력하는 렌더러.
- Canvas2D 시절의 좌표계(좌상 원점, 픽셀 단위)와 상태 모델(변환/알파 스택)을
  그대로 재현한다. 모든 드로우는 drawVertices() 한 지점으로 수렴한다.

예제: 씬의 draw 에서 도형과 글 그리기

```js
import { Engine, EngineConfiguration, Scene, Vector2, Rect } from "./build/vanilla.js";

class MainScene extends Scene {
	draw(graphic) {
		super.draw(graphic);
		graphic.setFillColor("#203040");
		graphic.drawRoundRect(Rect.create(40, 40, 260, 160), 16);
		graphic.setStrokeColor("#ffcc00");
		graphic.drawStrokeCircle(Vector2.create(460, 120), 60, 4);
		graphic.setFillColor("#ffffff");
		graphic.setFontString("24px sans-serif");
		graphic.setTextAlign("center");
		graphic.setTextBaseline("middle");
		graphic.drawFillText("Graphic", 170, 120);
	}
}

const engineConfiguration = new EngineConfiguration();
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());
```

- `constructor(canvas, preserveDrawingBuffer, antialias = true, colorSpace = ColorSpace.gamma, trackGpuMemory = false)` (constructor, since 0.0.9): 생성.
  - `canvas` HTMLCanvasElement: 그릴 캔버스. (WebGL2 컨텍스트를 얻지 못하면 오류를 던진다)
  - `preserveDrawingBuffer` boolean: 프레임이 끝난 뒤에도 그린 것을 캔버스에 남길지. (true 일 때만 남긴다)
  - `antialias` boolean: 캔버스의 멀티샘플 안티에일리어싱을 켤지. (기본 true, false 일 때만 끈다)
  - `colorSpace` string: 3D 색 공간. (ColorSpace, 기본 ColorSpace.gamma, 엔진은 EngineConfiguration.colorSpace 를 넘긴다)
  - `trackGpuMemory` boolean: GPU 메모리 셈을 처음부터 켤지. (기본 false, 엔진은 EngineConfiguration.trackGpuMemory 를 넘긴다)
- `applySettings(engine)` (method, since 0.0.9): 설정 반영. (매 프레임 시작 시 엔진이 호출)
  - 캔버스 크기 변화 감지 및 뷰포트/프로젝션 갱신.
  - 프레임 시작 기준 상태로 리셋.
  - `engine` Engine: 엔진.
- `setImageSmoothingEnabled(value)` (method, since 0.2.1): 이미지 스무딩 활성화 여부 설정.
  - 도트(픽셀) 스프라이트 게임은 false 로 설정해 선명하게 렌더링.
  - `value` boolean: 참이면 이미지를 부드럽게(LINEAR), 거짓이면 또렷하게(NEAREST) 뽑는다.
- `isImageSmoothingEnabled()` (method, since 0.2.1): 이미지 스무딩 활성화 여부 반환.
  - returns boolean: 이미지 스무딩이 켜졌으면 참.
- `setImageMipmapEnabled(value)` (method, since 0.3.2): 이미지 밉맵 활성화 여부 설정. (기본 false)
  - 켜면 스무딩이 켜진 이미지 텍스처에 밉맵을 만들고 축소 필터를 LINEAR_MIPMAP_LINEAR 로 한다.
  - 큰 그림(아틀라스 등)을 크게 줄여 그릴 때 가장자리의 계단과 자글거림이 줄어든다.
  - 아틀라스는 그림 둘레의 여백(늘여 붙인 가장자리)이 넉넉해야 작은 밉맵 단계에서 옆 그림이 번져 들지 않는다.
  - `value` boolean: 이미지 밉맵을 켤지.
- `isImageMipmapEnabled()` (method, since 0.3.2): 이미지 밉맵 활성화 여부 반환.
  - returns boolean: 이미지 밉맵이 켜졌으면 참.
- `setImageMipmapBias(value)` (method, since 0.3.2): 이미지 밉맵 단계 보정 설정. (기본 0)
  - 밉맵 단계를 고를 때 더하는 값. 음수면 한 단계 큰 그림 쪽을 골라 또렷해지고, 너무 작으면 다시 자글거린다. (-0.5 안팎)
  - 기본 셰이더(낱장, 묶어 그리기, 파티클)에 적용한다. 바꿔 끼운 셰이더는 textureLodBias 유니폼이 있으면 받는다.
  - `value` number: 밉맵 단계에 더할 값. (음수면 또렷해진다)
- `getImageMipmapBias()` (method, since 0.3.2): 이미지 밉맵 단계 보정 반환.
  - returns number: 밉맵 단계 보정 값.
- `setImageSmoothingQuality(value)` (method, since 0.2.1): 이미지 스무딩 퀄리티 설정. ("low", "medium", "high")
  - WebGL2 에서는 LINEAR/NEAREST 이분법이라 보관만 한다.
  - `value` string: "low", "medium", "high" 가운데. (보관만 한다)
- `getImageSmoothingQuality()` (method, since 0.4.0): 이미지 스무딩 퀄리티 반환. ("low", "medium", "high", 처음은 "high")
  - returns string: 이미지 스무딩 퀄리티.
- `setForceGizmosVisible(isForceGizmosVisible)` (method, since 0.2.0): 모든 기즈모 강제 표시 설정.
  - `isForceGizmosVisible` boolean: 참이면 노드마다의 설정과 상관없이 모든 기즈모를 그린다.
- `isForceGizmosVisible()` (method, since 0.2.0): 모든 기즈모 강제 표시 여부 반환.
  - returns boolean: 모든 기즈모를 강제로 그리면 참.
- `pushState()` (method, since 0.3.0): 상태 저장. (변환/알파/블렌드/색상/폰트/틴트, Canvas2D save 대응)

  예제: 상태를 저장하고 돌려 그리기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2, Rect } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.pushState();
  		graphic.translate(320, 180);
  		graphic.rotate(Math.PI / 6);
  		graphic.setGlobalAlpha(0.5);
  		graphic.setFillColor("#ff6600");
  		graphic.drawRect(Rect.create(-50, -50, 100, 100));
  		graphic.popState();
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `popState()` (method, since 0.3.0): 상태 복원. (Canvas2D restore 대응)
- `translate(x, y)` (method, since 0.3.0): 이동 변환 누적.
  - `x` number: X 이동량.
  - `y` number: Y 이동량.
- `rotate(radian)` (method, since 0.3.0): 회전 변환 누적.
  - `radian` number: 회전각. (라디안, 양수면 화면에서 시계 방향)
- `scale(x, y)` (method, since 0.3.0): 크기 변환 누적.
  - `x` number: X 배율.
  - `y` number: Y 배율.
- `setTransform(a, b, c, d, e, f)` (method, since 0.3.0): 변환 행렬 직접 설정. (Canvas2D setTransform(a, b, c, d, e, f) 대응)
  - `a` number: 가로 배율. (x' = a x + c y + e)
  - `b` number: 세로 기울임. (y' = b x + d y + f)
  - `c` number: 가로 기울임. (x' = a x + c y + e)
  - `d` number: 세로 배율. (y' = b x + d y + f)
  - `e` number: 가로 이동. (x' = a x + c y + e)
  - `f` number: 세로 이동. (y' = b x + d y + f)
- `resetTransform()` (method, since 0.3.0): 변환 행렬 초기화.
- `getTransformMatrix()` (method, since 0.3.0): 현재 변환 행렬 반환.
  - returns TransformMatrix: 지금 변환 행렬. (Graphic 이 들고 고쳐 쓰므로 값을 남기려면 복제한다)
- `setGlobalAlpha(value)` (method, since 0.3.0): 전역 투명도 설정.
  - `value` number: 전역 투명도. (0 ~ 1 로 자른다)
- `getGlobalAlpha()` (method, since 0.3.0): 전역 투명도 반환.
  - returns number: 전역 투명도. (0 ~ 1)
- `multiplyGlobalAlpha(value)` (method, since 0.3.0): 전역 투명도 곱셈 누적. (노드 트리의 투명도 상속용)
  - `value` number: 곱할 투명도. (곱한 값은 0 ~ 1 로 자른다)
- `setBlendMode(blendMode)` (method, since 0.3.0): 블렌드 모드 설정. (SpriteBlendMode 문자열 수용, Canvas2D globalCompositeOperation 26 가지)
  - 고정 블렌딩으로 되는 13 가지(포터 더프 연산자, lighter, multiply, screen)는 blendFunc 로 건다.
  - 나머지 13 가지(overlay, darken, lighten, color-dodge, color-burn, hard-light, soft-light, difference, exclusion, hue, saturation, color, luminosity)는
    그리기마다 그릴 영역 아래를 떠 와 셰이더로 섞는다. 이 모드에서는 묶어 그리지 않고, 그리기 하나에 영역 복사 한 번과 드로우 콜 한 번이 든다.
    (바꿔 끼운 셰이더로 그릴 때는 덧그림 칸에 먼저 그리고 옮기므로 드로우 콜이 두 번)
  - multiply 는 렌더 타겟(프레임버퍼를 묶은 동안)에 그릴 때만 셰이더로 섞는다. (getDrawShaderBlendModeIndex)
  - 모르는 이름은 source-over 로 그린다.
  - `blendMode` string: 블렌드 모드. (Canvas2D globalCompositeOperation 이름, 모르는 이름은 한 번 경고하고 source-over 로 그린다)

  예제: 더하기 섞기로 빛 겹치기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.setBlendMode("lighter");
  		graphic.setFillColor("rgba(255, 80, 80, 0.8)");
  		graphic.drawCircle(Vector2.create(280, 180), 80);
  		graphic.setFillColor("rgba(80, 80, 255, 0.8)");
  		graphic.drawCircle(Vector2.create(360, 180), 80);
  		graphic.setBlendMode("source-over");
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `getBlendMode()` (method, since 0.3.0): 블렌드 모드 반환.
  - returns string: 블렌드 모드. (프레임마다 "source-over" 로 돌아간다)
- `setImageTintColor(color)` (method, since 0.3.0): 이미지 틴트 색상 설정. (null 이면 해제)
  - 이미지 실루엣(알파) 안쪽에만 tint.alpha 비율로 색을 덮는다.
  - `color` Color | null: 틴트 색. (사본을 둔다, Color 가 아니면 해제)
- `getImageTintColor()` (method, since 0.3.0): 이미지 틴트 색상 반환.
  - returns Color | null: 틴트 색. (없으면 null)
- `setFillColor(color)` (method, since 0.0.9): 색상 설정.
  - `color` Color | string: 채우기 색. (Color 나 "#rrggbb(aa)", "rgb(a)(...)" 글, 거짓 값이면 바꾸지 않는다)
- `getFillColor()` (method, since 0.3.0): 채우기 색상 반환.
  - returns Color: 채우기 색. (처음은 검정)
- `setStrokeColor(color)` (method, since 0.0.9): 색상 설정.
  - `color` Color | string: 선 색. (Color 나 "#rrggbb(aa)", "rgb(a)(...)" 글, 거짓 값이면 바꾸지 않는다)
- `getStrokeColor()` (method, since 0.3.0): 선 색상 반환.
  - returns Color: 선 색. (처음은 검정)
- `writeQuad(offset, leftX, topY, rightX, bottomY, leftU, topV, rightU, bottomV)` (method, since 0.3.0): 버텍스 데이터에 쿼드(삼각형 2개, 버텍스 6개) 기록.
  - 기록 후의 오프셋(플로트 단위)을 반환.
  - `offset` number: 적기 시작할 자리. (플로트 단위)
  - `leftX` number: 왼쪽 X.
  - `topY` number: 위 Y.
  - `rightX` number: 오른쪽 X.
  - `bottomY` number: 아래 Y.
  - `leftU` number: 왼쪽 U. (0 ~ 1)
  - `topV` number: 위 V. (0 ~ 1)
  - `rightU` number: 오른쪽 U. (0 ~ 1)
  - `bottomV` number: 아래 V. (0 ~ 1)
  - returns number: 적은 뒤의 자리. (플로트 단위, offset 에 24 를 더한 값)
- `drawVertices(vertexCount, texture, color)` (method, since 0.3.0): 기록된 버텍스 출력. (모든 드로우가 수렴하는 단일 지점, 추후 배칭 삽입 지점)
  - `vertexCount` number: 그릴 정점 수. (getVertexData 에 적은 것, 0 이하면 그리지 않는다)
  - `texture` WebGLTexture: 쓸 텍스처.
  - `color` Color: 곱할 색.

  예제: 정점을 직접 적어 그리기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2, Color } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		const floatCount = graphic.writeQuad(0, 100, 100, 300, 200, 0, 0, 1, 1);
  		const whiteTexture = graphic.getWhiteTexture();
  		const color = Color.createFromHEX("#ff00ff");
  		graphic.drawVertices(floatCount / 4, whiteTexture, color);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `uploadDrawUniforms(shaderProgram, color)` (method, since 0.4.0): 드로우 콜 하나의 유니폼 업로드. (drawVertices 가 부른다)
  - 유니폼 자리는 셰이더 프로그램이 바뀔 때만 다시 찾는다.
  - 기본 프로그램의 틴트와 전역 투명도는 지난번에 올린 값과 같으면 다시 올리지 않는다. (프레임 시작과 프로그램이 바뀔 때 잊는다)
  - 바꿔 끼운 셰이더 프로그램에는 늘 올린다.
  - `shaderProgram` ShaderProgram: 올릴 셰이더 프로그램.
  - `color` Color: mainColor 로 올릴 색.
- `isContextLost()` (method, since 0.4.0): WebGL 컨텍스트를 잃은 상태인지.
  - returns boolean: 잃었으면 true.

  예제: 잃은 동안 게임이 하던 그리기를 건너뛰기

  ```js
  import { Engine, EngineConfiguration, Scene } from "./build/vanilla.js";
  
  const engine = new Engine(new EngineConfiguration());
  engine.run(new Scene());
  if (!engine.getGraphic().isContextLost()) {
  	console.log("draw");
  }
  ```

- `enableGpuMemoryTracking()` (method, since 0.4.0): GPU 메모리 셈 켜기. (개발용)

  예제: GPU 메모리 셈 켜기

  ```js
  import { Engine, EngineConfiguration, Scene } from "./build/vanilla.js";
  
  const engine = new Engine(new EngineConfiguration());
  engine.run(new Scene());
  engine.getGraphic().enableGpuMemoryTracking();
  console.log(engine.getGraphic().isGpuMemoryTrackingEnabled());
  ```

- `isGpuMemoryTrackingEnabled()` (method, since 0.4.0): GPU 메모리 셈이 켜져 있는지.
  - returns boolean: 켜져 있으면 true.

  예제: GPU 메모리 셈이 켜져 있는지 읽기

  ```js
  import { Engine, EngineConfiguration, Scene } from "./build/vanilla.js";
  
  const engine = new Engine(new EngineConfiguration());
  engine.run(new Scene());
  console.log(engine.getGraphic().isGpuMemoryTrackingEnabled());
  ```

- `readGpuMemoryUsage()` (method, since 0.4.0): GPU 메모리 읽기. (개발용)
  - returns { totalBytes: number, canvasBytes: number, kindTable: object, ownerList: Array<{ owner: string, kind: string, count: number, bytes: number }> }: 합(캔버스 기본 프레임 버퍼 몫 포함), 캔버스 몫, 종류별 { count, bytes }, 주인별 몫(큰 것부터, 주인은 지은 호출 스택의 위쪽 세 칸).

  예제: GPU 메모리 합과 가장 큰 주인 읽기

  ```js
  import { Engine, EngineConfiguration, Scene } from "./build/vanilla.js";
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.trackGpuMemory = true;
  const engine = new Engine(engineConfiguration);
  engine.run(new Scene());
  const usage = engine.getGraphic().readGpuMemoryUsage();
  console.log(usage.totalBytes, usage.ownerList.length > 0 ? usage.ownerList[0].owner : "none");
  ```

- `beginFrameStatistics()` (method, since 0.3.2): 프레임 그리기 통계 시작.
  - 엔진이 매 프레임 씬을 그리기 전에 부른다. 지난 프레임의 드로우 콜 / 정점 수를 넘겨 두고 이번 프레임 값을 비운다.
  - 2D 경로(drawVertices, drawColoredQuads)만 센다. 3D 렌더러와 화면 효과 패스는 세지 않는다.
- `getLastFrameDrawCallCount()` (method, since 0.3.2): 지난 프레임의 드로우 콜 수 반환.
  - returns number: 지난 프레임의 드로우 콜 수.
- `getLastFrameVertexCount()` (method, since 0.3.2): 지난 프레임에 그린 정점 수 반환.
  - returns number: 지난 프레임에 그린 정점 수.
- `getLastFrameTriangleCount()` (method, since 0.3.2): 지난 프레임에 그린 삼각형 수 반환. (모든 드로우 콜이 삼각형 목록이다)
  - returns number: 지난 프레임에 그린 삼각형 수.
- `setCullingEnabled(isCullingEnabled)` (method, since 0.4.0): 화면 밖 거르기 설정. (기본 true)
  - 켜면 WorldNode 가 컴포넌트를 그리기 전에, 켜진 컴포넌트가 모두 내용 영역 안에서만 그린다고 알리면(Component.isDrawnInsideContent)
    내용 영역이 화면 밖일 때 그 노드의 컴포넌트 그리기를 건너뛴다. 자식은 저마다 따로 보고 그대로 그린다.
  - 판정은 그릴 때의 지금 변환(부모의 위치, 배율, 회전과 pushState 로 건 것 모두)으로 옮긴 영역의 경계 상자로 한다.
  - 알리지 않는 컴포넌트(기본, 글자, 파티클, 직접 만든 컴포넌트)가 하나라도 켜져 있으면 그 노드는 거르지 않는다. draw 를 덮어쓴 노드도 거르지 않는다.
  - 하위 트리 거르기(setSubtreeCullingEnabled, 기본 켜짐)를 켜 두면 노드의 하위 트리 그리기 경계(TransformNode.readSubtreeDrawBounds)가 화면 밖일 때
    그 노드와 자손의 그리기 순회를 통째로 건너뛴다. (갱신 tick 은 그대로 돈다)
  - `isCullingEnabled` boolean: 화면 밖 거르기를 켤지. (true 일 때만 켠다)
- `isCullingEnabled()` (method, since 0.4.0): 화면 밖 거르기 여부 반환.
  - returns boolean: 화면 밖 거르기가 켜졌으면 참.
- `setSubtreeCullingEnabled(isSubtreeCullingEnabled)` (method, since 0.4.0): 화면 밖 하위 트리 거르기 설정. (기본 true, 화면 밖 거르기 setCullingEnabled 가 켜졌을 때만 거른다)
  - 켜면 drawNode 가 노드에 변환을 건 뒤 그 노드의 하위 트리 그리기 경계(TransformNode.readSubtreeDrawBounds)를 지금 변환으로 옮겨,
    화면과 걸린 자르기(beginClipRect) 밖이면 그 노드와 자손의 그리기 순회를 통째로 건너뛴다. (스크롤 목록의 보이지 않는 줄을 돌지 않는다)
  - 경계는 변환, 내용 크기, 자식, 켜짐, 보임, 컴포넌트가 바뀐 때만 다시 셈한다. 어디에 그리는지 모르는 것이 든 하위 트리는 건너뛰지 않는다.
  - 갱신(tick)은 그대로 돈다. 기즈모를 모두 그리게 했으면(setForceGizmosVisible) 건너뛰지 않는다.
  - `isSubtreeCullingEnabled` boolean: 화면 밖 하위 트리 거르기를 켤지. (true 일 때만 켠다)

  예제: 스크롤 목록에서 건너뛴 줄 수 보기

  ```js
  import { Engine, EngineConfiguration, Scene } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		graphic.setSubtreeCullingEnabled(true);
  		super.draw(graphic);
  		console.log(graphic.isSubtreeCullingEnabled(), graphic.getLastFrameCulledSubtreeCount());
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `isSubtreeCullingEnabled()` (method, since 0.4.0): 화면 밖 하위 트리 거르기 여부 반환.
  - returns boolean: 켜졌으면 참. (화면 밖 거르기가 꺼져 있으면 켜져 있어도 거르지 않는다)
- `getLastFrameCulledSubtreeCount()` (method, since 0.4.0): 지난 프레임에 화면 밖이라 그리기를 통째로 건너뛴 하위 트리 수 반환.
  - returns number: 지난 프레임에 건너뛴 하위 트리 수.
- `isInsideVisibleBounds()` (method, since 0.4.0): 하위 트리가 보이는 사각형 안에 다 든 노드를 그리는 중인지 반환. (그리기 순회가 정한다)
  - 하위 트리 거르기가 노드의 하위 트리 경계가 보이는 사각형(화면과 걸린 자르기를 한 디바이스 픽셀 좁힌 것) 안에 다 든다고 보면, 그 노드를 그리는 동안 참이다.
    그 아래 자손은 화면 밖 견주기(하위 트리 경계, 컴포넌트 거르기, 보이는 자식 범위)를 하지 않고 그린다. 그리는 것이 없는 자손(경계 크기 0)만 건너뛴다.
  - 그 아래에서 자르기(beginClipRect, 마스크와 스크롤 칸)를 새로 걸면 그 자르기를 풀 때까지 거짓이다. (새 자르기 안에서 다시 견준다)
  - 화면 밖 거르기나 하위 트리 거르기가 꺼졌거나 기즈모를 모두 그리면 거짓.
  - returns boolean: 지금 그리는 노드가 보이는 사각형 안에 다 들면 참.

  예제: 보이는 사각형 안에 다 든 노드의 컴포넌트가 견주기를 건너뛰기

  ```js
  import { Engine, EngineConfiguration, Scene, WorldNode, Component, Paint, Rect, Vector2, Pivot, Colors } from "./build/vanilla.js";
  
  class InsideProbe extends Component {
  	isDrawnInsideContent() {
  		return true;
  	}
  	draw(graphic) {
  		graphic.setFillColor(Colors.white);
  		graphic.drawRect(Rect.create(0, 0, 10, 10));
  		console.log(graphic.isInsideVisibleBounds());
  	}
  }
  
  class MainScene extends Scene {
  	initialize(engine) {
  		super.initialize(engine);
  		const node = new WorldNode();
  		node.setPivot(Pivot.topLeft);
  		node.setRect(100, 100, 40, 40);
  		node.addComponent(Paint);
  		node.addComponent(InsideProbe);
  		this.getRoot().addChild(node);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `readLocalVisibleBounds(rect)` (method, since 0.4.0): 보이는 사각형(화면과 걸린 자르기)을 지금 변환의 지역 좌표로 거꾸로 옮긴 경계 상자 읽기. (하위 트리 거르기가 켜졌을 때만, 알면 true)
  - 돌림이나 기울임이 있으면 넉넉하다(네 꼭짓점의 경계 상자, 한 디바이스 픽셀씩 넓힘). 이 사각형 밖에 그리는 것은 보이지 않는다.
  - 노드가 많은 자식 가운데 보이는 범위를 찾을 때 쓴다(TransformNode.drawChildren). 변환과 자르기가 같으면 다시 셈하지 않는다.
  - 화면 밖 거르기나 하위 트리 거르기가 꺼졌거나, 기즈모를 모두 그리거나, 뷰포트를 아직 정하지 않았거나, 변환을 거꾸로 걸 수 없으면(배율 0) false.
  - `rect` Rect: 경계 상자를 적을 곳. (지금 변환의 지역 좌표)
  - returns boolean: 알면 참. (모르면 rect 를 건드리지 않는다)

  예제: 지금 변환에서 보이는 사각형 읽기

  ```js
  import { Engine, EngineConfiguration, Scene, Rect } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		const visibleRect = Rect.zero();
  		graphic.pushState();
  		graphic.translate(100, 0);
  		console.log(graphic.readLocalVisibleBounds(visibleRect), visibleRect.position.x < -100);
  		graphic.popState();
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `addCulledSubtreeCount(culledSubtreeCount)` (method, since 0.4.0): 이번 프레임에 화면 밖이라 그리기를 통째로 건너뛴 하위 트리 수 더하기. (TransformNode.drawChildren 이 보이는 범위 밖 자식을 한꺼번에 건너뛰고 부른다)
  - `culledSubtreeCount` number: 더할 하위 트리 수.
- `isLocalRectVisible(rect)` (method, since 0.4.0): 지금 변환으로 옮긴 사각형이 화면(드로잉 버퍼)과 걸린 자르기 안에 걸치는지 반환. (네 꼭짓점을 옮긴 경계 상자로 본다)
  - 투영과 같은 디바이스 픽셀 좌표로 보므로 클립 공간 밖인지와 같다. (뷰포트를 줄여 그려도 맞다)
  - beginClipRect 로 건 자르기(겹친 것 모두)의 경계 상자 밖이면 보이지 않는 것으로 본다. (유니티 RectMask2D 처럼 스크롤 칸 밖 줄을 그리지 않는다)
  - 뷰포트를 아직 정하지 않았으면(applySettings 전) 걸치는 것으로 본다.
  - `rect` Rect: 지금 변환으로 옮기기 전의 사각형. (로컬 좌표)
  - returns boolean: 화면에 걸치면 참.
- `addCulledNodeCount(culledNodeCount)` (method, since 0.4.0): 이번 프레임에 화면 밖이라 컴포넌트를 건너뛴 노드 수 더하기. (WorldNode 가 부른다)
  - `culledNodeCount` number: 더할 노드 수.
- `getLastFrameCulledNodeCount()` (method, since 0.4.0): 지난 프레임에 화면 밖이라 컴포넌트를 건너뛴 노드 수 반환.
  - returns number: 지난 프레임에 건너뛴 노드 수.
- `setBatchingEnabled(isBatchingEnabled)` (method, since 0.4.0): 묶어 그리기 켜고 끄기. (엔진이 처음에 켠다, 끄면 그리기 하나에 드로우 콜 하나)
  - 켜면 연이은 드로우(이미지, 도형, 글자, 정점 색 쿼드)를 정점에 변환과 색을 실어 쌓아 두었다가 한 번의 드로우 콜로 그린다.
  - 텍스처는 한 묶음에 여러 장(기기 텍스처 유닛 수와 16 가운데 작은 것)까지 묶어 텍스처가 바뀌어도 이어진다. (PixiJS 와 같은 꼴)
  - 축에 맞고 화소 경계에 놓인 자르기(beginClipRect)는 정점의 자르기 사각형으로 셰이더가 잘라 묶음을 끊지 않는다. (돌아갔거나 둥근 자르기는 스텐실)
  - 텍스처 칸이 차거나, 블렌드, 스텐실 자르기, 바꿔 끼운 셰이더가 바뀌거나 버퍼가 차면 그때까지 쌓인 것을 그리고, 프레임 끝에 엔진이 남은 것을 그린다.
  - 엔진 루프 밖에서 그려도(엔진 없이 만든 Graphic, 제 requestAnimationFrame, 입력 처리기) 그 작업이 끝날 때(마이크로태스크) 남은 것을 그린다. 브라우저가 캔버스를 화면에 내기 전이라, 2D 캔버스처럼 따로 내보내지 않아도 보인다.
  - 켠 채로 WebGL 을 직접 다루는 패스(외부 렌더러 등)를 끼울 때는 그 전에 flushBatch() 를 부른다.
  - `isBatchingEnabled` boolean: 묶어 그리기를 켤지. (true 일 때만 켠다, 끄면 쌓인 것을 먼저 그린다)
- `isBatchingEnabled()` (method, since 0.4.0): 묶어 그리기를 켰는지 반환.
  - returns boolean: 묶어 그리기가 켜졌으면 참.
- `flushBatch()` (method, since 0.4.0): 쌓인 묶음 그리기. (쌓인 것이 없으면 아무것도 하지 않는다)
  - 묶음의 텍스처를 0 번부터의 유닛에 묶는다. 쓰지 않는 칸의 유닛에는 흰 텍스처를 묶어, 지난 그리기의 텍스처가 지금 그리는 칸(렌더 타겟)이어도 되먹임이 생기지 않게 한다.
- `setGeometryCachingEnabled(isGeometryCachingEnabled)` (method, since 0.4.0): 기하 캐시 켜기 / 끄기. (기본 켜짐)
  - 켜져 있으면 writeGeometryKey 로 그리기 입력을 알리는 컴포넌트(Paint, UIView, Text 등)가 그린 정점을 컴포넌트마다 캐시해 둔다.
    입력, 변환, 투명도가 그대로면 draw 를 부르지 않고 캐시를 묶음에 옮기고, 이동(스크롤 등)만 바뀌면 캐시한 지역 정점에 새 행렬만 곱한다.
    (유니티 UGUI 가 Graphic 의 메시를 지역 좌표로 두고 바뀐 것만 다시 짓는 것, 언리얼 Slate Invalidation 과 같은 사상)
  - 끄면 지난 판처럼 프레임마다 모든 컴포넌트의 draw 를 부른다. (화면 결과는 같다)
  - `isGeometryCachingEnabled` boolean: 켤지.

  예제: 기하 캐시를 끄고 켜며 재사용 수 보기

  ```js
  import { Engine, EngineConfiguration, Scene, WorldNode, Paint, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	initialize(engine) {
  		super.initialize(engine);
  		const boxNode = new WorldNode();
  		boxNode.setLocalPosition(Vector2.create(320, 180));
  		boxNode.setContentSize(Vector2.create(200, 100));
  		boxNode.addComponent(Paint).setColor("#3399ff");
  		this.getRoot().addChild(boxNode);
  	}
  	draw(graphic) {
  		graphic.setGeometryCachingEnabled(true);
  		super.draw(graphic);
  		console.log(graphic.isGeometryCachingEnabled(), graphic.getLastFrameGeometryCacheHitCount());
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `isGeometryCachingEnabled()` (method, since 0.4.0): 기하 캐시가 켜져 있는지 반환.
  - returns boolean: 켜져 있으면 참.
- `getLastFrameGeometryCacheHitCount()` (method, since 0.4.0): 지난 프레임에 기하 캐시로 그린 컴포넌트 수 반환. (draw 를 부르지 않은 것)
  - returns number: 캐시를 그대로 옮기거나 새 행렬만 곱해 그린 컴포넌트 수.
- `getLastFrameGeometryRebuildCount()` (method, since 0.4.0): 지난 프레임에 기하 캐시를 다시 적은 컴포넌트 수 반환. (캐시하는 컴포넌트 가운데 draw 를 부른 것)
  - returns number: 입력이나 배율, 회전 등이 바뀌어 draw 를 다시 부른 컴포넌트 수.
- `getLastFrameRetainedBatchCount()` (method, since 0.4.0): 지난 프레임에 정점을 다시 올리지 않고 GPU 에 남겨 둔 버퍼로 그린 묶음 수 반환.
  - 묶음에 넣은 조각(기하 캐시 조각과 판, 캐시 없이 바로 쓴 구간의 정점 값)이 지난 프레임 같은 차례의 묶음과 모두 같으면 정점을 옮기지도 올리지도 않고 드로 콜만 낸다.
  - 일부만 바뀐 묶음은 바뀐 범위만 bufferSubData 로 고쳐 올리고, 이 수에 들지 않는다.
  - returns number: 남긴 버퍼로 그린 묶음 수.

  예제: 멈춘 UI 가 남긴 묶음으로 그려지는지 보기

  ```js
  import { Engine, EngineConfiguration, Scene, WorldNode, Paint, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	initialize(engine) {
  		super.initialize(engine);
  		const boxNode = new WorldNode();
  		boxNode.setLocalPosition(Vector2.create(320, 180));
  		boxNode.setContentSize(Vector2.create(200, 100));
  		boxNode.addComponent(Paint).setColor("#3399ff");
  		this.getRoot().addChild(boxNode);
  	}
  	draw(graphic) {
  		super.draw(graphic);
  		console.log(graphic.getLastFrameRetainedBatchCount(), graphic.getLastFrameDrawCallCount());
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `drawComponent(component)` (method, since 0.4.0): 컴포넌트 그리기. (노드가 컴포넌트마다 부른다, 기하 캐시를 거친다)
  - 컴포넌트가 writeGeometryKey 로 입력을 알리지 않거나, 캐시가 꺼졌거나, 묶어 그리지 않는 상태면 draw 를 그대로 부른다.
  - 입력과 그리는 상태(배율, 회전, 섞기, 틴트, 글 방향)가 지난번과 같으면:
    이동과 투명도도 같으면 캐시한 디바이스 정점을 묶음에 그대로 옮기고, 다르면 캐시한 지역 정점에 지금 행렬과 투명도를 다시 건다.
    (스크롤은 부모의 이동만 바뀌므로 자식 컴포넌트는 draw 없이 행렬 곱만 한다, 글은 픽셀 스냅까지 같게 다시 셈한다)
  - 그 밖에는 draw 를 불러 캐시를 다시 적는다. 그리기 중에 자르기, 층, 섞기 바꾸기 등 묶음 밖의 일을 하면 그 컴포넌트는 캐시하지 않는다.
  - `component` Component: 그릴 컴포넌트.
- `getParticleVertexData(minimumFloatCount)` (method, since 0.3.0): 파티클 배치 버텍스 배열 반환. (필요 시 증설, x, y, u, v, r, g, b, a 인터리브)
  - `minimumFloatCount` number: 적어도 필요한 플로트 수. (모자라면 두 배씩 늘린다)
  - returns Float32Array: 파티클 정점 배열. (정점마다 x, y, u, v, r, g, b, a, 늘리면 새 배열이다)
- `drawColoredQuads(vertexCount, texture)` (method, since 0.3.0): 파티클 배치 출력. (getParticleVertexData 에 채운 정점을 한 번에 그린다)
  - `vertexCount` number: 그릴 정점 수. (0 이하면 그리지 않는다)
  - `texture` WebGLTexture: 쓸 텍스처. (getSoftDiscTexture 같은)

  예제: 정점마다 색을 실은 쿼드 한 번에 그리기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  const COLOR_LIST = [[1, 0.3, 0.3], [0.3, 1, 0.3], [0.3, 0.5, 1]];
  const CORNER_LIST = [[0, 0], [1, 0], [0, 1], [0, 1], [1, 0], [1, 1]];
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		const quadCount = COLOR_LIST.length;
  		const vertexData = graphic.getParticleVertexData(quadCount * 6 * 8);
  		let offset = 0;
  		for (let quadIndex = 0; quadIndex < quadCount; ++quadIndex) {
  			const leftX = 120 + quadIndex * 150;
  			const topY = 140;
  			const size = 80;
  			const color = COLOR_LIST[quadIndex];
  			for (const corner of CORNER_LIST) {
  				vertexData[offset++] = leftX + corner[0] * size;
  				vertexData[offset++] = topY + corner[1] * size;
  				vertexData[offset++] = corner[0];
  				vertexData[offset++] = corner[1];
  				vertexData[offset++] = color[0];
  				vertexData[offset++] = color[1];
  				vertexData[offset++] = color[2];
  				vertexData[offset++] = 1;
  			}
  		}
  		const softDiscTexture = graphic.getSoftDiscTexture();
  		graphic.drawColoredQuads(quadCount * 6, softDiscTexture);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `getSoftDiscTexture()` (method, since 0.3.0): 부드러운 원 텍스처 반환. (가장자리가 잦아드는 64x64 원, 파티클 기본 스프라이트)
  - returns WebGLTexture: 부드러운 원 텍스처. (처음 부를 때 만든다)
- `drawLine(positions, size = 1)` (method, since 0.0.9): 선 출력.
  - setStrokeColor()
  - `positions` Vector2[]: 선이 지날 점 목록. (2 개보다 적으면 그리지 않는다)
  - `size` number: 선 굵기. (기본 1)
- `drawLineLoop(positions, size = 1)` (method, since 0.3.0): 닫힌 선 출력. (마지막 점과 첫 점을 잇는 루프)
  - setStrokeColor()
  - `positions` Vector2[]: 선이 지날 점 목록. (2 개보다 적으면 그리지 않는다)
  - `size` number: 선 굵기. (기본 1)
- `drawPolyline(positions, size, isClosed)` (method, since 0.3.0): 폴리라인 출력. (세그먼트별 두께 확장 쿼드)
  - 내부 조인트는 반두께 연장으로 이음새를 메운다.
  - 정점 버퍼가 차면 쌓인 것을 그리고 비운 뒤 이어 적는다. (점이 많아도 선분을 버리지 않는다)
  - `positions` Vector2[]: 선이 지날 점 목록. (2 개보다 적으면 그리지 않는다)
  - `size` number: 선 굵기.
  - `isClosed` boolean: 참이면 마지막 점과 첫 점을 잇는다.
- `drawRect(rect)` (method, since 0.0.9): 사각형 출력.
  - setFillColor()
  - `rect` Rect: 칠할 사각형.
- `drawStrokeRect(rect, lineWidth = 1)` (method, since 0.3.0): 사각형 외곽선 출력. (Canvas2D strokeRect 대응, 선 중심이 경계선 위)
  - setStrokeColor()
  - `rect` Rect: 테를 그릴 사각형.
  - `lineWidth` number: 선 굵기. (기본 1)
- `buildRoundRectPositions(rect, roundSize)` (method, since 0.3.0): 라운드 사각형 경로 좌표 목록 생성. (시계 방향, 볼록 다각형)
  - `rect` Rect: 사각형.
  - `roundSize` number: 모서리 반지름. (짧은 변의 반을 넘으면 반으로 자른다)
  - returns Vector2[]: 경로의 점 목록. (새 배열)
- `writeRoundRectPositionData(rect, roundSize)` (method, since 0.4.0): 라운드 사각형 경로 좌표를 ROUND_RECT_POSITION_DATA 에 적는다. (시계 방향, 볼록 다각형, x, y 차례)
  - 점마다의 cos / sin 은 처음에 구해 둔 표를 쓴다.
  - `rect` Rect: 사각형.
  - `roundSize` number: 모서리 반지름. (짧은 변의 반을 넘으면 반으로 자른다)
- `drawConvexPolygon(positions, color)` (method, since 0.3.0): 볼록 다각형 채움 출력. (첫 점 기준 팬 분할)
  - 정점 버퍼가 차면 쌓인 삼각형을 그리고 비운 뒤 이어 적는다. (점이 많아도 삼각형을 버리지 않는다)
  - `positions` Vector2[]: 볼록 다각형의 점 목록. (3 개보다 적으면 그리지 않는다)
  - `color` Color: 칠할 색.
- `drawRoundRect(rect, roundSize)` (method, since 0.0.9): 라운드 사각형 출력.
  - setFillColor()
  - `rect` Rect: 칠할 사각형.
  - `roundSize` number: 모서리 반지름. (0 이하면 각진 사각형, 짧은 변의 반을 넘으면 반으로 자른다)
- `drawRoundRectPositionData(color)` (method, since 0.4.0): ROUND_RECT_POSITION_DATA 에 적힌 라운드 사각형 채움 출력. (첫 점 기준 팬 분할, drawConvexPolygon 과 같은 삼각형)
  - `color` Color: 칠할 색.
- `drawStrokeRoundRect(rect, roundSize, lineWidth = 1)` (method, since 0.3.0): 라운드 사각형 외곽선 출력.
  - setStrokeColor()
  - `rect` Rect: 테를 그릴 사각형.
  - `roundSize` number: 모서리 반지름. (0 이하면 각진 사각형, 짧은 변의 반을 넘으면 반으로 자른다)
  - `lineWidth` number: 선 굵기. (기본 1)
- `drawCircle(center, radius)` (method, since 0.0.9): 원 출력.
  - setFillColor()
  - `center` Vector2: 가운데.
  - `radius` number: 반지름. (0 이하면 그리지 않는다)
- `drawStrokeCircle(center, radius, lineWidth = 1)` (method, since 0.3.0): 원 외곽선 출력.
  - setStrokeColor()
  - `center` Vector2: 가운데.
  - `radius` number: 반지름. (0 이하면 그리지 않는다)
  - `lineWidth` number: 선 굵기. (기본 1)
- `drawRing(center, innerRadius, outerRadius, startRadian = 0, endRadian = Math.PI * 2)` (method, since 0.4.0): 고리(띠) 출력. (안쪽 반지름과 바깥 반지름 사이를 startRadian 부터 endRadian 까지 칠한다)
  - setFillColor()
  - 각도는 라디안, 0 이 오른쪽이고 화면에서 시계 방향으로 는다. (12 시에서 시작하려면 -PI / 2)
  - 조각마다 네모 하나를 겹치지 않게 이어 붙여 한 번에 그리므로, 반투명 색이어도 조각의 이음매가 짙어지지 않는다.
  - 조각 수는 drawCircle 처럼 화면에서의 바깥 반지름을 따라 정하고(한 바퀴 16 ~ 64), 그리는 각도만큼만 쓴다.
  - `center` Vector2: 가운데.
  - `innerRadius` number: 안쪽 반지름.
  - `outerRadius` number: 바깥 반지름. (0 이하이거나 안쪽 반지름 이하면 그리지 않는다)
  - `startRadian` number: 기본 0.
  - `endRadian` number: 기본 PI * 2.

  예제: 12 시부터 시계 방향으로 고리 채우기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		const center = Vector2.create(320, 180);
  		const progress = 0.7;
  		const startRadian = -Math.PI / 2;
  		graphic.setFillColor("#44dd88");
  		graphic.drawRing(center, 50, 70, startRadian, startRadian + Math.PI * 2 * progress);
  		graphic.setStrokeColor("#ffffff");
  		graphic.drawArc(center, 90, startRadian, startRadian + Math.PI, 3);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `drawArc(center, radius, startRadian, endRadian, lineWidth = 1)` (method, since 0.4.0): 호 출력. (반지름을 따라 lineWidth 두께의 선으로 startRadian 부터 endRadian 까지)
  - setStrokeColor()
  - 각도와 조각 수는 drawRing 과 같다. 선의 두께 가운데가 반지름에 온다.
  - `center` Vector2: 가운데.
  - `radius` number: 반지름. (선 굵기의 가운데)
  - `startRadian` number: 시작 각. (라디안)
  - `endRadian` number: 끝 각. (라디안)
  - `lineWidth` number: 기본 1.
- `drawRingWithColor(centerX, centerY, innerRadius, outerRadius, startRadian, endRadian, color)` (method, since 0.4.0): 고리 출력의 셈. (drawRing, drawArc 가 부른다)
  - `centerX` number: 가운데 X.
  - `centerY` number: 가운데 Y.
  - `innerRadius` number: 안쪽 반지름.
  - `outerRadius` number: 바깥 반지름. (0 이하이거나 안쪽 반지름 이하면 그리지 않는다)
  - `startRadian` number: 시작 각. (라디안)
  - `endRadian` number: 끝 각. (라디안, 시작 각과 같으면 그리지 않는다, 한 바퀴를 넘으면 한 바퀴로 자른다)
  - `color` Color: 칠할 색.
- `drawLineSegments(positionValues, size = 1)` (method, since 0.4.0): 선분 여럿 출력. (위치 배열 하나에 선분마다 x0, y0, x1, y1 넷씩, 한 번에 그린다)
  - setStrokeColor()
  - 선분마다 두께만큼 넓힌 네모 하나다. (drawLine 과 달리 이음새를 메우지 않는다, 따로 떨어진 선분 용)
  - Vector2 배열을 만들지 않고 숫자 배열(Array, Float32Array)을 그대로 읽는다. 길이가 0 인 선분은 건너뛴다.
  - 정점 버퍼가 차면 거기까지 그리고 이어서 담는다. (묶어 그리기가 켜져 있으면 같은 텍스처라 한 번의 드로우 콜로 이어진다)
  - `positionValues` number[] | Float32Array: 선분마다 x0, y0, x1, y1 넷씩 놓인 숫자 배열. (넷보다 적으면 그리지 않는다)
  - `size` number: 기본 1.

  예제: 격자 선 한 번에 그리기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		const positionValues = [];
  		for (let x = 0; x <= 640; x += 40) {
  			positionValues.push(x, 0, x, 360);
  		}
  		for (let y = 0; y <= 360; y += 40) {
  			positionValues.push(0, y, 640, y);
  		}
  		graphic.setStrokeColor("rgba(255, 255, 255, 0.3)");
  		graphic.drawLineSegments(positionValues, 1);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `prepareImage(image)` (method, since 0.4.0): 그림을 미리 GPU 에 올리기. (로딩 때 불러, 처음 그리는 프레임에 풀기와 올리기가 몰리지 않게)
  - 지금 이미지 스무딩과 밉맵 설정으로 올린다. (그릴 때 설정이 다르면 그때 거르기만 바꾼다)
  - 이미 올린 그림이면 아무것도 하지 않는다. 아직 읽히지 않은 그림(크기 0)은 올리지 않는다.
  - 코드로 만든 캔버스처럼 ImageAsset 으로 읽지 않은 그림을 씬의 load 에서 올려 둘 때 쓴다.
  - `image` HTMLImageElement | HTMLCanvasElement | OffscreenCanvas: 올릴 그림.
  - returns boolean: 텍스처가 있으면 true. (null 이거나 아직 읽히지 않은 그림이면 false)

  예제: 씬을 불러오는 동안 코드로 만든 그림을 올려 두기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	async load(engine) {
  		await super.load(engine);
  		this.dotImage = new OffscreenCanvas(32, 32);
  		const context = this.dotImage.getContext("2d");
  		context.fillStyle = "#ff6600";
  		context.fillRect(0, 0, 32, 32);
  		const isPrepared = engine.getGraphic().prepareImage(this.dotImage);
  		console.log(isPrepared);
  	}
  
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.drawImage(this.dotImage, Vector2.create(304, 164), Vector2.create(32, 32));
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `prepareLoadedImages(timeLimitMilliseconds = System.Infinity)` (method, since 0.4.0): 읽었지만 아직 올리지 않은 그림 올리기. (ImageAsset 이 읽은 그림, 읽은 차례로)
  - SceneManager 가 씬의 load 가 끝난 뒤(로딩 화면 동안) 프레임마다 나눠 부른다. 씬이 따로 부를 일은 없다.
  - 시간 한도를 주면 그 시간을 넘긴 뒤에는 멈추고 남은 수를 돌려준다. (한 번에 적어도 하나는 올린다, 유니티의 asyncUploadTimeSlice 와 같다)
  - 미리 푼 그림(ImageBitmap)은 올린 뒤 닫는다. 미리 풀지 않은 꼴의 그림은 그림 요소를 그대로 올린다.
  - `timeLimitMilliseconds` number: 이번에 쓸 시간 한도. (밀리초, 기본 Infinity 는 모두)
  - returns number: 아직 올리지 않고 남은 그림 수. (0 이면 다 올렸다)

  예제: 그림을 읽은 뒤 바로 올리기

  ```js
  import { Engine, EngineConfiguration, Scene, ImageAsset, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	async load(engine) {
  		await super.load(engine);
  		this.imageAsset = new ImageAsset();
  		await this.imageAsset.load("examples/assets/spritesheet.png");
  		const remainingCount = engine.getGraphic().prepareLoadedImages();
  		console.log(remainingCount);
  	}
  
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.drawImage(this.imageAsset.getImage(), Vector2.create(170, 30), Vector2.create(300, 300));
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `drawImage(image, position, contentSize)` (method, since 0.0.9): 이미지 출력.
  - setFillColor() Not Supported.
  - `image` HTMLImageElement | HTMLCanvasElement: 그릴 그림. (null 이나 undefined 면 오류를 던진다)
  - `position` Vector2: 그릴 왼쪽 위.
  - `contentSize` Vector2: 그릴 크기. (음수면 뒤집힌다)
- `drawImageWithImageRect(image, position, contentSize, imageRect)` (method, since 0.0.9): 이미지의 일부만 출력.
  - setFillColor() Not Supported.
  - `image` HTMLImageElement | HTMLCanvasElement: 그릴 그림. (null 이나 undefined 면 오류를 던진다)
  - `position` Vector2: 그릴 왼쪽 위.
  - `contentSize` Vector2: 그릴 크기. (음수면 뒤집힌다)
  - `imageRect` Rect: 그림 안에서 그릴 영역. (픽셀, null 이거나 비었으면 그림 전체)
- `drawImageWithSourceAndDestination(image, sourceX, sourceY, sourceWidth, sourceHeight, destinationX, destinationY, destinationWidth, destinationHeight)` (method, since 0.3.0): 이미지의 소스 영역을 지정 영역에 출력. (Canvas2D drawImage 9인자 대응)
  - `image` HTMLImageElement | HTMLCanvasElement: 그릴 그림. (아직 불러오지 않아 크기가 0 이면 그리지 않는다)
  - `sourceX` number: 그림 안의 왼쪽. (픽셀)
  - `sourceY` number: 그림 안의 위. (픽셀)
  - `sourceWidth` number: 그림 안의 너비. (픽셀)
  - `sourceHeight` number: 그림 안의 높이. (픽셀)
  - `destinationX` number: 그릴 왼쪽.
  - `destinationY` number: 그릴 위.
  - `destinationWidth` number: 그릴 너비. (음수면 뒤집힌다)
  - `destinationHeight` number: 그릴 높이. (음수면 뒤집힌다)

  예제: 그림의 한 조각 그리기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2, ImageAsset } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	async load(engine) {
  		await super.load(engine);
  		this.imageAsset = new ImageAsset();
  		await this.imageAsset.load("examples/assets/spritesheet.png");
  	}
  
  	draw(graphic) {
  		super.draw(graphic);
  		const image = this.imageAsset.image;
  		graphic.drawImageWithSourceAndDestination(image, 200, 0, 200, 200, 220, 80, 200, 200);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `drawImageWithNineSlice(image, position, size, nineSlice)` (method, since 0.0.9): 이미지 나인패치 출력.
  - setFillColor() Not Supported.
  - `image` HTMLImageElement | HTMLCanvasElement: 그릴 그림.
  - `position` Vector2: 그릴 왼쪽 위. (내림한다)
  - `size` Vector2: 그릴 크기. (올림한다, 경계 두께 합보다 작으면 그 합)
  - `nineSlice` Rect: 나인 슬라이스 경계. (position.x 왼쪽, position.y 위, size.x 오른쪽, size.y 아래 두께, 픽셀)
- `setFontString(fontString)` (method, since 0.3.0): 폰트 문자열 설정. (Canvas2D font 대응, 예: "16px DOSGothic", 이름 default 는 엔진 기본 글꼴 사슬)
  - `fontString` string: CSS 글꼴 글. (예: "16px DOSGothic", 이름 default 는 엔진 기본 글꼴 사슬 SYSTEM_FONT_STRING, 비었으면 바꾸지 않는다)
- `getFontString()` (method, since 0.3.0): 폰트 문자열 반환.
  - returns string: CSS 글꼴 글. (처음은 "10px sans-serif")
- `setTextAlign(textAlign)` (method, since 0.3.0): 텍스트 가로 정렬 설정. ("left" | "center" | "right" | "start" | "end")
  - `textAlign` string: 가로 정렬. (비었으면 바꾸지 않는다)
- `getTextAlign()` (method, since 0.3.0): 텍스트 가로 정렬 반환.
  - returns string: 가로 정렬. (처음은 "start")
- `setTextDirection(textDirection)` (method, since 0.3.2): 텍스트 방향 설정. ("inherit" | "ltr" | "rtl" | "auto", Canvas2D direction 대응)
  - 문단의 방향이다. 글자 안의 순서(양방향 알고리즘)와 정렬 "start" / "end" 의 왼쪽, 오른쪽이 이것을 따른다.
  - "inherit" 는 "ltr" 로 본다. (기본, 지금까지와 같다)
  - "auto" 는 문자열마다 처음 나오는 방향이 강한 글자로 정한다. (HTML 의 dir="auto", 없으면 "ltr") 사용자가 쓴 글(닉네임 등)에 쓴다.
  - `textDirection` string: 글 방향. (비었으면 바꾸지 않는다)
- `getTextDirection()` (method, since 0.3.2): 텍스트 방향 반환.
  - returns string: 글 방향. (처음은 "inherit")
- `resolveTextDirection(text)` (method, since 0.3.2): 문자열의 실제 방향 계산. ("ltr" 또는 "rtl", "auto" 는 처음 나오는 방향이 강한 글자로)
  - `text` string: 방향을 정할 글. ("auto" 일 때만 본다)
  - returns string: "ltr" 또는 "rtl".
- `resolveTextAlign(textAlign, textDirection)` (method, since 0.3.2): 실제 가로 정렬 계산. ("start" / "end" 를 방향에 따라 "left" / "right" 로)
  - `textAlign` string: 정렬. ("left", "center", "right", "start", "end", 모르는 값은 "left")
  - `textDirection` string: "ltr" 또는 "rtl".
  - returns string: "left" | "center" | "right"
- `setTextBaseline(textBaseline)` (method, since 0.3.0): 텍스트 베이스라인 설정. ("top" | "hanging" | "middle" | "alphabetic" | "ideographic" | "bottom")
  - `textBaseline` string: 세로 기준. (비었으면 바꾸지 않는다)
- `getTextBaseline()` (method, since 0.3.0): 텍스트 베이스라인 반환.
  - returns string: 세로 기준. (처음은 "alphabetic")
- `measureText(text)` (method, since 0.3.0): 문자열 측정. (현재 폰트 기준, Canvas2D measureText 대응)
  - `text` string: 잴 글.
  - returns TextMetrics: 지금 글꼴로 잰 치수. (캐시가 나눠 쓰므로 고치지 않는다)
- `measureTextWithFontString(fontString, text)` (method, since 0.4.0): 문자열 측정. (주어진 폰트 문자열 기준, 현재 폰트 문자열은 바꾸지 않는다)
  - `fontString` string: 잴 때 쓸 폰트 문자열. (Canvas2D font 꼴)
  - `text` string: 잴 글.
  - returns TextMetrics: 그 글꼴로 잰 치수. (캐시가 나눠 쓰므로 고치지 않는다, 지금 변환은 보지 않는다)

  예제: 지금 글꼴을 바꾸지 않고 큰 글꼴로 재기

  ```js
  import { Engine, EngineConfiguration } from "./build/vanilla.js";
  
  const engine = new Engine(new EngineConfiguration());
  const graphic = engine.getGraphic();
  const metrics = graphic.measureTextWithFontString("32px sans-serif", "Vanilla");
  console.log(metrics.width > 0, graphic.getFontString());
  ```

- `setTextBakeScaleStep(textBakeScaleStep)` (method, since 0.3.2): 텍스트 베이크 스케일 양자화 단위 설정.
  - 기본 0.25. 확대 축소가 잦은 글자가 스케일마다 새로 구워지지 않게 묶는다.
  - 0 이면 양자화하지 않고 실제 스케일 그대로 굽는다. (스케일이 고정된 UI 글자를 늘리지 않고 1:1 로 그릴 때)
  - `textBakeScaleStep` number: 양자화 단위. (음수는 0, 0 이면 양자화하지 않는다)
- `getTextBakeScaleStep()` (method, since 0.3.2): 텍스트 베이크 스케일 양자화 단위 반환.
  - returns number: 양자화 단위.
- `setTextBakeMotionScaleStep(textBakeMotionScaleStep)` (method, since 0.4.0): 배율이 움직이는 노드의 텍스트 베이크 스케일 양자화 단위 설정. (기본 0.25)
  - 양자화 단위(setTextBakeScaleStep)가 0 일 때, 그리는 노드의 변환 배율이 지난 프레임과 다르면(확대 움직임, 팝업, 트윈, 카메라 확대)
    이 단위로 묶은 배율로 굽는다. 프레임마다 다른 배율로 새로 굽지 않는다.
  - 배율이 멈추면(지난 프레임과 같으면) 정확한 배율로 다시 구워 1:1 로 또렷하다.
  - 0 이면 움직이는 동안에도 묶지 않는다. (지금까지와 같다)
  - `textBakeMotionScaleStep` number: 움직이는 동안의 양자화 단위. (음수는 0, 0 이면 묶지 않는다)
- `getTextBakeMotionScaleStep()` (method, since 0.4.0): 배율이 움직이는 노드의 텍스트 베이크 스케일 양자화 단위 반환.
  - returns number: 움직이는 동안의 양자화 단위.
- `setTextBakeScaleMoving(isTextBakeScaleMoving)` (method, since 0.4.0): 지금 그리는 노드의 배율이 움직이는 중인지 설정. (drawNode 가 정한다, 노드 밖에서 직접 그릴 때 부르는 쪽이 정할 수 있다)
  - `isTextBakeScaleMoving` boolean: 배율이 움직이는 중인지. (true 일 때만 움직이는 것으로 본다)
- `isTextBakeScaleMoving()` (method, since 0.4.0): 지금 그리는 노드의 배율이 움직이는 중인지 반환.
  - returns boolean: 배율이 움직이는 중이면 참.
- `readNodeTextBakeScaleMoving(node)` (method, since 0.4.0): 노드의 변환 배율이 지난 프레임과 달라 움직이는 중인지 셈하고 기억하기. (drawNode 가 pushTransform 뒤에 부른다)
  - 양자화 단위가 0 이 아니면 늘 묶어 굽으므로 셈하지 않는다.
  - 처음 그리는 노드는 움직이지 않는 것으로 본다. (첫 프레임에 두 번 굽지 않게)
  - 지난 프레임에 그리지 않은 노드(숨겼거나 화면 밖이라 하위 트리를 건너뛴 노드)도 처음 그리는 것처럼 본다. (건너뛴 사이에 배율이 바뀌어도 건너뛰지 않은 때와 같은 화면)
  - `node` TransformNode: 그리는 노드. (지금 배율을 노드에 적어 둔다)
  - returns boolean: 배율이 지난 프레임과 달라 움직이는 중이면 참.
- `setTextPixelSnapEnabled(isTextPixelSnapEnabled)` (method, since 0.3.2): 텍스트 픽셀 스냅 설정.
  - 켜면 회전 / 기울임이 없는 변환에서 글자 쿼드의 왼쪽 위를 디바이스 픽셀 격자에 맞춘다.
  - 베이크 스케일이 실제 스케일과 같을 때(setTextBakeScaleStep(0)) 텍셀과 픽셀이 1:1 로 맞아 가장 선명하다.
  - `isTextPixelSnapEnabled` boolean: 글자 쿼드를 디바이스 픽셀 격자에 맞출지.

  예제: UI 글자를 1:1 로 또렷하게

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	initialize(engine) {
  		const graphic = engine.getGraphic();
  		graphic.setTextBakeScaleStep(0);
  		graphic.setTextPixelSnapEnabled(true);
  	}
  
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.setFillColor("#ffffff");
  		graphic.setFontString("16px sans-serif");
  		graphic.setTextAlign("left");
  		graphic.setTextBaseline("top");
  		graphic.drawFillText("Score 12345", 20, 20);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `isTextPixelSnapEnabled()` (method, since 0.3.2): 텍스트 픽셀 스냅 여부 반환.
  - returns boolean: 텍스트 픽셀 스냅이 켜졌으면 참.
- `setTextAntialiasEnabled(isTextAntialiasEnabled)` (method, since 0.4.0): 글자 안티앨리어싱 켬 / 끔. (러스트 Graphic::set_text_antialias_enabled 와 같다)
  
  끄면 구운 글자의 알파를 문턱값 128 로 0 과 255 로 가르고 텍스처를 NEAREST 로 뽑는다. (도트 글꼴용)
  이 Graphic 에만 걸린다. 바꾼 뒤 그리는 글부터 새 꼴이다. (이미 만든 글도 다음 그리기부터, 구운 글은 꼴마다 따로 남아 되돌리면 다시 굽지 않는다, 기본 켬)
  - `isTextAntialiasEnabled` boolean: 켜면 참.

  예제: 도트 글꼴처럼 또렷한 글자

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	initialize(engine) {
  		engine.getGraphic().setTextAntialiasEnabled(false);
  	}
  
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.setFillColor("#ffffff");
  		graphic.setFontString("16px sans-serif");
  		graphic.setTextAlign("left");
  		graphic.setTextBaseline("top");
  		graphic.drawFillText("PIXEL 123", 20, 20);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `isTextAntialiasEnabled()` (method, since 0.4.0): 글자 안티앨리어싱이 켜져 있는지.
  - returns boolean: 켜졌으면 참.
- `calculateTextBakeScale()` (method, since 0.3.0): 텍스트 베이크 스케일 계산. (현재 변환 행렬 기반, 양자화 단위는 setTextBakeScaleStep)
  - returns number: 굽는 배율. (0.25 ~ 8)
- `drawTextEntry(entry, x, y, color = null, textDirection = "ltr")` (method, since 0.3.0): 글 배치 엔트리를 정렬/베이스라인에 맞춰 글리프 쿼드로 출력.
  - 문자열을 통째로 구웠을 때의 사각형 자리(픽셀 스냅 포함)를 셈하고, 그 안의 글리프 사각형을 아틀라스에서 뽑아 그린다.
  - `entry` object: 글 배치 엔트리. (TextStringTextureCache.getEntry)
  - `x` number: 기준 X. (정렬의 기준점)
  - `y` number: 기준 Y. (세로 기준의 자리)
  - `color` Color | null: 흰색으로 구운 글자에 곱할 색. (null 이면 흰색 그대로)
  - `textDirection` string: 정렬 "start" / "end" 를 가를 방향. ("ltr" 또는 "rtl", 기본 "ltr")
- `drawFillText(text, x, y)` (method, since 0.3.0): 텍스트 채움 출력. (Canvas2D fillText 대응)
  - setFillColor() / setFontString() / setTextAlign() / setTextBaseline()
  - `text` string: 그릴 글. (비었으면 그리지 않는다)
  - `x` number: 기준 X. (정렬의 기준점)
  - `y` number: 기준 Y. (세로 기준의 자리)
- `drawStrokeText(text, x, y, lineWidth = 1)` (method, since 0.3.0): 텍스트 외곽선 출력. (Canvas2D strokeText 대응)
  - setStrokeColor() / setFontString() / setTextAlign() / setTextBaseline()
  - `text` string: 그릴 글. (비었으면 그리지 않는다)
  - `x` number: 기준 X. (정렬의 기준점)
  - `y` number: 기준 Y. (세로 기준의 자리)
  - `lineWidth` number: 선 굵기. (기본 1)
- `drawNode(node)` (method, since 0.0.9): 노드 출력.
  - `node` TransformNode: 그릴 노드. (null 이거나 꺼져 있으면 그리지 않는다)
- `beginClipRect(rect, roundSize = 0)` (method, since 0.0.9): 출력 영역 제한 시작.
  - 스텐실 버퍼 기반이라 회전/스케일이 걸린 영역도 정확히 잘린다.
  - roundSize 를 주면 둥근 사각형으로 잘린다. (Paint 의 roundSize 와 같은 값이면 배경과 정확히 맞는다)
  - `rect` Rect: 자를 사각형. (지금 변환으로 옮기기 전의 로컬 좌표)
  - `roundSize` number: 모서리 반지름. (기본 0, 0 이하면 각진 사각형)

  예제: 둥근 사각형 안으로 잘라 그리기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2, Rect } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.beginClipRect(Rect.create(100, 60, 200, 200), 24);
  		graphic.setFillColor("#3399ff");
  		graphic.drawCircle(Vector2.create(300, 160), 120);
  		graphic.endClipRect();
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `beginOpacityLayer()` (method, since 0.4.0): 투명도 층 시작. (CSS opacity, 어도비 투명도 묶음처럼 endOpacityLayer 까지 그린 것을 따로 칸에 모았다가 지금 전역 알파로 한 번에 얹는다)
  - 층 안의 그림은 서로 겹친 자리가 비치지 않는다. (노드마다 투명도를 곱해 따로 얹으면 겹친 자리에서 아래 그림이 비친다)
  - 층 안은 전역 알파 1 에서 시작한다. 층 칸은 화면과 같은 크기의 RGBA8 이고 깊이를 비우고 스텐실을 지금 자르기 깊이로 채워 둬 층 안의 자르기와 3D 패스(clearDepth: false)도 그대로 된다.
    바깥 자르기는 얹을 때 걸린다. 층은 겹쳐 열 수 있다. 칸을 지을 수 없으면 층 없이 그대로 그린다.
  - 노드는 setOpacityLayer 를 켜고 투명도가 1 보다 작으면 그 노드와 자손을 층으로 그린다.

  예제: 겹친 두 사각형을 묶어 반투명하게 (겹친 자리에서 아래 사각형이 비치지 않는다)

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2, Rect } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.pushState();
  		graphic.setGlobalAlpha(0.5);
  		graphic.beginOpacityLayer();
  		graphic.setFillColor("#ff0000");
  		graphic.drawRect(Rect.create(100, 100, 200, 100));
  		graphic.setFillColor("#0000ff");
  		graphic.drawRect(Rect.create(200, 150, 200, 100));
  		graphic.endOpacityLayer();
  		graphic.popState();
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `endOpacityLayer()` (method, since 0.4.0): 투명도 층 끝. (beginOpacityLayer 뒤에 그린 것을 앞 프레임버퍼에 층을 열 때의 전역 알파로 얹는다)
- `endClipRect()` (method, since 0.0.9): 출력 영역 제한 종료.
- `getCanvas()` (method, since 0.3.0): 캔버스 반환.
  - returns HTMLCanvasElement: 캔버스.
- `getColorSpace()` (method, since 0.4.0): 3D 색 공간 반환. (ColorSpace, 툰 렌더러와 후처리가 엔진에서 읽는 기본값, 이 묶음의 2D 는 어느 값이든 감마 공간에서 합성한다)
  - returns string: ColorSpace.gamma 나 ColorSpace.linear.

  예제: 캔버스로 지은 Graphic 의 색 공간

  ```js
  import { Graphic, ColorSpace } from "./vanilla.js";
  const graphic = new Graphic(document.createElement("canvas"), false, true, ColorSpace.linear);
  if (graphic.getColorSpace() !== ColorSpace.linear) {
  	throw new Error("color space is not linear");
  }
  ```

- `getWebGL2RenderingContext()` (method, since 0.3.0): WebGL2 렌더링 컨텍스트 반환.
  - returns WebGL2RenderingContext: WebGL2 렌더링 컨텍스트.
- `getCurrentFramebuffer()` (method, since 0.4.0): 지금 그리는 프레임 버퍼 반환. (null 이면 캔버스, GL 에 묻지 않고 기억한 값)
  - returns WebGLFramebuffer | null: 지금 묶인 그리기 프레임 버퍼. (null 이면 캔버스의 기본 프레임 버퍼)

  예제: 바깥 패스에서 렌더 타깃을 바꿨다가 되돌리기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.runExternalPass((webGL2RenderingContext) => {
  			const previousFramebuffer = graphic.getCurrentFramebuffer();
  			const framebuffer = webGL2RenderingContext.createFramebuffer();
  			webGL2RenderingContext.bindFramebuffer(webGL2RenderingContext.FRAMEBUFFER, framebuffer);
  			webGL2RenderingContext.bindFramebuffer(webGL2RenderingContext.FRAMEBUFFER, previousFramebuffer);
  			webGL2RenderingContext.deleteFramebuffer(framebuffer);
  		}, { clearDepth: false });
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `getCurrentViewport()` (method, since 0.4.0): 지금 뷰포트 반환. (디바이스 픽셀, GL 처럼 왼쪽 아래가 원점, GL 에 묻지 않고 기억한 값)
  - returns Rect: 지금 뷰포트. (위치 x, y 와 크기 너비, 높이, 새 Rect)

  예제: 지금 뷰포트 크기 읽기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		const viewport = graphic.getCurrentViewport();
  		console.log(viewport.position.x, viewport.position.y, viewport.width, viewport.height);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `resetGLStateCache()` (method, since 0.4.0): GL 상태 기억 다시 맞추기. (three.js 의 resetState 처럼 바깥 GL 코드가 상태를 바꾼 뒤 부른다)
  - 엔진은 컨텍스트의 상태 함수(bindFramebuffer, viewport, enable 같은 것)를 가로채 기억하므로, 같은 컨텍스트 객체로 부른 것은 따로 알리지 않아도 된다.
  - 프로토타입 함수를 직접 부르는 것처럼 가로채지 못한 길로 바꿨을 때 부른다. 기억을 모두 잊고 다음에 읽을 때 GL 에 한 번씩 묻는다.
    Graphic 은 묶음과 상태를 따로 기억하지 않고 이 기억에 견주므로, 그 뒤의 2D 그리기도 제 프로그램, 텍스처, 섞기를 다시 건다.

  예제: 가로채지 못한 길로 상태를 바꾼 뒤 기억 맞추기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2 } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.runExternalPass((webGL2RenderingContext) => {
  			WebGL2RenderingContext.prototype.viewport.call(webGL2RenderingContext, 0, 0, 64, 64);
  			graphic.resetGLStateCache();
  			console.log(graphic.getCurrentViewport().width);
  		}, { clearDepth: false });
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `getDrawingBufferWidth()` (method, since 0.4.0): 드로잉 버퍼 너비 반환. (픽셀, 마지막으로 맞춘 뷰포트)
  - returns number: 드로잉 버퍼 너비. (픽셀)
- `getDrawingBufferHeight()` (method, since 0.4.0): 드로잉 버퍼 높이 반환. (픽셀, 마지막으로 맞춘 뷰포트)
  - returns number: 드로잉 버퍼 높이. (픽셀)
- `readFramebufferPixels()` (method, since 0.4.0): 지금 그린 화면 읽기. (너비, 높이, 위에서 아래로 놓인 RGBA. 화면을 넘기기 전에 부른다)
  - 캔버스처럼 불투명으로 본다. (알파 255)
  - returns { width: number, height: number, pixels: Uint8Array }: 화면 픽셀. ({ width, height, pixels }, pixels 는 위 줄부터 RGBA, 알파 255)
- `getShaderProgram()` (method, since 0.3.0): 셰이더 프로그램 반환.
  - returns ShaderProgram: 지금 쓰는 셰이더 프로그램. (바꿔 끼운 것이 있으면 그것)
- `setShaderProgramOverride(shaderProgram)` (method, since 0.3.0): 셰이더 프로그램 바꿔 끼우기. (null 이면 기본 프로그램으로 복귀)
  - 기본 프로그램과 같은 어트리뷰트 위치 / 유니폼 이름(projectionMatrix, modelMatrix, mainColor, tintColor, globalAlpha, mainTexture)을 갖춰야 한다.
  - `shaderProgram` ShaderProgram | null: 바꿔 끼울 셰이더 프로그램. (null 이면 기본 프로그램)
- `restoreRenderState()` (method, since 0.3.0): 렌더 상태 복구. (외부 WebGL 패스가 프로그램 / 버텍스 어레이 / 뷰포트를 바꾼 뒤 Graphic 출력을 이어갈 때)
- `useShaderProgram(shaderProgram)` (method, since 0.4.0): 셰이더 프로그램 쓰게 하기. (상태 캐시가 이미 이 프로그램을 쓴다고 기억하면 다시 걸지 않는다)
  - Graphic 은 쓰게 한 프로그램을 따로 기억하지 않는다. 게임이 같은 컨텍스트로 다른 프로그램을 쓰게 해도 다음 그리기가 제 프로그램을 다시 건다.
  - `shaderProgram` ShaderProgram: 쓸 셰이더 프로그램.
- `bindTexture(texture)` (method, since 0.4.0): 0 번 텍스처 유닛에 텍스처 묶기. (상태 캐시가 이미 묶였다고 기억하면 다시 묶지 않는다)
  - 활성 유닛이 0 번이 아니면 0 번으로 돌린다. (게임이 다른 유닛을 활성으로 두고 돌아와도 0 번에 묶는다)
  - `texture` WebGLTexture: 묶을 텍스처.
- `clearDepthBuffer()` (method, since 0.4.0): 깊이 버퍼 비우기. (2D 그리기 사이에 3D 를 끼우기 전에)
  - 자르기(beginClipRect, 스텐실)를 건 뒤 그리는 도중에 깊이를 비우면 갤럭시 폴드3(Adreno 660)의 드라이버가 3D 를 하나도 그리지 못한 일이 있다.
    자르기 안에 3D 를 그릴 노드는 beginClipRect 앞에서 이것을 부르고, runExternalPass 에는 clearDepth: false 를 준다.
- `runExternalPass(callback, options = {})` (method, since 0.4.0): 2D 그리기 사이에 WebGL 패스 끼우기. (앞의 2D 묶음을 그리고, 깊이를 비운 뒤 callback, 끝나면 restoreRenderState)
  - callback 은 WebGL2 컨텍스트를 받아 프로그램, 버텍스 어레이, 뷰포트, 섞기, 깊이, 면 가리기를 마음대로 바꿔도 된다. (스텐실 자르기는 그대로 걸려 있고, 스텐실 상태는 되돌리지 않으므로 바꾸지 않는다)
  - callback 이 던지면 상태를 되돌린 뒤 다시 던진다.
  - 이 함수 밖에서 같은 컨텍스트로 WebGL 을 써도 다음 2D 그리기가 프로그램, 버텍스 어레이, 텍스처 유닛, 섞기, 깊이, 면 가리기, 가위, 뷰포트를 상태 캐시에 견주어 다시 건다.
    남는 약속은 둘이다. 2D 는 지금 묶인 프레임 버퍼에 그리므로 게임 프레임 버퍼를 묶었으면 들어올 때 것으로 돌려 두고, 스텐실 상태는 바꾸지 않는다.
  - `callback` Function: (webGL2RenderingContext) => any
  - `options` object: { clearDepth 깊이를 비울지 (기본 true, 자르기 안이면 clearDepthBuffer 머리말) }
  - returns any: callback 이 돌려준 것.

  예제: 2D 사이에 WebGL 직접 그리기 끼우기

  ```js
  import { Engine, EngineConfiguration, Scene, Vector2, Rect } from "./build/vanilla.js";
  
  class MainScene extends Scene {
  	draw(graphic) {
  		super.draw(graphic);
  		graphic.setFillColor("#888888");
  		graphic.drawRect(Rect.create(0, 0, 640, 360));
  		graphic.runExternalPass((webGL2RenderingContext) => {
  			webGL2RenderingContext.enable(webGL2RenderingContext.SCISSOR_TEST);
  			webGL2RenderingContext.scissor(20, 20, 100, 100);
  			webGL2RenderingContext.clearColor(0.2, 0.4, 0.8, 1);
  			webGL2RenderingContext.clear(webGL2RenderingContext.COLOR_BUFFER_BIT);
  			webGL2RenderingContext.disable(webGL2RenderingContext.SCISSOR_TEST);
  		}, { clearDepth: false });
  		graphic.setFillColor("#ffffff");
  		graphic.drawCircle(Vector2.create(320, 180), 40);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

- `getVertexArray()` (method, since 0.3.0): 버텍스 어레이 반환.
  - returns WebGLVertexArrayObject: 버텍스 어레이.
- `getVertexBuffer()` (method, since 0.3.0): 버텍스 버퍼 반환.
  - returns WebGLBuffer: 버텍스 버퍼.
- `getVertexData()` (method, since 0.3.0): 스크래치 버텍스 데이터 반환.
  - returns Float32Array: 스크래치 버텍스 데이터. (정점마다 x, y, u, v)
- `getWhiteTexture()` (method, since 0.3.0): 흰색 텍스처 반환. (단색 도형용)
  - returns WebGLTexture: 1x1 흰색 텍스처.
- `getWhiteColor()` (method, since 0.3.0): 흰색 색상 반환. (이미지/텍스트 출력용 기본 색상)
  - returns Color: 흰색. (나눠 쓰므로 고치지 않는다)
- `getImageTextureCache()` (method, since 0.3.0): 이미지 텍스처 캐시 반환.
  - returns ImageTextureCache: 이미지 텍스처 캐시.
- `getTextStringTextureCache()` (method, since 0.3.0): 문자열 텍스처 캐시 반환.
  - returns TextStringTextureCache: 문자열 텍스처 캐시.
- `resolveShaderProgram(programGroupName, programName, createShaderSource)` (method, since 0.4.0): 이름으로 담아 둔 바꿔 끼울 셰이더 프로그램 반환. (없으면 createShaderSource 가 준 소스로 만들어 담는다)
  - 어트리뷰트 위치를 기본 프로그램과 같게 고정해 링크하므로 기본 버텍스 어레이를 그대로 쓴다.
  - 만들기에 실패하면 한 번만 알리고 null 을 담아 두어 다시 만들지 않는다.
  - `programGroupName` string: 묶음 이름. (효과 종류 같은 것, 열쇠의 앞)
  - `programName` string: 프로그램 이름. (열쇠의 뒤)
  - `createShaderSource` () => [string, string]: 담긴 것이 없을 때만 부르는 함수. ([버텍스 소스, 프래그먼트 소스], GLSL ES 3.00)
  - returns ShaderProgram | null: 담아 둔 프로그램. 만들기에 실패했으면 null. (그 뒤로도 null)

  예제: 흑백 셰이더로 바꿔 끼워 도형 그리기

  ```js
  import { Engine, EngineConfiguration, Scene, Color, Rect } from "./build/vanilla.js";
  
  const VERTEXSHADER_SOURCE = `#version 300 es
  in vec2 vertexPosition;
  in vec2 vertexTextureCoordinate;
  uniform mat3 projectionMatrix;
  uniform mat3 modelMatrix;
  out vec2 fragmentTextureCoordinate;
  void main() {
  	vec3 transformedPosition = projectionMatrix * (modelMatrix * vec3(vertexPosition, 1.0));
  	gl_Position = vec4(transformedPosition.xy, 0.0, 1.0);
  	fragmentTextureCoordinate = vertexTextureCoordinate;
  }
  `;
  const GRAY_FRAGMENTSHADER_SOURCE = `#version 300 es
  precision highp float;
  in vec2 fragmentTextureCoordinate;
  uniform sampler2D mainTexture;
  uniform vec4 mainColor;
  uniform float globalAlpha;
  out vec4 outputColor;
  void main() {
  	vec4 textureColor = texture(mainTexture, fragmentTextureCoordinate);
  	float gray = dot(textureColor.rgb * mainColor.rgb, vec3(0.299, 0.587, 0.114));
  	float alpha = textureColor.a * mainColor.a * globalAlpha;
  	outputColor = vec4(vec3(gray) * alpha, alpha);
  }
  `;
  
  class MainScene extends Scene {
  	preDraw(graphic) {
  		super.preDraw(graphic);
  		const shaderProgram = graphic.resolveShaderProgram("example", "gray", () => [VERTEXSHADER_SOURCE, GRAY_FRAGMENTSHADER_SOURCE]);
  		graphic.setShaderProgramOverride(shaderProgram);
  		graphic.setFillColor(new Color(1, 0.4, 0.2, 1));
  		graphic.drawRect(Rect.create(220, 100, 200, 160));
  		graphic.setShaderProgramOverride(null);
  	}
  }
  
  const engineConfiguration = new EngineConfiguration();
  const engine = new Engine(engineConfiguration);
  engine.run(new MainScene());
  ```

## Functions and constants

- `detectTextDirection(text)` (method, since 0.4.0): 글의 첫 강한 방향. ("ltr" 또는 "rtl", 글자 갈래 문자와 LRM, RLM, ALM 가운데 처음 것, 없으면 "ltr". setTextDirection("auto") 가 쓴다)
  - `text` string: 볼 글. (비었으면 "ltr")
  - returns string: "ltr" 또는 "rtl".
