This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

View File

@@ -0,0 +1,54 @@
import type { WebGLOptions } from './gl/WebGLRenderer';
import type { WebGPUOptions } from './gpu/WebGPURenderer';
import type { Renderer, RendererOptions } from './types';
/**
* Options for {@link rendering.autoDetectRenderer}.
* @memberof rendering
*/
export interface AutoDetectOptions extends RendererOptions {
/** The preferred renderer type. WebGPU is recommended as its generally faster than WebGL. */
preference?: 'webgl' | 'webgpu';
/** Optional WebGPUOptions to pass only to WebGPU renderer. */
webgpu?: Partial<WebGPUOptions>;
/** Optional WebGLOptions to pass only to the WebGL renderer */
webgl?: Partial<WebGLOptions>;
}
/**
* Automatically determines the most appropriate renderer for the current environment.
*
* The function will prioritize the WebGL renderer as it is the most tested safe API to use.
* In the near future as WebGPU becomes more stable and ubiquitous, it will be prioritized over WebGL.
*
* The selected renderer's code is then dynamically imported to optimize
* performance and minimize the initial bundle size.
*
* To maximize the benefits of dynamic imports, it's recommended to use a modern bundler
* that supports code splitting. This will place the renderer code in a separate chunk,
* which is loaded only when needed.
* @example
*
* // create a renderer
* const renderer = await autoDetectRenderer({
* width: 800,
* height: 600,
* antialias: true,
* });
*
* // custom for each renderer
* const renderer = await autoDetectRenderer({
* width: 800,
* height: 600,
* webgpu:{
* antialias: true,
* backgroundColor: 'red'
* },
* webgl:{
* antialias: true,
* backgroundColor: 'green'
* }
* });
* @param options - A partial configuration object based on the `AutoDetectOptions` type.
* @returns A Promise that resolves to an instance of the selected renderer.
* @memberof rendering
*/
export declare function autoDetectRenderer(options: Partial<AutoDetectOptions>): Promise<Renderer>;

View File

@@ -0,0 +1,53 @@
'use strict';
var isWebGLSupported = require('../../utils/browser/isWebGLSupported.js');
var isWebGPUSupported = require('../../utils/browser/isWebGPUSupported.js');
var AbstractRenderer = require('./shared/system/AbstractRenderer.js');
"use strict";
const renderPriority = ["webgl", "webgpu", "canvas"];
async function autoDetectRenderer(options) {
let preferredOrder = [];
if (options.preference) {
preferredOrder.push(options.preference);
renderPriority.forEach((item) => {
if (item !== options.preference) {
preferredOrder.push(item);
}
});
} else {
preferredOrder = renderPriority.slice();
}
let RendererClass;
let finalOptions = {};
for (let i = 0; i < preferredOrder.length; i++) {
const rendererType = preferredOrder[i];
if (rendererType === "webgpu" && await isWebGPUSupported.isWebGPUSupported()) {
const { WebGPURenderer } = await Promise.resolve().then(function () { return require('./gpu/WebGPURenderer.js'); });
RendererClass = WebGPURenderer;
finalOptions = { ...options, ...options.webgpu };
break;
} else if (rendererType === "webgl" && isWebGLSupported.isWebGLSupported(
options.failIfMajorPerformanceCaveat ?? AbstractRenderer.AbstractRenderer.defaultOptions.failIfMajorPerformanceCaveat
)) {
const { WebGLRenderer } = await Promise.resolve().then(function () { return require('./gl/WebGLRenderer.js'); });
RendererClass = WebGLRenderer;
finalOptions = { ...options, ...options.webgl };
break;
} else if (rendererType === "canvas") {
finalOptions = { ...options };
throw new Error("CanvasRenderer is not yet implemented");
}
}
delete finalOptions.webgpu;
delete finalOptions.webgl;
if (!RendererClass) {
throw new Error("No available renderer for the current environment");
}
const renderer = new RendererClass();
await renderer.init(finalOptions);
return renderer;
}
exports.autoDetectRenderer = autoDetectRenderer;
//# sourceMappingURL=autoDetectRenderer.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,51 @@
import { isWebGLSupported } from '../../utils/browser/isWebGLSupported.mjs';
import { isWebGPUSupported } from '../../utils/browser/isWebGPUSupported.mjs';
import { AbstractRenderer } from './shared/system/AbstractRenderer.mjs';
"use strict";
const renderPriority = ["webgl", "webgpu", "canvas"];
async function autoDetectRenderer(options) {
let preferredOrder = [];
if (options.preference) {
preferredOrder.push(options.preference);
renderPriority.forEach((item) => {
if (item !== options.preference) {
preferredOrder.push(item);
}
});
} else {
preferredOrder = renderPriority.slice();
}
let RendererClass;
let finalOptions = {};
for (let i = 0; i < preferredOrder.length; i++) {
const rendererType = preferredOrder[i];
if (rendererType === "webgpu" && await isWebGPUSupported()) {
const { WebGPURenderer } = await import('./gpu/WebGPURenderer.mjs');
RendererClass = WebGPURenderer;
finalOptions = { ...options, ...options.webgpu };
break;
} else if (rendererType === "webgl" && isWebGLSupported(
options.failIfMajorPerformanceCaveat ?? AbstractRenderer.defaultOptions.failIfMajorPerformanceCaveat
)) {
const { WebGLRenderer } = await import('./gl/WebGLRenderer.mjs');
RendererClass = WebGLRenderer;
finalOptions = { ...options, ...options.webgl };
break;
} else if (rendererType === "canvas") {
finalOptions = { ...options };
throw new Error("CanvasRenderer is not yet implemented");
}
}
delete finalOptions.webgpu;
delete finalOptions.webgl;
if (!RendererClass) {
throw new Error("No available renderer for the current environment");
}
const renderer = new RendererClass();
await renderer.init(finalOptions);
return renderer;
}
export { autoDetectRenderer };
//# sourceMappingURL=autoDetectRenderer.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,67 @@
import { ExtensionType } from '../../../extensions/Extensions';
import type { RenderOptions } from '../shared/system/AbstractRenderer';
import type { System } from '../shared/system/System';
import type { WebGLRenderer } from './WebGLRenderer';
/**
* The options for the back buffer system.
* @memberof rendering
* @property {boolean} [useBackBuffer=false] - if true will use the back buffer where required
* @property {boolean} [antialias=false] - if true will ensure the texture is antialiased
*/
export interface GlBackBufferOptions {
/**
* if true will use the back buffer where required
* @default false
* @memberof rendering.WebGLOptions
*/
useBackBuffer?: boolean;
/** if true will ensure the texture is antialiased */
antialias?: boolean;
}
/**
* For blend modes you need to know what pixels you are actually drawing to. For this to be possible in WebGL
* we need to render to a texture and then present that texture to the screen. This system manages that process.
*
* As the main scene is rendered to a texture, it means we can sample it and copy its pixels,
* something not possible on the main canvas.
*
* If antialiasing is set to to true and useBackBuffer is set to true, then the back buffer will be antialiased.
* and the main gl context will not.
*
* You only need to activate this back buffer if you are using a blend mode that requires it.
*
* to activate is simple, you pass `useBackBuffer:true` to your render options
* @memberof rendering
*/
export declare class GlBackBufferSystem implements System<GlBackBufferOptions> {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "backBuffer";
readonly priority: 1;
};
/** default options for the back buffer system */
static defaultOptions: GlBackBufferOptions;
/** if true, the back buffer is used */
useBackBuffer: boolean;
private _backBufferTexture;
private readonly _renderer;
private _targetTexture;
private _useBackBufferThisRender;
private _antialias;
private _state;
private _bigTriangleShader;
constructor(renderer: WebGLRenderer);
init(options?: GlBackBufferOptions): void;
/**
* This is called before the RenderTargetSystem is started. This is where
* we replace the target with the back buffer if required.
* @param options - The options for this render.
*/
protected renderStart(options: RenderOptions): void;
protected renderEnd(): void;
private _presentBackBuffer;
private _getBackBufferTexture;
/** destroys the back buffer */
destroy(): void;
}

View File

@@ -0,0 +1,145 @@
'use strict';
var Extensions = require('../../../extensions/Extensions.js');
var warn = require('../../../utils/logging/warn.js');
var Geometry = require('../shared/geometry/Geometry.js');
var Shader = require('../shared/shader/Shader.js');
var State = require('../shared/state/State.js');
var TextureSource = require('../shared/texture/sources/TextureSource.js');
var Texture = require('../shared/texture/Texture.js');
var GlProgram = require('./shader/GlProgram.js');
"use strict";
const bigTriangleGeometry = new Geometry.Geometry({
attributes: {
aPosition: [
-1,
-1,
// Bottom left corner
3,
-1,
// Bottom right corner, extending beyond right edge
-1,
3
// Top left corner, extending beyond top edge
]
}
});
const _GlBackBufferSystem = class _GlBackBufferSystem {
constructor(renderer) {
/** if true, the back buffer is used */
this.useBackBuffer = false;
this._useBackBufferThisRender = false;
this._renderer = renderer;
}
init(options = {}) {
const { useBackBuffer, antialias } = { ..._GlBackBufferSystem.defaultOptions, ...options };
this.useBackBuffer = useBackBuffer;
this._antialias = antialias;
if (!this._renderer.context.supports.msaa) {
warn.warn("antialiasing, is not supported on when using the back buffer");
this._antialias = false;
}
this._state = State.State.for2d();
const bigTriangleProgram = new GlProgram.GlProgram({
vertex: `
attribute vec2 aPosition;
out vec2 vUv;
void main() {
gl_Position = vec4(aPosition, 0.0, 1.0);
vUv = (aPosition + 1.0) / 2.0;
// flip dem UVs
vUv.y = 1.0 - vUv.y;
}`,
fragment: `
in vec2 vUv;
out vec4 finalColor;
uniform sampler2D uTexture;
void main() {
finalColor = texture(uTexture, vUv);
}`,
name: "big-triangle"
});
this._bigTriangleShader = new Shader.Shader({
glProgram: bigTriangleProgram,
resources: {
uTexture: Texture.Texture.WHITE.source
}
});
}
/**
* This is called before the RenderTargetSystem is started. This is where
* we replace the target with the back buffer if required.
* @param options - The options for this render.
*/
renderStart(options) {
const renderTarget = this._renderer.renderTarget.getRenderTarget(options.target);
this._useBackBufferThisRender = this.useBackBuffer && !!renderTarget.isRoot;
if (this._useBackBufferThisRender) {
const renderTarget2 = this._renderer.renderTarget.getRenderTarget(options.target);
this._targetTexture = renderTarget2.colorTexture;
options.target = this._getBackBufferTexture(renderTarget2.colorTexture);
}
}
renderEnd() {
this._presentBackBuffer();
}
_presentBackBuffer() {
const renderer = this._renderer;
renderer.renderTarget.finishRenderPass();
if (!this._useBackBufferThisRender)
return;
renderer.renderTarget.bind(this._targetTexture, false);
this._bigTriangleShader.resources.uTexture = this._backBufferTexture.source;
renderer.encoder.draw({
geometry: bigTriangleGeometry,
shader: this._bigTriangleShader,
state: this._state
});
}
_getBackBufferTexture(targetSourceTexture) {
this._backBufferTexture = this._backBufferTexture || new Texture.Texture({
source: new TextureSource.TextureSource({
width: targetSourceTexture.width,
height: targetSourceTexture.height,
resolution: targetSourceTexture._resolution,
antialias: this._antialias
})
});
this._backBufferTexture.source.resize(
targetSourceTexture.width,
targetSourceTexture.height,
targetSourceTexture._resolution
);
return this._backBufferTexture;
}
/** destroys the back buffer */
destroy() {
if (this._backBufferTexture) {
this._backBufferTexture.destroy();
this._backBufferTexture = null;
}
}
};
/** @ignore */
_GlBackBufferSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem
],
name: "backBuffer",
priority: 1
};
/** default options for the back buffer system */
_GlBackBufferSystem.defaultOptions = {
/** if true will use the back buffer where required */
useBackBuffer: false
};
let GlBackBufferSystem = _GlBackBufferSystem;
exports.GlBackBufferSystem = GlBackBufferSystem;
//# sourceMappingURL=GlBackBufferSystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,143 @@
import { ExtensionType } from '../../../extensions/Extensions.mjs';
import { warn } from '../../../utils/logging/warn.mjs';
import { Geometry } from '../shared/geometry/Geometry.mjs';
import { Shader } from '../shared/shader/Shader.mjs';
import { State } from '../shared/state/State.mjs';
import { TextureSource } from '../shared/texture/sources/TextureSource.mjs';
import { Texture } from '../shared/texture/Texture.mjs';
import { GlProgram } from './shader/GlProgram.mjs';
"use strict";
const bigTriangleGeometry = new Geometry({
attributes: {
aPosition: [
-1,
-1,
// Bottom left corner
3,
-1,
// Bottom right corner, extending beyond right edge
-1,
3
// Top left corner, extending beyond top edge
]
}
});
const _GlBackBufferSystem = class _GlBackBufferSystem {
constructor(renderer) {
/** if true, the back buffer is used */
this.useBackBuffer = false;
this._useBackBufferThisRender = false;
this._renderer = renderer;
}
init(options = {}) {
const { useBackBuffer, antialias } = { ..._GlBackBufferSystem.defaultOptions, ...options };
this.useBackBuffer = useBackBuffer;
this._antialias = antialias;
if (!this._renderer.context.supports.msaa) {
warn("antialiasing, is not supported on when using the back buffer");
this._antialias = false;
}
this._state = State.for2d();
const bigTriangleProgram = new GlProgram({
vertex: `
attribute vec2 aPosition;
out vec2 vUv;
void main() {
gl_Position = vec4(aPosition, 0.0, 1.0);
vUv = (aPosition + 1.0) / 2.0;
// flip dem UVs
vUv.y = 1.0 - vUv.y;
}`,
fragment: `
in vec2 vUv;
out vec4 finalColor;
uniform sampler2D uTexture;
void main() {
finalColor = texture(uTexture, vUv);
}`,
name: "big-triangle"
});
this._bigTriangleShader = new Shader({
glProgram: bigTriangleProgram,
resources: {
uTexture: Texture.WHITE.source
}
});
}
/**
* This is called before the RenderTargetSystem is started. This is where
* we replace the target with the back buffer if required.
* @param options - The options for this render.
*/
renderStart(options) {
const renderTarget = this._renderer.renderTarget.getRenderTarget(options.target);
this._useBackBufferThisRender = this.useBackBuffer && !!renderTarget.isRoot;
if (this._useBackBufferThisRender) {
const renderTarget2 = this._renderer.renderTarget.getRenderTarget(options.target);
this._targetTexture = renderTarget2.colorTexture;
options.target = this._getBackBufferTexture(renderTarget2.colorTexture);
}
}
renderEnd() {
this._presentBackBuffer();
}
_presentBackBuffer() {
const renderer = this._renderer;
renderer.renderTarget.finishRenderPass();
if (!this._useBackBufferThisRender)
return;
renderer.renderTarget.bind(this._targetTexture, false);
this._bigTriangleShader.resources.uTexture = this._backBufferTexture.source;
renderer.encoder.draw({
geometry: bigTriangleGeometry,
shader: this._bigTriangleShader,
state: this._state
});
}
_getBackBufferTexture(targetSourceTexture) {
this._backBufferTexture = this._backBufferTexture || new Texture({
source: new TextureSource({
width: targetSourceTexture.width,
height: targetSourceTexture.height,
resolution: targetSourceTexture._resolution,
antialias: this._antialias
})
});
this._backBufferTexture.source.resize(
targetSourceTexture.width,
targetSourceTexture.height,
targetSourceTexture._resolution
);
return this._backBufferTexture;
}
/** destroys the back buffer */
destroy() {
if (this._backBufferTexture) {
this._backBufferTexture.destroy();
this._backBufferTexture = null;
}
}
};
/** @ignore */
_GlBackBufferSystem.extension = {
type: [
ExtensionType.WebGLSystem
],
name: "backBuffer",
priority: 1
};
/** default options for the back buffer system */
_GlBackBufferSystem.defaultOptions = {
/** if true will use the back buffer where required */
useBackBuffer: false
};
let GlBackBufferSystem = _GlBackBufferSystem;
export { GlBackBufferSystem };
//# sourceMappingURL=GlBackBufferSystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
import { ExtensionType } from '../../../extensions/Extensions';
import type { System } from '../shared/system/System';
import type { WebGLRenderer } from './WebGLRenderer';
/**
* The system that handles color masking for the WebGL.
* @memberof rendering
*/
export declare class GlColorMaskSystem implements System {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "colorMask";
};
private readonly _renderer;
private _colorMaskCache;
constructor(renderer: WebGLRenderer);
setMask(colorMask: number): void;
destroy?: () => void;
}

View File

@@ -0,0 +1,32 @@
'use strict';
var Extensions = require('../../../extensions/Extensions.js');
"use strict";
class GlColorMaskSystem {
constructor(renderer) {
this._colorMaskCache = 15;
this._renderer = renderer;
}
setMask(colorMask) {
if (this._colorMaskCache === colorMask)
return;
this._colorMaskCache = colorMask;
this._renderer.gl.colorMask(
!!(colorMask & 8),
!!(colorMask & 4),
!!(colorMask & 2),
!!(colorMask & 1)
);
}
}
/** @ignore */
GlColorMaskSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem
],
name: "colorMask"
};
exports.GlColorMaskSystem = GlColorMaskSystem;
//# sourceMappingURL=GlColorMaskSystem.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlColorMaskSystem.js","sources":["../../../../src/rendering/renderers/gl/GlColorMaskSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../extensions/Extensions';\n\nimport type { System } from '../shared/system/System';\nimport type { WebGLRenderer } from './WebGLRenderer';\n\n/**\n * The system that handles color masking for the WebGL.\n * @memberof rendering\n */\nexport class GlColorMaskSystem implements System\n{\n /** @ignore */\n public static extension = {\n type: [\n ExtensionType.WebGLSystem,\n ],\n name: 'colorMask',\n } as const;\n\n private readonly _renderer: WebGLRenderer;\n private _colorMaskCache = 0b1111;\n\n constructor(renderer: WebGLRenderer)\n {\n this._renderer = renderer;\n }\n\n public setMask(colorMask: number)\n {\n if (this._colorMaskCache === colorMask) return;\n this._colorMaskCache = colorMask;\n\n this._renderer.gl.colorMask(\n !!(colorMask & 0b1000),\n !!(colorMask & 0b0100),\n !!(colorMask & 0b0010),\n !!(colorMask & 0b0001)\n );\n }\n\n public destroy?: () => void;\n}\n"],"names":["ExtensionType"],"mappings":";;;;;AASO,MAAM,iBACb,CAAA;AAAA,EAYI,YAAY,QACZ,EAAA;AAHA,IAAA,IAAA,CAAQ,eAAkB,GAAA,EAAA,CAAA;AAItB,IAAA,IAAA,CAAK,SAAY,GAAA,QAAA,CAAA;AAAA,GACrB;AAAA,EAEO,QAAQ,SACf,EAAA;AACI,IAAA,IAAI,KAAK,eAAoB,KAAA,SAAA;AAAW,MAAA,OAAA;AACxC,IAAA,IAAA,CAAK,eAAkB,GAAA,SAAA,CAAA;AAEvB,IAAA,IAAA,CAAK,UAAU,EAAG,CAAA,SAAA;AAAA,MACd,CAAC,EAAE,SAAY,GAAA,CAAA,CAAA;AAAA,MACf,CAAC,EAAE,SAAY,GAAA,CAAA,CAAA;AAAA,MACf,CAAC,EAAE,SAAY,GAAA,CAAA,CAAA;AAAA,MACf,CAAC,EAAE,SAAY,GAAA,CAAA,CAAA;AAAA,KACnB,CAAA;AAAA,GACJ;AAGJ,CAAA;AAAA;AAhCa,iBAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACFA,wBAAc,CAAA,WAAA;AAAA,GAClB;AAAA,EACA,IAAM,EAAA,WAAA;AACV,CAAA;;;;"}

View File

@@ -0,0 +1,30 @@
import { ExtensionType } from '../../../extensions/Extensions.mjs';
"use strict";
class GlColorMaskSystem {
constructor(renderer) {
this._colorMaskCache = 15;
this._renderer = renderer;
}
setMask(colorMask) {
if (this._colorMaskCache === colorMask)
return;
this._colorMaskCache = colorMask;
this._renderer.gl.colorMask(
!!(colorMask & 8),
!!(colorMask & 4),
!!(colorMask & 2),
!!(colorMask & 1)
);
}
}
/** @ignore */
GlColorMaskSystem.extension = {
type: [
ExtensionType.WebGLSystem
],
name: "colorMask"
};
export { GlColorMaskSystem };
//# sourceMappingURL=GlColorMaskSystem.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlColorMaskSystem.mjs","sources":["../../../../src/rendering/renderers/gl/GlColorMaskSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../extensions/Extensions';\n\nimport type { System } from '../shared/system/System';\nimport type { WebGLRenderer } from './WebGLRenderer';\n\n/**\n * The system that handles color masking for the WebGL.\n * @memberof rendering\n */\nexport class GlColorMaskSystem implements System\n{\n /** @ignore */\n public static extension = {\n type: [\n ExtensionType.WebGLSystem,\n ],\n name: 'colorMask',\n } as const;\n\n private readonly _renderer: WebGLRenderer;\n private _colorMaskCache = 0b1111;\n\n constructor(renderer: WebGLRenderer)\n {\n this._renderer = renderer;\n }\n\n public setMask(colorMask: number)\n {\n if (this._colorMaskCache === colorMask) return;\n this._colorMaskCache = colorMask;\n\n this._renderer.gl.colorMask(\n !!(colorMask & 0b1000),\n !!(colorMask & 0b0100),\n !!(colorMask & 0b0010),\n !!(colorMask & 0b0001)\n );\n }\n\n public destroy?: () => void;\n}\n"],"names":[],"mappings":";;;AASO,MAAM,iBACb,CAAA;AAAA,EAYI,YAAY,QACZ,EAAA;AAHA,IAAA,IAAA,CAAQ,eAAkB,GAAA,EAAA,CAAA;AAItB,IAAA,IAAA,CAAK,SAAY,GAAA,QAAA,CAAA;AAAA,GACrB;AAAA,EAEO,QAAQ,SACf,EAAA;AACI,IAAA,IAAI,KAAK,eAAoB,KAAA,SAAA;AAAW,MAAA,OAAA;AACxC,IAAA,IAAA,CAAK,eAAkB,GAAA,SAAA,CAAA;AAEvB,IAAA,IAAA,CAAK,UAAU,EAAG,CAAA,SAAA;AAAA,MACd,CAAC,EAAE,SAAY,GAAA,CAAA,CAAA;AAAA,MACf,CAAC,EAAE,SAAY,GAAA,CAAA,CAAA;AAAA,MACf,CAAC,EAAE,SAAY,GAAA,CAAA,CAAA;AAAA,MACf,CAAC,EAAE,SAAY,GAAA,CAAA,CAAA;AAAA,KACnB,CAAA;AAAA,GACJ;AAGJ,CAAA;AAAA;AAhCa,iBAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACF,aAAc,CAAA,WAAA;AAAA,GAClB;AAAA,EACA,IAAM,EAAA,WAAA;AACV,CAAA;;;;"}

View File

