Work on public APIs

This commit is contained in:
2023-07-30 21:28:48 +02:00
parent 5b8b8fa057
commit 89576c33bd
8 changed files with 538 additions and 48 deletions

View File

@@ -107,7 +107,7 @@ export class IndexBuffer {
ensureSizeDiscard({
indexFormat = this._indexFormat,
indexCount = this.indexCount,
}): IndexBuffer {
}: IndexBufferResizeProps): IndexBuffer {
if (this.indexCount >= indexCount && indexSize(this._indexFormat) >= indexSize(indexFormat)) {
return this;
}

View File

@@ -23,6 +23,12 @@ export interface Texture2DProps {
readonly format: Texture2DFormat;
}
export interface Texture2DResizeProps {
readonly width?: number;
readonly height?: number;
readonly format?: Texture2DFormat;
}
export interface Texture2DAdvancedWriteProps {
readonly origin: Vector2Object | Vector2Tuple,
readonly data: BufferSource | SharedArrayBuffer,
@@ -69,6 +75,11 @@ export class Texture2D {
this._format = format;
}
/**
* Destroys owned GPU resources. The texture should not be used after
* calling this method.
* @returns `this` for chaining
*/
dispose(): Texture2D {
this._texture.destroy();
return this;
@@ -124,6 +135,36 @@ export class Texture2D {
);
return this;
}
/**
* Resize the texture and/or change its format, discarding currently stored
* data.
* @param props Desired texture properties. Any unspecified property will
* stay unchanged.
* @returns `this` for chaining
*/
resizeDiscard({
width = this._texture.width,
height = this._texture.height,
format = this._format,
}: Texture2DResizeProps): Texture2D {
this._texture.destroy();
const gpuFormat = gpuTextureFormat(format);
this._texture = this._renderer._device.createTexture({
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST,
size: { width, height },
format: gpuFormat,
label: this._name
});
this._textureView = this._texture.createView({
format: gpuFormat,
dimension: "2d",
label: `${this._name}.textureView`,
});
return this;
}
}
Object.defineProperty(Texture2D.prototype, "type", { value: "Texture2D" });