Next2D Player は、リッチでインタラクティブなグラフィックス、ゲーム、クロスプラットフォームアプリケーションを作成するための WebGL/WebGPU ベースの 2D グラフィックスレンダリングエンジンです。ハードウェアアクセラレーションによるグラフィックス処理と、OffscreenCanvas + Web Worker によるマルチスレッドレンダリングを採用しています。
Next2D Player is a WebGL/WebGPU-based 2D graphics rendering engine for creating rich, interactive graphics, games, and cross-platform applications. It uses hardware acceleration for graphics processing and OffscreenCanvas with web workers for multi-threaded rendering performance.
Middleware required for development and supported versions
node >= v22.x
TypeScript ES2020 target
git clone git@github.com:Next2D/player.git
cd player
npm install
npm start
npm test
Tests use Vitest. To run a specific test file:
npx vitest packages/webgl/src/Blend/service/BlendAddService.test.tsOr run tests matching a pattern:
npx vitest --testNamePattern "BlendAddService"npm run lint
npm run build:vite # Build production bundle
npm run clean # Clean build artifacts各 class の method は usecase もしくは service で実装しています。但し、service から service をコールするのは禁止しています。method が簡素な場合は、service を直接コールし、複雑な場合や、複数の service を呼び出したい場合は usecase を実装しています。ロジックは usecase もしくは service に責務を置き、 method の役割は、 private や protected など、class 変数への値のセットまでとしています。
The method of each class is implemented by usecase or service. However, calling service from service is prohibited. If the method is simple, call service directly. If the method is complex or you want to call multiple service, implement usecase. The logic places the responsibility on the usecase or service, and the role of the method is limited to setting values in class variables, such as private or protected.
class => method => service
class => method => usecase => service
packages/webgl/src/
Context.ts # Main class
Context/
service/ContextResetService.ts # Simple operations
service/ContextResetService.test.ts
usecase/ContextBindUseCase.ts # Complex operations
usecase/ContextBindUseCase.test.ts
packages ディレクトリの依存関係で注意する点は以下の通りです。
@next2d/coreは他のpackagesからの参照を禁止しています。@next2d/events,@next2d/cache,@next2d/filters,@next2d/geom,@next2d/texture-packer,@next2d/render-queueは疎結合で設計されている為、他のpackagesのimportを禁止しています。@next2d/rendererはOffscreenCanvasがworkerで処理されるため、@next2d/webgl,@next2d/webgpuのみimportを許可しています。
The dependencies to note in the packages directory are as follows
@next2d/coredoes not allow references from otherpackages.@next2d/events,@next2d/cache,@next2d/filters,@next2d/geom,@next2d/texture-packerand@next2d/render-queueare designed to be loosely coupled, soimportof otherpackagesis prohibited.@next2d/rendererallowsimportonly for@next2d/webgl,@next2d/webgpu, because OffscreenCanvas is processed by the worker.
Core packages (loosely coupled, no cross-imports allowed):
@next2d/events- Event system@next2d/cache- Caching utilities@next2d/filters- Image filters@next2d/geom- Geometry/matrix utilities@next2d/texture-packer- Texture atlas packing@next2d/render-queue- Render command queue
Rendering layer:
@next2d/webgl- WebGL rendering context and operations@next2d/webgpu- WebGPU rendering (alternative backend)@next2d/renderer- OffscreenCanvas worker-based renderer (imports only@next2d/webgl)
Display layer:
@next2d/display- DisplayObject hierarchy (Shape, MovieClip, Bitmap, etc.)@next2d/text- TextField rendering@next2d/media- Audio/Video support@next2d/ui- UI components@next2d/net- Network/loading utilities
Entry point:
@next2d/core- Main Next2D class, Player, Canvas (references other packages but cannot be referenced BY other packages)
Playerは2スレッド構成で動作します。
- メインスレッド: DisplayObjectツリーの管理、イベント処理、アニメーションロジック
- ワーカースレッド: OffscreenCanvas経由のWebGL/WebGPUレンダリング
The player uses a two-thread architecture:
- Main thread: DisplayObject tree management, event handling, animation logic
- Worker thread: WebGL/WebGPU rendering via OffscreenCanvas
Flow: DisplayObjects -> RenderQueue -> Worker -> WebGL Context -> Canvas
Key rendering features:
- Texture Atlas with binary tree packing for efficient GPU memory
- Instanced array rendering for batch drawing
- Filter/blend effects rendered to texture cache
- Mask rendering with stencil buffer
The renderer backend is controlled by the useWebGPU flag in:
packages/renderer/src/Command/service/CommandInitializeContextService.ts
const useWebGPU: boolean = true;→ WebGPU rendererconst useWebGPU: boolean = false;→ WebGL renderer
E2E tests use whichever renderer is set by this flag. To compare WebGL vs WebGPU output:
- Set
useWebGPU = false, run e2e tests for WebGL snapshots - Set
useWebGPU = true, run e2e tests for WebGPU snapshots - Compare the generated snapshots
E2E tests use Playwright. Run from the e2e/ directory:
cd e2e
npx playwright test tests/sprite.spec.ts --project=webgl --update-snapshots
npx playwright test tests/sprite.spec.ts --project=webgpu --update-snapshotsSnapshots are saved to:
e2e/snapshots/webgl/{spec}-snapshots/e2e/snapshots/webgpu/{spec}-snapshots/
フレームタイム(median/p95)を計測するベンチマークです。PERF=1 が設定されたときのみ実行され、通常のe2e実行ではスキップされます。シナリオ: sprites / filters / text / blend(e2e/pages/perf/)。閾値(e2e/tests/perf.spec.ts)はマシン依存です。
Frame-time benchmarks (median/p95) run via Playwright, gated behind PERF=1
(skipped in normal e2e runs). Scenarios: sprites / filters / text / blend
(e2e/pages/perf/). Thresholds in e2e/tests/perf.spec.ts are machine-dependent.
npm run test:e2e:perf # both renderers (respects useWebGPU flag pairing)
npm run test:e2e:perf:webgl # WebGL only (set useWebGPU=false first)
npm run test:e2e:perf:webgpu # WebGPU only (set useWebGPU=true first)This project is licensed under the MIT License - see the LICENSE file for details.