@@ -0,0 +1,34 @@
import { ExtensionType } from '../../../extensions/Extensions';
import type { Topology } from '../shared/geometry/const';
import type { Geometry } from '../shared/geometry/Geometry';
import type { Shader } from '../shared/shader/Shader';
import type { State } from '../shared/state/State';
import type { System } from '../shared/system/System';
import type { WebGLRenderer } from './WebGLRenderer';
/**
* The system that handles encoding commands for the WebGL.
* @memberof rendering
*/
export declare class GlEncoderSystem implements System {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "encoder";
};
readonly commandFinished: Promise<void>;
private readonly _renderer;
constructor(renderer: WebGLRenderer);
setGeometry(geometry: Geometry, shader?: Shader): void;
finishRenderPass(): void;
draw(options: {
geometry: Geometry;
shader: Shader;
state?: State;
topology?: Topology;
size?: number;
start?: number;
instanceCount?: number;
skipSync?: boolean;
}): void;
destroy(): void;
}

View File

@@ -0,0 +1,39 @@
'use strict';
var Extensions = require('../../../extensions/Extensions.js');
"use strict";
class GlEncoderSystem {
constructor(renderer) {
this.commandFinished = Promise.resolve();
this._renderer = renderer;
}
setGeometry(geometry, shader) {
this._renderer.geometry.bind(geometry, shader.glProgram);
}
finishRenderPass() {
}
draw(options) {
const renderer = this._renderer;
const { geometry, shader, state, skipSync, topology: type, size, start, instanceCount } = options;
renderer.shader.bind(shader, skipSync);
renderer.geometry.bind(geometry, renderer.shader._activeProgram);
if (state) {
renderer.state.set(state);
}
renderer.geometry.draw(type, size, start, instanceCount ?? geometry.instanceCount);
}
destroy() {
this._renderer = null;
}
}
/** @ignore */
GlEncoderSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem
],
name: "encoder"
};
exports.GlEncoderSystem = GlEncoderSystem;
//# sourceMappingURL=GlEncoderSystem.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlEncoderSystem.js","sources":["../../../../src/rendering/renderers/gl/GlEncoderSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../extensions/Extensions';\n\nimport type { Topology } from '../shared/geometry/const';\nimport type { Geometry } from '../shared/geometry/Geometry';\nimport type { Shader } from '../shared/shader/Shader';\nimport type { State } from '../shared/state/State';\nimport type { System } from '../shared/system/System';\nimport type { WebGLRenderer } from './WebGLRenderer';\n\n/**\n * The system that handles encoding commands for the WebGL.\n * @memberof rendering\n */\nexport class GlEncoderSystem implements System\n{\n /** @ignore */\n public static extension = {\n type: [\n ExtensionType.WebGLSystem,\n ],\n name: 'encoder',\n } as const;\n\n public readonly commandFinished = Promise.resolve();\n private readonly _renderer: WebGLRenderer;\n\n constructor(renderer: WebGLRenderer)\n {\n this._renderer = renderer;\n }\n\n public setGeometry(geometry: Geometry, shader?: Shader)\n {\n this._renderer.geometry.bind(geometry, shader.glProgram);\n }\n\n public finishRenderPass()\n {\n // noop\n }\n\n public draw(options: {\n geometry: Geometry,\n shader: Shader,\n state?: State,\n topology?: Topology,\n size?: number,\n start?: number,\n instanceCount?: number\n skipSync?: boolean,\n })\n {\n const renderer = this._renderer;\n const { geometry, shader, state, skipSync, topology: type, size, start, instanceCount } = options;\n\n renderer.shader.bind(shader, skipSync);\n\n renderer.geometry.bind(geometry, renderer.shader._activeProgram);\n\n if (state)\n {\n renderer.state.set(state);\n }\n\n renderer.geometry.draw(type, size, start, instanceCount ?? geometry.instanceCount);\n }\n\n public destroy()\n {\n (this._renderer as null) = null;\n }\n}\n"],"names":["ExtensionType"],"mappings":";;;;;AAaO,MAAM,eACb,CAAA;AAAA,EAYI,YAAY,QACZ,EAAA;AAJA,IAAgB,IAAA,CAAA,eAAA,GAAkB,QAAQ,OAAQ,EAAA,CAAA;AAK9C,IAAA,IAAA,CAAK,SAAY,GAAA,QAAA,CAAA;AAAA,GACrB;AAAA,EAEO,WAAA,CAAY,UAAoB,MACvC,EAAA;AACI,IAAA,IAAA,CAAK,SAAU,CAAA,QAAA,CAAS,IAAK,CAAA,QAAA,EAAU,OAAO,SAAS,CAAA,CAAA;AAAA,GAC3D;AAAA,EAEO,gBACP,GAAA;AAAA,GAEA;AAAA,EAEO,KAAK,OAUZ,EAAA;AACI,IAAA,MAAM,WAAW,IAAK,CAAA,SAAA,CAAA;AACtB,IAAM,MAAA,EAAE,QAAU,EAAA,MAAA,EAAQ,KAAO,EAAA,QAAA,EAAU,UAAU,IAAM,EAAA,IAAA,EAAM,KAAO,EAAA,aAAA,EAAkB,GAAA,OAAA,CAAA;AAE1F,IAAS,QAAA,CAAA,MAAA,CAAO,IAAK,CAAA,MAAA,EAAQ,QAAQ,CAAA,CAAA;AAErC,IAAA,QAAA,CAAS,QAAS,CAAA,IAAA,CAAK,QAAU,EAAA,QAAA,CAAS,OAAO,cAAc,CAAA,CAAA;AAE/D,IAAA,IAAI,KACJ,EAAA;AACI,MAAS,QAAA,CAAA,KAAA,CAAM,IAAI,KAAK,CAAA,CAAA;AAAA,KAC5B;AAEA,IAAA,QAAA,CAAS,SAAS,IAAK,CAAA,IAAA,EAAM,MAAM,KAAO,EAAA,aAAA,IAAiB,SAAS,aAAa,CAAA,CAAA;AAAA,GACrF;AAAA,EAEO,OACP,GAAA;AACI,IAAC,KAAK,SAAqB,GAAA,IAAA,CAAA;AAAA,GAC/B;AACJ,CAAA;AAAA;AA1Da,eAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACFA,wBAAc,CAAA,WAAA;AAAA,GAClB;AAAA,EACA,IAAM,EAAA,SAAA;AACV,CAAA;;;;"}

View File

@@ -0,0 +1,37 @@
import { ExtensionType } from '../../../extensions/Extensions.mjs';
"use strict";
class GlEncoderSystem {
constructor(renderer) {
this.commandFinished = Promise.resolve();
this._renderer = renderer;
}
setGeometry(geometry, shader) {
this._renderer.geometry.bind(geometry, shader.glProgram);
}
finishRenderPass() {
}
draw(options) {
const renderer = this._renderer;
const { geometry, shader, state, skipSync, topology: type, size, start, instanceCount } = options;
renderer.shader.bind(shader, skipSync);
renderer.geometry.bind(geometry, renderer.shader._activeProgram);
if (state) {
renderer.state.set(state);
}
renderer.geometry.draw(type, size, start, instanceCount ?? geometry.instanceCount);
}
destroy() {
this._renderer = null;
}
}
/** @ignore */
GlEncoderSystem.extension = {
type: [
ExtensionType.WebGLSystem
],
name: "encoder"
};
export { GlEncoderSystem };
//# sourceMappingURL=GlEncoderSystem.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlEncoderSystem.mjs","sources":["../../../../src/rendering/renderers/gl/GlEncoderSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../extensions/Extensions';\n\nimport type { Topology } from '../shared/geometry/const';\nimport type { Geometry } from '../shared/geometry/Geometry';\nimport type { Shader } from '../shared/shader/Shader';\nimport type { State } from '../shared/state/State';\nimport type { System } from '../shared/system/System';\nimport type { WebGLRenderer } from './WebGLRenderer';\n\n/**\n * The system that handles encoding commands for the WebGL.\n * @memberof rendering\n */\nexport class GlEncoderSystem implements System\n{\n /** @ignore */\n public static extension = {\n type: [\n ExtensionType.WebGLSystem,\n ],\n name: 'encoder',\n } as const;\n\n public readonly commandFinished = Promise.resolve();\n private readonly _renderer: WebGLRenderer;\n\n constructor(renderer: WebGLRenderer)\n {\n this._renderer = renderer;\n }\n\n public setGeometry(geometry: Geometry, shader?: Shader)\n {\n this._renderer.geometry.bind(geometry, shader.glProgram);\n }\n\n public finishRenderPass()\n {\n // noop\n }\n\n public draw(options: {\n geometry: Geometry,\n shader: Shader,\n state?: State,\n topology?: Topology,\n size?: number,\n start?: number,\n instanceCount?: number\n skipSync?: boolean,\n })\n {\n const renderer = this._renderer;\n const { geometry, shader, state, skipSync, topology: type, size, start, instanceCount } = options;\n\n renderer.shader.bind(shader, skipSync);\n\n renderer.geometry.bind(geometry, renderer.shader._activeProgram);\n\n if (state)\n {\n renderer.state.set(state);\n }\n\n renderer.geometry.draw(type, size, start, instanceCount ?? geometry.instanceCount);\n }\n\n public destroy()\n {\n (this._renderer as null) = null;\n }\n}\n"],"names":[],"mappings":";;;AAaO,MAAM,eACb,CAAA;AAAA,EAYI,YAAY,QACZ,EAAA;AAJA,IAAgB,IAAA,CAAA,eAAA,GAAkB,QAAQ,OAAQ,EAAA,CAAA;AAK9C,IAAA,IAAA,CAAK,SAAY,GAAA,QAAA,CAAA;AAAA,GACrB;AAAA,EAEO,WAAA,CAAY,UAAoB,MACvC,EAAA;AACI,IAAA,IAAA,CAAK,SAAU,CAAA,QAAA,CAAS,IAAK,CAAA,QAAA,EAAU,OAAO,SAAS,CAAA,CAAA;AAAA,GAC3D;AAAA,EAEO,gBACP,GAAA;AAAA,GAEA;AAAA,EAEO,KAAK,OAUZ,EAAA;AACI,IAAA,MAAM,WAAW,IAAK,CAAA,SAAA,CAAA;AACtB,IAAM,MAAA,EAAE,QAAU,EAAA,MAAA,EAAQ,KAAO,EAAA,QAAA,EAAU,UAAU,IAAM,EAAA,IAAA,EAAM,KAAO,EAAA,aAAA,EAAkB,GAAA,OAAA,CAAA;AAE1F,IAAS,QAAA,CAAA,MAAA,CAAO,IAAK,CAAA,MAAA,EAAQ,QAAQ,CAAA,CAAA;AAErC,IAAA,QAAA,CAAS,QAAS,CAAA,IAAA,CAAK,QAAU,EAAA,QAAA,CAAS,OAAO,cAAc,CAAA,CAAA;AAE/D,IAAA,IAAI,KACJ,EAAA;AACI,MAAS,QAAA,CAAA,KAAA,CAAM,IAAI,KAAK,CAAA,CAAA;AAAA,KAC5B;AAEA,IAAA,QAAA,CAAS,SAAS,IAAK,CAAA,IAAA,EAAM,MAAM,KAAO,EAAA,aAAA,IAAiB,SAAS,aAAa,CAAA,CAAA;AAAA,GACrF;AAAA,EAEO,OACP,GAAA;AACI,IAAC,KAAK,SAAqB,GAAA,IAAA,CAAA;AAAA,GAC/B;AACJ,CAAA;AAAA;AA1Da,eAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACF,aAAc,CAAA,WAAA;AAAA,GAClB;AAAA,EACA,IAAM,EAAA,SAAA;AACV,CAAA;;;;"}

View File

@@ -0,0 +1,14 @@
/**
* Represents a render target.
* @memberof rendering
* @ignore
*/
export declare class GlRenderTarget {
width: number;
height: number;
msaa: boolean;
framebuffer: WebGLFramebuffer;
resolveTargetFramebuffer: WebGLFramebuffer;
msaaRenderBuffer: WebGLRenderbuffer[];
depthStencilRenderBuffer: WebGLRenderbuffer;
}

View File

@@ -0,0 +1,14 @@
'use strict';
"use strict";
class GlRenderTarget {
constructor() {
this.width = -1;
this.height = -1;
this.msaa = false;
this.msaaRenderBuffer = [];
}
}
exports.GlRenderTarget = GlRenderTarget;
//# sourceMappingURL=GlRenderTarget.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlRenderTarget.js","sources":["../../../../src/rendering/renderers/gl/GlRenderTarget.ts"],"sourcesContent":["/**\n * Represents a render target.\n * @memberof rendering\n * @ignore\n */\nexport class GlRenderTarget\n{\n public width = -1;\n public height = -1;\n public msaa = false;\n public framebuffer: WebGLFramebuffer;\n public resolveTargetFramebuffer: WebGLFramebuffer;\n public msaaRenderBuffer: WebGLRenderbuffer[] = [];\n public depthStencilRenderBuffer: WebGLRenderbuffer;\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,cACb,CAAA;AAAA,EADO,WAAA,GAAA;AAEH,IAAA,IAAA,CAAO,KAAQ,GAAA,CAAA,CAAA,CAAA;AACf,IAAA,IAAA,CAAO,MAAS,GAAA,CAAA,CAAA,CAAA;AAChB,IAAA,IAAA,CAAO,IAAO,GAAA,KAAA,CAAA;AAGd,IAAA,IAAA,CAAO,mBAAwC,EAAC,CAAA;AAAA,GAAA;AAEpD;;;;"}

View File

@@ -0,0 +1,12 @@
"use strict";
class GlRenderTarget {
constructor() {
this.width = -1;
this.height = -1;
this.msaa = false;
this.msaaRenderBuffer = [];
}
}
export { GlRenderTarget };
//# sourceMappingURL=GlRenderTarget.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlRenderTarget.mjs","sources":["../../../../src/rendering/renderers/gl/GlRenderTarget.ts"],"sourcesContent":["/**\n * Represents a render target.\n * @memberof rendering\n * @ignore\n */\nexport class GlRenderTarget\n{\n public width = -1;\n public height = -1;\n public msaa = false;\n public framebuffer: WebGLFramebuffer;\n public resolveTargetFramebuffer: WebGLFramebuffer;\n public msaaRenderBuffer: WebGLRenderbuffer[] = [];\n public depthStencilRenderBuffer: WebGLRenderbuffer;\n}\n"],"names":[],"mappings":";AAKO,MAAM,cACb,CAAA;AAAA,EADO,WAAA,GAAA;AAEH,IAAA,IAAA,CAAO,KAAQ,GAAA,CAAA,CAAA,CAAA;AACf,IAAA,IAAA,CAAO,MAAS,GAAA,CAAA,CAAA,CAAA;AAChB,IAAA,IAAA,CAAO,IAAO,GAAA,KAAA,CAAA;AAGd,IAAA,IAAA,CAAO,mBAAwC,EAAC,CAAA;AAAA,GAAA;AAEpD;;;;"}

View File

@@ -0,0 +1,27 @@
import { ExtensionType } from '../../../extensions/Extensions';
import { STENCIL_MODES } from '../shared/state/const';
import type { RenderTarget } from '../shared/renderTarget/RenderTarget';
import type { System } from '../shared/system/System';
import type { WebGLRenderer } from './WebGLRenderer';
/**
* This manages the stencil buffer. Used primarily for masking
* @memberof rendering
*/
export declare class GlStencilSystem implements System {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "stencil";
};
private _gl;
private readonly _stencilCache;
private _renderTargetStencilState;
private _stencilOpsMapping;
private _comparisonFuncMapping;
private _activeRenderTarget;
constructor(renderer: WebGLRenderer);
protected contextChange(gl: WebGLRenderingContext): void;
protected onRenderTargetChange(renderTarget: RenderTarget): void;
setStencilMode(stencilMode: STENCIL_MODES, stencilReference: number): void;
destroy?: () => void;
}

View File

@@ -0,0 +1,92 @@
'use strict';
var Extensions = require('../../../extensions/Extensions.js');
var GpuStencilModesToPixi = require('../gpu/state/GpuStencilModesToPixi.js');
var _const = require('../shared/state/const.js');
"use strict";
class GlStencilSystem {
constructor(renderer) {
this._stencilCache = {
enabled: false,
stencilReference: 0,
stencilMode: _const.STENCIL_MODES.NONE
};
this._renderTargetStencilState = /* @__PURE__ */ Object.create(null);
renderer.renderTarget.onRenderTargetChange.add(this);
}
contextChange(gl) {
this._gl = gl;
this._comparisonFuncMapping = {
always: gl.ALWAYS,
never: gl.NEVER,
equal: gl.EQUAL,
"not-equal": gl.NOTEQUAL,
less: gl.LESS,
"less-equal": gl.LEQUAL,
greater: gl.GREATER,
"greater-equal": gl.GEQUAL
};
this._stencilOpsMapping = {
keep: gl.KEEP,
zero: gl.ZERO,
replace: gl.REPLACE,
invert: gl.INVERT,
"increment-clamp": gl.INCR,
"decrement-clamp": gl.DECR,
"increment-wrap": gl.INCR_WRAP,
"decrement-wrap": gl.DECR_WRAP
};
this._stencilCache.enabled = false;
this._stencilCache.stencilMode = _const.STENCIL_MODES.NONE;
this._stencilCache.stencilReference = 0;
}
onRenderTargetChange(renderTarget) {
if (this._activeRenderTarget === renderTarget)
return;
this._activeRenderTarget = renderTarget;
let stencilState = this._renderTargetStencilState[renderTarget.uid];
if (!stencilState) {
stencilState = this._renderTargetStencilState[renderTarget.uid] = {
stencilMode: _const.STENCIL_MODES.DISABLED,
stencilReference: 0
};
}
this.setStencilMode(stencilState.stencilMode, stencilState.stencilReference);
}
setStencilMode(stencilMode, stencilReference) {
const stencilState = this._renderTargetStencilState[this._activeRenderTarget.uid];
const gl = this._gl;
const mode = GpuStencilModesToPixi.GpuStencilModesToPixi[stencilMode];
const _stencilCache = this._stencilCache;
stencilState.stencilMode = stencilMode;
stencilState.stencilReference = stencilReference;
if (stencilMode === _const.STENCIL_MODES.DISABLED) {
if (this._stencilCache.enabled) {
this._stencilCache.enabled = false;
gl.disable(gl.STENCIL_TEST);
}
return;
}
if (!this._stencilCache.enabled) {
this._stencilCache.enabled = true;
gl.enable(gl.STENCIL_TEST);
}
if (stencilMode !== _stencilCache.stencilMode || _stencilCache.stencilReference !== stencilReference) {
_stencilCache.stencilMode = stencilMode;
_stencilCache.stencilReference = stencilReference;
gl.stencilFunc(this._comparisonFuncMapping[mode.stencilBack.compare], stencilReference, 255);
gl.stencilOp(gl.KEEP, gl.KEEP, this._stencilOpsMapping[mode.stencilBack.passOp]);
}
}
}
/** @ignore */
GlStencilSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem
],
name: "stencil"
};
exports.GlStencilSystem = GlStencilSystem;
//# sourceMappingURL=GlStencilSystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,90 @@
import { ExtensionType } from '../../../extensions/Extensions.mjs';
import { GpuStencilModesToPixi } from '../gpu/state/GpuStencilModesToPixi.mjs';
import { STENCIL_MODES } from '../shared/state/const.mjs';
"use strict";
class GlStencilSystem {
constructor(renderer) {
this._stencilCache = {
enabled: false,
stencilReference: 0,
stencilMode: STENCIL_MODES.NONE
};
this._renderTargetStencilState = /* @__PURE__ */ Object.create(null);
renderer.renderTarget.onRenderTargetChange.add(this);
}
contextChange(gl) {
this._gl = gl;
this._comparisonFuncMapping = {
always: gl.ALWAYS,
never: gl.NEVER,
equal: gl.EQUAL,
"not-equal": gl.NOTEQUAL,
less: gl.LESS,
"less-equal": gl.LEQUAL,
greater: gl.GREATER,
"greater-equal": gl.GEQUAL
};
this._stencilOpsMapping = {
keep: gl.KEEP,
zero: gl.ZERO,
replace: gl.REPLACE,
invert: gl.INVERT,
"increment-clamp": gl.INCR,
"decrement-clamp": gl.DECR,
"increment-wrap": gl.INCR_WRAP,
"decrement-wrap": gl.DECR_WRAP
};
this._stencilCache.enabled = false;
this._stencilCache.stencilMode = STENCIL_MODES.NONE;
this._stencilCache.stencilReference = 0;
}
onRenderTargetChange(renderTarget) {
if (this._activeRenderTarget === renderTarget)
return;
this._activeRenderTarget = renderTarget;
let stencilState = this._renderTargetStencilState[renderTarget.uid];
if (!stencilState) {
stencilState = this._renderTargetStencilState[renderTarget.uid] = {
stencilMode: STENCIL_MODES.DISABLED,
stencilReference: 0
};
}
this.setStencilMode(stencilState.stencilMode, stencilState.stencilReference);
}
setStencilMode(stencilMode, stencilReference) {
const stencilState = this._renderTargetStencilState[this._activeRenderTarget.uid];
const gl = this._gl;
const mode = GpuStencilModesToPixi[stencilMode];
const _stencilCache = this._stencilCache;
stencilState.stencilMode = stencilMode;
stencilState.stencilReference = stencilReference;
if (stencilMode === STENCIL_MODES.DISABLED) {
if (this._stencilCache.enabled) {
this._stencilCache.enabled = false;
gl.disable(gl.STENCIL_TEST);
}
return;
}
if (!this._stencilCache.enabled) {
this._stencilCache.enabled = true;
gl.enable(gl.STENCIL_TEST);
}
if (stencilMode !== _stencilCache.stencilMode || _stencilCache.stencilReference !== stencilReference) {
_stencilCache.stencilMode = stencilMode;
_stencilCache.stencilReference = stencilReference;
gl.stencilFunc(this._comparisonFuncMapping[mode.stencilBack.compare], stencilReference, 255);
gl.stencilOp(gl.KEEP, gl.KEEP, this._stencilOpsMapping[mode.stencilBack.passOp]);
}
}
}
/** @ignore */
GlStencilSystem.extension = {
type: [
ExtensionType.WebGLSystem
],
name: "stencil"
};
export { GlStencilSystem };
//# sourceMappingURL=GlStencilSystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,14 @@
import { ExtensionType } from '../../../extensions/Extensions';
import { UboSystem } from '../shared/shader/UboSystem';
/**
* System plugin to the renderer to manage uniform buffers. But with an WGSL adaptor.
* @memberof rendering
*/
export declare class GlUboSystem extends UboSystem {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "ubo";
};
constructor();
}

View File

@@ -0,0 +1,24 @@
'use strict';
var Extensions = require('../../../extensions/Extensions.js');
var UboSystem = require('../shared/shader/UboSystem.js');
var createUboElementsSTD40 = require('./shader/utils/createUboElementsSTD40.js');
var createUboSyncSTD40 = require('./shader/utils/createUboSyncSTD40.js');
"use strict";
class GlUboSystem extends UboSystem.UboSystem {
constructor() {
super({
createUboElements: createUboElementsSTD40.createUboElementsSTD40,
generateUboSync: createUboSyncSTD40.createUboSyncFunctionSTD40
});
}
}
/** @ignore */
GlUboSystem.extension = {
type: [Extensions.ExtensionType.WebGLSystem],
name: "ubo"
};
exports.GlUboSystem = GlUboSystem;
//# sourceMappingURL=GlUboSystem.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlUboSystem.js","sources":["../../../../src/rendering/renderers/gl/GlUboSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../extensions/Extensions';\nimport { UboSystem } from '../shared/shader/UboSystem';\nimport { createUboElementsSTD40 } from './shader/utils/createUboElementsSTD40';\nimport { createUboSyncFunctionSTD40 } from './shader/utils/createUboSyncSTD40';\n\n/**\n * System plugin to the renderer to manage uniform buffers. But with an WGSL adaptor.\n * @memberof rendering\n */\nexport class GlUboSystem extends UboSystem\n{\n /** @ignore */\n public static extension = {\n type: [ExtensionType.WebGLSystem],\n name: 'ubo',\n } as const;\n\n constructor()\n {\n super({\n createUboElements: createUboElementsSTD40,\n generateUboSync: createUboSyncFunctionSTD40,\n });\n }\n}\n"],"names":["UboSystem","createUboElementsSTD40","createUboSyncFunctionSTD40","ExtensionType"],"mappings":";;;;;;;;AASO,MAAM,oBAAoBA,mBACjC,CAAA;AAAA,EAOI,WACA,GAAA;AACI,IAAM,KAAA,CAAA;AAAA,MACF,iBAAmB,EAAAC,6CAAA;AAAA,MACnB,eAAiB,EAAAC,6CAAA;AAAA,KACpB,CAAA,CAAA;AAAA,GACL;AACJ,CAAA;AAAA;AAfa,WAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAA,EAAM,CAACC,wBAAA,CAAc,WAAW,CAAA;AAAA,EAChC,IAAM,EAAA,KAAA;AACV,CAAA;;;;"}

