A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(minigame): sprite masks draw in a mini-game package
esengine3c8930c8c44b
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.jsonindex b1156648d..7202d6ea9 100644--- a/docs/astro/src/data/apiStability.generated.json+++ b/docs/astro/src/data/apiStability.generated.json@@ -3,10 +3,10 @@"counts": {"public": 115,"beta": 103,- "experimental": 2126,+ "experimental": 2127,"deprecated": 3},- "total": 2344,+ "total": 2345,"subsystems": [{"id": "ecs",diff --git a/pipeline/src/runtime/gameHost.ts b/pipeline/src/runtime/gameHost.tsindex fec25194e..44d3b6a16 100644--- a/pipeline/src/runtime/gameHost.ts+++ b/pipeline/src/runtime/gameHost.ts@@ -21,7 +21,7 @@ import {AnimatorRootMotion, Playthrough, Name,worldResidencyReport, PostProcess, Renderer, Audio, Camera,getComponentRegistry,- startDebugChannel,+ startDebugChannel, glContextAttributes,} from 'esengine';/**@@ -187,14 +187,7 @@ async function boot(): Promise<void> {canvas.id ||= 'canvas';renderSurface = { kind: 'webgpu', canvasSelector: `#${canvas.id}` };} else {- gl = canvas.getContext('webgl2', {- alpha: false,- antialias: true,- depth: true,- stencil: true,- premultipliedAlpha: false,- preserveDrawingBuffer: headless,- }) as WebGL2RenderingContext | null;+ gl = canvas.getContext('webgl2', glContextAttributes(headless)) as WebGL2RenderingContext | null;if (!gl) throw new Error('WebGL2 is not available.');renderSurface = {kind: 'gl-context',diff --git a/pipeline/src/runtime/playableHost.ts b/pipeline/src/runtime/playableHost.tsindex adcf73332..766e0c711 100644--- a/pipeline/src/runtime/playableHost.ts+++ b/pipeline/src/runtime/playableHost.ts@@ -14,7 +14,7 @@*/import {createWebApp, setEditorMode, setPlayMode, initPlayableRuntime, createEmbeddedSideModuleHost,- packagedAppOptions, packagedRuntimeInit,+ packagedAppOptions, packagedRuntimeInit, glContextAttributes,} from 'esengine';import type { SceneData, EmbeddedSideModuleRegistry, EmbeddedSideModuleEntry } from 'esengine';import type { ESEngineModule as EngineModule } from 'esengine/wasm';@@ -113,14 +113,7 @@ async function boot(): Promise<void> {// preserved, so a working playable captures as pure black — which reads as// "renders nothing" and is the failure this flag exists to stop faking.const headless = new URLSearchParams(location.search).has('headless');- const gl = canvas.getContext('webgl2', {- alpha: false,- antialias: true,- depth: true,- stencil: true,- premultipliedAlpha: false,- preserveDrawingBuffer: headless,- }) as WebGL2RenderingContext | null;+ const gl = canvas.getContext('webgl2', glContextAttributes(headless)) as WebGL2RenderingContext | null;if (!gl) throw new Error('WebGL2 is not available.');const glHandle = module.GL.registerContext(gl, { majorVersion: 2, minorVersion: 0, enableExtensionsByDefault: true });diff --git a/pipeline/tests/export-playable.test.ts b/pipeline/tests/export-playable.test.tsindex 5cf734459..54efccb15 100644--- a/pipeline/tests/export-playable.test.ts+++ b/pipeline/tests/export-playable.test.ts@@ -78,7 +78,8 @@ beforeAll(() => {writeFileSync(path.join(root, '_sdk', 'index.js'),`export function createWebApp(){return{GL:{registerContext(){}}};}\nexport function setEditorMode(){}\nexport function setPlayMode(){}\nexport function initPlayableRuntime(){return Promise.resolve();}\nexport function createEmbeddedSideModuleHost(){return{acquire(){return Promise.resolve(null);}};}\nexport function defineComponent(){}\nexport function parseThemeOverrides(){}export function packagedAppOptions(c){return c;}-export function packagedRuntimeInit(c){return c;}\n`);+export function packagedRuntimeInit(c){return c;}+export function glContextAttributes(){return {};}\n`);// Stub web wasm runtime (glue text + wasm) — playable inlines these, no separate build.mkdirSync(path.join(root, '_wasm'), { recursive: true });writeFileSync(path.join(root, '_wasm', 'esengine.js'), `export default function(){}/*WEB_GLUE*/\n`);@@ -345,7 +346,8 @@ describe('exportGame (playable) — side-module embedding', () => {writeFileSync(path.join(r, '_sdk', 'index.js'),`export function createWebApp(){return{GL:{registerContext(){}}};}\nexport function setEditorMode(){}\nexport function setPlayMode(){}\nexport function initPlayableRuntime(){return Promise.resolve();}\nexport function createEmbeddedSideModuleHost(){return{acquire(){return Promise.resolve(null);}};}\nexport function parseThemeOverrides(){}export function packagedAppOptions(c){return c;}-export function packagedRuntimeInit(c){return c;}\n`);+export function packagedRuntimeInit(c){return c;}+export function glContextAttributes(){return {};}\n`);mkdirSync(path.join(r, '_wasm'), { recursive: true });writeFileSync(path.join(r, '_wasm', 'esengine.js'), `export default function(){}\n`);writeFileSync(path.join(r, '_wasm', 'esengine.wasm'), 'WASMBYTES');@@ -449,7 +451,8 @@ describe('exportGame (playable) — spine embedding', () => {writeFileSync(path.join(r, '_sdk', 'index.js'),`export function createWebApp(){return{GL:{registerContext(){}}};}\nexport function setEditorMode(){}\nexport function setPlayMode(){}\nexport function initPlayableRuntime(){return Promise.resolve();}\nexport function createEmbeddedSideModuleHost(){return{acquire(){return Promise.resolve(null);}};}\nexport function parseThemeOverrides(){}export function packagedAppOptions(c){return c;}-export function packagedRuntimeInit(c){return c;}\n`);+export function packagedRuntimeInit(c){return c;}+export function glContextAttributes(){return {};}\n`);mkdirSync(path.join(r, '_wasm'), { recursive: true });writeFileSync(path.join(r, '_wasm', 'esengine.js'), `export default function(){}\n`);writeFileSync(path.join(r, '_wasm', 'esengine.wasm'), 'WASMBYTES');diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 4c89d6470..80e6bf946 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -1,7 +1,7 @@# API surface — esengine/index<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 91 beta · 1512 experimental · 3 deprecated+Symbols: 115 public · 91 beta · 1513 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -11114,6 +11114,11 @@ FocusPlugin(): Array<{ type: string; value: string; }>```+## glContextAttributes — function @experimental+```+(preserveDrawingBuffer?: boolean): WebGLContextAttributes+```+## hasPlayableCta — function @experimental```(): booleandiff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex ad1941327..13dbab512 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.native<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 96 beta · 1531 experimental · 3 deprecated+Symbols: 115 public · 96 beta · 1532 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```@@ -11355,6 +11355,11 @@ FocusPlugin(): Array<{ type: string; value: string; }>```+## glContextAttributes — function @experimental+```+(preserveDrawingBuffer?: boolean): WebGLContextAttributes+```+## hasPlayableCta — function @experimental```(): booleandiff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex e2295f315..981944b2d 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.node<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 93 beta · 1511 experimental · 3 deprecated+Symbols: 115 public · 93 beta · 1512 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -11109,6 +11109,11 @@ FocusPlugin(): Array<{ type: string; value: string; }>```+## glContextAttributes — function @experimental+```+(preserveDrawingBuffer?: boolean): WebGLContextAttributes+```+## hasPlayableCta — function @experimental```(): booleandiff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex 4f0cac303..e678f7a68 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -1,7 +1,7 @@# API surface — esengine/minigame<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 91 beta · 1533 experimental · 3 deprecated+Symbols: 115 public · 91 beta · 1534 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -11390,6 +11390,11 @@ FocusPlugin(): Array<{ type: string; value: string; }>```+## glContextAttributes — function @experimental+```+(preserveDrawingBuffer?: boolean): WebGLContextAttributes+```+## hasPlayableCta — function @experimental```(): booleandiff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex e7987463f..65fe66ed9 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -1,7 +1,7 @@# API surface — esengine/wechat<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 115 public · 91 beta · 1524 experimental · 3 deprecated+Symbols: 115 public · 91 beta · 1525 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -11140,6 +11140,11 @@ FocusPlugin(): Array<{ type: string; value: string; }>```+## glContextAttributes — function @experimental+```+(preserveDrawingBuffer?: boolean): WebGLContextAttributes+```+## hasPlayableCta — function @experimental```(): booleandiff --git a/sdk/src/core-content.ts b/sdk/src/core-content.tsindex 5fe9ad518..55c9887ad 100644--- a/sdk/src/core-content.ts+++ b/sdk/src/core-content.ts@@ -442,6 +442,7 @@ export {registerPackagedSideModules,packagedAppOptions,packagedRuntimeInit,+ glContextAttributes,type PackagedAssetIndex,type PackagedAssetSourceOptions,type PackagedGameConfig,diff --git a/sdk/src/runtime/miniGameRuntime.ts b/sdk/src/runtime/miniGameRuntime.tsindex ca74cb1d5..6dc71d364 100644--- a/sdk/src/runtime/miniGameRuntime.ts+++ b/sdk/src/runtime/miniGameRuntime.ts@@ -25,7 +25,7 @@ import { getPlatform, platformReadTextFile, platformInstantiateWasm } from '../pimport { MiniGamePlatformAdapter } from '../platform/minigame';import {loadPackagedAssetIndex, createPackagedAssetSource, applyAssetRefResolvers,- registerPackagedSideModules,+ registerPackagedSideModules, glContextAttributes,} from './packagedRuntime';import { createMiniGameSideModuleHost, type MiniGameSideModuleFactories } from '../sideModules';import type { Physics2DPluginConfig } from '../physics/PhysicsTypes';@@ -264,7 +264,7 @@ export async function initMiniGameRuntime(config: MiniGameRuntimeConfig): Promisconst glxLinked = typeof (module as { _glxInit?: unknown })._glxInit === 'function';const hostEnv = (adapter.host as { env?: { isSupportEmscriptenGLX?: boolean } }).env;const wantGlx = glxLinked && hostEnv?.isSupportEmscriptenGLX === true;- const gl = canvas.getContext(wantGlx ? 'wxwebgl2' : 'webgl2') as WebGLRenderingContext | null;+ const gl = canvas.getContext(wantGlx ? 'wxwebgl2' : 'webgl2', glContextAttributes()) as WebGLRenderingContext | null;if (!gl) {// The renderer is GLSL ES 3.0 throughout, so a WebGL1 context would boot// to shader failures and a black screen; this says why instead.diff --git a/sdk/src/runtime/packagedRuntime.ts b/sdk/src/runtime/packagedRuntime.tsindex ad48ff7ef..399c544ab 100644--- a/sdk/src/runtime/packagedRuntime.ts+++ b/sdk/src/runtime/packagedRuntime.ts@@ -177,6 +177,22 @@ export function registerPackagedSideModules(config: Pick<PackagedGameConfig, 'si* ignore it. One projection, so a field added to the config reaches every realm* that spreads it.*/+/**+ * The attributes every host creates the engine's WebGL2 context with. WebGL+ * gives no stencil buffer unless asked, and sprite masks draw through one.+ * `preserveDrawingBuffer` is for a harness that reads a composited frame back.+ */+export function glContextAttributes(preserveDrawingBuffer = false): WebGLContextAttributes {+ return {+ alpha: false,+ antialias: true,+ depth: true,+ stencil: true,+ premultipliedAlpha: false,+ preserveDrawingBuffer,+ };+}+export function packagedAppOptions(config: Pick<PackagedGameConfig,'ySortLayers' | 'depthLayers' | 'colorSpace' | 'outputTransform' | 'screenFit'