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,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;;;;"}