View File

@@ -0,0 +1,22 @@
import { ExtensionType } from '../../../extensions/Extensions.mjs';
import { UboSystem } from '../shared/shader/UboSystem.mjs';
import { createUboElementsSTD40 } from './shader/utils/createUboElementsSTD40.mjs';
import { createUboSyncFunctionSTD40 } from './shader/utils/createUboSyncSTD40.mjs';
"use strict";
class GlUboSystem extends UboSystem {
constructor() {
super({
createUboElements: createUboElementsSTD40,
generateUboSync: createUboSyncFunctionSTD40
});
}
}
/** @ignore */
GlUboSystem.extension = {
type: [ExtensionType.WebGLSystem],
name: "ubo"
};
export { GlUboSystem };
//# sourceMappingURL=GlUboSystem.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlUboSystem.mjs","sources":["../../../../src/rendering/renderers/gl/GlUboSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../extensions/Extensions';\nimport { UboSystem } from '../shared/shader/UboSystem';\nimport { createUboElementsSTD40 } from './shader/utils/createUboElementsSTD40';\nimport { createUboSyncFunctionSTD40 } from './shader/utils/createUboSyncSTD40';\n\n/**\n * System plugin to the renderer to manage uniform buffers. But with an WGSL adaptor.\n * @memberof rendering\n */\nexport class GlUboSystem extends UboSystem\n{\n /** @ignore */\n public static extension = {\n type: [ExtensionType.WebGLSystem],\n name: 'ubo',\n } as const;\n\n constructor()\n {\n super({\n createUboElements: createUboElementsSTD40,\n generateUboSync: createUboSyncFunctionSTD40,\n });\n }\n}\n"],"names":[],"mappings":";;;;;;AASO,MAAM,oBAAoB,SACjC,CAAA;AAAA,EAOI,WACA,GAAA;AACI,IAAM,KAAA,CAAA;AAAA,MACF,iBAAmB,EAAA,sBAAA;AAAA,MACnB,eAAiB,EAAA,0BAAA;AAAA,KACpB,CAAA,CAAA;AAAA,GACL;AACJ,CAAA;AAAA;AAfa,WAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAA,EAAM,CAAC,aAAA,CAAc,WAAW,CAAA;AAAA,EAChC,IAAM,EAAA,KAAA;AACV,CAAA;;;;"}

View File

@@ -0,0 +1,106 @@
import { AbstractRenderer } from '../shared/system/AbstractRenderer';
import { GlBufferSystem } from './buffer/GlBufferSystem';
import { GlContextSystem } from './context/GlContextSystem';
import { GlGeometrySystem } from './geometry/GlGeometrySystem';
import { GlBackBufferSystem } from './GlBackBufferSystem';
import { GlColorMaskSystem } from './GlColorMaskSystem';
import { GlEncoderSystem } from './GlEncoderSystem';
import { GlStencilSystem } from './GlStencilSystem';
import { GlUboSystem } from './GlUboSystem';
import { GlRenderTargetSystem } from './renderTarget/GlRenderTargetSystem';
import { GlShaderSystem } from './shader/GlShaderSystem';
import { GlUniformGroupSystem } from './shader/GlUniformGroupSystem';
import { GlStateSystem } from './state/GlStateSystem';
import { GlTextureSystem } from './texture/GlTextureSystem';
import type { ICanvas } from '../../../environment/canvas/ICanvas';
import type { SharedRendererOptions } from '../shared/system/SharedSystems';
import type { ExtractRendererOptions, ExtractSystemTypes } from '../shared/system/utils/typeUtils';
import type { GlRenderingContext } from './context/GlRenderingContext';
declare const DefaultWebGLSystems: (typeof import("../..").BackgroundSystem | typeof import("../..").GenerateTextureSystem | typeof import("../..").GlobalUniformSystem | typeof import("../..").HelloSystem | typeof import("../..").ViewSystem | typeof import("../../..").RenderGroupSystem | typeof import("../..").TextureGCSystem | typeof import("../..").ExtractSystem | typeof import("../../..").RendererInitHook | typeof import("../..").RenderableGCSystem | typeof import("../..").SchedulerSystem | typeof GlUboSystem | typeof GlBackBufferSystem | typeof GlContextSystem | typeof GlBufferSystem | typeof GlTextureSystem | typeof GlRenderTargetSystem | typeof GlGeometrySystem | typeof GlUniformGroupSystem | typeof GlShaderSystem | typeof GlEncoderSystem | typeof GlStateSystem | typeof GlStencilSystem | typeof GlColorMaskSystem)[];
declare const DefaultWebGLPipes: (typeof import("../..").BlendModePipe | typeof import("../..").BatcherPipe | typeof import("../../..").SpritePipe | typeof import("../../..").RenderGroupPipe | typeof import("../..").AlphaMaskPipe | typeof import("../..").StencilMaskPipe | typeof import("../..").ColorMaskPipe | typeof import("../../..").CustomRenderPipe)[];
/** The default WebGL renderer, uses WebGL2 contexts. */
type WebGLSystems = ExtractSystemTypes<typeof DefaultWebGLSystems> & PixiMixins.RendererSystems & PixiMixins.WebGLSystems;
/** The default WebGL renderer, uses WebGL2 contexts. */
export type WebGLPipes = ExtractSystemTypes<typeof DefaultWebGLPipes> & PixiMixins.RendererPipes & PixiMixins.WebGLPipes;
/**
* Options for WebGLRenderer.
* @memberof rendering
*/
export interface WebGLOptions extends SharedRendererOptions, ExtractRendererOptions<typeof DefaultWebGLSystems>, PixiMixins.WebGLOptions {
}
/**
* The default WebGL renderer, uses WebGL2 contexts.
* @memberof rendering
*/
export interface WebGLRenderer<T extends ICanvas = HTMLCanvasElement> extends AbstractRenderer<WebGLPipes, WebGLOptions, T>, WebGLSystems {
}
/**
* The WebGL PixiJS Renderer. This renderer allows you to use the most common graphics API, WebGL (and WebGL2).
*
* ```ts
* // Create a new renderer
* const renderer = new WebGLRenderer();
* await renderer.init();
*
* // Add the renderer to the stage
* document.body.appendChild(renderer.canvas);
*
* // Create a new stage
* const stage = new Container();
*
* // Render the stage
* renderer.render(stage);
* ```
*
* You can use {@link rendering.autoDetectRenderer} to create a renderer that will automatically detect the best
* renderer for the environment.
*
*
* ```ts
* // Create a new renderer
* const renderer = await rendering.autoDetectRenderer({
* preference:'webgl',
* });
* ```
*
* The renderer is composed of systems that manage specific tasks. The following systems are added by default
* whenever you create a WebGL renderer:
*
* | WebGL Core Systems | Systems that are specific to the WebGL renderer |
* | ------------------------------------------- | ----------------------------------------------------------------------------- |
* | {@link rendering.GlUboSystem} | This manages WebGL2 uniform buffer objects feature for shaders |
* | {@link rendering.GlBackBufferSystem} | manages the back buffer, used so that we can pixi can pixels from the screen |
* | {@link rendering.GlContextSystem} | This manages the WebGL context and its extensions |
* | {@link rendering.GlBufferSystem} | This manages buffers and their GPU resources, keeps everything in sync |
* | {@link rendering.GlTextureSystem} | This manages textures and their GPU resources, keeps everything in sync |
* | {@link rendering.GlRenderTargetSystem} | This manages what we render too. For example the screen, or another texture |
* | {@link rendering.GlGeometrySystem} | This manages geometry, used for drawing meshes via the GPU |
* | {@link rendering.GlUniformGroupSystem} | This manages uniform groups. Syncing shader properties with the GPU |
* | {@link rendering.GlShaderSystem} | This manages shaders, programs that run on the GPU to output lovely pixels |
* | {@link rendering.GlEncoderSystem} | This manages encoders, a WebGPU Paradigm, use it to draw a mesh + shader |
* | {@link rendering.GlStateSystem} | This manages the state of the WebGL context. eg the various flags that can be set blend modes / depthTesting etc |
* | {@link rendering.GlStencilSystem} | This manages the stencil buffer. Used primarily for masking |
* | {@link rendering.GlColorMaskSystem} | This manages the color mask. Used for color masking |
*
* The breadth of the API surface provided by the renderer is contained within these systems.
* @memberof rendering
* @property {rendering.GlUboSystem} ubo - UboSystem instance.
* @property {rendering.GlBackBufferSystem} backBuffer - BackBufferSystem instance.
* @property {rendering.GlContextSystem} context - ContextSystem instance.
* @property {rendering.GlBufferSystem} buffer - BufferSystem instance.
* @property {rendering.GlTextureSystem} texture - TextureSystem instance.
* @property {rendering.GlRenderTargetSystem} renderTarget - RenderTargetSystem instance.
* @property {rendering.GlGeometrySystem} geometry - GeometrySystem instance.
* @property {rendering.GlUniformGroupSystem} uniformGroup - UniformGroupSystem instance.
* @property {rendering.GlShaderSystem} shader - ShaderSystem instance.
* @property {rendering.GlEncoderSystem} encoder - EncoderSystem instance.
* @property {rendering.GlStateSystem} state - StateSystem instance.
* @property {rendering.GlStencilSystem} stencil - StencilSystem instance.
* @property {rendering.GlColorMaskSystem} colorMask - ColorMaskSystem instance.
* @extends rendering.AbstractRenderer
*/
export declare class WebGLRenderer<T extends ICanvas = HTMLCanvasElement> extends AbstractRenderer<WebGLPipes, WebGLOptions, T> implements WebGLSystems {
gl: GlRenderingContext;
constructor();
}
export {};

View File

@@ -0,0 +1,64 @@
'use strict';
var Extensions = require('../../../extensions/Extensions.js');
var GlGraphicsAdaptor = require('../../../scene/graphics/gl/GlGraphicsAdaptor.js');
var GlMeshAdaptor = require('../../../scene/mesh/gl/GlMeshAdaptor.js');
var GlBatchAdaptor = require('../../batcher/gl/GlBatchAdaptor.js');
var AbstractRenderer = require('../shared/system/AbstractRenderer.js');
var SharedSystems = require('../shared/system/SharedSystems.js');
var types = require('../types.js');
var GlBufferSystem = require('./buffer/GlBufferSystem.js');
var GlContextSystem = require('./context/GlContextSystem.js');
var GlGeometrySystem = require('./geometry/GlGeometrySystem.js');
var GlBackBufferSystem = require('./GlBackBufferSystem.js');
var GlColorMaskSystem = require('./GlColorMaskSystem.js');
var GlEncoderSystem = require('./GlEncoderSystem.js');
var GlStencilSystem = require('./GlStencilSystem.js');
var GlUboSystem = require('./GlUboSystem.js');
var GlRenderTargetSystem = require('./renderTarget/GlRenderTargetSystem.js');
var GlShaderSystem = require('./shader/GlShaderSystem.js');
var GlUniformGroupSystem = require('./shader/GlUniformGroupSystem.js');
var GlStateSystem = require('./state/GlStateSystem.js');
var GlTextureSystem = require('./texture/GlTextureSystem.js');
"use strict";
const DefaultWebGLSystems = [
...SharedSystems.SharedSystems,
GlUboSystem.GlUboSystem,
GlBackBufferSystem.GlBackBufferSystem,
GlContextSystem.GlContextSystem,
GlBufferSystem.GlBufferSystem,
GlTextureSystem.GlTextureSystem,
GlRenderTargetSystem.GlRenderTargetSystem,
GlGeometrySystem.GlGeometrySystem,
GlUniformGroupSystem.GlUniformGroupSystem,
GlShaderSystem.GlShaderSystem,
GlEncoderSystem.GlEncoderSystem,
GlStateSystem.GlStateSystem,
GlStencilSystem.GlStencilSystem,
GlColorMaskSystem.GlColorMaskSystem
];
const DefaultWebGLPipes = [...SharedSystems.SharedRenderPipes];
const DefaultWebGLAdapters = [GlBatchAdaptor.GlBatchAdaptor, GlMeshAdaptor.GlMeshAdaptor, GlGraphicsAdaptor.GlGraphicsAdaptor];
const systems = [];
const renderPipes = [];
const renderPipeAdaptors = [];
Extensions.extensions.handleByNamedList(Extensions.ExtensionType.WebGLSystem, systems);
Extensions.extensions.handleByNamedList(Extensions.ExtensionType.WebGLPipes, renderPipes);
Extensions.extensions.handleByNamedList(Extensions.ExtensionType.WebGLPipesAdaptor, renderPipeAdaptors);
Extensions.extensions.add(...DefaultWebGLSystems, ...DefaultWebGLPipes, ...DefaultWebGLAdapters);
class WebGLRenderer extends AbstractRenderer.AbstractRenderer {
constructor() {
const systemConfig = {
name: "webgl",
type: types.RendererType.WEBGL,
systems,
renderPipes,
renderPipeAdaptors
};
super(systemConfig);
}
}
exports.WebGLRenderer = WebGLRenderer;
//# sourceMappingURL=WebGLRenderer.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,62 @@
import { extensions, ExtensionType } from '../../../extensions/Extensions.mjs';
import { GlGraphicsAdaptor } from '../../../scene/graphics/gl/GlGraphicsAdaptor.mjs';
import { GlMeshAdaptor } from '../../../scene/mesh/gl/GlMeshAdaptor.mjs';
import { GlBatchAdaptor } from '../../batcher/gl/GlBatchAdaptor.mjs';
import { AbstractRenderer } from '../shared/system/AbstractRenderer.mjs';
import { SharedSystems, SharedRenderPipes } from '../shared/system/SharedSystems.mjs';
import { RendererType } from '../types.mjs';
import { GlBufferSystem } from './buffer/GlBufferSystem.mjs';
import { GlContextSystem } from './context/GlContextSystem.mjs';
import { GlGeometrySystem } from './geometry/GlGeometrySystem.mjs';
import { GlBackBufferSystem } from './GlBackBufferSystem.mjs';
import { GlColorMaskSystem } from './GlColorMaskSystem.mjs';
import { GlEncoderSystem } from './GlEncoderSystem.mjs';
import { GlStencilSystem } from './GlStencilSystem.mjs';
import { GlUboSystem } from './GlUboSystem.mjs';
import { GlRenderTargetSystem } from './renderTarget/GlRenderTargetSystem.mjs';
import { GlShaderSystem } from './shader/GlShaderSystem.mjs';
import { GlUniformGroupSystem } from './shader/GlUniformGroupSystem.mjs';
import { GlStateSystem } from './state/GlStateSystem.mjs';
import { GlTextureSystem } from './texture/GlTextureSystem.mjs';
"use strict";
const DefaultWebGLSystems = [
...SharedSystems,
GlUboSystem,
GlBackBufferSystem,
GlContextSystem,
GlBufferSystem,
GlTextureSystem,
GlRenderTargetSystem,
GlGeometrySystem,
GlUniformGroupSystem,
GlShaderSystem,
GlEncoderSystem,
GlStateSystem,
GlStencilSystem,
GlColorMaskSystem
];
const DefaultWebGLPipes = [...SharedRenderPipes];
const DefaultWebGLAdapters = [GlBatchAdaptor, GlMeshAdaptor, GlGraphicsAdaptor];
const systems = [];
const renderPipes = [];
const renderPipeAdaptors = [];
extensions.handleByNamedList(ExtensionType.WebGLSystem, systems);
extensions.handleByNamedList(ExtensionType.WebGLPipes, renderPipes);
extensions.handleByNamedList(ExtensionType.WebGLPipesAdaptor, renderPipeAdaptors);
extensions.add(...DefaultWebGLSystems, ...DefaultWebGLPipes, ...DefaultWebGLAdapters);
class WebGLRenderer extends AbstractRenderer {
constructor() {
const systemConfig = {
name: "webgl",
type: RendererType.WEBGL,
systems,
renderPipes,
renderPipeAdaptors
};
super(systemConfig);
}
}
export { WebGLRenderer };
//# sourceMappingURL=WebGLRenderer.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
import type { BUFFER_TYPE } from './const';
export declare class GlBuffer {
buffer: WebGLBuffer;
updateID: number;
byteLength: number;
type: number;
constructor(buffer: WebGLBuffer, type: BUFFER_TYPE);
}

View File

@@ -0,0 +1,14 @@
'use strict';
"use strict";
class GlBuffer {
constructor(buffer, type) {
this.buffer = buffer || null;
this.updateID = -1;
this.byteLength = -1;
this.type = type;
}
}
exports.GlBuffer = GlBuffer;
//# sourceMappingURL=GlBuffer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlBuffer.js","sources":["../../../../../src/rendering/renderers/gl/buffer/GlBuffer.ts"],"sourcesContent":["import type { BUFFER_TYPE } from './const';\n\nexport class GlBuffer\n{\n public buffer: WebGLBuffer;\n public updateID: number;\n public byteLength: number;\n public type: number;\n\n constructor(buffer: WebGLBuffer, type: BUFFER_TYPE)\n {\n this.buffer = buffer || null;\n this.updateID = -1;\n this.byteLength = -1;\n this.type = type;\n }\n}\n"],"names":[],"mappings":";;;AAEO,MAAM,QACb,CAAA;AAAA,EAMI,WAAA,CAAY,QAAqB,IACjC,EAAA;AACI,IAAA,IAAA,CAAK,SAAS,MAAU,IAAA,IAAA,CAAA;AACxB,IAAA,IAAA,CAAK,QAAW,GAAA,CAAA,CAAA,CAAA;AAChB,IAAA,IAAA,CAAK,UAAa,GAAA,CAAA,CAAA,CAAA;AAClB,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AAAA,GAChB;AACJ;;;;"}

View File

@@ -0,0 +1,12 @@
"use strict";
class GlBuffer {
constructor(buffer, type) {
this.buffer = buffer || null;
this.updateID = -1;
this.byteLength = -1;
this.type = type;
}
}
export { GlBuffer };
//# sourceMappingURL=GlBuffer.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlBuffer.mjs","sources":["../../../../../src/rendering/renderers/gl/buffer/GlBuffer.ts"],"sourcesContent":["import type { BUFFER_TYPE } from './const';\n\nexport class GlBuffer\n{\n public buffer: WebGLBuffer;\n public updateID: number;\n public byteLength: number;\n public type: number;\n\n constructor(buffer: WebGLBuffer, type: BUFFER_TYPE)\n {\n this.buffer = buffer || null;\n this.updateID = -1;\n this.byteLength = -1;\n this.type = type;\n }\n}\n"],"names":[],"mappings":";AAEO,MAAM,QACb,CAAA;AAAA,EAMI,WAAA,CAAY,QAAqB,IACjC,EAAA;AACI,IAAA,IAAA,CAAK,SAAS,MAAU,IAAA,IAAA,CAAA;AACxB,IAAA,IAAA,CAAK,QAAW,GAAA,CAAA,CAAA,CAAA;AAChB,IAAA,IAAA,CAAK,UAAa,GAAA,CAAA,CAAA,CAAA;AAClB,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AAAA,GAChB;AACJ;;;;"}

View File

@@ -0,0 +1,85 @@
import { ExtensionType } from '../../../../extensions/Extensions';
import { GlBuffer } from './GlBuffer';
import type { Buffer } from '../../shared/buffer/Buffer';
import type { System } from '../../shared/system/System';
import type { WebGLRenderer } from '../WebGLRenderer';
/**
* System plugin to the renderer to manage buffers.
*
* WebGL uses Buffers as a way to store objects to the GPU.
* This system makes working with them a lot easier.
*
* Buffers are used in three main places in WebGL
* - geometry information
* - Uniform information (via uniform buffer objects - a WebGL 2 only feature)
* - Transform feedback information. (WebGL 2 only feature)
*
* This system will handle the binding of buffers to the GPU as well as uploading
* them. With this system, you never need to work directly with GPU buffers, but instead work with
* the Buffer class.
* @class
* @memberof rendering
*/
export declare class GlBufferSystem implements System {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "buffer";
};
private _gl;
private _gpuBuffers;
/** Cache keeping track of the base bound buffer bases */
private readonly _boundBufferBases;
private _renderer;
/**
* @param {Renderer} renderer - The renderer this System works for.
*/
constructor(renderer: WebGLRenderer);
/**
* @ignore
*/
destroy(): void;
/** Sets up the renderer context and necessary buffers. */
protected contextChange(): void;
getGlBuffer(buffer: Buffer): GlBuffer;
/**
* This binds specified buffer. On first run, it will create the webGL buffers for the context too
* @param buffer - the buffer to bind to the renderer
*/
bind(buffer: Buffer): void;
/**
* Binds an uniform buffer to at the given index.
*
* A cache is used so a buffer will not be bound again if already bound.
* @param buffer - the buffer to bind
* @param index - the base index to bind it to.
*/
bindBufferBase(buffer: Buffer, index: number): void;
/**
* Binds a buffer whilst also binding its range.
* This will make the buffer start from the offset supplied rather than 0 when it is read.
* @param buffer - the buffer to bind
* @param index - the base index to bind at, defaults to 0
* @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
*/
bindBufferRange(buffer: Buffer, index?: number, offset?: number): void;
/**
* Will ensure the data in the buffer is uploaded to the GPU.
* @param {Buffer} buffer - the buffer to update
*/
updateBuffer(buffer: Buffer): GlBuffer;
/** dispose all WebGL resources of all managed buffers */
destroyAll(): void;
/**
* Disposes buffer
* @param {Buffer} buffer - buffer with data
* @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
*/
protected onBufferDestroy(buffer: Buffer, contextLost?: boolean): void;
/**
* creates and attaches a GLBuffer object tied to the current context.
* @param buffer
* @protected
*/
protected createGLBuffer(buffer: Buffer): GlBuffer;
}

View File

