@babylonjs/lite-gl 1.23.0 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +103 -6
- package/blend.d.ts +1 -1
- package/blend.js +1 -1
- package/blend.js.map +1 -1
- package/context.d.ts +52 -4
- package/context.js +108 -11
- package/context.js.map +1 -1
- package/depth-stencil.d.ts +4 -16
- package/depth-stencil.js +10 -11
- package/depth-stencil.js.map +1 -1
- package/dynamic-texture.d.ts +6 -3
- package/dynamic-texture.js +16 -4
- package/dynamic-texture.js.map +1 -1
- package/effect-renderer.d.ts +1 -11
- package/effect-renderer.js.map +1 -1
- package/effect.d.ts +16 -29
- package/effect.js +52 -19
- package/effect.js.map +1 -1
- package/family.d.ts +474 -0
- package/family.js +14 -0
- package/family.js.map +1 -0
- package/framebuffer-validation.d.ts +20 -0
- package/framebuffer-validation.js +37 -0
- package/framebuffer-validation.js.map +1 -0
- package/html-texture.d.ts +2 -2
- package/html-texture.js.map +1 -1
- package/index.d.ts +10 -7
- package/index.js +5 -4
- package/index.js.map +1 -1
- package/mesh.d.ts +72 -15
- package/mesh.js +221 -64
- package/mesh.js.map +1 -1
- package/native/command-stream.d.ts +1 -0
- package/native/command-stream.js +135 -0
- package/native/command-stream.js.map +1 -0
- package/native/context.d.ts +26 -0
- package/native/context.js +89 -0
- package/native/context.js.map +1 -0
- package/native/effect.d.ts +44 -0
- package/native/effect.js +276 -0
- package/native/effect.js.map +1 -0
- package/native/family.d.ts +75 -0
- package/native/family.js +2 -0
- package/native/family.js.map +1 -0
- package/native/identity.d.ts +11 -0
- package/native/identity.js +2 -0
- package/native/identity.js.map +1 -0
- package/native/index.d.ts +25 -0
- package/native/index.js +7 -0
- package/native/index.js.map +1 -0
- package/native/mesh.d.ts +53 -0
- package/native/mesh.js +137 -0
- package/native/mesh.js.map +1 -0
- package/native/render-target.d.ts +35 -0
- package/native/render-target.js +159 -0
- package/native/render-target.js.map +1 -0
- package/native/runtime.d.ts +1 -0
- package/native/runtime.js +12 -0
- package/native/runtime.js.map +1 -0
- package/native/state.d.ts +19 -0
- package/native/state.js +104 -0
- package/native/state.js.map +1 -0
- package/native/texture.d.ts +37 -0
- package/native/texture.js +86 -0
- package/native/texture.js.map +1 -0
- package/package.json +11 -3
- package/render-target.d.ts +18 -9
- package/render-target.js +84 -31
- package/render-target.js.map +1 -1
- package/scissor.d.ts +3 -3
- package/scissor.js +2 -2
- package/scissor.js.map +1 -1
- package/sprites.d.ts +5 -3
- package/sprites.js +24 -23
- package/sprites.js.map +1 -1
- package/state.d.ts +26 -13
- package/state.js +15 -15
- package/state.js.map +1 -1
- package/text/_gpu/text-instances.js +1 -1
- package/text/_gpu/text-instances.js.map +1 -1
- package/text/text-renderer.js.map +1 -1
- package/texture-3d.d.ts +2 -1
- package/texture-3d.js +7 -2
- package/texture-3d.js.map +1 -1
- package/texture-source.d.ts +4 -2
- package/texture-source.js +3 -2
- package/texture-source.js.map +1 -1
- package/texture.d.ts +18 -8
- package/texture.js +61 -35
- package/texture.js.map +1 -1
- package/web-family.d.ts +88 -0
- package/web-family.js +2 -0
- package/web-family.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-target.js","sourceRoot":"","sources":["../../src/native/render-target.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAwBlG,2KAA2K;AAC3K,MAAM,UAAU,kBAAkB,CAAC,MAAuB,EAAE,KAAa,EAAE,MAAc,EAAE,OAA+B;IACtH,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;IACxG,CAAC;IACD,mBAAmB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,C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CAAC,WAAW,CAAC,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,CAAC;AACtB,CAAC;AAED,oHAAoH;AACpH,MAAM,UAAU,mBAAmB,CAAC,MAAyC;IACzE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QAC9B,OAAO;IACX,CAAC;IACD,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACpB,IAAI,MAAM,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;YAC5B,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpC,CAAC;QACD,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACtD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACb,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;QACtB,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;AACL,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\nimport type { NativeResource, NativeResourceFields } from \"./identity.js\";\nimport type { NativeHandle } from \"./runtime.js\";\nimport { setNormalizedViewport } from \"./state.js\";\nimport { configureTexture, disposeTexture, makeTexture, validateTextureSize } from \"./texture.js\";\nimport type { GLTexture, NativeTextureHandle } from \"./texture.js\";\n\n/** Options for {@link createRenderTarget}. */\nexport interface GLRenderTargetOptions {\n /** Caller-owned color attachment to render into instead of an owned RGBA8 texture. */\n colorTexture?: GLTexture;\n}\n\n/** Native framebuffer and its color attachment. */\nexport interface GLRenderTarget extends NativeResource<\"renderTarget\"> {\n readonly width: number;\n readonly height: number;\n readonly texture: GLTexture;\n /** @internal */\n _framebuffer: NativeHandle;\n /** @internal */\n readonly _ownsTexture: boolean;\n /** @internal The engine that owns this framebuffer. */\n readonly _engine: GLEngineContext;\n /** @internal */\n _disposed: boolean;\n}\n\n/** Creates a composition target around an owned or supplied color attachment of a live engine; a supplied attachment must be a live, renderable texture of this engine. */\nexport function createRenderTarget(engine: GLEngineContext, width: number, height: number, options?: GLRenderTargetOptions): GLRenderTarget {\n if (engine._disposed) {\n throw new Error(\"Native Lite GL createRenderTarget requires an engine that has not been disposed.\");\n }\n validateTextureSize(engine, width, height);\n const colorTexture = options?.colorTexture;\n if (colorTexture && (colorTexture._engine !== engine || colorTexture._disposed)) {\n throw new Error(\"Native Lite GL createRenderTarget requires a color texture of this engine that has not been disposed.\");\n }\n if (colorTexture?._sampledOnly) {\n throw new Error(\"Native Lite GL createRenderTarget cannot render into a sampled-only texture such as one from createRawTexture.\");\n }\n let texture = colorTexture;\n if (!texture) {\n const handle = engine._native.createTexture();\n try {\n engine._native.initializeTexture(handle, width, height, false, engine._runtime.Engine.TEXTURE_FORMAT_RGBA8, true, false, 1);\n texture = makeTexture(engine, handle, true, false);\n } catch (error) {\n engine._native.deleteTexture(handle);\n throw error;\n }\n }\n try {\n const fields: NativeResourceFields<GLRenderTarget> = {\n width,\n height,\n texture,\n _framebuffer: engine._native.createFrameBuffer(texture._handle, width, height, false, false, 1),\n _ownsTexture: !colorTexture,\n _engine: engine,\n _disposed: false,\n };\n const target = fields as GLRenderTarget;\n texture._targets.push(target);\n return target;\n } catch (error) {\n if (!colorTexture) {\n disposeTexture(texture);\n }\n throw error;\n }\n}\n\n/**\n * Selects the drawing target, resolving the prior framebuffer before changing it,\n * and sets the viewport to cover it. No-op for a disposed target or engine.\n */\nexport function bindRenderTarget(target: GLRenderTarget): void {\n if (target._disposed || target._engine._disposed) {\n return;\n }\n selectFramebuffer(target._engine, target);\n setNormalizedViewport(target._engine, 0, 0, 1, 1, 1, 1);\n}\n\n/** Selects the default output, resolving the prior framebuffer, and sets the viewport to cover it. No-op for a disposed engine. */\nexport function restoreDefaultFramebuffer(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n selectFramebuffer(engine, null);\n setNormalizedViewport(engine, 0, 0, 1, 1, 1, 1);\n}\n\nfunction selectFramebuffer(engine: GLEngineContext, target: GLRenderTarget | null): void {\n if (engine._target === target) {\n return;\n }\n const commands = engine._commands;\n if (engine._target) {\n commands.start(engine._runtime.Engine.COMMAND_UNBINDFRAMEBUFFER);\n commands.handle(engine._target._framebuffer);\n commands.finish();\n }\n if (target) {\n commands.start(engine._runtime.Engine.COMMAND_BINDFRAMEBUFFER);\n commands.handle(target._framebuffer);\n commands.finish();\n }\n engine._target = target;\n // The native viewport belongs to the framebuffer binding, so the cached value no longer applies.\n engine._viewport.fill(NaN);\n}\n\nconst NO_FRAMEBUFFERS: readonly NativeHandle[] = [];\n\n/**\n * Repoints a borrowed texture while preserving its render-target identities.\n * If the host cannot create a replacement framebuffer, the texture and its\n * targets keep their previous handles, but Lite GL cannot restore host storage\n * that already changed behind them; retry the update or restore the host\n * storage before using the texture or its targets.\n * A host can replace the storage behind the same handle object, so every call\n * rebuilds the framebuffers; call it only when the storage has changed.\n */\nexport function updateWrappedNativeTexture(texture: GLTexture, replacement: NativeTextureHandle): void {\n const engine = texture._engine;\n if (texture._owned || texture.width !== engine._native.getTextureWidth(replacement) || texture.height !== engine._native.getTextureHeight(replacement)) {\n throw new Error(\"Replacement native texture must preserve the borrowed texture's shape.\");\n }\n const targets = texture._targets;\n const framebuffers = targets.length === 0 ? NO_FRAMEBUFFERS : createFramebuffers(engine, targets, replacement);\n for (const target of targets) {\n if (engine._target === target) {\n selectFramebuffer(engine, null);\n }\n }\n texture._handle = replacement;\n configureTexture(engine, texture);\n for (let index = 0; index < targets.length; index++) {\n const target = targets[index] as GLRenderTarget;\n deleteFramebuffer(engine, target._framebuffer);\n target._framebuffer = framebuffers[index] as NativeHandle;\n }\n}\n\nfunction createFramebuffers(engine: GLEngineContext, targets: readonly GLRenderTarget[], texture: NativeHandle): NativeHandle[] {\n const framebuffers: NativeHandle[] = [];\n try {\n for (const target of targets) {\n framebuffers.push(engine._native.createFrameBuffer(texture, target.width, target.height, false, false, 1));\n }\n return framebuffers;\n } catch (error) {\n for (const framebuffer of framebuffers) {\n deleteFramebuffer(engine, framebuffer);\n }\n throw error;\n }\n}\n\nfunction deleteFramebuffer(engine: GLEngineContext, framebuffer: NativeHandle): void {\n const commands = engine._commands;\n commands.start(engine._runtime.Engine.COMMAND_DELETEFRAMEBUFFER);\n commands.handle(framebuffer);\n commands.finish();\n}\n\n/** Releases a framebuffer and only the color storage it owns; after engine disposal it only marks them disposed. */\nexport function disposeRenderTarget(target: GLRenderTarget | null | undefined): void {\n if (!target || target._disposed) {\n return;\n }\n target._disposed = true;\n const engine = target._engine;\n if (!engine._disposed) {\n if (engine._target === target) {\n selectFramebuffer(engine, null);\n }\n deleteFramebuffer(engine, target._framebuffer);\n }\n const index = target.texture._targets.indexOf(target);\n if (index >= 0) {\n target.texture._targets.splice(index, 1);\n }\n if (target._ownsTexture) {\n disposeTexture(target.texture);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export function getRuntime() {
|
|
3
|
+
const runtime = globalThis._native;
|
|
4
|
+
if (!runtime) {
|
|
5
|
+
throw new Error("Native Lite GL requires the Babylon Native runtime.");
|
|
6
|
+
}
|
|
7
|
+
if (runtime.Engine.PROTOCOL_VERSION !== 9) {
|
|
8
|
+
throw new Error(`Native Lite GL requires protocol 9, received ${runtime.Engine.PROTOCOL_VERSION}.`);
|
|
9
|
+
}
|
|
10
|
+
return runtime;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/native/runtime.ts"],"names":[],"mappings":"AA2GA,gBAAgB;AAChB,MAAM,UAAU,UAAU;IACtB,MAAM,OAAO,GAAI,UAA8D,CAAC,OAAO,CAAC;IACxF,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,CAAC,gBAAgB,KAAK,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,gDAAgD,OAAO,CAAC,MAAM,CAAC,gBAAgB,GAAG,CAAC,CAAC;IACxG,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC","sourcesContent":["/** @internal */\nexport type NativeHandle = Uint32Array<ArrayBuffer>;\n\n/** @internal */\nexport interface NativeEngine {\n dispose(): void;\n setRenderResetCallback(callback: () => void): void;\n setHardwareScalingLevel(level: number): void;\n getRenderWidth(): number;\n getRenderHeight(): number;\n setCommandDataStream(stream: object): void;\n submitCommands(): void;\n createProgram(vertex: string, fragment: string): NativeHandle;\n getUniforms(program: NativeHandle, names: string[]): (NativeHandle | null)[];\n getAttributes(program: NativeHandle, names: string[]): number[];\n createVertexArray(): NativeHandle;\n createVertexBuffer(data: ArrayBufferLike, offset: number, length: number, dynamic: boolean): NativeHandle;\n createIndexBuffer(data: ArrayBufferLike, offset: number, length: number, is32Bits: boolean, dynamic: boolean): NativeHandle;\n recordIndexBuffer(vao: NativeHandle, buffer: NativeHandle): void;\n recordVertexBuffer(\n vao: NativeHandle,\n buffer: NativeHandle,\n location: number,\n offset: number,\n stride: number,\n components: number,\n type: number,\n normalized: boolean,\n divisor: number\n ): void;\n createTexture(): NativeHandle;\n loadRawTexture(handle: NativeHandle, data: ArrayBufferView, width: number, height: number, format: number, mipmaps: boolean, invertY: boolean): void;\n initializeTexture(handle: NativeHandle, width: number, height: number, mipmaps: boolean, format: number, renderTarget: boolean, srgb: boolean, samples: number): void;\n getTextureWidth(handle: NativeHandle): number;\n getTextureHeight(handle: NativeHandle): number;\n deleteTexture(handle: NativeHandle): void;\n createFrameBuffer(texture: NativeHandle, width: number, height: number, stencil: boolean, depth: boolean, samples: number): NativeHandle;\n}\n\ntype CommandName =\n | \"SETPROGRAM\"\n | \"DELETEPROGRAM\"\n | \"SETFLOAT\"\n | \"SETFLOAT2\"\n | \"SETFLOAT3\"\n | \"SETFLOAT4\"\n | \"SETINT\"\n | \"SETFLOATARRAY\"\n | \"SETFLOATARRAY2\"\n | \"SETFLOATARRAY3\"\n | \"SETFLOATARRAY4\"\n | \"SETMATRICES\"\n | \"SETTEXTURE\"\n | \"SETTEXTURESAMPLING\"\n | \"SETTEXTUREWRAPMODE\"\n | \"SETTEXTUREANISOTROPICLEVEL\"\n | \"DELETEVERTEXBUFFER\"\n | \"DELETEINDEXBUFFER\"\n | \"DELETEVERTEXARRAY\"\n | \"BINDVERTEXARRAY\"\n | \"DRAWINDEXED\"\n | \"BINDFRAMEBUFFER\"\n | \"UNBINDFRAMEBUFFER\"\n | \"DELETEFRAMEBUFFER\"\n | \"SETVIEWPORT\"\n | \"SETSCISSOR\"\n | \"SETBLENDMODE\"\n | \"SETDEPTHTEST\"\n | \"SETDEPTHWRITE\"\n | \"SETSTATE\"\n | \"CLEAR\";\n\n/** @internal */\nexport type NativeEngineConstructor = {\n new (info: { version: string; nonFloatVertexBuffers: true }): NativeEngine;\n readonly PROTOCOL_VERSION: number;\n readonly CAPS_LIMITS_MAX_TEXTURE_SIZE: number;\n readonly ATTRIB_TYPE_FLOAT: number;\n readonly TEXTURE_FORMAT_RGBA8: number;\n readonly TEXTURE_LINEAR_LINEAR: number;\n readonly TEXTURE_NEAREST_NEAREST: number;\n readonly ADDRESS_MODE_CLAMP: number;\n readonly DEPTH_TEST_ALWAYS: number;\n readonly ALPHA_DISABLE: number;\n readonly ALPHA_COMBINE: number;\n readonly ALPHA_ADD: number;\n readonly ALPHA_PREMULTIPLIED: number;\n} & { readonly [K in CommandName as `COMMAND_${K}`]: NativeHandle };\n\n/** @internal */\nexport interface NativeDataStreamConstructor {\n new (flush: () => void): { writeBuffer(buffer: ArrayBuffer, words: number): void };\n readonly VALIDATION_ENABLED: boolean;\n readonly VALIDATION_UINT_32: number;\n readonly VALIDATION_INT_32: number;\n readonly VALIDATION_FLOAT_32: number;\n readonly VALIDATION_FLOAT_32_ARRAY: number;\n readonly VALIDATION_NATIVE_DATA: number;\n readonly VALIDATION_BOOLEAN: number;\n}\n\n/** @internal */\nexport interface NativeRuntime {\n Engine: NativeEngineConstructor;\n NativeDataStream: NativeDataStreamConstructor;\n}\n\n/** @internal */\nexport function getRuntime(): NativeRuntime {\n const runtime = (globalThis as typeof globalThis & { _native?: NativeRuntime })._native;\n if (!runtime) {\n throw new Error(\"Native Lite GL requires the Babylon Native runtime.\");\n }\n if (runtime.Engine.PROTOCOL_VERSION !== 9) {\n throw new Error(`Native Lite GL requires protocol 9, received ${runtime.Engine.PROTOCOL_VERSION}.`);\n }\n return runtime;\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GLEngineContext } from "./context.js";
|
|
2
|
+
import type { GLClearOptions, GLViewport } from "../family.js";
|
|
3
|
+
/** Blend presets shared with Lite GL: disabled, additive, combine and premultiplied. */
|
|
4
|
+
export type GLBlendMode = 0 | 1 | 2 | 7;
|
|
5
|
+
/** Changes the drawing viewport in pixels of the bound target. Defaults to the size of the default output, whichever target is bound. No-op for a disposed engine. */
|
|
6
|
+
export declare function setViewport(engine: GLEngineContext, viewport?: GLViewport): void;
|
|
7
|
+
/**
|
|
8
|
+
* Restricts drawing and clearing to a bottom-left-origin rectangle in physical
|
|
9
|
+
* pixels; portable callers pass nonnegative integer dimensions. A rectangle
|
|
10
|
+
* without area allows neither until the scissor changes. No-op for a disposed
|
|
11
|
+
* engine.
|
|
12
|
+
*/
|
|
13
|
+
export declare function setScissor(engine: GLEngineContext, x: number, y: number, width: number, height: number): void;
|
|
14
|
+
/** Restores unrestricted drawing. No-op for a disposed engine. */
|
|
15
|
+
export declare function disableScissor(engine: GLEngineContext): void;
|
|
16
|
+
/** Sets a Lite GL blend preset. No-op for a disposed engine. */
|
|
17
|
+
export declare function setBlendMode(engine: GLEngineContext, mode: GLBlendMode): void;
|
|
18
|
+
/** Clears the current composition target within its scissor, without changing the scissor. No-op for a disposed engine. */
|
|
19
|
+
export declare function clearEngine(engine: GLEngineContext, options: GLClearOptions): void;
|
package/native/state.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { getRenderHeight, getRenderWidth } from "./context.js";
|
|
2
|
+
/** Changes the drawing viewport in pixels of the bound target. Defaults to the size of the default output, whichever target is bound. No-op for a disposed engine. */
|
|
3
|
+
export function setViewport(engine, viewport) {
|
|
4
|
+
if (engine._disposed) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const target = engine._target;
|
|
8
|
+
// The default output size is a host query, so an explicit viewport of a bound target does not read it.
|
|
9
|
+
if (viewport && target) {
|
|
10
|
+
setNormalizedViewport(engine, viewport.x, viewport.y, viewport.w, viewport.h, target.width, target.height);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const outputWidth = getRenderWidth(engine);
|
|
14
|
+
const outputHeight = getRenderHeight(engine);
|
|
15
|
+
setNormalizedViewport(engine, viewport?.x ?? 0, viewport?.y ?? 0, viewport?.w ?? outputWidth, viewport?.h ?? outputHeight, target?.width ?? outputWidth, target?.height ?? outputHeight);
|
|
16
|
+
}
|
|
17
|
+
/** @internal Native viewports are fractions of the bound target. */
|
|
18
|
+
export function setNormalizedViewport(engine, x, y, width, height, targetWidth, targetHeight) {
|
|
19
|
+
x /= targetWidth;
|
|
20
|
+
y /= targetHeight;
|
|
21
|
+
width /= targetWidth;
|
|
22
|
+
height /= targetHeight;
|
|
23
|
+
const values = engine._viewport;
|
|
24
|
+
if (values[0] === x && values[1] === y && values[2] === width && values[3] === height) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
values[0] = x;
|
|
28
|
+
values[1] = y;
|
|
29
|
+
values[2] = width;
|
|
30
|
+
values[3] = height;
|
|
31
|
+
const commands = engine._commands;
|
|
32
|
+
commands.start(engine._runtime.Engine.COMMAND_SETVIEWPORT);
|
|
33
|
+
commands.float(x);
|
|
34
|
+
commands.float(y);
|
|
35
|
+
commands.float(width);
|
|
36
|
+
commands.float(height);
|
|
37
|
+
commands.finish();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Restricts drawing and clearing to a bottom-left-origin rectangle in physical
|
|
41
|
+
* pixels; portable callers pass nonnegative integer dimensions. A rectangle
|
|
42
|
+
* without area allows neither until the scissor changes. No-op for a disposed
|
|
43
|
+
* engine.
|
|
44
|
+
*/
|
|
45
|
+
export function setScissor(engine, x, y, width, height) {
|
|
46
|
+
if (engine._disposed) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// The host reads an all-zero rectangle as "no scissor", so an empty one is enforced here instead.
|
|
50
|
+
engine._scissorEmpty = width <= 0 || height <= 0;
|
|
51
|
+
if (!engine._scissorEmpty) {
|
|
52
|
+
encodeScissor(engine, x, y, width, height);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Restores unrestricted drawing. No-op for a disposed engine. */
|
|
56
|
+
export function disableScissor(engine) {
|
|
57
|
+
if (engine._disposed) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
engine._scissorEmpty = false;
|
|
61
|
+
encodeScissor(engine, 0, 0, 0, 0);
|
|
62
|
+
}
|
|
63
|
+
function encodeScissor(engine, x, y, width, height) {
|
|
64
|
+
const commands = engine._commands;
|
|
65
|
+
commands.start(engine._runtime.Engine.COMMAND_SETSCISSOR);
|
|
66
|
+
commands.float(x);
|
|
67
|
+
commands.float(y);
|
|
68
|
+
commands.float(width);
|
|
69
|
+
commands.float(height);
|
|
70
|
+
commands.finish();
|
|
71
|
+
}
|
|
72
|
+
/** Sets a Lite GL blend preset. No-op for a disposed engine. */
|
|
73
|
+
export function setBlendMode(engine, mode) {
|
|
74
|
+
if (engine._blend === mode || engine._disposed) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const native = engine._runtime.Engine;
|
|
78
|
+
const resolved = mode === 0 ? native.ALPHA_DISABLE : mode === 1 ? native.ALPHA_ADD : mode === 2 ? native.ALPHA_COMBINE : native.ALPHA_PREMULTIPLIED;
|
|
79
|
+
const commands = engine._commands;
|
|
80
|
+
commands.start(native.COMMAND_SETBLENDMODE);
|
|
81
|
+
commands.uint(resolved);
|
|
82
|
+
commands.finish();
|
|
83
|
+
engine._blend = mode;
|
|
84
|
+
}
|
|
85
|
+
/** Clears the current composition target within its scissor, without changing the scissor. No-op for a disposed engine. */
|
|
86
|
+
export function clearEngine(engine, options) {
|
|
87
|
+
if (engine._scissorEmpty || engine._disposed) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const color = options.color;
|
|
91
|
+
const commands = engine._commands;
|
|
92
|
+
commands.start(engine._runtime.Engine.COMMAND_CLEAR);
|
|
93
|
+
commands.uint(color ? 1 : 0);
|
|
94
|
+
commands.float(color?.r ?? 0);
|
|
95
|
+
commands.float(color?.g ?? 0);
|
|
96
|
+
commands.float(color?.b ?? 0);
|
|
97
|
+
commands.float(color?.a ?? 1);
|
|
98
|
+
commands.uint(options.depth ? 1 : 0);
|
|
99
|
+
commands.float(1);
|
|
100
|
+
commands.uint(options.stencil ? 1 : 0);
|
|
101
|
+
commands.uint(0);
|
|
102
|
+
commands.finish();
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/native/state.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAM/D,sKAAsK;AACtK,MAAM,UAAU,WAAW,CAAC,MA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{ GLClearOptions, GLViewport } from \"../family.js\";\n\n/** Blend presets shared with Lite GL: disabled, additive, combine and premultiplied. */\nexport type GLBlendMode = 0 | 1 | 2 | 7;\n\n/** Changes the drawing viewport in pixels of the bound target. Defaults to the size of the default output, whichever target is bound. No-op for a disposed engine. */\nexport function setViewport(engine: GLEngineContext, viewport?: GLViewport): void {\n if (engine._disposed) {\n return;\n }\n const target = engine._target;\n // The default output size is a host query, so an explicit viewport of a bound target does not read it.\n if (viewport && target) {\n setNormalizedViewport(engine, viewport.x, viewport.y, viewport.w, viewport.h, target.width, target.height);\n return;\n }\n const outputWidth = getRenderWidth(engine);\n const outputHeight = getRenderHeight(engine);\n setNormalizedViewport(\n engine,\n viewport?.x ?? 0,\n viewport?.y ?? 0,\n viewport?.w ?? outputWidth,\n viewport?.h ?? outputHeight,\n target?.width ?? outputWidth,\n target?.height ?? outputHeight\n );\n}\n\n/** @internal Native viewports are fractions of the bound target. */\nexport function setNormalizedViewport(engine: GLEngineContext, x: number, y: number, width: number, height: number, targetWidth: number, targetHeight: number): void {\n x /= targetWidth;\n y /= targetHeight;\n width /= targetWidth;\n height /= targetHeight;\n const values = engine._viewport;\n if (values[0] === x && values[1] === y && values[2] === width && values[3] === height) {\n return;\n }\n values[0] = x;\n values[1] = y;\n values[2] = width;\n values[3] = height;\n const commands = engine._commands;\n commands.start(engine._runtime.Engine.COMMAND_SETVIEWPORT);\n commands.float(x);\n commands.float(y);\n commands.float(width);\n commands.float(height);\n commands.finish();\n}\n\n/**\n * Restricts drawing and clearing to a bottom-left-origin rectangle in physical\n * pixels; portable callers pass nonnegative integer dimensions. A rectangle\n * without area allows neither until the scissor changes. No-op for a disposed\n * engine.\n */\nexport function setScissor(engine: GLEngineContext, x: number, y: number, width: number, height: number): void {\n if (engine._disposed) {\n return;\n }\n // The host reads an all-zero rectangle as \"no scissor\", so an empty one is enforced here instead.\n engine._scissorEmpty = width <= 0 || height <= 0;\n if (!engine._scissorEmpty) {\n encodeScissor(engine, x, y, width, height);\n }\n}\n\n/** Restores unrestricted drawing. No-op for a disposed engine. */\nexport function disableScissor(engine: GLEngineContext): void {\n if (engine._disposed) {\n return;\n }\n engine._scissorEmpty = false;\n encodeScissor(engine, 0, 0, 0, 0);\n}\n\nfunction encodeScissor(engine: GLEngineContext, x: number, y: number, width: number, height: number): void {\n const commands = engine._commands;\n commands.start(engine._runtime.Engine.COMMAND_SETSCISSOR);\n commands.float(x);\n commands.float(y);\n commands.float(width);\n commands.float(height);\n commands.finish();\n}\n\n/** Sets a Lite GL blend preset. No-op for a disposed engine. */\nexport function setBlendMode(engine: GLEngineContext, mode: GLBlendMode): void {\n if (engine._blend === mode || engine._disposed) {\n return;\n }\n const native = engine._runtime.Engine;\n const resolved = mode === 0 ? native.ALPHA_DISABLE : mode === 1 ? native.ALPHA_ADD : mode === 2 ? native.ALPHA_COMBINE : native.ALPHA_PREMULTIPLIED;\n const commands = engine._commands;\n commands.start(native.COMMAND_SETBLENDMODE);\n commands.uint(resolved);\n commands.finish();\n engine._blend = mode;\n}\n\n/** Clears the current composition target within its scissor, without changing the scissor. No-op for a disposed engine. */\nexport function clearEngine(engine: GLEngineContext, options: GLClearOptions): void {\n if (engine._scissorEmpty || engine._disposed) {\n return;\n }\n const color = options.color;\n const commands = engine._commands;\n commands.start(engine._runtime.Engine.COMMAND_CLEAR);\n commands.uint(color ? 1 : 0);\n commands.float(color?.r ?? 0);\n commands.float(color?.g ?? 0);\n commands.float(color?.b ?? 0);\n commands.float(color?.a ?? 1);\n commands.uint(options.depth ? 1 : 0);\n commands.float(1);\n commands.uint(options.stencil ? 1 : 0);\n commands.uint(0);\n commands.finish();\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { GLEngineContext } from "./context.js";
|
|
2
|
+
import type { NativeResource } from "./identity.js";
|
|
3
|
+
/** Opaque texture storage supplied by the Babylon Native host. */
|
|
4
|
+
export type NativeTextureHandle = Uint32Array<ArrayBuffer>;
|
|
5
|
+
/** Sampled native image with explicit storage ownership. */
|
|
6
|
+
export interface GLTexture extends NativeResource<"texture"> {
|
|
7
|
+
readonly width: number;
|
|
8
|
+
readonly height: number;
|
|
9
|
+
/** Whether the image is available for sampling. */
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Borrows native texture storage without taking responsibility for deleting it. */
|
|
13
|
+
export declare function wrapNativeTexture(engine: GLEngineContext, handle: NativeTextureHandle): GLTexture;
|
|
14
|
+
/** Upload options shared by native texture creators. */
|
|
15
|
+
export interface GLTextureOptions {
|
|
16
|
+
/** Flip rows during upload. Default `false`. */
|
|
17
|
+
invertY?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Options for {@link createRawTexture}. */
|
|
20
|
+
export interface GLRawTextureOptions extends GLTextureOptions {
|
|
21
|
+
/** Pixel format of `data`. Only `gl.RGBA` (the default) is supported. */
|
|
22
|
+
format?: number;
|
|
23
|
+
/** Pixel type of `data`. Only `gl.UNSIGNED_BYTE` (the default) is supported. */
|
|
24
|
+
type?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates an owned, sampled-only texture from raw pixels. Only `gl.RGBA` / `gl.UNSIGNED_BYTE` data is supported.
|
|
28
|
+
* The host submits the commands recorded so far before uploading, so create raw textures before `beginFrame` when the number of submissions matters.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createRawTexture(engine: GLEngineContext, data: Uint8Array, width: number, height: number, options?: GLRawTextureOptions): GLTexture;
|
|
31
|
+
/**
|
|
32
|
+
* Releases owned image storage, never a borrowed host texture. The storage
|
|
33
|
+
* outlives every command already recorded, so a frame may still draw with,
|
|
34
|
+
* or into, a texture it disposes. After engine disposal it only marks the
|
|
35
|
+
* texture disposed.
|
|
36
|
+
*/
|
|
37
|
+
export declare function disposeTexture(texture: GLTexture): void;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export function configureTexture(engine, texture, linear = true) {
|
|
3
|
+
const native = engine._runtime.Engine;
|
|
4
|
+
const commands = engine._commands;
|
|
5
|
+
commands.start(native.COMMAND_SETTEXTURESAMPLING);
|
|
6
|
+
commands.handle(texture._handle);
|
|
7
|
+
commands.uint(linear ? native.TEXTURE_LINEAR_LINEAR : native.TEXTURE_NEAREST_NEAREST);
|
|
8
|
+
commands.finish();
|
|
9
|
+
commands.start(native.COMMAND_SETTEXTUREWRAPMODE);
|
|
10
|
+
commands.handle(texture._handle);
|
|
11
|
+
commands.uint(native.ADDRESS_MODE_CLAMP);
|
|
12
|
+
commands.uint(native.ADDRESS_MODE_CLAMP);
|
|
13
|
+
commands.uint(native.ADDRESS_MODE_CLAMP);
|
|
14
|
+
commands.finish();
|
|
15
|
+
commands.start(native.COMMAND_SETTEXTUREANISOTROPICLEVEL);
|
|
16
|
+
commands.handle(texture._handle);
|
|
17
|
+
commands.uint(1);
|
|
18
|
+
commands.finish();
|
|
19
|
+
}
|
|
20
|
+
/** @internal */
|
|
21
|
+
export function makeTexture(engine, handle, owned, sampledOnly) {
|
|
22
|
+
const fields = {
|
|
23
|
+
width: engine._native.getTextureWidth(handle),
|
|
24
|
+
height: engine._native.getTextureHeight(handle),
|
|
25
|
+
isReady: true,
|
|
26
|
+
_handle: handle,
|
|
27
|
+
_owned: owned,
|
|
28
|
+
_sampledOnly: sampledOnly,
|
|
29
|
+
_targets: [],
|
|
30
|
+
_engine: engine,
|
|
31
|
+
_disposed: false,
|
|
32
|
+
};
|
|
33
|
+
const texture = fields;
|
|
34
|
+
configureTexture(engine, texture);
|
|
35
|
+
return texture;
|
|
36
|
+
}
|
|
37
|
+
/** Borrows native texture storage without taking responsibility for deleting it. */
|
|
38
|
+
export function wrapNativeTexture(engine, handle) {
|
|
39
|
+
return makeTexture(engine, handle, false, false);
|
|
40
|
+
}
|
|
41
|
+
const GL_RGBA = 0x1908;
|
|
42
|
+
const GL_UNSIGNED_BYTE = 0x1401;
|
|
43
|
+
/** @internal Rejects a texture size the host cannot allocate, before any host call. */
|
|
44
|
+
export function validateTextureSize(engine, width, height) {
|
|
45
|
+
const max = engine.caps.maxTextureSize;
|
|
46
|
+
// 0 means the host has not reported a limit, so only the host can bound the size.
|
|
47
|
+
const limited = max > 0;
|
|
48
|
+
if (!Number.isInteger(width) || !Number.isInteger(height) || width < 1 || height < 1 || (limited && (width > max || height > max))) {
|
|
49
|
+
throw new Error(`Native Lite GL texture size must be positive integers${limited ? ` no larger than ${max}` : ""}, got ${width}x${height}.`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates an owned, sampled-only texture from raw pixels. Only `gl.RGBA` / `gl.UNSIGNED_BYTE` data is supported.
|
|
54
|
+
* The host submits the commands recorded so far before uploading, so create raw textures before `beginFrame` when the number of submissions matters.
|
|
55
|
+
*/
|
|
56
|
+
export function createRawTexture(engine, data, width, height, options) {
|
|
57
|
+
if ((options?.format ?? GL_RGBA) !== GL_RGBA || (options?.type ?? GL_UNSIGNED_BYTE) !== GL_UNSIGNED_BYTE) {
|
|
58
|
+
throw new Error("Native Lite GL raw textures support only RGBA / UNSIGNED_BYTE data.");
|
|
59
|
+
}
|
|
60
|
+
validateTextureSize(engine, width, height);
|
|
61
|
+
const handle = engine._native.createTexture();
|
|
62
|
+
try {
|
|
63
|
+
engine._native.loadRawTexture(handle, data, width, height, engine._runtime.Engine.TEXTURE_FORMAT_RGBA8, false, options?.invertY ?? false);
|
|
64
|
+
return makeTexture(engine, handle, true, true);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
engine._native.deleteTexture(handle);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Releases owned image storage, never a borrowed host texture. The storage
|
|
73
|
+
* outlives every command already recorded, so a frame may still draw with,
|
|
74
|
+
* or into, a texture it disposes. After engine disposal it only marks the
|
|
75
|
+
* texture disposed.
|
|
76
|
+
*/
|
|
77
|
+
export function disposeTexture(texture) {
|
|
78
|
+
if (!texture._disposed) {
|
|
79
|
+
texture._disposed = true;
|
|
80
|
+
texture.isReady = false;
|
|
81
|
+
if (texture._owned && !texture._engine._disposed) {
|
|
82
|
+
texture._engine._commands.deleteTexture(texture._handle);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=texture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture.js","sourceRoot":"","sources":["../../src/native/texture.ts"],"names":[],"mappings":"AA4BA,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,MAAuB,EAAE,OAAkB,EAAE,MAAM,GAAG,IAAI;IACvF,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC;IAClC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAClD,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC;IACtF,QAAQ,CAAC,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAClD,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACzC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACzC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,kCAAkC,CAAC,CAAC;IAC1D,Q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M,UAAU,cAAc,CAAC,OAAkB;IAC7C,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACrB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QACzB,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;QACxB,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC/C,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC7D,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import type { GLEngineContext } from \"./context.js\";\nimport type { NativeResource, NativeResourceFields } from \"./identity.js\";\nimport type { NativeHandle } from \"./runtime.js\";\nimport type { GLRenderTarget } from \"./render-target.js\";\n\n/** Opaque texture storage supplied by the Babylon Native host. */\nexport type NativeTextureHandle = Uint32Array<ArrayBuffer>;\n\n/** Sampled native image with explicit storage ownership. */\nexport interface GLTexture extends NativeResource<\"texture\"> {\n readonly width: number;\n readonly height: number;\n /** Whether the image is available for sampling. */\n isReady: boolean;\n /** @internal */\n _handle: NativeHandle;\n /** @internal */\n readonly _owned: boolean;\n /** @internal Whether the storage is known to be unusable as a render-target attachment. */\n readonly _sampledOnly: boolean;\n /** @internal */\n readonly _targets: GLRenderTarget[];\n /** @internal The engine that owns this texture wrapper. */\n readonly _engine: GLEngineContext;\n /** @internal */\n _disposed: boolean;\n}\n\n/** @internal */\nexport function configureTexture(engine: GLEngineContext, texture: GLTexture, linear = true): void {\n const native = engine._runtime.Engine;\n const commands = engine._commands;\n commands.start(native.COMMAND_SETTEXTURESAMPLING);\n commands.handle(texture._handle);\n commands.uint(linear ? native.TEXTURE_LINEAR_LINEAR : native.TEXTURE_NEAREST_NEAREST);\n commands.finish();\n commands.start(native.COMMAND_SETTEXTUREWRAPMODE);\n commands.handle(texture._handle);\n commands.uint(native.ADDRESS_MODE_CLAMP);\n commands.uint(native.ADDRESS_MODE_CLAMP);\n commands.uint(native.ADDRESS_MODE_CLAMP);\n commands.finish();\n commands.start(native.COMMAND_SETTEXTUREANISOTROPICLEVEL);\n commands.handle(texture._handle);\n commands.uint(1);\n commands.finish();\n}\n\n/** @internal */\nexport function makeTexture(engine: GLEngineContext, handle: NativeHandle, owned: boolean, sampledOnly: boolean): GLTexture {\n const fields: NativeResourceFields<GLTexture> = {\n width: engine._native.getTextureWidth(handle),\n height: engine._native.getTextureHeight(handle),\n isReady: true,\n _handle: handle,\n _owned: owned,\n _sampledOnly: sampledOnly,\n _targets: [],\n _engine: engine,\n _disposed: false,\n };\n const texture = fields as GLTexture;\n configureTexture(engine, texture);\n return texture;\n}\n\n/** Borrows native texture storage without taking responsibility for deleting it. */\nexport function wrapNativeTexture(engine: GLEngineContext, handle: NativeTextureHandle): GLTexture {\n return makeTexture(engine, handle, false, false);\n}\n\n/** Upload options shared by native texture creators. */\nexport interface GLTextureOptions {\n /** Flip rows during upload. Default `false`. */\n invertY?: boolean;\n}\n\n/** Options for {@link createRawTexture}. */\nexport interface GLRawTextureOptions extends GLTextureOptions {\n /** Pixel format of `data`. Only `gl.RGBA` (the default) is supported. */\n format?: number;\n /** Pixel type of `data`. Only `gl.UNSIGNED_BYTE` (the default) is supported. */\n type?: number;\n}\n\nconst GL_RGBA = 0x1908;\nconst GL_UNSIGNED_BYTE = 0x1401;\n\n/** @internal Rejects a texture size the host cannot allocate, before any host call. */\nexport function validateTextureSize(engine: GLEngineContext, width: number, height: number): void {\n const max = engine.caps.maxTextureSize;\n // 0 means the host has not reported a limit, so only the host can bound the size.\n const limited = max > 0;\n if (!Number.isInteger(width) || !Number.isInteger(height) || width < 1 || height < 1 || (limited && (width > max || height > max))) {\n throw new Error(`Native Lite GL texture size must be positive integers${limited ? ` no larger than ${max}` : \"\"}, got ${width}x${height}.`);\n }\n}\n\n/**\n * Creates an owned, sampled-only texture from raw pixels. Only `gl.RGBA` / `gl.UNSIGNED_BYTE` data is supported.\n * The host submits the commands recorded so far before uploading, so create raw textures before `beginFrame` when the number of submissions matters.\n */\nexport function createRawTexture(engine: GLEngineContext, data: Uint8Array, width: number, height: number, options?: GLRawTextureOptions): GLTexture {\n if ((options?.format ?? GL_RGBA) !== GL_RGBA || (options?.type ?? GL_UNSIGNED_BYTE) !== GL_UNSIGNED_BYTE) {\n throw new Error(\"Native Lite GL raw textures support only RGBA / UNSIGNED_BYTE data.\");\n }\n validateTextureSize(engine, width, height);\n const handle = engine._native.createTexture();\n try {\n engine._native.loadRawTexture(handle, data, width, height, engine._runtime.Engine.TEXTURE_FORMAT_RGBA8, false, options?.invertY ?? false);\n return makeTexture(engine, handle, true, true);\n } catch (error) {\n engine._native.deleteTexture(handle);\n throw error;\n }\n}\n\n/**\n * Releases owned image storage, never a borrowed host texture. The storage\n * outlives every command already recorded, so a frame may still draw with,\n * or into, a texture it disposes. After engine disposal it only marks the\n * texture disposed.\n */\nexport function disposeTexture(texture: GLTexture): void {\n if (!texture._disposed) {\n texture._disposed = true;\n texture.isReady = false;\n if (texture._owned && !texture._engine._disposed) {\n texture._engine._commands.deleteTexture(texture._handle);\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babylonjs/lite-gl",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.1",
|
|
4
4
|
"description": "Function-based, tree-shakeable WebGL2 micro-engine for fullscreen effects, sprites and dynamic textures — the WebGL counterpart of @babylonjs/lite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babylon",
|
|
@@ -32,11 +32,19 @@
|
|
|
32
32
|
".": {
|
|
33
33
|
"import": "./index.js",
|
|
34
34
|
"types": "./index.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./native": {
|
|
37
|
+
"import": "./native/index.js",
|
|
38
|
+
"types": "./native/index.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./family": {
|
|
41
|
+
"import": "./family.js",
|
|
42
|
+
"types": "./family.d.ts"
|
|
35
43
|
}
|
|
36
44
|
},
|
|
37
45
|
"babylonLiteRelease": {
|
|
38
|
-
"azureBuildId": "
|
|
39
|
-
"sourceVersion": "
|
|
46
|
+
"azureBuildId": "165139003",
|
|
47
|
+
"sourceVersion": "8c00303e30cdbb2ac623d9707e8f1bab894c09d8"
|
|
40
48
|
},
|
|
41
49
|
"publishConfig": {
|
|
42
50
|
"tag": "latest"
|
package/render-target.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* carries the `RGBA16F` / `RGBA32F` table, so RGBA8 consumers tree-shake it
|
|
20
20
|
* away).
|
|
21
21
|
*
|
|
22
|
-
*
|
|
22
|
+
* Unless the engine is host-owned (`createHostOwnedGLEngine`), the full color/depth/stencil GPU set is rebuilt automatically on
|
|
23
23
|
* `webglcontextrestored` — the render target registers itself with the engine's
|
|
24
24
|
* `_renderTargets` registry, and the context-restore protocol calls its
|
|
25
25
|
* `_restore` closure AFTER the standalone texture replay. A caller-supplied
|
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import { type GLTexture } from "./texture.js";
|
|
30
30
|
import type { GLEngineContext } from "./context.js";
|
|
31
|
+
/**
|
|
32
|
+
* Presents a retained composition target to the whole canvas without disturbing
|
|
33
|
+
* its contents; an active scissor rectangle does not clip the presentation.
|
|
34
|
+
* Presentation copies framebuffers, which WebGL2 forbids into a multisampled
|
|
35
|
+
* canvas, so it throws for an engine created with `antialias: true`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function presentRenderTarget(target: GLRenderTarget): void;
|
|
31
38
|
/** Options for {@link createRenderTarget}. Every field has a Babylon-matching
|
|
32
39
|
* default: the bare `createRenderTarget(engine, width, height)` makes an RGBA8
|
|
33
40
|
* color-only target with linear filtering and clamp wrapping. */
|
|
@@ -126,13 +133,14 @@ export interface GLRenderTarget {
|
|
|
126
133
|
* caller-managed (BYO) one. Mirrors Babylon's `createRenderTargetTexture`.
|
|
127
134
|
*
|
|
128
135
|
* @param engine - The engine to allocate GL resources on.
|
|
129
|
-
* @param width - Color attachment width in texels. Must be a positive integer.
|
|
130
|
-
* @param height - Color attachment height in texels. Must be a positive integer.
|
|
136
|
+
* @param width - Color attachment width in texels. Must be a positive integer up to `caps.maxTextureSize`.
|
|
137
|
+
* @param height - Color attachment height in texels. Must be a positive integer up to `caps.maxTextureSize`.
|
|
131
138
|
* @param options - See {@link GLRenderTargetOptions}.
|
|
132
139
|
* @returns The new {@link GLRenderTarget}.
|
|
133
140
|
* @throws If `format` is not `RGBA` / `RG` / `RED`, `width`/`height` are not
|
|
134
|
-
* positive integers
|
|
135
|
-
* framebuffer is not complete
|
|
141
|
+
* positive integers up to `caps.maxTextureSize`, a GL handle could not be allocated, or the resulting
|
|
142
|
+
* framebuffer is not complete (unless `setFramebufferValidation(engine, false)`
|
|
143
|
+
* opted out of completeness checks). On failure every partial GPU object (including
|
|
136
144
|
* an owned color texture) is released first.
|
|
137
145
|
*/
|
|
138
146
|
export declare function createRenderTarget(engine: GLEngineContext, width: number, height: number, options?: GLRenderTargetOptions): GLRenderTarget;
|
|
@@ -147,8 +155,8 @@ export declare function createRenderTarget(engine: GLEngineContext, width: numbe
|
|
|
147
155
|
* supports (mirroring Babylon's `getTextureType`).
|
|
148
156
|
*
|
|
149
157
|
* @param engine - The engine to allocate GL resources on.
|
|
150
|
-
* @param width - Color attachment width in texels. Must be a positive integer.
|
|
151
|
-
* @param height - Color attachment height in texels. Must be a positive integer.
|
|
158
|
+
* @param width - Color attachment width in texels. Must be a positive integer up to `caps.maxTextureSize`.
|
|
159
|
+
* @param height - Color attachment height in texels. Must be a positive integer up to `caps.maxTextureSize`.
|
|
152
160
|
* @param options - See {@link GLFloatRenderTargetOptions}.
|
|
153
161
|
* @returns The new {@link GLRenderTarget}.
|
|
154
162
|
* @throws As {@link createRenderTarget}.
|
|
@@ -192,8 +200,9 @@ export declare function generateRenderTargetMipMaps(rt: GLRenderTarget): void;
|
|
|
192
200
|
* restore hook.
|
|
193
201
|
*
|
|
194
202
|
* @param rt - The render target to resize.
|
|
195
|
-
* @param width - New width in texels (
|
|
196
|
-
* @param height - New height in texels (
|
|
203
|
+
* @param width - New width in texels (1 to `caps.maxTextureSize`).
|
|
204
|
+
* @param height - New height in texels (1 to `caps.maxTextureSize`).
|
|
205
|
+
* @throws If the size is invalid; the target keeps its current size.
|
|
197
206
|
*/
|
|
198
207
|
export declare function resizeRenderTarget(rt: GLRenderTarget, width: number, height: number): void;
|
|
199
208
|
/**
|