@tolokoban/tgd
Version:
ToloGameDev library for WebGL2
128 lines • 4.4 kB
TypeScript
import type { TgdBuffer, TgdBufferOptionTarget, TgdBufferOptionUsage } from "../buffer";
import type { TgdProgram } from "../program";
export type TgdDatasetType = "float" | "vec2" | "vec3" | "vec4";
export interface TgdDatasetOptions {
name?: string;
divisor: number;
target: TgdBufferOptionTarget;
usage: TgdBufferOptionUsage;
data?: ArrayBuffer;
/**
* When passing a Dataset to a VAO, you can use
* this prop to tell the VAO to use this buffer
* instead of creating a new one.
*/
buffer?: TgdBuffer;
}
export type TgdDatasetTypeRecord = Record<string, TgdDatasetType>;
export declare class TgdDataset {
private readonly attributesDefinition;
private readonly options;
readonly name: string;
readonly divisor: number;
readonly buffer: TgdBuffer | undefined;
target: TgdBufferOptionTarget;
usage: TgdBufferOptionUsage;
private stride;
private definitions;
private _data;
private _count;
private static id;
constructor(attributesDefinition: TgdDatasetTypeRecord, options?: Partial<TgdDatasetOptions>);
getType(attribName: string): TgdDatasetType;
getTypeRecord(): TgdDatasetTypeRecord;
private initialize;
assertAttributes(attributesDefinition: TgdDatasetTypeRecord): void;
/**
* Throw an exception if the attribute `attribName` does not exist,
* or if it is not of any of the `types`.
* @param attribName
* @param types
*/
assertAttribType(attribName: string, ...types: string[]): this;
renameAttributes(newNames: string[]): this;
addAttributes(attributesDefinition: TgdDatasetTypeRecord): this;
clone(): TgdDataset;
copyAttributes({ fromIndex, toIndex, toDataset, }: {
fromIndex: number;
toIndex: number;
toDataset?: TgdDataset;
}): void;
/**
* Warning!
*
* This ArrayBuffer will be detached as soon as its
* size is changed!
*/
get data(): Readonly<ArrayBuffer>;
/**
* Dataset does not own any GL Buffer.
* So setting its data won't change anything in WebGL.
* You can use a `TgdVertexArray` for this.
*/
set data(arrayBuffer: Readonly<ArrayBuffer>);
/** Get number of attributes. */
get count(): number;
/** Set number of attributes (reallocate data accordingly) */
set count(count: number);
get attributesNames(): string[];
hasAttribute(attribName: string): boolean;
getAttribAccessor(attribName: string): {
get: (index: number, dimension?: number) => number;
set: (value: number, index: number, dimension?: number) => void;
};
get(attribName: string, target?: number[]): number[];
/**
* Set the data for one attribute.
*
* If you try to set more element that the current buffer
* can hold, the buffer will be expanded.
* And the property `count` will change accordingly.
*
* @param attribName If the attribute does not exist,
* you will get an exception.
* @param value The ArrayBuffer holding the data you
* want to set to this attribute
* @param param2
*/
set(attribName: string, value: ArrayBuffer | Int8Array | Uint8Array | Int16Array | Uint16Array | Uint32Array | Float32Array | {
buffer: ArrayBuffer;
}, { byteOffset, byteStride, first, count, targetFirst, }?: Partial<{
/**
* First byte of meaningful data in this buffer.
*/
byteOffset: number;
/**
* Number of bytes between two elements.
* If data is packed, you can leave it undefined.
*/
byteStride: number;
/**
* Index if the first source element.
* Default to 0.
*/
first: number;
/**
* Maximum number of elements to store.
* Default to Infinity.
*/
count: number;
/**
* Index if the first destination element.
* Default to 0.
*/
targetFirst: number;
}>): void;
private getDef;
/**
* Enable the vertex attrib array, and set
* the vertex attrib pointer for every declared
* attribute.
*/
defineAttributes(gl: WebGL2RenderingContext, prg: TgdProgram): void;
toCode({ indent }?: Partial<{
indent: string;
}>): string;
debug(caption?: string): void;
}
//# sourceMappingURL=dataset.d.ts.map