@@ -0,0 +1,144 @@
'use strict';
var Extensions = require('../../../../extensions/Extensions.js');
var _const = require('../../shared/buffer/const.js');
var _const$1 = require('./const.js');
var GlBuffer = require('./GlBuffer.js');
"use strict";
class GlBufferSystem {
/**
* @param {Renderer} renderer - The renderer this System works for.
*/
constructor(renderer) {
this._gpuBuffers = /* @__PURE__ */ Object.create(null);
/** Cache keeping track of the base bound buffer bases */
this._boundBufferBases = /* @__PURE__ */ Object.create(null);
this._renderer = renderer;
}
/**
* @ignore
*/
destroy() {
this._renderer = null;
this._gl = null;
this._gpuBuffers = null;
this._boundBufferBases = null;
}
/** Sets up the renderer context and necessary buffers. */
contextChange() {
this._gpuBuffers = /* @__PURE__ */ Object.create(null);
this._gl = this._renderer.gl;
}
getGlBuffer(buffer) {
return this._gpuBuffers[buffer.uid] || this.createGLBuffer(buffer);
}
/**
* This binds specified buffer. On first run, it will create the webGL buffers for the context too
* @param buffer - the buffer to bind to the renderer
*/
bind(buffer) {
const { _gl: gl } = this;
const glBuffer = this.getGlBuffer(buffer);
gl.bindBuffer(glBuffer.type, glBuffer.buffer);
}
/**
* Binds an uniform buffer to at the given index.
*
* A cache is used so a buffer will not be bound again if already bound.
* @param buffer - the buffer to bind
* @param index - the base index to bind it to.
*/
bindBufferBase(buffer, index) {
const { _gl: gl } = this;
if (this._boundBufferBases[index] !== buffer) {
const glBuffer = this.getGlBuffer(buffer);
this._boundBufferBases[index] = buffer;
gl.bindBufferBase(gl.UNIFORM_BUFFER, index, glBuffer.buffer);
}
}
/**
* Binds a buffer whilst also binding its range.
* This will make the buffer start from the offset supplied rather than 0 when it is read.
* @param buffer - the buffer to bind
* @param index - the base index to bind at, defaults to 0
* @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
*/
bindBufferRange(buffer, index, offset) {
const { _gl: gl } = this;
offset = offset || 0;
const glBuffer = this.getGlBuffer(buffer);
gl.bindBufferRange(gl.UNIFORM_BUFFER, index || 0, glBuffer.buffer, offset * 256, 256);
}
/**
* Will ensure the data in the buffer is uploaded to the GPU.
* @param {Buffer} buffer - the buffer to update
*/
updateBuffer(buffer) {
const { _gl: gl } = this;
const glBuffer = this.getGlBuffer(buffer);
if (buffer._updateID === glBuffer.updateID) {
return glBuffer;
}
glBuffer.updateID = buffer._updateID;
gl.bindBuffer(glBuffer.type, glBuffer.buffer);
const data = buffer.data;
if (glBuffer.byteLength >= buffer.data.byteLength) {
gl.bufferSubData(glBuffer.type, 0, data, 0, buffer._updateSize / data.BYTES_PER_ELEMENT);
} else {
const drawType = buffer.descriptor.usage & _const.BufferUsage.STATIC ? gl.STATIC_DRAW : gl.DYNAMIC_DRAW;
glBuffer.byteLength = data.byteLength;
gl.bufferData(glBuffer.type, data, drawType);
}
return glBuffer;
}
/** dispose all WebGL resources of all managed buffers */
destroyAll() {
const gl = this._gl;
for (const id in this._gpuBuffers) {
gl.deleteBuffer(this._gpuBuffers[id].buffer);
}
this._gpuBuffers = /* @__PURE__ */ Object.create(null);
}
/**
* Disposes buffer
* @param {Buffer} buffer - buffer with data
* @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
*/
onBufferDestroy(buffer, contextLost) {
const glBuffer = this._gpuBuffers[buffer.uid];
const gl = this._gl;
if (!contextLost) {
gl.deleteBuffer(glBuffer.buffer);
}
this._gpuBuffers[buffer.uid] = null;
}
/**
* creates and attaches a GLBuffer object tied to the current context.
* @param buffer
* @protected
*/
createGLBuffer(buffer) {
const { _gl: gl } = this;
let type = _const$1.BUFFER_TYPE.ARRAY_BUFFER;
if (buffer.descriptor.usage & _const.BufferUsage.INDEX) {
type = _const$1.BUFFER_TYPE.ELEMENT_ARRAY_BUFFER;
} else if (buffer.descriptor.usage & _const.BufferUsage.UNIFORM) {
type = _const$1.BUFFER_TYPE.UNIFORM_BUFFER;
}
const glBuffer = new GlBuffer.GlBuffer(gl.createBuffer(), type);
this._gpuBuffers[buffer.uid] = glBuffer;
buffer.on("destroy", this.onBufferDestroy, this);
return glBuffer;
}
}
/** @ignore */
GlBufferSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem
],
name: "buffer"
};
exports.GlBufferSystem = GlBufferSystem;
//# sourceMappingURL=GlBufferSystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,142 @@
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { BufferUsage } from '../../shared/buffer/const.mjs';
import { BUFFER_TYPE } from './const.mjs';
import { GlBuffer } from './GlBuffer.mjs';
"use strict";
class GlBufferSystem {
/**
* @param {Renderer} renderer - The renderer this System works for.
*/
constructor(renderer) {
this._gpuBuffers = /* @__PURE__ */ Object.create(null);
/** Cache keeping track of the base bound buffer bases */
this._boundBufferBases = /* @__PURE__ */ Object.create(null);
this._renderer = renderer;
}
/**
* @ignore
*/
destroy() {
this._renderer = null;
this._gl = null;
this._gpuBuffers = null;
this._boundBufferBases = null;
}
/** Sets up the renderer context and necessary buffers. */
contextChange() {
this._gpuBuffers = /* @__PURE__ */ Object.create(null);
this._gl = this._renderer.gl;
}
getGlBuffer(buffer) {
return this._gpuBuffers[buffer.uid] || this.createGLBuffer(buffer);
}
/**
* This binds specified buffer. On first run, it will create the webGL buffers for the context too
* @param buffer - the buffer to bind to the renderer
*/
bind(buffer) {
const { _gl: gl } = this;
const glBuffer = this.getGlBuffer(buffer);
gl.bindBuffer(glBuffer.type, glBuffer.buffer);
}
/**
* Binds an uniform buffer to at the given index.
*
* A cache is used so a buffer will not be bound again if already bound.
* @param buffer - the buffer to bind
* @param index - the base index to bind it to.
*/
bindBufferBase(buffer, index) {
const { _gl: gl } = this;
if (this._boundBufferBases[index] !== buffer) {
const glBuffer = this.getGlBuffer(buffer);
this._boundBufferBases[index] = buffer;
gl.bindBufferBase(gl.UNIFORM_BUFFER, index, glBuffer.buffer);
}
}
/**
* Binds a buffer whilst also binding its range.
* This will make the buffer start from the offset supplied rather than 0 when it is read.
* @param buffer - the buffer to bind
* @param index - the base index to bind at, defaults to 0
* @param offset - the offset to bind at (this is blocks of 256). 0 = 0, 1 = 256, 2 = 512 etc
*/
bindBufferRange(buffer, index, offset) {
const { _gl: gl } = this;
offset = offset || 0;
const glBuffer = this.getGlBuffer(buffer);
gl.bindBufferRange(gl.UNIFORM_BUFFER, index || 0, glBuffer.buffer, offset * 256, 256);
}
/**
* Will ensure the data in the buffer is uploaded to the GPU.
* @param {Buffer} buffer - the buffer to update
*/
updateBuffer(buffer) {
const { _gl: gl } = this;
const glBuffer = this.getGlBuffer(buffer);
if (buffer._updateID === glBuffer.updateID) {
return glBuffer;
}
glBuffer.updateID = buffer._updateID;
gl.bindBuffer(glBuffer.type, glBuffer.buffer);
const data = buffer.data;
if (glBuffer.byteLength >= buffer.data.byteLength) {
gl.bufferSubData(glBuffer.type, 0, data, 0, buffer._updateSize / data.BYTES_PER_ELEMENT);
} else {
const drawType = buffer.descriptor.usage & BufferUsage.STATIC ? gl.STATIC_DRAW : gl.DYNAMIC_DRAW;
glBuffer.byteLength = data.byteLength;
gl.bufferData(glBuffer.type, data, drawType);
}
return glBuffer;
}
/** dispose all WebGL resources of all managed buffers */
destroyAll() {
const gl = this._gl;
for (const id in this._gpuBuffers) {
gl.deleteBuffer(this._gpuBuffers[id].buffer);
}
this._gpuBuffers = /* @__PURE__ */ Object.create(null);
}
/**
* Disposes buffer
* @param {Buffer} buffer - buffer with data
* @param {boolean} [contextLost=false] - If context was lost, we suppress deleteVertexArray
*/
onBufferDestroy(buffer, contextLost) {
const glBuffer = this._gpuBuffers[buffer.uid];
const gl = this._gl;
if (!contextLost) {
gl.deleteBuffer(glBuffer.buffer);
}
this._gpuBuffers[buffer.uid] = null;
}
/**
* creates and attaches a GLBuffer object tied to the current context.
* @param buffer
* @protected
*/
createGLBuffer(buffer) {
const { _gl: gl } = this;
let type = BUFFER_TYPE.ARRAY_BUFFER;
if (buffer.descriptor.usage & BufferUsage.INDEX) {
type = BUFFER_TYPE.ELEMENT_ARRAY_BUFFER;
} else if (buffer.descriptor.usage & BufferUsage.UNIFORM) {
type = BUFFER_TYPE.UNIFORM_BUFFER;
}
const glBuffer = new GlBuffer(gl.createBuffer(), type);
this._gpuBuffers[buffer.uid] = glBuffer;
buffer.on("destroy", this.onBufferDestroy, this);
return glBuffer;
}
}
/** @ignore */
GlBufferSystem.extension = {
type: [
ExtensionType.WebGLSystem
],
name: "buffer"
};
export { GlBufferSystem };
//# sourceMappingURL=GlBufferSystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,15 @@
/**
* Constants for various buffer types in Pixi
* @see BUFFER_TYPE
* @name BUFFER_TYPE
* @static
* @enum {number}
* @property {number} ELEMENT_ARRAY_BUFFER - buffer type for using as an index buffer
* @property {number} ARRAY_BUFFER - buffer type for using attribute data
* @property {number} UNIFORM_BUFFER - the buffer type is for uniform buffer objects
*/
export declare enum BUFFER_TYPE {
ELEMENT_ARRAY_BUFFER = 34963,
ARRAY_BUFFER = 34962,
UNIFORM_BUFFER = 35345
}

View File

@@ -0,0 +1,12 @@
'use strict';
"use strict";
var BUFFER_TYPE = /* @__PURE__ */ ((BUFFER_TYPE2) => {
BUFFER_TYPE2[BUFFER_TYPE2["ELEMENT_ARRAY_BUFFER"] = 34963] = "ELEMENT_ARRAY_BUFFER";
BUFFER_TYPE2[BUFFER_TYPE2["ARRAY_BUFFER"] = 34962] = "ARRAY_BUFFER";
BUFFER_TYPE2[BUFFER_TYPE2["UNIFORM_BUFFER"] = 35345] = "UNIFORM_BUFFER";
return BUFFER_TYPE2;
})(BUFFER_TYPE || {});
exports.BUFFER_TYPE = BUFFER_TYPE;
//# sourceMappingURL=const.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.js","sources":["../../../../../src/rendering/renderers/gl/buffer/const.ts"],"sourcesContent":["/**\n * Constants for various buffer types in Pixi\n * @see BUFFER_TYPE\n * @name BUFFER_TYPE\n * @static\n * @enum {number}\n * @property {number} ELEMENT_ARRAY_BUFFER - buffer type for using as an index buffer\n * @property {number} ARRAY_BUFFER - buffer type for using attribute data\n * @property {number} UNIFORM_BUFFER - the buffer type is for uniform buffer objects\n */\nexport enum BUFFER_TYPE\n // eslint-disable-next-line @typescript-eslint/indent\n {\n ELEMENT_ARRAY_BUFFER = 34963,\n ARRAY_BUFFER = 34962,\n UNIFORM_BUFFER = 35345,\n}\n\n"],"names":["BUFFER_TYPE"],"mappings":";;;AAUY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AAGH,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,0BAAuB,KAAvB,CAAA,GAAA,sBAAA,CAAA;AACA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,kBAAe,KAAf,CAAA,GAAA,cAAA,CAAA;AACA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,oBAAiB,KAAjB,CAAA,GAAA,gBAAA,CAAA;AALQ,EAAAA,OAAAA,YAAAA,CAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;;;;"}

View File

@@ -0,0 +1,10 @@
"use strict";
var BUFFER_TYPE = /* @__PURE__ */ ((BUFFER_TYPE2) => {
BUFFER_TYPE2[BUFFER_TYPE2["ELEMENT_ARRAY_BUFFER"] = 34963] = "ELEMENT_ARRAY_BUFFER";
BUFFER_TYPE2[BUFFER_TYPE2["ARRAY_BUFFER"] = 34962] = "ARRAY_BUFFER";
BUFFER_TYPE2[BUFFER_TYPE2["UNIFORM_BUFFER"] = 35345] = "UNIFORM_BUFFER";
return BUFFER_TYPE2;
})(BUFFER_TYPE || {});
export { BUFFER_TYPE };
//# sourceMappingURL=const.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.mjs","sources":["../../../../../src/rendering/renderers/gl/buffer/const.ts"],"sourcesContent":["/**\n * Constants for various buffer types in Pixi\n * @see BUFFER_TYPE\n * @name BUFFER_TYPE\n * @static\n * @enum {number}\n * @property {number} ELEMENT_ARRAY_BUFFER - buffer type for using as an index buffer\n * @property {number} ARRAY_BUFFER - buffer type for using attribute data\n * @property {number} UNIFORM_BUFFER - the buffer type is for uniform buffer objects\n */\nexport enum BUFFER_TYPE\n // eslint-disable-next-line @typescript-eslint/indent\n {\n ELEMENT_ARRAY_BUFFER = 34963,\n ARRAY_BUFFER = 34962,\n UNIFORM_BUFFER = 35345,\n}\n\n"],"names":["BUFFER_TYPE"],"mappings":";AAUY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AAGH,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,0BAAuB,KAAvB,CAAA,GAAA,sBAAA,CAAA;AACA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,kBAAe,KAAf,CAAA,GAAA,cAAA,CAAA;AACA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,oBAAiB,KAAjB,CAAA,GAAA,gBAAA,CAAA;AALQ,EAAAA,OAAAA,YAAAA,CAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;;;;"}

View File

@@ -0,0 +1,12 @@
export declare enum CLEAR {
NONE = 0,
COLOR = 16384,
STENCIL = 1024,
DEPTH = 256,
COLOR_DEPTH = 16640,
COLOR_STENCIL = 17408,
DEPTH_STENCIL = 1280,
ALL = 17664
}
/** Used for clearing render textures. true is the same as `ALL` false is the same as `NONE` */
export type CLEAR_OR_BOOL = CLEAR | boolean;

View File

@@ -0,0 +1,17 @@
'use strict';
"use strict";
var CLEAR = /* @__PURE__ */ ((CLEAR2) => {
CLEAR2[CLEAR2["NONE"] = 0] = "NONE";
CLEAR2[CLEAR2["COLOR"] = 16384] = "COLOR";
CLEAR2[CLEAR2["STENCIL"] = 1024] = "STENCIL";
CLEAR2[CLEAR2["DEPTH"] = 256] = "DEPTH";
CLEAR2[CLEAR2["COLOR_DEPTH"] = 16640] = "COLOR_DEPTH";
CLEAR2[CLEAR2["COLOR_STENCIL"] = 17408] = "COLOR_STENCIL";
CLEAR2[CLEAR2["DEPTH_STENCIL"] = 1280] = "DEPTH_STENCIL";
CLEAR2[CLEAR2["ALL"] = 17664] = "ALL";
return CLEAR2;
})(CLEAR || {});
exports.CLEAR = CLEAR;
//# sourceMappingURL=const.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.js","sources":["../../../../src/rendering/renderers/gl/const.ts"],"sourcesContent":["export enum CLEAR\n// eslint-disable-next-line @typescript-eslint/indent\n{\n NONE = 0,\n COLOR = 16384,\n STENCIL = 1024,\n DEPTH = 256,\n\n COLOR_DEPTH = COLOR | DEPTH,\n COLOR_STENCIL = COLOR | STENCIL,\n DEPTH_STENCIL = DEPTH | STENCIL,\n ALL = COLOR | DEPTH | STENCIL,\n\n}\n\n/** Used for clearing render textures. true is the same as `ALL` false is the same as `NONE` */\nexport type CLEAR_OR_BOOL = CLEAR | boolean;\n"],"names":["CLEAR"],"mappings":";;;AAAY,IAAA,KAAA,qBAAAA,MAAL,KAAA;AAGH,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,UAAO,CAAP,CAAA,GAAA,MAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,WAAQ,KAAR,CAAA,GAAA,OAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,aAAU,IAAV,CAAA,GAAA,SAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,WAAQ,GAAR,CAAA,GAAA,OAAA,CAAA;AAEA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,iBAAc,KAAd,CAAA,GAAA,aAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,mBAAgB,KAAhB,CAAA,GAAA,eAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,mBAAgB,IAAhB,CAAA,GAAA,eAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,SAAM,KAAN,CAAA,GAAA,KAAA,CAAA;AAXQ,EAAAA,OAAAA,MAAAA,CAAAA;AAAA,CAAA,EAAA,KAAA,IAAA,EAAA;;;;"}

View File

@@ -0,0 +1,15 @@
"use strict";
var CLEAR = /* @__PURE__ */ ((CLEAR2) => {
CLEAR2[CLEAR2["NONE"] = 0] = "NONE";
CLEAR2[CLEAR2["COLOR"] = 16384] = "COLOR";
CLEAR2[CLEAR2["STENCIL"] = 1024] = "STENCIL";
CLEAR2[CLEAR2["DEPTH"] = 256] = "DEPTH";
CLEAR2[CLEAR2["COLOR_DEPTH"] = 16640] = "COLOR_DEPTH";
CLEAR2[CLEAR2["COLOR_STENCIL"] = 17408] = "COLOR_STENCIL";
CLEAR2[CLEAR2["DEPTH_STENCIL"] = 1280] = "DEPTH_STENCIL";
CLEAR2[CLEAR2["ALL"] = 17664] = "ALL";
return CLEAR2;
})(CLEAR || {});
export { CLEAR };
//# sourceMappingURL=const.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.mjs","sources":["../../../../src/rendering/renderers/gl/const.ts"],"sourcesContent":["export enum CLEAR\n// eslint-disable-next-line @typescript-eslint/indent\n{\n NONE = 0,\n COLOR = 16384,\n STENCIL = 1024,\n DEPTH = 256,\n\n COLOR_DEPTH = COLOR | DEPTH,\n COLOR_STENCIL = COLOR | STENCIL,\n DEPTH_STENCIL = DEPTH | STENCIL,\n ALL = COLOR | DEPTH | STENCIL,\n\n}\n\n/** Used for clearing render textures. true is the same as `ALL` false is the same as `NONE` */\nexport type CLEAR_OR_BOOL = CLEAR | boolean;\n"],"names":["CLEAR"],"mappings":";AAAY,IAAA,KAAA,qBAAAA,MAAL,KAAA;AAGH,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,UAAO,CAAP,CAAA,GAAA,MAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,WAAQ,KAAR,CAAA,GAAA,OAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,aAAU,IAAV,CAAA,GAAA,SAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,WAAQ,GAAR,CAAA,GAAA,OAAA,CAAA;AAEA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,iBAAc,KAAd,CAAA,GAAA,aAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,mBAAgB,KAAhB,CAAA,GAAA,eAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,mBAAgB,IAAhB,CAAA,GAAA,eAAA,CAAA;AACA,EAAAA,MAAAA,CAAAA,MAAAA,CAAA,SAAM,KAAN,CAAA,GAAA,KAAA,CAAA;AAXQ,EAAAA,OAAAA,MAAAA,CAAAA;AAAA,CAAA,EAAA,KAAA,IAAA,EAAA;;;;"}

View File

@@ -0,0 +1,181 @@
import { ExtensionType } from '../../../../extensions/Extensions';
import { type GpuPowerPreference } from '../../types';
import type { ICanvas } from '../../../../environment/canvas/ICanvas';
import type { System } from '../../shared/system/System';
import type { WebGLRenderer } from '../WebGLRenderer';
import type { WebGLExtensions } from './WebGLExtensions';
/**
* Options for the context system.
* @memberof rendering
* @property {WebGL2RenderingContext | null} [context=null] - User-provided WebGL rendering context object.
* @property {GpuPowerPreference} [powerPreference='default'] - An optional hint indicating what configuration
* of GPU is suitable for the WebGL context, can be `'high-performance'` or `'low-power'`. Setting to `'high-performance'`
* will prioritize rendering performance over power consumption, while setting to `'low-power'` will prioritize power saving
* over rendering performance.
* @property {boolean} [premultipliedAlpha=true] - Whether the compositor will assume the drawing buffer contains
* colors with premultiplied alpha.
* @property {boolean} [preserveDrawingBuffer=false] - Whether to enable drawing buffer preservation.
* If enabled, the drawing buffer will preserve
* its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.
* @property {boolean} [antialias] - Whether to enable antialiasing.
* @property {1 | 2} [preferWebGLVersion=2] - The preferred WebGL version to use.
*/
export interface ContextSystemOptions {
/**
* User-provided WebGL rendering context object.
* @default null
* @memberof rendering.SharedRendererOptions
*/
context: WebGL2RenderingContext | null;
/**
* An optional hint indicating what configuration of GPU is suitable for the WebGL context,
* can be `'high-performance'` or `'low-power'`.
* Setting to `'high-performance'` will prioritize rendering performance over power consumption,
* while setting to `'low-power'` will prioritize power saving over rendering performance.
* @memberof rendering.SharedRendererOptions
* @default undefined
*/
powerPreference?: GpuPowerPreference;
/**
* Whether the compositor will assume the drawing buffer contains colors with premultiplied alpha.
* @default true
* @memberof rendering.SharedRendererOptions
*/
premultipliedAlpha: boolean;
/**
* Whether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve
* its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.
* @default false
* @memberof rendering.SharedRendererOptions
*/
preserveDrawingBuffer: boolean;
antialias?: boolean;
/**
* The preferred WebGL version to use.
* @default 2
* @memberof rendering.SharedRendererOptions
*/
preferWebGLVersion?: 1 | 2;
/**
* Whether to enable multi-view rendering. Set to true when rendering to multiple
* canvases on the dom.
* @default false
* @memberof rendering.SharedRendererOptions
*/
multiView: boolean;
}
/**
* System plugin to the renderer to manage the context
* @memberof rendering
*/
export declare class GlContextSystem implements System<ContextSystemOptions> {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "context";
};
/** The default options for the system. */
static defaultOptions: ContextSystemOptions;
protected CONTEXT_UID: number;
protected gl: WebGL2RenderingContext;
/**
* Features supported by current renderer.
* @type {object}
* @readonly
*/
supports: {
/** Support for 32-bit indices buffer. */
uint32Indices: boolean;
/** Support for UniformBufferObjects */
uniformBufferObject: boolean;
/** Support for VertexArrayObjects */
vertexArrayObject: boolean;
/** Support for SRGB texture format */
srgbTextures: boolean;
/** Support for wrapping modes if a texture is non-power of two */
nonPowOf2wrapping: boolean;
/** Support for MSAA (antialiasing of dynamic textures) */
msaa: boolean;
/** Support for mipmaps if a texture is non-power of two */
nonPowOf2mipmaps: boolean;
};
/**
* Extensions available.
* @type {object}
* @readonly
* @property {WEBGL_draw_buffers} drawBuffers - WebGL v1 extension
* @property {WEBGL_depth_texture} depthTexture - WebGL v1 extension
* @property {OES_texture_float} floatTexture - WebGL v1 extension
* @property {WEBGL_lose_context} loseContext - WebGL v1 extension
* @property {OES_vertex_array_object} vertexArrayObject - WebGL v1 extension
* @property {EXT_texture_filter_anisotropic} anisotropicFiltering - WebGL v1 and v2 extension
*/
extensions: WebGLExtensions;
webGLVersion: 1 | 2;
/**
* Whether to enable multi-view rendering. Set to true when rendering to multiple
* canvases on the dom.
* @default false
*/
multiView: boolean;
/**
* The canvas that the WebGL Context is rendering to.
* This will be the view canvas. But if multiView is enabled, this canvas will not be attached to the DOM.
* It will be rendered to and then copied to the target canvas.
* @readonly
*/
canvas: ICanvas;
private _renderer;
private _contextLossForced;
/** @param renderer - The renderer this System works for. */
constructor(renderer: WebGLRenderer);
/**
* `true` if the context is lost
* @readonly
*/
get isLost(): boolean;
/**
* Handles the context change event.
* @param {WebGLRenderingContext} gl - New WebGL context.
*/
protected contextChange(gl: WebGL2RenderingContext): void;
init(options: ContextSystemOptions): void;
ensureCanvasSize(targetCanvas: ICanvas): void;
/**
* Initializes the context.
* @protected
* @param {WebGLRenderingContext} gl - WebGL context
*/
protected initFromContext(gl: WebGL2RenderingContext): void;
/**
* Initialize from context options
* @protected
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
* @param preferWebGLVersion
* @param {object} options - context attributes
*/
protected createContext(preferWebGLVersion: 1 | 2, options: WebGLContextAttributes): void;
/** Auto-populate the {@link GlContextSystem.extensions extensions}. */
protected getExtensions(): void;
/**
* Handles a lost webgl context
* @param {WebGLContextEvent} event - The context lost event.
*/
protected handleContextLost(event: WebGLContextEvent): void;
/** Handles a restored webgl context. */
protected handleContextRestored(): void;
destroy(): void;
/**
* this function can be called to force a webGL context loss
* this will release all resources on the GPU.
* Useful if you need to put Pixi to sleep, and save some GPU memory
*
* As soon as render is called - all resources will be created again.
*/
forceContextLoss(): void;
/**
* Validate context.
* @param {WebGLRenderingContext} gl - Render context.
*/
protected validateContext(gl: WebGL2RenderingContext): void;
}

