@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
94 lines (78 loc) • 2.27 kB
JavaScript
import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
import { combine_hash } from "../../../../../core/collection/array/combine_hash.js";
import { computeStringHash } from "../../../../../core/primitives/strings/computeStringHash.js";
import { ResourceDescriptor } from "./ResourceDescriptor.js";
import { TextureInitialState } from "./TextureInitialState.js";
export class TextureResourceDescriptor extends ResourceDescriptor {
/**
*
* @type {number}
*/
height = 0;
/**
*
* @type {number}
*/
width = 0;
/**
* Render texture type
* @type {BinaryDataType}
*/
format = BinaryDataType.Uint8;
/**
*
* @type {number}
*/
channel_count = 1;
/**
* What should the texture be initialized to
* @type {number}
*/
initial_state = TextureInitialState.Clear;
get type() {
return 'texture';
}
hash() {
return combine_hash(
this.width,
this.height,
computeStringHash(this.format),
this.channel_count,
)
}
/**
*
* @param {TextureResourceDescriptor} other
* @returns {boolean}
*/
equals(other) {
if (this === other) {
// shortcut
return true;
}
if (!super.equals(other)) {
return false;
}
return this.width === other.width
&& this.height === other.height
&& this.format === other.format
&& this.channel_count === other.channel_count
&& this.initial_state === other.initial_state
;
}
static from({
height = 0,
width = 0,
format = BinaryDataType.Uint8,
channel_count = 1,
initial_state = TextureInitialState.Clear
}) {
const r = new TextureResourceDescriptor();
r.height = height;
r.width = width;
r.format = format;
r.channel_count = channel_count;
r.initial_state = initial_state;
return r;
}
}