View File

@@ -0,0 +1,279 @@
'use strict';
var adapter = require('../../../../environment/adapter.js');
var Extensions = require('../../../../extensions/Extensions.js');
var warn = require('../../../../utils/logging/warn.js');
"use strict";
const _GlContextSystem = class _GlContextSystem {
/** @param renderer - The renderer this System works for. */
constructor(renderer) {
/**
* Features supported by current renderer.
* @type {object}
* @readonly
*/
this.supports = {
/** Support for 32-bit indices buffer. */
uint32Indices: true,
/** Support for UniformBufferObjects */
uniformBufferObject: true,
/** Support for VertexArrayObjects */
vertexArrayObject: true,
/** Support for SRGB texture format */
srgbTextures: true,
/** Support for wrapping modes if a texture is non-power of two */
nonPowOf2wrapping: true,
/** Support for MSAA (antialiasing of dynamic textures) */
msaa: true,
/** Support for mipmaps if a texture is non-power of two */
nonPowOf2mipmaps: true
};
this._renderer = renderer;
this.extensions = /* @__PURE__ */ Object.create(null);
this.handleContextLost = this.handleContextLost.bind(this);
this.handleContextRestored = this.handleContextRestored.bind(this);
}
/**
* `true` if the context is lost
* @readonly
*/
get isLost() {
return !this.gl || this.gl.isContextLost();
}
/**
* Handles the context change event.
* @param {WebGLRenderingContext} gl - New WebGL context.
*/
contextChange(gl) {
this.gl = gl;
this._renderer.gl = gl;
}
init(options) {
options = { ..._GlContextSystem.defaultOptions, ...options };
let multiView = this.multiView = options.multiView;
if (options.context && multiView) {
warn.warn("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together.");
multiView = false;
}
if (multiView) {
this.canvas = adapter.DOMAdapter.get().createCanvas(this._renderer.canvas.width, this._renderer.canvas.height);
} else {
this.canvas = this._renderer.view.canvas;
}
if (options.context) {
this.initFromContext(options.context);
} else {
const alpha = this._renderer.background.alpha < 1;
const premultipliedAlpha = options.premultipliedAlpha ?? true;
const antialias = options.antialias && !this._renderer.backBuffer.useBackBuffer;
this.createContext(options.preferWebGLVersion, {
alpha,
premultipliedAlpha,
antialias,
stencil: true,
preserveDrawingBuffer: options.preserveDrawingBuffer,
powerPreference: options.powerPreference ?? "default"
});
}
}
ensureCanvasSize(targetCanvas) {
if (!this.multiView) {
if (targetCanvas !== this.canvas) {
warn.warn("multiView is disabled, but targetCanvas is not the main canvas");
}
return;
}
const { canvas } = this;
if (canvas.width < targetCanvas.width || canvas.height < targetCanvas.height) {
canvas.width = Math.max(targetCanvas.width, targetCanvas.width);
canvas.height = Math.max(targetCanvas.height, targetCanvas.height);
}
}
/**
* Initializes the context.
* @protected
* @param {WebGLRenderingContext} gl - WebGL context
*/
initFromContext(gl) {
this.gl = gl;
this.webGLVersion = gl instanceof adapter.DOMAdapter.get().getWebGLRenderingContext() ? 1 : 2;
this.getExtensions();
this.validateContext(gl);
this._renderer.runners.contextChange.emit(gl);
const element = this._renderer.view.canvas;
element.addEventListener("webglcontextlost", this.handleContextLost, false);
element.addEventListener("webglcontextrestored", this.handleContextRestored, false);
}
/**
* Initialize from context options
* @protected
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
* @param preferWebGLVersion
* @param {object} options - context attributes
*/
createContext(preferWebGLVersion, options) {
let gl;
const canvas = this.canvas;
if (preferWebGLVersion === 2) {
gl = canvas.getContext("webgl2", options);
}
if (!gl) {
gl = canvas.getContext("webgl", options);
if (!gl) {
throw new Error("This browser does not support WebGL. Try using the canvas renderer");
}
}
this.gl = gl;
this.initFromContext(this.gl);
}
/** Auto-populate the {@link GlContextSystem.extensions extensions}. */
getExtensions() {
const { gl } = this;
const common = {
anisotropicFiltering: gl.getExtension("EXT_texture_filter_anisotropic"),
floatTextureLinear: gl.getExtension("OES_texture_float_linear"),
s3tc: gl.getExtension("WEBGL_compressed_texture_s3tc"),
s3tc_sRGB: gl.getExtension("WEBGL_compressed_texture_s3tc_srgb"),
// eslint-disable-line camelcase
etc: gl.getExtension("WEBGL_compressed_texture_etc"),
etc1: gl.getExtension("WEBGL_compressed_texture_etc1"),
pvrtc: gl.getExtension("WEBGL_compressed_texture_pvrtc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
atc: gl.getExtension("WEBGL_compressed_texture_atc"),
astc: gl.getExtension("WEBGL_compressed_texture_astc"),
bptc: gl.getExtension("EXT_texture_compression_bptc"),
rgtc: gl.getExtension("EXT_texture_compression_rgtc"),
loseContext: gl.getExtension("WEBGL_lose_context")
};
if (this.webGLVersion === 1) {
this.extensions = {
...common,
drawBuffers: gl.getExtension("WEBGL_draw_buffers"),
depthTexture: gl.getExtension("WEBGL_depth_texture"),
vertexArrayObject: gl.getExtension("OES_vertex_array_object") || gl.getExtension("MOZ_OES_vertex_array_object") || gl.getExtension("WEBKIT_OES_vertex_array_object"),
uint32ElementIndex: gl.getExtension("OES_element_index_uint"),
// Floats and half-floats
floatTexture: gl.getExtension("OES_texture_float"),
floatTextureLinear: gl.getExtension("OES_texture_float_linear"),
textureHalfFloat: gl.getExtension("OES_texture_half_float"),
textureHalfFloatLinear: gl.getExtension("OES_texture_half_float_linear"),
vertexAttribDivisorANGLE: gl.getExtension("ANGLE_instanced_arrays"),
srgb: gl.getExtension("EXT_sRGB")
};
} else {
this.extensions = {
...common,
colorBufferFloat: gl.getExtension("EXT_color_buffer_float")
};
const provokeExt = gl.getExtension("WEBGL_provoking_vertex");
if (provokeExt) {
provokeExt.provokingVertexWEBGL(provokeExt.FIRST_VERTEX_CONVENTION_WEBGL);
}
}
}
/**
* Handles a lost webgl context
* @param {WebGLContextEvent} event - The context lost event.
*/
handleContextLost(event) {
event.preventDefault();
if (this._contextLossForced) {
this._contextLossForced = false;
setTimeout(() => {
if (this.gl.isContextLost()) {
this.extensions.loseContext?.restoreContext();
}
}, 0);
}
}
/** Handles a restored webgl context. */
handleContextRestored() {
this._renderer.runners.contextChange.emit(this.gl);
}
destroy() {
const element = this._renderer.view.canvas;
this._renderer = null;
element.removeEventListener("webglcontextlost", this.handleContextLost);
element.removeEventListener("webglcontextrestored", this.handleContextRestored);
this.gl.useProgram(null);
this.extensions.loseContext?.loseContext();
}
/**
* this function can be called to force a webGL context loss
* this will release all resources on the GPU.
* Useful if you need to put Pixi to sleep, and save some GPU memory
*
* As soon as render is called - all resources will be created again.
*/
forceContextLoss() {
this.extensions.loseContext?.loseContext();
this._contextLossForced = true;
}
/**
* Validate context.
* @param {WebGLRenderingContext} gl - Render context.
*/
validateContext(gl) {
const attributes = gl.getContextAttributes();
if (attributes && !attributes.stencil) {
warn.warn("Provided WebGL context does not have a stencil buffer, masks may not render correctly");
}
const supports = this.supports;
const isWebGl2 = this.webGLVersion === 2;
const extensions = this.extensions;
supports.uint32Indices = isWebGl2 || !!extensions.uint32ElementIndex;
supports.uniformBufferObject = isWebGl2;
supports.vertexArrayObject = isWebGl2 || !!extensions.vertexArrayObject;
supports.srgbTextures = isWebGl2 || !!extensions.srgb;
supports.nonPowOf2wrapping = isWebGl2;
supports.nonPowOf2mipmaps = isWebGl2;
supports.msaa = isWebGl2;
if (!supports.uint32Indices) {
warn.warn("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly");
}
}
};
/** @ignore */
_GlContextSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem
],
name: "context"
};
/** The default options for the system. */
_GlContextSystem.defaultOptions = {
/**
* {@link WebGLOptions.context}
* @default null
*/
context: null,
/**
* {@link WebGLOptions.premultipliedAlpha}
* @default true
*/
premultipliedAlpha: true,
/**
* {@link WebGLOptions.preserveDrawingBuffer}
* @default false
*/
preserveDrawingBuffer: false,
/**
* {@link WebGLOptions.powerPreference}
* @default default
*/
powerPreference: void 0,
/**
* {@link WebGLOptions.webGLVersion}
* @default 2
*/
preferWebGLVersion: 2,
/**
* {@link WebGLOptions.multiView}
* @default false
*/
multiView: false
};
let GlContextSystem = _GlContextSystem;
exports.GlContextSystem = GlContextSystem;
//# sourceMappingURL=GlContextSystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,277 @@
import { DOMAdapter } from '../../../../environment/adapter.mjs';
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { warn } from '../../../../utils/logging/warn.mjs';
"use strict";
const _GlContextSystem = class _GlContextSystem {
/** @param renderer - The renderer this System works for. */
constructor(renderer) {
/**
* Features supported by current renderer.
* @type {object}
* @readonly
*/
this.supports = {
/** Support for 32-bit indices buffer. */
uint32Indices: true,
/** Support for UniformBufferObjects */
uniformBufferObject: true,
/** Support for VertexArrayObjects */
vertexArrayObject: true,
/** Support for SRGB texture format */
srgbTextures: true,
/** Support for wrapping modes if a texture is non-power of two */
nonPowOf2wrapping: true,
/** Support for MSAA (antialiasing of dynamic textures) */
msaa: true,
/** Support for mipmaps if a texture is non-power of two */
nonPowOf2mipmaps: true
};
this._renderer = renderer;
this.extensions = /* @__PURE__ */ Object.create(null);
this.handleContextLost = this.handleContextLost.bind(this);
this.handleContextRestored = this.handleContextRestored.bind(this);
}
/**
* `true` if the context is lost
* @readonly
*/
get isLost() {
return !this.gl || this.gl.isContextLost();
}
/**
* Handles the context change event.
* @param {WebGLRenderingContext} gl - New WebGL context.
*/
contextChange(gl) {
this.gl = gl;
this._renderer.gl = gl;
}
init(options) {
options = { ..._GlContextSystem.defaultOptions, ...options };
let multiView = this.multiView = options.multiView;
if (options.context && multiView) {
warn("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together.");
multiView = false;
}
if (multiView) {
this.canvas = DOMAdapter.get().createCanvas(this._renderer.canvas.width, this._renderer.canvas.height);
} else {
this.canvas = this._renderer.view.canvas;
}
if (options.context) {
this.initFromContext(options.context);
} else {
const alpha = this._renderer.background.alpha < 1;
const premultipliedAlpha = options.premultipliedAlpha ?? true;
const antialias = options.antialias && !this._renderer.backBuffer.useBackBuffer;
this.createContext(options.preferWebGLVersion, {
alpha,
premultipliedAlpha,
antialias,
stencil: true,
preserveDrawingBuffer: options.preserveDrawingBuffer,
powerPreference: options.powerPreference ?? "default"
});
}
}
ensureCanvasSize(targetCanvas) {
if (!this.multiView) {
if (targetCanvas !== this.canvas) {
warn("multiView is disabled, but targetCanvas is not the main canvas");
}
return;
}
const { canvas } = this;
if (canvas.width < targetCanvas.width || canvas.height < targetCanvas.height) {
canvas.width = Math.max(targetCanvas.width, targetCanvas.width);
canvas.height = Math.max(targetCanvas.height, targetCanvas.height);
}
}
/**
* Initializes the context.
* @protected
* @param {WebGLRenderingContext} gl - WebGL context
*/
initFromContext(gl) {
this.gl = gl;
this.webGLVersion = gl instanceof DOMAdapter.get().getWebGLRenderingContext() ? 1 : 2;
this.getExtensions();
this.validateContext(gl);
this._renderer.runners.contextChange.emit(gl);
const element = this._renderer.view.canvas;
element.addEventListener("webglcontextlost", this.handleContextLost, false);
element.addEventListener("webglcontextrestored", this.handleContextRestored, false);
}
/**
* Initialize from context options
* @protected
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
* @param preferWebGLVersion
* @param {object} options - context attributes
*/
createContext(preferWebGLVersion, options) {
let gl;
const canvas = this.canvas;
if (preferWebGLVersion === 2) {
gl = canvas.getContext("webgl2", options);
}
if (!gl) {
gl = canvas.getContext("webgl", options);
if (!gl) {
throw new Error("This browser does not support WebGL. Try using the canvas renderer");
}
}
this.gl = gl;
this.initFromContext(this.gl);
}
/** Auto-populate the {@link GlContextSystem.extensions extensions}. */
getExtensions() {
const { gl } = this;
const common = {
anisotropicFiltering: gl.getExtension("EXT_texture_filter_anisotropic"),
floatTextureLinear: gl.getExtension("OES_texture_float_linear"),
s3tc: gl.getExtension("WEBGL_compressed_texture_s3tc"),
s3tc_sRGB: gl.getExtension("WEBGL_compressed_texture_s3tc_srgb"),
// eslint-disable-line camelcase
etc: gl.getExtension("WEBGL_compressed_texture_etc"),
etc1: gl.getExtension("WEBGL_compressed_texture_etc1"),
pvrtc: gl.getExtension("WEBGL_compressed_texture_pvrtc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),
atc: gl.getExtension("WEBGL_compressed_texture_atc"),
astc: gl.getExtension("WEBGL_compressed_texture_astc"),
bptc: gl.getExtension("EXT_texture_compression_bptc"),
rgtc: gl.getExtension("EXT_texture_compression_rgtc"),
loseContext: gl.getExtension("WEBGL_lose_context")
};
if (this.webGLVersion === 1) {
this.extensions = {
...common,
drawBuffers: gl.getExtension("WEBGL_draw_buffers"),
depthTexture: gl.getExtension("WEBGL_depth_texture"),
vertexArrayObject: gl.getExtension("OES_vertex_array_object") || gl.getExtension("MOZ_OES_vertex_array_object") || gl.getExtension("WEBKIT_OES_vertex_array_object"),
uint32ElementIndex: gl.getExtension("OES_element_index_uint"),
// Floats and half-floats
floatTexture: gl.getExtension("OES_texture_float"),
floatTextureLinear: gl.getExtension("OES_texture_float_linear"),
textureHalfFloat: gl.getExtension("OES_texture_half_float"),
textureHalfFloatLinear: gl.getExtension("OES_texture_half_float_linear"),
vertexAttribDivisorANGLE: gl.getExtension("ANGLE_instanced_arrays"),
srgb: gl.getExtension("EXT_sRGB")
};
} else {
this.extensions = {
...common,
colorBufferFloat: gl.getExtension("EXT_color_buffer_float")
};
const provokeExt = gl.getExtension("WEBGL_provoking_vertex");
if (provokeExt) {
provokeExt.provokingVertexWEBGL(provokeExt.FIRST_VERTEX_CONVENTION_WEBGL);
}
}
}
/**
* Handles a lost webgl context
* @param {WebGLContextEvent} event - The context lost event.
*/
handleContextLost(event) {
event.preventDefault();
if (this._contextLossForced) {
this._contextLossForced = false;
setTimeout(() => {
if (this.gl.isContextLost()) {
this.extensions.loseContext?.restoreContext();
}
}, 0);
}
}
/** Handles a restored webgl context. */
handleContextRestored() {
this._renderer.runners.contextChange.emit(this.gl);
}
destroy() {
const element = this._renderer.view.canvas;
this._renderer = null;
element.removeEventListener("webglcontextlost", this.handleContextLost);
element.removeEventListener("webglcontextrestored", this.handleContextRestored);
this.gl.useProgram(null);
this.extensions.loseContext?.loseContext();
}
/**
* this function can be called to force a webGL context loss
* this will release all resources on the GPU.
* Useful if you need to put Pixi to sleep, and save some GPU memory
*
* As soon as render is called - all resources will be created again.
*/
forceContextLoss() {
this.extensions.loseContext?.loseContext();
this._contextLossForced = true;
}
/**
* Validate context.
* @param {WebGLRenderingContext} gl - Render context.
*/
validateContext(gl) {
const attributes = gl.getContextAttributes();
if (attributes && !attributes.stencil) {
warn("Provided WebGL context does not have a stencil buffer, masks may not render correctly");
}
const supports = this.supports;
const isWebGl2 = this.webGLVersion === 2;
const extensions = this.extensions;
supports.uint32Indices = isWebGl2 || !!extensions.uint32ElementIndex;
supports.uniformBufferObject = isWebGl2;
supports.vertexArrayObject = isWebGl2 || !!extensions.vertexArrayObject;
supports.srgbTextures = isWebGl2 || !!extensions.srgb;
supports.nonPowOf2wrapping = isWebGl2;
supports.nonPowOf2mipmaps = isWebGl2;
supports.msaa = isWebGl2;
if (!supports.uint32Indices) {
warn("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly");
}
}
};
/** @ignore */
_GlContextSystem.extension = {
type: [
ExtensionType.WebGLSystem
],
name: "context"
};
/** The default options for the system. */
_GlContextSystem.defaultOptions = {
/**
* {@link WebGLOptions.context}
* @default null
*/
context: null,
/**
* {@link WebGLOptions.premultipliedAlpha}
* @default true
*/
premultipliedAlpha: true,
/**
* {@link WebGLOptions.preserveDrawingBuffer}
* @default false
*/
preserveDrawingBuffer: false,
/**
* {@link WebGLOptions.powerPreference}
* @default default
*/
powerPreference: void 0,
/**
* {@link WebGLOptions.webGLVersion}
* @default 2
*/
preferWebGLVersion: 2,
/**
* {@link WebGLOptions.multiView}
* @default false
*/
multiView: false
};
let GlContextSystem = _GlContextSystem;
export { GlContextSystem };
//# sourceMappingURL=GlContextSystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
export type GlRenderingContext = WebGL2RenderingContext;

View File

@@ -0,0 +1,4 @@
'use strict';
"use strict";
//# sourceMappingURL=GlRenderingContext.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlRenderingContext.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}

View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=GlRenderingContext.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlRenderingContext.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,62 @@
export interface WEBGL_compressed_texture_pvrtc {
COMPRESSED_RGB_PVRTC_4BPPV1_IMG: number;
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: number;
COMPRESSED_RGB_PVRTC_2BPPV1_IMG: number;
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: number;
}
export interface WEBGL_compressed_texture_etc {
COMPRESSED_R11_EAC: number;
COMPRESSED_SIGNED_R11_EAC: number;
COMPRESSED_RG11_EAC: number;
COMPRESSED_SIGNED_RG11_EAC: number;
COMPRESSED_RGB8_ETC2: number;
COMPRESSED_RGBA8_ETC2_EAC: number;
COMPRESSED_SRGB8_ETC2: number;
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: number;
COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: number;
COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: number;
}
export interface WEBGL_compressed_texture_etc1 {
COMPRESSED_RGB_ETC1_WEBGL: number;
}
export interface WEBGL_compressed_texture_atc {
COMPRESSED_RGB_ATC_WEBGL: number;
COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: number;
COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: number;
}
export interface EXT_texture_compression_bptc {
COMPRESSED_RGBA_BPTC_UNORM_EXT: number;
COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: number;
COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: number;
COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: number;
}
export interface EXT_texture_compression_rgtc {
COMPRESSED_RED_RGTC1_EXT: number;
COMPRESSED_SIGNED_RED_RGTC1_EXT: number;
COMPRESSED_RED_GREEN_RGTC2_EXT: number;
COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: number;
}
export interface WebGLExtensions {
drawBuffers?: WEBGL_draw_buffers;
depthTexture?: OES_texture_float;
loseContext?: WEBGL_lose_context;
vertexArrayObject?: OES_vertex_array_object;
anisotropicFiltering?: EXT_texture_filter_anisotropic;
uint32ElementIndex?: OES_element_index_uint;
floatTexture?: OES_texture_float;
floatTextureLinear?: OES_texture_float_linear;
textureHalfFloat?: OES_texture_half_float;
textureHalfFloatLinear?: OES_texture_half_float_linear;
colorBufferFloat?: EXT_color_buffer_float;
vertexAttribDivisorANGLE?: ANGLE_instanced_arrays;
s3tc?: WEBGL_compressed_texture_s3tc;
s3tc_sRGB?: WEBGL_compressed_texture_s3tc_srgb;
etc?: WEBGL_compressed_texture_etc;
etc1?: WEBGL_compressed_texture_etc1;
pvrtc?: WEBGL_compressed_texture_pvrtc;
atc?: WEBGL_compressed_texture_atc;
astc?: WEBGL_compressed_texture_astc;
bptc?: EXT_texture_compression_bptc;
rgtc?: EXT_texture_compression_rgtc;
srgb?: EXT_sRGB;
}

View File

@@ -0,0 +1,4 @@
'use strict';
"use strict";
//# sourceMappingURL=WebGLExtensions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"WebGLExtensions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}

View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=WebGLExtensions.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"WebGLExtensions.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,102 @@
import { ExtensionType } from '../../../../extensions/Extensions';
import type { Topology } from '../../shared/geometry/const';
import type { Geometry } from '../../shared/geometry/Geometry';
import type { System } from '../../shared/system/System';
import type { GlRenderingContext } from '../context/GlRenderingContext';
import type { GlProgram } from '../shader/GlProgram';
import type { WebGLRenderer } from '../WebGLRenderer';
/**
* System plugin to the renderer to manage geometry.
* @memberof rendering
*/
export declare class GlGeometrySystem implements System {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "geometry";
};
/**
* `true` if we has `*_vertex_array_object` extension.
* @readonly
*/
hasVao: boolean;
/**
* `true` if has `ANGLE_instanced_arrays` extension.
* @readonly
*/
hasInstance: boolean;
protected gl: GlRenderingContext;
protected _activeGeometry: Geometry;
protected _activeVao: WebGLVertexArrayObject;
protected _geometryVaoHash: Record<number, Record<string, WebGLVertexArrayObject>>;
/** Renderer that owns this {@link GeometrySystem}. */
private _renderer;
/** @param renderer - The renderer this System works for. */
constructor(renderer: WebGLRenderer);
/** Sets up the renderer context and necessary buffers. */
protected contextChange(): void;
/**
* Binds geometry so that is can be drawn. Creating a Vao if required
* @param geometry - Instance of geometry to bind.
* @param program - Instance of program to use vao for.
*/
bind(geometry?: Geometry, program?: GlProgram): void;
/** Reset and unbind any active VAO and geometry. */
reset(): void;
/** Update buffers of the currently bound geometry. */
updateBuffers(): void;
/**
* Check compatibility between a geometry and a program
* @param geometry - Geometry instance.
* @param program - Program instance.
*/
protected checkCompatibility(geometry: Geometry, program: GlProgram): void;
/**
* Takes a geometry and program and generates a unique signature for them.
* @param geometry - To get signature from.
* @param program - To test geometry against.
* @returns - Unique signature of the geometry and program
*/
protected getSignature(geometry: Geometry, program: GlProgram): string;
protected getVao(geometry: Geometry, program: GlProgram): WebGLVertexArrayObject;
/**
* Creates or gets Vao with the same structure as the geometry and stores it on the geometry.
* If vao is created, it is bound automatically. We use a shader to infer what and how to set up the
* attribute locations.
* @param geometry - Instance of geometry to to generate Vao for.
* @param program
* @param _incRefCount - Increment refCount of all geometry buffers.
*/
protected initGeometryVao(geometry: Geometry, program: GlProgram, _incRefCount?: boolean): WebGLVertexArrayObject;
/**
* Disposes geometry.
* @param geometry - Geometry with buffers. Only VAO will be disposed
* @param [contextLost=false] - If context was lost, we suppress deleteVertexArray
*/
protected onGeometryDestroy(geometry: Geometry, contextLost?: boolean): void;
/**
* Dispose all WebGL resources of all managed geometries.
* @param [contextLost=false] - If context was lost, we suppress `gl.delete` calls
*/
destroyAll(contextLost?: boolean): void;
/**
* Activate vertex array object.
* @param geometry - Geometry instance.
* @param program - Shader program instance.
*/
protected activateVao(geometry: Geometry, program: GlProgram): void;
/**
* Draws the currently bound geometry.
* @param topology - The type primitive to render.
* @param size - The number of elements to be rendered. If not specified, all vertices after the
* starting vertex will be drawn.
* @param start - The starting vertex in the geometry to start drawing from. If not specified,
* drawing will start from the first vertex.
* @param instanceCount - The number of instances of the set of elements to execute. If not specified,
* all instances will be drawn.
*/
draw(topology?: Topology, size?: number, start?: number, instanceCount?: number): this;
/** Unbind/reset everything. */
protected unbind(): void;
destroy(): void;
}

View File

@@ -0,0 +1,299 @@
'use strict';
var Extensions = require('../../../../extensions/Extensions.js');
var getAttributeInfoFromFormat = require('../../shared/geometry/utils/getAttributeInfoFromFormat.js');
var ensureAttributes = require('../shader/program/ensureAttributes.js');
var getGlTypeFromFormat = require('./utils/getGlTypeFromFormat.js');
"use strict";
const topologyToGlMap = {
"point-list": 0,
"line-list": 1,
"line-strip": 3,
"triangle-list": 4,
"triangle-strip": 5
};
class GlGeometrySystem {
/** @param renderer - The renderer this System works for. */
constructor(renderer) {
this._geometryVaoHash = /* @__PURE__ */ Object.create(null);
this._renderer = renderer;
this._activeGeometry = null;
this._activeVao = null;
this.hasVao = true;
this.hasInstance = true;
}
/** Sets up the renderer context and necessary buffers. */
contextChange() {
const gl = this.gl = this._renderer.gl;
if (!this._renderer.context.supports.vertexArrayObject) {
throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");
}
const nativeVaoExtension = this._renderer.context.extensions.vertexArrayObject;
if (nativeVaoExtension) {
gl.createVertexArray = () => nativeVaoExtension.createVertexArrayOES();
gl.bindVertexArray = (vao) => nativeVaoExtension.bindVertexArrayOES(vao);
gl.deleteVertexArray = (vao) => nativeVaoExtension.deleteVertexArrayOES(vao);
}
const nativeInstancedExtension = this._renderer.context.extensions.vertexAttribDivisorANGLE;
if (nativeInstancedExtension) {
gl.drawArraysInstanced = (a, b, c, d) => {
nativeInstancedExtension.drawArraysInstancedANGLE(a, b, c, d);
};
gl.drawElementsInstanced = (a, b, c, d, e) => {
nativeInstancedExtension.drawElementsInstancedANGLE(a, b, c, d, e);
};
gl.vertexAttribDivisor = (a, b) => nativeInstancedExtension.vertexAttribDivisorANGLE(a, b);
}
this._activeGeometry = null;
this._activeVao = null;
this._geometryVaoHash = /* @__PURE__ */ Object.create(null);
}
/**
* Binds geometry so that is can be drawn. Creating a Vao if required
* @param geometry - Instance of geometry to bind.
* @param program - Instance of program to use vao for.
*/
bind(geometry, program) {
const gl = this.gl;
this._activeGeometry = geometry;
const vao = this.getVao(geometry, program);
if (this._activeVao !== vao) {
this._activeVao = vao;
gl.bindVertexArray(vao);
}
this.updateBuffers();
}
/** Reset and unbind any active VAO and geometry. */
reset() {
this.unbind();
}
/** Update buffers of the currently bound geometry. */
updateBuffers() {
const geometry = this._activeGeometry;
const bufferSystem = this._renderer.buffer;
for (let i = 0; i < geometry.buffers.length; i++) {
const buffer = geometry.buffers[i];
bufferSystem.updateBuffer(buffer);
}
}
/**
* Check compatibility between a geometry and a program
* @param geometry - Geometry instance.
* @param program - Program instance.
*/
checkCompatibility(geometry, program) {
const geometryAttributes = geometry.attributes;
const shaderAttributes = program._attributeData;
for (const j in shaderAttributes) {
if (!geometryAttributes[j]) {
throw new Error(`shader and geometry incompatible, geometry missing the "${j}" attribute`);
}
}
}
/**
* Takes a geometry and program and generates a unique signature for them.
* @param geometry - To get signature from.
* @param program - To test geometry against.
* @returns - Unique signature of the geometry and program
*/
getSignature(geometry, program) {
const attribs = geometry.attributes;
const shaderAttributes = program._attributeData;
const strings = ["g", geometry.uid];
for (const i in attribs) {
if (shaderAttributes[i]) {
strings.push(i, shaderAttributes[i].location);
}
}
return strings.join("-");
}
getVao(geometry, program) {
return this._geometryVaoHash[geometry.uid]?.[program._key] || this.initGeometryVao(geometry, program);
}
/**
* Creates or gets Vao with the same structure as the geometry and stores it on the geometry.
* If vao is created, it is bound automatically. We use a shader to infer what and how to set up the
* attribute locations.
* @param geometry - Instance of geometry to to generate Vao for.
* @param program
* @param _incRefCount - Increment refCount of all geometry buffers.
*/
initGeometryVao(geometry, program, _incRefCount = true) {
const gl = this._renderer.gl;
const bufferSystem = this._renderer.buffer;
this._renderer.shader._getProgramData(program);
this.checkCompatibility(geometry, program);
const signature = this.getSignature(geometry, program);
if (!this._geometryVaoHash[geometry.uid]) {
this._geometryVaoHash[geometry.uid] = /* @__PURE__ */ Object.create(null);
geometry.on("destroy", this.onGeometryDestroy, this);
}
const vaoObjectHash = this._geometryVaoHash[geometry.uid];
let vao = vaoObjectHash[signature];
if (vao) {
vaoObjectHash[program._key] = vao;
return vao;
}
ensureAttributes.ensureAttributes(geometry, program._attributeData);
const buffers = geometry.buffers;
vao = gl.createVertexArray();
gl.bindVertexArray(vao);
for (let i = 0; i < buffers.length; i++) {
const buffer = buffers[i];
bufferSystem.bind(buffer);
}
this.activateVao(geometry, program);
vaoObjectHash[program._key] = vao;
vaoObjectHash[signature] = vao;
gl.bindVertexArray(null);
return vao;
}
/**
* Disposes geometry.
* @param geometry - Geometry with buffers. Only VAO will be disposed
* @param [contextLost=false] - If context was lost, we suppress deleteVertexArray
*/
onGeometryDestroy(geometry, contextLost) {
const vaoObjectHash = this._geometryVaoHash[geometry.uid];
const gl = this.gl;
if (vaoObjectHash) {
if (contextLost) {
for (const i in vaoObjectHash) {
if (this._activeVao !== vaoObjectHash[i]) {
this.unbind();
}
gl.deleteVertexArray(vaoObjectHash[i]);
}
}
this._geometryVaoHash[geometry.uid] = null;
}
}
/**
* Dispose all WebGL resources of all managed geometries.
* @param [contextLost=false] - If context was lost, we suppress `gl.delete` calls
*/
destroyAll(contextLost = false) {
const gl = this.gl;
for (const i in this._geometryVaoHash) {
if (contextLost) {
for (const j in this._geometryVaoHash[i]) {
const vaoObjectHash = this._geometryVaoHash[i];
if (this._activeVao !== vaoObjectHash) {
this.unbind();
}
gl.deleteVertexArray(vaoObjectHash[j]);
}
}
this._geometryVaoHash[i] = null;
}
}
/**
* Activate vertex array object.
* @param geometry - Geometry instance.
* @param program - Shader program instance.
*/
activateVao(geometry, program) {
const gl = this._renderer.gl;
const bufferSystem = this._renderer.buffer;
const attributes = geometry.attributes;
if (geometry.indexBuffer) {
bufferSystem.bind(geometry.indexBuffer);
}
let lastBuffer = null;
for (const j in attributes) {
const attribute = attributes[j];
const buffer = attribute.buffer;
const glBuffer = bufferSystem.getGlBuffer(buffer);
const programAttrib = program._attributeData[j];
if (programAttrib) {
if (lastBuffer !== glBuffer) {
bufferSystem.bind(buffer);
lastBuffer = glBuffer;
}
const location = programAttrib.location;
gl.enableVertexAttribArray(location);
const attributeInfo = getAttributeInfoFromFormat.getAttributeInfoFromFormat(attribute.format);
const type = getGlTypeFromFormat.getGlTypeFromFormat(attribute.format);
if (programAttrib.format?.substring(1, 4) === "int") {
gl.vertexAttribIPointer(
location,
attributeInfo.size,
type,
attribute.stride,
attribute.offset
);
} else {
gl.vertexAttribPointer(
location,
attributeInfo.size,
type,
attributeInfo.normalised,
attribute.stride,
attribute.offset
);
}
if (attribute.instance) {
if (this.hasInstance) {
const divisor = attribute.divisor ?? 1;
gl.vertexAttribDivisor(location, divisor);
} else {
throw new Error("geometry error, GPU Instancing is not supported on this device");
}
}
}
}
}
/**
* Draws the currently bound geometry.
* @param topology - The type primitive to render.
* @param size - The number of elements to be rendered. If not specified, all vertices after the
* starting vertex will be drawn.
* @param start - The starting vertex in the geometry to start drawing from. If not specified,
* drawing will start from the first vertex.
* @param instanceCount - The number of instances of the set of elements to execute. If not specified,
* all instances will be drawn.
*/
draw(topology, size, start, instanceCount) {
const { gl } = this._renderer;
const geometry = this._activeGeometry;
const glTopology = topologyToGlMap[geometry.topology || topology];
instanceCount || (instanceCount = geometry.instanceCount);
if (geometry.indexBuffer) {
const byteSize = geometry.indexBuffer.data.BYTES_PER_ELEMENT;
const glType = byteSize === 2 ? gl.UNSIGNED_SHORT : gl.UNSIGNED_INT;
if (instanceCount > 1) {
gl.drawElementsInstanced(glTopology, size || geometry.indexBuffer.data.length, glType, (start || 0) * byteSize, instanceCount);
} else {
gl.drawElements(glTopology, size || geometry.indexBuffer.data.length, glType, (start || 0) * byteSize);
}
} else if (instanceCount > 1) {
gl.drawArraysInstanced(glTopology, start || 0, size || geometry.getSize(), instanceCount);
} else {
gl.drawArrays(glTopology, start || 0, size || geometry.getSize());
}
return this;
}
/** Unbind/reset everything. */
unbind() {
this.gl.bindVertexArray(null);
this._activeVao = null;
this._activeGeometry = null;
}
destroy() {
this._renderer = null;
this.gl = null;
this._activeVao = null;
this._activeGeometry = null;
}
}
/** @ignore */
GlGeometrySystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem
],
name: "geometry"
};
exports.GlGeometrySystem = GlGeometrySystem;
//# sourceMappingURL=GlGeometrySystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,297 @@
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { getAttributeInfoFromFormat } from '../../shared/geometry/utils/getAttributeInfoFromFormat.mjs';
import { ensureAttributes } from '../shader/program/ensureAttributes.mjs';
import { getGlTypeFromFormat } from './utils/getGlTypeFromFormat.mjs';
"use strict";
const topologyToGlMap = {
"point-list": 0,
"line-list": 1,
"line-strip": 3,
"triangle-list": 4,
"triangle-strip": 5
};
class GlGeometrySystem {
/** @param renderer - The renderer this System works for. */
constructor(renderer) {
this._geometryVaoHash = /* @__PURE__ */ Object.create(null);
this._renderer = renderer;
this._activeGeometry = null;
this._activeVao = null;
this.hasVao = true;
this.hasInstance = true;
}
/** Sets up the renderer context and necessary buffers. */
contextChange() {
const gl = this.gl = this._renderer.gl;
if (!this._renderer.context.supports.vertexArrayObject) {
throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");
}
const nativeVaoExtension = this._renderer.context.extensions.vertexArrayObject;
if (nativeVaoExtension) {
gl.createVertexArray = () => nativeVaoExtension.createVertexArrayOES();
gl.bindVertexArray = (vao) => nativeVaoExtension.bindVertexArrayOES(vao);
gl.deleteVertexArray = (vao) => nativeVaoExtension.deleteVertexArrayOES(vao);
}
const nativeInstancedExtension = this._renderer.context.extensions.vertexAttribDivisorANGLE;
if (nativeInstancedExtension) {
gl.drawArraysInstanced = (a, b, c, d) => {
nativeInstancedExtension.drawArraysInstancedANGLE(a, b, c, d);
};
gl.drawElementsInstanced = (a, b, c, d, e) => {
nativeInstancedExtension.drawElementsInstancedANGLE(a, b, c, d, e);
};
gl.vertexAttribDivisor = (a, b) => nativeInstancedExtension.vertexAttribDivisorANGLE(a, b);
}
this._activeGeometry = null;
this._activeVao = null;
this._geometryVaoHash = /* @__PURE__ */ Object.create(null);
}
/**
* Binds geometry so that is can be drawn. Creating a Vao if required
* @param geometry - Instance of geometry to bind.
* @param program - Instance of program to use vao for.
*/
bind(geometry, program) {
const gl = this.gl;
this._activeGeometry = geometry;
const vao = this.getVao(geometry, program);
if (this._activeVao !== vao) {
this._activeVao = vao;
gl.bindVertexArray(vao);
}
this.updateBuffers();
}
/** Reset and unbind any active VAO and geometry. */
reset() {
this.unbind();
}
/** Update buffers of the currently bound geometry. */
updateBuffers() {
const geometry = this._activeGeometry;
const bufferSystem = this._renderer.buffer;
for (let i = 0; i < geometry.buffers.length; i++) {
const buffer = geometry.buffers[i];
bufferSystem.updateBuffer(buffer);
}
}
/**
* Check compatibility between a geometry and a program
* @param geometry - Geometry instance.
* @param program - Program instance.
*/
checkCompatibility(geometry, program) {
const geometryAttributes = geometry.attributes;
const shaderAttributes = program._attributeData;
for (const j in shaderAttributes) {
if (!geometryAttributes[j]) {
throw new Error(`shader and geometry incompatible, geometry missing the "${j}" attribute`);
}
}
}
/**
* Takes a geometry and program and generates a unique signature for them.
* @param geometry - To get signature from.
* @param program - To test geometry against.
* @returns - Unique signature of the geometry and program
*/
getSignature(geometry, program) {
const attribs = geometry.attributes;
const shaderAttributes = program._attributeData;
const strings = ["g", geometry.uid];
for (const i in attribs) {
if (shaderAttributes[i]) {
strings.push(i, shaderAttributes[i].location);
}
}
return strings.join("-");
}
getVao(geometry, program) {
return this._geometryVaoHash[geometry.uid]?.[program._key] || this.initGeometryVao(geometry, program);
}
/**
* Creates or gets Vao with the same structure as the geometry and stores it on the geometry.
* If vao is created, it is bound automatically. We use a shader to infer what and how to set up the
* attribute locations.
* @param geometry - Instance of geometry to to generate Vao for.
* @param program
* @param _incRefCount - Increment refCount of all geometry buffers.
*/
initGeometryVao(geometry, program, _incRefCount = true) {
const gl = this._renderer.gl;
const bufferSystem = this._renderer.buffer;
this._renderer.shader._getProgramData(program);
this.checkCompatibility(geometry, program);
const signature = this.getSignature(geometry, program);
if (!this._geometryVaoHash[geometry.uid]) {
this._geometryVaoHash[geometry.uid] = /* @__PURE__ */ Object.create(null);
geometry.on("destroy", this.onGeometryDestroy, this);
}
const vaoObjectHash = this._geometryVaoHash[geometry.uid];
let vao = vaoObjectHash[signature];
if (vao) {
vaoObjectHash[program._key] = vao;
return vao;
}
ensureAttributes(geometry, program._attributeData);
const buffers = geometry.buffers;
vao = gl.createVertexArray();
gl.bindVertexArray(vao);
for (let i = 0; i < buffers.length; i++) {
const buffer = buffers[i];
bufferSystem.bind(buffer);
}
this.activateVao(geometry, program);
vaoObjectHash[program._key] = vao;
vaoObjectHash[signature] = vao;
gl.bindVertexArray(null);
return vao;
}
/**
* Disposes geometry.
* @param geometry - Geometry with buffers. Only VAO will be disposed
* @param [contextLost=false] - If context was lost, we suppress deleteVertexArray
*/
onGeometryDestroy(geometry, contextLost) {
const vaoObjectHash = this._geometryVaoHash[geometry.uid];
const gl = this.gl;
if (vaoObjectHash) {
if (contextLost) {
for (const i in vaoObjectHash) {
if (this._activeVao !== vaoObjectHash[i]) {
this.unbind();
}
gl.deleteVertexArray(vaoObjectHash[i]);
}
}
this._geometryVaoHash[geometry.uid] = null;
}
}
/**
* Dispose all WebGL resources of all managed geometries.
* @param [contextLost=false] - If context was lost, we suppress `gl.delete` calls
*/
destroyAll(contextLost = false) {
const gl = this.gl;
for (const i in this._geometryVaoHash) {
if (contextLost) {
for (const j in this._geometryVaoHash[i]) {
const vaoObjectHash = this._geometryVaoHash[i];
if (this._activeVao !== vaoObjectHash) {
this.unbind();
}
gl.deleteVertexArray(vaoObjectHash[j]);
}
}
this._geometryVaoHash[i] = null;
}
}
/**
* Activate vertex array object.
* @param geometry - Geometry instance.
* @param program - Shader program instance.
*/
activateVao(geometry, program) {
const gl = this._renderer.gl;
const bufferSystem = this._renderer.buffer;
const attributes = geometry.attributes;
if (geometry.indexBuffer) {
bufferSystem.bind(geometry.indexBuffer);
}
let lastBuffer = null;
for (const j in attributes) {
const attribute = attributes[j];
const buffer = attribute.buffer;
const glBuffer = bufferSystem.getGlBuffer(buffer);
const programAttrib = program._attributeData[j];
if (programAttrib) {
if (lastBuffer !== glBuffer) {
bufferSystem.bind(buffer);
lastBuffer = glBuffer;
}
const location = programAttrib.location;
gl.enableVertexAttribArray(location);
const attributeInfo = getAttributeInfoFromFormat(attribute.format);
const type = getGlTypeFromFormat(attribute.format);
if (programAttrib.format?.substring(1, 4) === "int") {
gl.vertexAttribIPointer(
location,
attributeInfo.size,
type,
attribute.stride,
attribute.offset
);
} else {
gl.vertexAttribPointer(
location,
attributeInfo.size,
type,
attributeInfo.normalised,
attribute.stride,
attribute.offset
);
}
if (attribute.instance) {
if (this.hasInstance) {
const divisor = attribute.divisor ?? 1;
gl.vertexAttribDivisor(location, divisor);
} else {
throw new Error("geometry error, GPU Instancing is not supported on this device");
}
}
}
}
}
/**
* Draws the currently bound geometry.
* @param topology - The type primitive to render.
* @param size - The number of elements to be rendered. If not specified, all vertices after the
* starting vertex will be drawn.
* @param start - The starting vertex in the geometry to start drawing from. If not specified,
* drawing will start from the first vertex.
* @param instanceCount - The number of instances of the set of elements to execute. If not specified,
* all instances will be drawn.
*/
draw(topology, size, start, instanceCount) {
const { gl } = this._renderer;
const geometry = this._activeGeometry;
const glTopology = topologyToGlMap[geometry.topology || topology];
instanceCount || (instanceCount = geometry.instanceCount);
if (geometry.indexBuffer) {
const byteSize = geometry.indexBuffer.data.BYTES_PER_ELEMENT;
const glType = byteSize === 2 ? gl.UNSIGNED_SHORT : gl.UNSIGNED_INT;
if (instanceCount > 1) {
gl.drawElementsInstanced(glTopology, size || geometry.indexBuffer.data.length, glType, (start || 0) * byteSize, instanceCount);
} else {
gl.drawElements(glTopology, size || geometry.indexBuffer.data.length, glType, (start || 0) * byteSize);
}
} else if (instanceCount > 1) {
gl.drawArraysInstanced(glTopology, start || 0, size || geometry.getSize(), instanceCount);
} else {
gl.drawArrays(glTopology, start || 0, size || geometry.getSize());
}
return this;
}
/** Unbind/reset everything. */
unbind() {
this.gl.bindVertexArray(null);
this._activeVao = null;
this._activeGeometry = null;
}
destroy() {
this._renderer = null;
this.gl = null;
this._activeVao = null;
this._activeGeometry = null;
}
}
/** @ignore */
GlGeometrySystem.extension = {
type: [
ExtensionType.WebGLSystem
],
name: "geometry"
};
export { GlGeometrySystem };
//# sourceMappingURL=GlGeometrySystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
import type { VertexFormat } from '../../../shared/geometry/const';
export declare function getGlTypeFromFormat(format: VertexFormat): number;

View File

@@ -0,0 +1,43 @@
'use strict';
var _const = require('../../texture/const.js');
"use strict";
const infoMap = {
uint8x2: _const.GL_TYPES.UNSIGNED_BYTE,
uint8x4: _const.GL_TYPES.UNSIGNED_BYTE,
sint8x2: _const.GL_TYPES.BYTE,
sint8x4: _const.GL_TYPES.BYTE,
unorm8x2: _const.GL_TYPES.UNSIGNED_BYTE,
unorm8x4: _const.GL_TYPES.UNSIGNED_BYTE,
snorm8x2: _const.GL_TYPES.BYTE,
snorm8x4: _const.GL_TYPES.BYTE,
uint16x2: _const.GL_TYPES.UNSIGNED_SHORT,
uint16x4: _const.GL_TYPES.UNSIGNED_SHORT,
sint16x2: _const.GL_TYPES.SHORT,
sint16x4: _const.GL_TYPES.SHORT,
unorm16x2: _const.GL_TYPES.UNSIGNED_SHORT,
unorm16x4: _const.GL_TYPES.UNSIGNED_SHORT,
snorm16x2: _const.GL_TYPES.SHORT,
snorm16x4: _const.GL_TYPES.SHORT,
float16x2: _const.GL_TYPES.HALF_FLOAT,
float16x4: _const.GL_TYPES.HALF_FLOAT,
float32: _const.GL_TYPES.FLOAT,
float32x2: _const.GL_TYPES.FLOAT,
float32x3: _const.GL_TYPES.FLOAT,
float32x4: _const.GL_TYPES.FLOAT,
uint32: _const.GL_TYPES.UNSIGNED_INT,
uint32x2: _const.GL_TYPES.UNSIGNED_INT,
uint32x3: _const.GL_TYPES.UNSIGNED_INT,
uint32x4: _const.GL_TYPES.UNSIGNED_INT,
sint32: _const.GL_TYPES.INT,
sint32x2: _const.GL_TYPES.INT,
sint32x3: _const.GL_TYPES.INT,
sint32x4: _const.GL_TYPES.INT
};
function getGlTypeFromFormat(format) {
return infoMap[format] ?? infoMap.float32;
}
exports.getGlTypeFromFormat = getGlTypeFromFormat;
//# sourceMappingURL=getGlTypeFromFormat.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getGlTypeFromFormat.js","sources":["../../../../../../src/rendering/renderers/gl/geometry/utils/getGlTypeFromFormat.ts"],"sourcesContent":["import { GL_TYPES } from '../../texture/const';\n\nimport type { VertexFormat } from '../../../shared/geometry/const';\n\nconst infoMap = {\n uint8x2: GL_TYPES.UNSIGNED_BYTE,\n uint8x4: GL_TYPES.UNSIGNED_BYTE,\n sint8x2: GL_TYPES.BYTE,\n sint8x4: GL_TYPES.BYTE,\n unorm8x2: GL_TYPES.UNSIGNED_BYTE,\n unorm8x4: GL_TYPES.UNSIGNED_BYTE,\n snorm8x2: GL_TYPES.BYTE,\n snorm8x4: GL_TYPES.BYTE,\n uint16x2: GL_TYPES.UNSIGNED_SHORT,\n uint16x4: GL_TYPES.UNSIGNED_SHORT,\n sint16x2: GL_TYPES.SHORT,\n sint16x4: GL_TYPES.SHORT,\n unorm16x2: GL_TYPES.UNSIGNED_SHORT,\n unorm16x4: GL_TYPES.UNSIGNED_SHORT,\n snorm16x2: GL_TYPES.SHORT,\n snorm16x4: GL_TYPES.SHORT,\n float16x2: GL_TYPES.HALF_FLOAT,\n float16x4: GL_TYPES.HALF_FLOAT,\n float32: GL_TYPES.FLOAT,\n float32x2: GL_TYPES.FLOAT,\n float32x3: GL_TYPES.FLOAT,\n float32x4: GL_TYPES.FLOAT,\n uint32: GL_TYPES.UNSIGNED_INT,\n uint32x2: GL_TYPES.UNSIGNED_INT,\n uint32x3: GL_TYPES.UNSIGNED_INT,\n uint32x4: GL_TYPES.UNSIGNED_INT,\n sint32: GL_TYPES.INT,\n sint32x2: GL_TYPES.INT,\n sint32x3: GL_TYPES.INT,\n sint32x4: GL_TYPES.INT\n};\n\nexport function getGlTypeFromFormat(format: VertexFormat): number\n{\n return infoMap[format] ?? infoMap.float32;\n}\n"],"names":["GL_TYPES"],"mappings":";;;;;AAIA,MAAM,OAAU,GAAA;AAAA,EACZ,SAASA,eAAS,CAAA,aAAA;AAAA,EAClB,SAASA,eAAS,CAAA,aAAA;AAAA,EAClB,SAASA,eAAS,CAAA,IAAA;AAAA,EAClB,SAASA,eAAS,CAAA,IAAA;AAAA,EAClB,UAAUA,eAAS,CAAA,aAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,aAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,IAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,IAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,cAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,cAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,KAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,KAAA;AAAA,EACnB,WAAWA,eAAS,CAAA,cAAA;AAAA,EACpB,WAAWA,eAAS,CAAA,cAAA;AAAA,EACpB,WAAWA,eAAS,CAAA,KAAA;AAAA,EACpB,WAAWA,eAAS,CAAA,KAAA;AAAA,EACpB,WAAWA,eAAS,CAAA,UAAA;AAAA,EACpB,WAAWA,eAAS,CAAA,UAAA;AAAA,EACpB,SAASA,eAAS,CAAA,KAAA;AAAA,EAClB,WAAWA,eAAS,CAAA,KAAA;AAAA,EACpB,WAAWA,eAAS,CAAA,KAAA;AAAA,EACpB,WAAWA,eAAS,CAAA,KAAA;AAAA,EACpB,QAAQA,eAAS,CAAA,YAAA;AAAA,EACjB,UAAUA,eAAS,CAAA,YAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,YAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,YAAA;AAAA,EACnB,QAAQA,eAAS,CAAA,GAAA;AAAA,EACjB,UAAUA,eAAS,CAAA,GAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,GAAA;AAAA,EACnB,UAAUA,eAAS,CAAA,GAAA;AACvB,CAAA,CAAA;AAEO,SAAS,oBAAoB,MACpC,EAAA;AACI,EAAO,OAAA,OAAA,CAAQ,MAAM,CAAA,IAAK,OAAQ,CAAA,OAAA,CAAA;AACtC;;;;"}

View File

@@ -0,0 +1,41 @@
import { GL_TYPES } from '../../texture/const.mjs';
"use strict";
const infoMap = {
uint8x2: GL_TYPES.UNSIGNED_BYTE,
uint8x4: GL_TYPES.UNSIGNED_BYTE,
sint8x2: GL_TYPES.BYTE,
sint8x4: GL_TYPES.BYTE,
unorm8x2: GL_TYPES.UNSIGNED_BYTE,
unorm8x4: GL_TYPES.UNSIGNED_BYTE,
snorm8x2: GL_TYPES.BYTE,
snorm8x4: GL_TYPES.BYTE,
uint16x2: GL_TYPES.UNSIGNED_SHORT,
uint16x4: GL_TYPES.UNSIGNED_SHORT,
sint16x2: GL_TYPES.SHORT,
sint16x4: GL_TYPES.SHORT,
unorm16x2: GL_TYPES.UNSIGNED_SHORT,
unorm16x4: GL_TYPES.UNSIGNED_SHORT,
snorm16x2: GL_TYPES.SHORT,
snorm16x4: GL_TYPES.SHORT,
float16x2: GL_TYPES.HALF_FLOAT,
float16x4: GL_TYPES.HALF_FLOAT,
float32: GL_TYPES.FLOAT,
float32x2: GL_TYPES.FLOAT,
float32x3: GL_TYPES.FLOAT,
float32x4: GL_TYPES.FLOAT,
uint32: GL_TYPES.UNSIGNED_INT,
uint32x2: GL_TYPES.UNSIGNED_INT,
uint32x3: GL_TYPES.UNSIGNED_INT,
uint32x4: GL_TYPES.UNSIGNED_INT,
sint32: GL_TYPES.INT,
sint32x2: GL_TYPES.INT,
sint32x3: GL_TYPES.INT,
sint32x4: GL_TYPES.INT
};
function getGlTypeFromFormat(format) {
return infoMap[format] ?? infoMap.float32;
}
export { getGlTypeFromFormat };
//# sourceMappingURL=getGlTypeFromFormat.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getGlTypeFromFormat.mjs","sources":["../../../../../../src/rendering/renderers/gl/geometry/utils/getGlTypeFromFormat.ts"],"sourcesContent":["import { GL_TYPES } from '../../texture/const';\n\nimport type { VertexFormat } from '../../../shared/geometry/const';\n\nconst infoMap = {\n uint8x2: GL_TYPES.UNSIGNED_BYTE,\n uint8x4: GL_TYPES.UNSIGNED_BYTE,\n sint8x2: GL_TYPES.BYTE,\n sint8x4: GL_TYPES.BYTE,\n unorm8x2: GL_TYPES.UNSIGNED_BYTE,\n unorm8x4: GL_TYPES.UNSIGNED_BYTE,\n snorm8x2: GL_TYPES.BYTE,\n snorm8x4: GL_TYPES.BYTE,\n uint16x2: GL_TYPES.UNSIGNED_SHORT,\n uint16x4: GL_TYPES.UNSIGNED_SHORT,\n sint16x2: GL_TYPES.SHORT,\n sint16x4: GL_TYPES.SHORT,\n unorm16x2: GL_TYPES.UNSIGNED_SHORT,\n unorm16x4: GL_TYPES.UNSIGNED_SHORT,\n snorm16x2: GL_TYPES.SHORT,\n snorm16x4: GL_TYPES.SHORT,\n float16x2: GL_TYPES.HALF_FLOAT,\n float16x4: GL_TYPES.HALF_FLOAT,\n float32: GL_TYPES.FLOAT,\n float32x2: GL_TYPES.FLOAT,\n float32x3: GL_TYPES.FLOAT,\n float32x4: GL_TYPES.FLOAT,\n uint32: GL_TYPES.UNSIGNED_INT,\n uint32x2: GL_TYPES.UNSIGNED_INT,\n uint32x3: GL_TYPES.UNSIGNED_INT,\n uint32x4: GL_TYPES.UNSIGNED_INT,\n sint32: GL_TYPES.INT,\n sint32x2: GL_TYPES.INT,\n sint32x3: GL_TYPES.INT,\n sint32x4: GL_TYPES.INT\n};\n\nexport function getGlTypeFromFormat(format: VertexFormat): number\n{\n return infoMap[format] ?? infoMap.float32;\n}\n"],"names":[],"mappings":";;;AAIA,MAAM,OAAU,GAAA;AAAA,EACZ,SAAS,QAAS,CAAA,aAAA;AAAA,EAClB,SAAS,QAAS,CAAA,aAAA;AAAA,EAClB,SAAS,QAAS,CAAA,IAAA;AAAA,EAClB,SAAS,QAAS,CAAA,IAAA;AAAA,EAClB,UAAU,QAAS,CAAA,aAAA;AAAA,EACnB,UAAU,QAAS,CAAA,aAAA;AAAA,EACnB,UAAU,QAAS,CAAA,IAAA;AAAA,EACnB,UAAU,QAAS,CAAA,IAAA;AAAA,EACnB,UAAU,QAAS,CAAA,cAAA;AAAA,EACnB,UAAU,QAAS,CAAA,cAAA;AAAA,EACnB,UAAU,QAAS,CAAA,KAAA;AAAA,EACnB,UAAU,QAAS,CAAA,KAAA;AAAA,EACnB,WAAW,QAAS,CAAA,cAAA;AAAA,EACpB,WAAW,QAAS,CAAA,cAAA;AAAA,EACpB,WAAW,QAAS,CAAA,KAAA;AAAA,EACpB,WAAW,QAAS,CAAA,KAAA;AAAA,EACpB,WAAW,QAAS,CAAA,UAAA;AAAA,EACpB,WAAW,QAAS,CAAA,UAAA;AAAA,EACpB,SAAS,QAAS,CAAA,KAAA;AAAA,EAClB,WAAW,QAAS,CAAA,KAAA;AAAA,EACpB,WAAW,QAAS,CAAA,KAAA;AAAA,EACpB,WAAW,QAAS,CAAA,KAAA;AAAA,EACpB,QAAQ,QAAS,CAAA,YAAA;AAAA,EACjB,UAAU,QAAS,CAAA,YAAA;AAAA,EACnB,UAAU,QAAS,CAAA,YAAA;AAAA,EACnB,UAAU,QAAS,CAAA,YAAA;AAAA,EACnB,QAAQ,QAAS,CAAA,GAAA;AAAA,EACjB,UAAU,QAAS,CAAA,GAAA;AAAA,EACnB,UAAU,QAAS,CAAA,GAAA;AAAA,EACnB,UAAU,QAAS,CAAA,GAAA;AACvB,CAAA,CAAA;AAEO,SAAS,oBAAoB,MACpC,EAAA;AACI,EAAO,OAAA,OAAA,CAAQ,MAAM,CAAA,IAAK,OAAQ,CAAA,OAAA,CAAA;AACtC;;;;"}

View File

@@ -0,0 +1,42 @@
import { Rectangle } from '../../../../maths/shapes/Rectangle';
import { GlRenderTarget } from '../GlRenderTarget';
import type { RgbaArray } from '../../../../color/Color';
import type { RenderTarget } from '../../shared/renderTarget/RenderTarget';
import type { RenderTargetAdaptor, RenderTargetSystem } from '../../shared/renderTarget/RenderTargetSystem';
import type { Texture } from '../../shared/texture/Texture';
import type { CLEAR_OR_BOOL } from '../const';
import type { WebGLRenderer } from '../WebGLRenderer';
/**
* The WebGL adaptor for the render target system. Allows the Render Target System to be used with the WebGL renderer
* @memberof rendering
* @ignore
*/
export declare class GlRenderTargetAdaptor implements RenderTargetAdaptor<GlRenderTarget> {
private _renderTargetSystem;
private _renderer;
private _clearColorCache;
private _viewPortCache;
init(renderer: WebGLRenderer, renderTargetSystem: RenderTargetSystem<GlRenderTarget>): void;
contextChange(): void;
copyToTexture(sourceRenderSurfaceTexture: RenderTarget, destinationTexture: Texture, originSrc: {
x: number;
y: number;
}, size: {
width: number;
height: number;
}, originDest: {
x: number;
y: number;
}): Texture<import("../../..").TextureSource<any>>;
startRenderPass(renderTarget: RenderTarget, clear?: CLEAR_OR_BOOL, clearColor?: RgbaArray, viewport?: Rectangle): void;
finishRenderPass(renderTarget?: RenderTarget): void;
initGpuRenderTarget(renderTarget: RenderTarget): GlRenderTarget;
destroyGpuRenderTarget(gpuRenderTarget: GlRenderTarget): void;
clear(_renderTarget: RenderTarget, clear: CLEAR_OR_BOOL, clearColor?: RgbaArray): void;
resizeGpuRenderTarget(renderTarget: RenderTarget): void;
private _initColor;
private _resizeColor;
private _initStencil;
private _resizeStencil;
postrender(renderTarget: RenderTarget): void;
}

View File

@@ -0,0 +1,301 @@
'use strict';
var Rectangle = require('../../../../maths/shapes/Rectangle.js');
var warn = require('../../../../utils/logging/warn.js');
var CanvasSource = require('../../shared/texture/sources/CanvasSource.js');
var _const = require('../const.js');
var GlRenderTarget = require('../GlRenderTarget.js');
"use strict";
class GlRenderTargetAdaptor {
constructor() {
this._clearColorCache = [0, 0, 0, 0];
this._viewPortCache = new Rectangle.Rectangle();
}
init(renderer, renderTargetSystem) {
this._renderer = renderer;
this._renderTargetSystem = renderTargetSystem;
renderer.runners.contextChange.add(this);
}
contextChange() {
this._clearColorCache = [0, 0, 0, 0];
this._viewPortCache = new Rectangle.Rectangle();
}
copyToTexture(sourceRenderSurfaceTexture, destinationTexture, originSrc, size, originDest) {
const renderTargetSystem = this._renderTargetSystem;
const renderer = this._renderer;
const glRenderTarget = renderTargetSystem.getGpuRenderTarget(sourceRenderSurfaceTexture);
const gl = renderer.gl;
this.finishRenderPass(sourceRenderSurfaceTexture);
gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.resolveTargetFramebuffer);
renderer.texture.bind(destinationTexture, 0);
gl.copyTexSubImage2D(
gl.TEXTURE_2D,
0,
originDest.x,
originDest.y,
originSrc.x,
originSrc.y,
size.width,
size.height
);
return destinationTexture;
}
startRenderPass(renderTarget, clear = true, clearColor, viewport) {
const renderTargetSystem = this._renderTargetSystem;
const source = renderTarget.colorTexture;
const gpuRenderTarget = renderTargetSystem.getGpuRenderTarget(renderTarget);
let viewPortY = viewport.y;
if (renderTarget.isRoot) {
viewPortY = source.pixelHeight - viewport.height;
}
renderTarget.colorTextures.forEach((texture) => {
this._renderer.texture.unbind(texture);
});
const gl = this._renderer.gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, gpuRenderTarget.framebuffer);
const viewPortCache = this._viewPortCache;
if (viewPortCache.x !== viewport.x || viewPortCache.y !== viewPortY || viewPortCache.width !== viewport.width || viewPortCache.height !== viewport.height) {
viewPortCache.x = viewport.x;
viewPortCache.y = viewPortY;
viewPortCache.width = viewport.width;
viewPortCache.height = viewport.height;
gl.viewport(
viewport.x,
viewPortY,
viewport.width,
viewport.height
);
}
if (!gpuRenderTarget.depthStencilRenderBuffer && (renderTarget.stencil || renderTarget.depth)) {
this._initStencil(gpuRenderTarget);
}
this.clear(renderTarget, clear, clearColor);
}
finishRenderPass(renderTarget) {
const renderTargetSystem = this._renderTargetSystem;
const glRenderTarget = renderTargetSystem.getGpuRenderTarget(renderTarget);
if (!glRenderTarget.msaa)
return;
const gl = this._renderer.gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.resolveTargetFramebuffer);
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, glRenderTarget.framebuffer);
gl.blitFramebuffer(
0,
0,
glRenderTarget.width,
glRenderTarget.height,
0,
0,
glRenderTarget.width,
glRenderTarget.height,
gl.COLOR_BUFFER_BIT,
gl.NEAREST
);
gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.framebuffer);
}
initGpuRenderTarget(renderTarget) {
const renderer = this._renderer;
const gl = renderer.gl;
const glRenderTarget = new GlRenderTarget.GlRenderTarget();
const colorTexture = renderTarget.colorTexture;
if (CanvasSource.CanvasSource.test(colorTexture.resource)) {
this._renderer.context.ensureCanvasSize(renderTarget.colorTexture.resource);
glRenderTarget.framebuffer = null;
return glRenderTarget;
}
this._initColor(renderTarget, glRenderTarget);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return glRenderTarget;
}
destroyGpuRenderTarget(gpuRenderTarget) {
const gl = this._renderer.gl;
if (gpuRenderTarget.framebuffer) {
gl.deleteFramebuffer(gpuRenderTarget.framebuffer);
gpuRenderTarget.framebuffer = null;
}
if (gpuRenderTarget.resolveTargetFramebuffer) {
gl.deleteFramebuffer(gpuRenderTarget.resolveTargetFramebuffer);
gpuRenderTarget.resolveTargetFramebuffer = null;
}
if (gpuRenderTarget.depthStencilRenderBuffer) {
gl.deleteRenderbuffer(gpuRenderTarget.depthStencilRenderBuffer);
gpuRenderTarget.depthStencilRenderBuffer = null;
}
gpuRenderTarget.msaaRenderBuffer.forEach((renderBuffer) => {
gl.deleteRenderbuffer(renderBuffer);
});
gpuRenderTarget.msaaRenderBuffer = null;
}
clear(_renderTarget, clear, clearColor) {
if (!clear)
return;
const renderTargetSystem = this._renderTargetSystem;
if (typeof clear === "boolean") {
clear = clear ? _const.CLEAR.ALL : _const.CLEAR.NONE;
}
const gl = this._renderer.gl;
if (clear & _const.CLEAR.COLOR) {
clearColor ?? (clearColor = renderTargetSystem.defaultClearColor);
const clearColorCache = this._clearColorCache;
const clearColorArray = clearColor;
if (clearColorCache[0] !== clearColorArray[0] || clearColorCache[1] !== clearColorArray[1] || clearColorCache[2] !== clearColorArray[2] || clearColorCache[3] !== clearColorArray[3]) {
clearColorCache[0] = clearColorArray[0];
clearColorCache[1] = clearColorArray[1];
clearColorCache[2] = clearColorArray[2];
clearColorCache[3] = clearColorArray[3];
gl.clearColor(clearColorArray[0], clearColorArray[1], clearColorArray[2], clearColorArray[3]);
}
}
gl.clear(clear);
}
resizeGpuRenderTarget(renderTarget) {
if (renderTarget.isRoot)
return;
const renderTargetSystem = this._renderTargetSystem;
const glRenderTarget = renderTargetSystem.getGpuRenderTarget(renderTarget);
this._resizeColor(renderTarget, glRenderTarget);
if (renderTarget.stencil || renderTarget.depth) {
this._resizeStencil(glRenderTarget);
}
}
_initColor(renderTarget, glRenderTarget) {
const renderer = this._renderer;
const gl = renderer.gl;
const resolveTargetFramebuffer = gl.createFramebuffer();
glRenderTarget.resolveTargetFramebuffer = resolveTargetFramebuffer;
gl.bindFramebuffer(gl.FRAMEBUFFER, resolveTargetFramebuffer);
glRenderTarget.width = renderTarget.colorTexture.source.pixelWidth;
glRenderTarget.height = renderTarget.colorTexture.source.pixelHeight;
renderTarget.colorTextures.forEach((colorTexture, i) => {
const source = colorTexture.source;
if (source.antialias) {
if (renderer.context.supports.msaa) {
glRenderTarget.msaa = true;
} else {
warn.warn("[RenderTexture] Antialiasing on textures is not supported in WebGL1");
}
}
renderer.texture.bindSource(source, 0);
const glSource = renderer.texture.getGlSource(source);
const glTexture = glSource.texture;
gl.framebufferTexture2D(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0 + i,
3553,
// texture.target,
glTexture,
0
);
});
if (glRenderTarget.msaa) {
const viewFramebuffer = gl.createFramebuffer();
glRenderTarget.framebuffer = viewFramebuffer;
gl.bindFramebuffer(gl.FRAMEBUFFER, viewFramebuffer);
renderTarget.colorTextures.forEach((_, i) => {
const msaaRenderBuffer = gl.createRenderbuffer();
glRenderTarget.msaaRenderBuffer[i] = msaaRenderBuffer;
});
} else {
glRenderTarget.framebuffer = resolveTargetFramebuffer;
}
this._resizeColor(renderTarget, glRenderTarget);
}
_resizeColor(renderTarget, glRenderTarget) {
const source = renderTarget.colorTexture.source;
glRenderTarget.width = source.pixelWidth;
glRenderTarget.height = source.pixelHeight;
renderTarget.colorTextures.forEach((colorTexture, i) => {
if (i === 0)
return;
colorTexture.source.resize(source.width, source.height, source._resolution);
});
if (glRenderTarget.msaa) {
const renderer = this._renderer;
const gl = renderer.gl;
const viewFramebuffer = glRenderTarget.framebuffer;
gl.bindFramebuffer(gl.FRAMEBUFFER, viewFramebuffer);
renderTarget.colorTextures.forEach((colorTexture, i) => {
const source2 = colorTexture.source;
renderer.texture.bindSource(source2, 0);
const glSource = renderer.texture.getGlSource(source2);
const glInternalFormat = glSource.internalFormat;
const msaaRenderBuffer = glRenderTarget.msaaRenderBuffer[i];
gl.bindRenderbuffer(
gl.RENDERBUFFER,
msaaRenderBuffer
);
gl.renderbufferStorageMultisample(
gl.RENDERBUFFER,
4,
glInternalFormat,
source2.pixelWidth,
source2.pixelHeight
);
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0 + i,
gl.RENDERBUFFER,
msaaRenderBuffer
);
});
}
}
_initStencil(glRenderTarget) {
if (glRenderTarget.framebuffer === null)
return;
const gl = this._renderer.gl;
const depthStencilRenderBuffer = gl.createRenderbuffer();
glRenderTarget.depthStencilRenderBuffer = depthStencilRenderBuffer;
gl.bindRenderbuffer(
gl.RENDERBUFFER,
depthStencilRenderBuffer
);
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER,
gl.DEPTH_STENCIL_ATTACHMENT,
gl.RENDERBUFFER,
depthStencilRenderBuffer
);
this._resizeStencil(glRenderTarget);
}
_resizeStencil(glRenderTarget) {
const gl = this._renderer.gl;
gl.bindRenderbuffer(
gl.RENDERBUFFER,
glRenderTarget.depthStencilRenderBuffer
);
if (glRenderTarget.msaa) {
gl.renderbufferStorageMultisample(
gl.RENDERBUFFER,
4,
gl.DEPTH24_STENCIL8,
glRenderTarget.width,
glRenderTarget.height
);
} else {
gl.renderbufferStorage(
gl.RENDERBUFFER,
this._renderer.context.webGLVersion === 2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL,
glRenderTarget.width,
glRenderTarget.height
);
}
}
postrender(renderTarget) {
if (!this._renderer.context.multiView)
return;
if (CanvasSource.CanvasSource.test(renderTarget.colorTexture.resource)) {
const contextCanvas = this._renderer.context.canvas;
const canvasSource = renderTarget.colorTexture;
canvasSource.context2D.drawImage(
contextCanvas,
0,
canvasSource.pixelHeight - contextCanvas.height
);
}
}
}
exports.GlRenderTargetAdaptor = GlRenderTargetAdaptor;
//# sourceMappingURL=GlRenderTargetAdaptor.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,299 @@
import { Rectangle } from '../../../../maths/shapes/Rectangle.mjs';
import { warn } from '../../../../utils/logging/warn.mjs';
import { CanvasSource } from '../../shared/texture/sources/CanvasSource.mjs';
import { CLEAR } from '../const.mjs';
import { GlRenderTarget } from '../GlRenderTarget.mjs';
"use strict";
class GlRenderTargetAdaptor {
constructor() {
this._clearColorCache = [0, 0, 0, 0];
this._viewPortCache = new Rectangle();
}
init(renderer, renderTargetSystem) {
this._renderer = renderer;
this._renderTargetSystem = renderTargetSystem;
renderer.runners.contextChange.add(this);
}
contextChange() {
this._clearColorCache = [0, 0, 0, 0];
this._viewPortCache = new Rectangle();
}
copyToTexture(sourceRenderSurfaceTexture, destinationTexture, originSrc, size, originDest) {
const renderTargetSystem = this._renderTargetSystem;
const renderer = this._renderer;
const glRenderTarget = renderTargetSystem.getGpuRenderTarget(sourceRenderSurfaceTexture);
const gl = renderer.gl;
this.finishRenderPass(sourceRenderSurfaceTexture);
gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.resolveTargetFramebuffer);
renderer.texture.bind(destinationTexture, 0);
gl.copyTexSubImage2D(
gl.TEXTURE_2D,
0,
originDest.x,
originDest.y,
originSrc.x,
originSrc.y,
size.width,
size.height
);
return destinationTexture;
}
startRenderPass(renderTarget, clear = true, clearColor, viewport) {
const renderTargetSystem = this._renderTargetSystem;
const source = renderTarget.colorTexture;
const gpuRenderTarget = renderTargetSystem.getGpuRenderTarget(renderTarget);
let viewPortY = viewport.y;
if (renderTarget.isRoot) {
viewPortY = source.pixelHeight - viewport.height;
}
renderTarget.colorTextures.forEach((texture) => {
this._renderer.texture.unbind(texture);
});
const gl = this._renderer.gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, gpuRenderTarget.framebuffer);
const viewPortCache = this._viewPortCache;
if (viewPortCache.x !== viewport.x || viewPortCache.y !== viewPortY || viewPortCache.width !== viewport.width || viewPortCache.height !== viewport.height) {
viewPortCache.x = viewport.x;
viewPortCache.y = viewPortY;
viewPortCache.width = viewport.width;
viewPortCache.height = viewport.height;
gl.viewport(
viewport.x,
viewPortY,
viewport.width,
viewport.height
);
}
if (!gpuRenderTarget.depthStencilRenderBuffer && (renderTarget.stencil || renderTarget.depth)) {
this._initStencil(gpuRenderTarget);
}
this.clear(renderTarget, clear, clearColor);
}
finishRenderPass(renderTarget) {
const renderTargetSystem = this._renderTargetSystem;
const glRenderTarget = renderTargetSystem.getGpuRenderTarget(renderTarget);
if (!glRenderTarget.msaa)
return;
const gl = this._renderer.gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.resolveTargetFramebuffer);
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, glRenderTarget.framebuffer);
gl.blitFramebuffer(
0,
0,
glRenderTarget.width,
glRenderTarget.height,
0,
0,
glRenderTarget.width,
glRenderTarget.height,
gl.COLOR_BUFFER_BIT,
gl.NEAREST
);
gl.bindFramebuffer(gl.FRAMEBUFFER, glRenderTarget.framebuffer);
}
initGpuRenderTarget(renderTarget) {
const renderer = this._renderer;
const gl = renderer.gl;
const glRenderTarget = new GlRenderTarget();
const colorTexture = renderTarget.colorTexture;
if (CanvasSource.test(colorTexture.resource)) {
this._renderer.context.ensureCanvasSize(renderTarget.colorTexture.resource);
glRenderTarget.framebuffer = null;
return glRenderTarget;
}
this._initColor(renderTarget, glRenderTarget);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return glRenderTarget;
}
destroyGpuRenderTarget(gpuRenderTarget) {
const gl = this._renderer.gl;
if (gpuRenderTarget.framebuffer) {
gl.deleteFramebuffer(gpuRenderTarget.framebuffer);
gpuRenderTarget.framebuffer = null;
}
if (gpuRenderTarget.resolveTargetFramebuffer) {
gl.deleteFramebuffer(gpuRenderTarget.resolveTargetFramebuffer);
gpuRenderTarget.resolveTargetFramebuffer = null;
}
if (gpuRenderTarget.depthStencilRenderBuffer) {
gl.deleteRenderbuffer(gpuRenderTarget.depthStencilRenderBuffer);
gpuRenderTarget.depthStencilRenderBuffer = null;
}
gpuRenderTarget.msaaRenderBuffer.forEach((renderBuffer) => {
gl.deleteRenderbuffer(renderBuffer);
});
gpuRenderTarget.msaaRenderBuffer = null;
}
clear(_renderTarget, clear, clearColor) {
if (!clear)
return;
const renderTargetSystem = this._renderTargetSystem;
if (typeof clear === "boolean") {
clear = clear ? CLEAR.ALL : CLEAR.NONE;
}
const gl = this._renderer.gl;
if (clear & CLEAR.COLOR) {
clearColor ?? (clearColor = renderTargetSystem.defaultClearColor);
const clearColorCache = this._clearColorCache;
const clearColorArray = clearColor;
if (clearColorCache[0] !== clearColorArray[0] || clearColorCache[1] !== clearColorArray[1] || clearColorCache[2] !== clearColorArray[2] || clearColorCache[3] !== clearColorArray[3]) {
clearColorCache[0] = clearColorArray[0];
clearColorCache[1] = clearColorArray[1];
clearColorCache[2] = clearColorArray[2];
clearColorCache[3] = clearColorArray[3];
gl.clearColor(clearColorArray[0], clearColorArray[1], clearColorArray[2], clearColorArray[3]);
}
}
gl.clear(clear);
}
resizeGpuRenderTarget(renderTarget) {
if (renderTarget.isRoot)
return;
const renderTargetSystem = this._renderTargetSystem;
const glRenderTarget = renderTargetSystem.getGpuRenderTarget(renderTarget);
this._resizeColor(renderTarget, glRenderTarget);
if (renderTarget.stencil || renderTarget.depth) {
this._resizeStencil(glRenderTarget);
}
}
_initColor(renderTarget, glRenderTarget) {
const renderer = this._renderer;
const gl = renderer.gl;
const resolveTargetFramebuffer = gl.createFramebuffer();
glRenderTarget.resolveTargetFramebuffer = resolveTargetFramebuffer;
gl.bindFramebuffer(gl.FRAMEBUFFER, resolveTargetFramebuffer);
glRenderTarget.width = renderTarget.colorTexture.source.pixelWidth;
glRenderTarget.height = renderTarget.colorTexture.source.pixelHeight;
renderTarget.colorTextures.forEach((colorTexture, i) => {
const source = colorTexture.source;
if (source.antialias) {
if (renderer.context.supports.msaa) {
glRenderTarget.msaa = true;
} else {
warn("[RenderTexture] Antialiasing on textures is not supported in WebGL1");
}
}
renderer.texture.bindSource(source, 0);
const glSource = renderer.texture.getGlSource(source);
const glTexture = glSource.texture;
gl.framebufferTexture2D(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0 + i,
3553,
// texture.target,
glTexture,
0
);
});
if (glRenderTarget.msaa) {
const viewFramebuffer = gl.createFramebuffer();
glRenderTarget.framebuffer = viewFramebuffer;
gl.bindFramebuffer(gl.FRAMEBUFFER, viewFramebuffer);
renderTarget.colorTextures.forEach((_, i) => {
const msaaRenderBuffer = gl.createRenderbuffer();
glRenderTarget.msaaRenderBuffer[i] = msaaRenderBuffer;
});
} else {
glRenderTarget.framebuffer = resolveTargetFramebuffer;
}
this._resizeColor(renderTarget, glRenderTarget);
}
_resizeColor(renderTarget, glRenderTarget) {
const source = renderTarget.colorTexture.source;
glRenderTarget.width = source.pixelWidth;
glRenderTarget.height = source.pixelHeight;
renderTarget.colorTextures.forEach((colorTexture, i) => {
if (i === 0)
return;
colorTexture.source.resize(source.width, source.height, source._resolution);
});
if (glRenderTarget.msaa) {
const renderer = this._renderer;
const gl = renderer.gl;
const viewFramebuffer = glRenderTarget.framebuffer;
gl.bindFramebuffer(gl.FRAMEBUFFER, viewFramebuffer);
renderTarget.colorTextures.forEach((colorTexture, i) => {
const source2 = colorTexture.source;
renderer.texture.bindSource(source2, 0);
const glSource = renderer.texture.getGlSource(source2);
const glInternalFormat = glSource.internalFormat;
const msaaRenderBuffer = glRenderTarget.msaaRenderBuffer[i];
gl.bindRenderbuffer(
gl.RENDERBUFFER,
msaaRenderBuffer
);
gl.renderbufferStorageMultisample(
gl.RENDERBUFFER,
4,
glInternalFormat,
source2.pixelWidth,
source2.pixelHeight
);
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0 + i,
gl.RENDERBUFFER,
msaaRenderBuffer
);
});
}
}
_initStencil(glRenderTarget) {
if (glRenderTarget.framebuffer === null)
return;
const gl = this._renderer.gl;
const depthStencilRenderBuffer = gl.createRenderbuffer();
glRenderTarget.depthStencilRenderBuffer = depthStencilRenderBuffer;
gl.bindRenderbuffer(
gl.RENDERBUFFER,
depthStencilRenderBuffer
);
gl.framebufferRenderbuffer(
gl.FRAMEBUFFER,
gl.DEPTH_STENCIL_ATTACHMENT,
gl.RENDERBUFFER,
depthStencilRenderBuffer
);
this._resizeStencil(glRenderTarget);
}
_resizeStencil(glRenderTarget) {
const gl = this._renderer.gl;
gl.bindRenderbuffer(
gl.RENDERBUFFER,
glRenderTarget.depthStencilRenderBuffer
);
if (glRenderTarget.msaa) {
gl.renderbufferStorageMultisample(
gl.RENDERBUFFER,
4,
gl.DEPTH24_STENCIL8,
glRenderTarget.width,
glRenderTarget.height
);
} else {
gl.renderbufferStorage(
gl.RENDERBUFFER,
this._renderer.context.webGLVersion === 2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL,
glRenderTarget.width,
glRenderTarget.height
);
}
}
postrender(renderTarget) {
if (!this._renderer.context.multiView)
return;
if (CanvasSource.test(renderTarget.colorTexture.resource)) {
const contextCanvas = this._renderer.context.canvas;
const canvasSource = renderTarget.colorTexture;
canvasSource.context2D.drawImage(
contextCanvas,
0,
canvasSource.pixelHeight - contextCanvas.height
);
}
}
}
export { GlRenderTargetAdaptor };
//# sourceMappingURL=GlRenderTargetAdaptor.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,18 @@
import { ExtensionType } from '../../../../extensions/Extensions';
import { RenderTargetSystem } from '../../shared/renderTarget/RenderTargetSystem';
import { GlRenderTargetAdaptor } from './GlRenderTargetAdaptor';
import type { GlRenderTarget } from '../GlRenderTarget';
import type { WebGLRenderer } from '../WebGLRenderer';
/**
* The WebGL adaptor for the render target system. Allows the Render Target System to be used with the WebGl renderer
* @memberof rendering
*/
export declare class GlRenderTargetSystem extends RenderTargetSystem<GlRenderTarget> {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem];
readonly name: "renderTarget";
};
adaptor: GlRenderTargetAdaptor;
constructor(renderer: WebGLRenderer);
}

View File

@@ -0,0 +1,22 @@
'use strict';
var Extensions = require('../../../../extensions/Extensions.js');
var RenderTargetSystem = require('../../shared/renderTarget/RenderTargetSystem.js');
var GlRenderTargetAdaptor = require('./GlRenderTargetAdaptor.js');
"use strict";
class GlRenderTargetSystem extends RenderTargetSystem.RenderTargetSystem {
constructor(renderer) {
super(renderer);
this.adaptor = new GlRenderTargetAdaptor.GlRenderTargetAdaptor();
this.adaptor.init(renderer, this);
}
}
/** @ignore */
GlRenderTargetSystem.extension = {
type: [Extensions.ExtensionType.WebGLSystem],
name: "renderTarget"
};
exports.GlRenderTargetSystem = GlRenderTargetSystem;
//# sourceMappingURL=GlRenderTargetSystem.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlRenderTargetSystem.js","sources":["../../../../../src/rendering/renderers/gl/renderTarget/GlRenderTargetSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../../extensions/Extensions';\nimport { RenderTargetSystem } from '../../shared/renderTarget/RenderTargetSystem';\nimport { GlRenderTargetAdaptor } from './GlRenderTargetAdaptor';\n\nimport type { GlRenderTarget } from '../GlRenderTarget';\nimport type { WebGLRenderer } from '../WebGLRenderer';\n\n/**\n * The WebGL adaptor for the render target system. Allows the Render Target System to be used with the WebGl renderer\n * @memberof rendering\n */\nexport class GlRenderTargetSystem extends RenderTargetSystem<GlRenderTarget>\n{\n /** @ignore */\n public static extension = {\n type: [ExtensionType.WebGLSystem],\n name: 'renderTarget',\n } as const;\n\n public adaptor = new GlRenderTargetAdaptor();\n\n constructor(renderer: WebGLRenderer)\n {\n super(renderer);\n\n this.adaptor.init(renderer, this);\n }\n}\n"],"names":["RenderTargetSystem","GlRenderTargetAdaptor","ExtensionType"],"mappings":";;;;;;;AAWO,MAAM,6BAA6BA,qCAC1C,CAAA;AAAA,EASI,YAAY,QACZ,EAAA;AACI,IAAA,KAAA,CAAM,QAAQ,CAAA,CAAA;AAJlB,IAAO,IAAA,CAAA,OAAA,GAAU,IAAIC,2CAAsB,EAAA,CAAA;AAMvC,IAAK,IAAA,CAAA,OAAA,CAAQ,IAAK,CAAA,QAAA,EAAU,IAAI,CAAA,CAAA;AAAA,GACpC;AACJ,CAAA;AAAA;AAhBa,oBAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAA,EAAM,CAACC,wBAAA,CAAc,WAAW,CAAA;AAAA,EAChC,IAAM,EAAA,cAAA;AACV,CAAA;;;;"}

View File

@@ -0,0 +1,20 @@
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { RenderTargetSystem } from '../../shared/renderTarget/RenderTargetSystem.mjs';
import { GlRenderTargetAdaptor } from './GlRenderTargetAdaptor.mjs';
"use strict";
class GlRenderTargetSystem extends RenderTargetSystem {
constructor(renderer) {
super(renderer);
this.adaptor = new GlRenderTargetAdaptor();
this.adaptor.init(renderer, this);
}
}
/** @ignore */
GlRenderTargetSystem.extension = {
type: [ExtensionType.WebGLSystem],
name: "renderTarget"
};
export { GlRenderTargetSystem };
//# sourceMappingURL=GlRenderTargetSystem.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"GlRenderTargetSystem.mjs","sources":["../../../../../src/rendering/renderers/gl/renderTarget/GlRenderTargetSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../../extensions/Extensions';\nimport { RenderTargetSystem } from '../../shared/renderTarget/RenderTargetSystem';\nimport { GlRenderTargetAdaptor } from './GlRenderTargetAdaptor';\n\nimport type { GlRenderTarget } from '../GlRenderTarget';\nimport type { WebGLRenderer } from '../WebGLRenderer';\n\n/**\n * The WebGL adaptor for the render target system. Allows the Render Target System to be used with the WebGl renderer\n * @memberof rendering\n */\nexport class GlRenderTargetSystem extends RenderTargetSystem<GlRenderTarget>\n{\n /** @ignore */\n public static extension = {\n type: [ExtensionType.WebGLSystem],\n name: 'renderTarget',\n } as const;\n\n public adaptor = new GlRenderTargetAdaptor();\n\n constructor(renderer: WebGLRenderer)\n {\n super(renderer);\n\n this.adaptor.init(renderer, this);\n }\n}\n"],"names":[],"mappings":";;;;;AAWO,MAAM,6BAA6B,kBAC1C,CAAA;AAAA,EASI,YAAY,QACZ,EAAA;AACI,IAAA,KAAA,CAAM,QAAQ,CAAA,CAAA;AAJlB,IAAO,IAAA,CAAA,OAAA,GAAU,IAAI,qBAAsB,EAAA,CAAA;AAMvC,IAAK,IAAA,CAAA,OAAA,CAAQ,IAAK,CAAA,QAAA,EAAU,IAAI,CAAA,CAAA;AAAA,GACpC;AACJ,CAAA;AAAA;AAhBa,oBAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAA,EAAM,CAAC,aAAA,CAAc,WAAW,CAAA;AAAA,EAChC,IAAM,EAAA,cAAA;AACV,CAAA;;;;"}

View File

@@ -0,0 +1,8 @@
import type { Shader } from '../../shared/shader/Shader';
import type { GlShaderSystem, ShaderSyncFunction } from './GlShaderSystem';
/**
* Generates the a function that will efficiently sync shader resources with the GPU.
* @param shader - The shader to generate the code for
* @param shaderSystem - An instance of the shader system
*/
export declare function generateShaderSyncCode(shader: Shader, shaderSystem: GlShaderSystem): ShaderSyncFunction;

View File

@@ -0,0 +1,74 @@
'use strict';
var BufferResource = require('../../shared/buffer/BufferResource.js');
var UniformGroup = require('../../shared/shader/UniformGroup.js');
var TextureSource = require('../../shared/texture/sources/TextureSource.js');
"use strict";
function generateShaderSyncCode(shader, shaderSystem) {
const funcFragments = [];
const headerFragments = [`
var g = s.groups;
var sS = r.shader;
var p = s.glProgram;
var ugS = r.uniformGroup;
var resources;
`];
let addedTextreSystem = false;
let blockIndex = 0;
let textureCount = 0;
const programData = shaderSystem._getProgramData(shader.glProgram);
for (const i in shader.groups) {
const group = shader.groups[i];
funcFragments.push(`
resources = g[${i}].resources;
`);
for (const j in group.resources) {
const resource = group.resources[j];
if (resource instanceof UniformGroup.UniformGroup) {
if (resource.ubo) {
funcFragments.push(`
sS.bindUniformBlock(
resources[${j}],
sS._uniformBindMap[${i}[${j}],
${blockIndex++}
);
`);
} else {
funcFragments.push(`
ugS.updateUniformGroup(resources[${j}], p, sD);
`);
}
} else if (resource instanceof BufferResource.BufferResource) {
funcFragments.push(`
sS.bindUniformBlock(
resources[${j}],
sS._uniformBindMap[${i}[${j}],
${blockIndex++}
);
`);
} else if (resource instanceof TextureSource.TextureSource) {
const uniformName = shader._uniformBindMap[i][j];
const uniformData = programData.uniformData[uniformName];
if (uniformData) {
if (!addedTextreSystem) {
addedTextreSystem = true;
headerFragments.push(`
var tS = r.texture;
`);
}
shaderSystem._gl.uniform1i(uniformData.location, textureCount);
funcFragments.push(`
tS.bind(resources[${j}], ${textureCount});
`);
textureCount++;
}
}
}
}
const functionSource = [...headerFragments, ...funcFragments].join("\n");
return new Function("r", "s", "sD", functionSource);
}
exports.generateShaderSyncCode = generateShaderSyncCode;
//# sourceMappingURL=GenerateShaderSyncCode.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,72 @@
import { BufferResource } from '../../shared/buffer/BufferResource.mjs';
import { UniformGroup } from '../../shared/shader/UniformGroup.mjs';
import { TextureSource } from '../../shared/texture/sources/TextureSource.mjs';
"use strict";
function generateShaderSyncCode(shader, shaderSystem) {
const funcFragments = [];
const headerFragments = [`
var g = s.groups;
var sS = r.shader;
var p = s.glProgram;
var ugS = r.uniformGroup;
var resources;
`];
let addedTextreSystem = false;
let blockIndex = 0;
let textureCount = 0;
const programData = shaderSystem._getProgramData(shader.glProgram);
for (const i in shader.groups) {
const group = shader.groups[i];
funcFragments.push(`
resources = g[${i}].resources;
`);
for (const j in group.resources) {
const resource = group.resources[j];
if (resource instanceof UniformGroup) {
if (resource.ubo) {
funcFragments.push(`
sS.bindUniformBlock(
resources[${j}],
sS._uniformBindMap[${i}[${j}],
${blockIndex++}
);
`);
} else {
funcFragments.push(`
ugS.updateUniformGroup(resources[${j}], p, sD);
`);
}
} else if (resource instanceof BufferResource) {
funcFragments.push(`
sS.bindUniformBlock(
resources[${j}],
sS._uniformBindMap[${i}[${j}],
${blockIndex++}
);
`);
} else if (resource instanceof TextureSource) {
const uniformName = shader._uniformBindMap[i][j];
const uniformData = programData.uniformData[uniformName];
if (uniformData) {
if (!addedTextreSystem) {
addedTextreSystem = true;
headerFragments.push(`
var tS = r.texture;
`);
}
shaderSystem._gl.uniform1i(uniformData.location, textureCount);
funcFragments.push(`
tS.bind(resources[${j}], ${textureCount});
`);
textureCount++;
}
}
}
}
const functionSource = [...headerFragments, ...funcFragments].join("\n");
return new Function("r", "s", "sD", functionSource);
}
export { generateShaderSyncCode };
//# sourceMappingURL=GenerateShaderSyncCode.mjs.map

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More