@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
26 lines (22 loc) • 1.04 kB
JavaScript
import { assert } from "../../../core/assert.js";
import { NumericType } from "../../../core/math/NumericType.js";
import { channelCountToThreeTextureFormat } from "./channelCountToThreeTextureFormat.js";
import { channelCountToThreIntegerTextureType } from "./channelCountToThreIntegerTextureType.js";
import { numericTypeFromBinaryDataType } from "./numericTypeFromBinaryDataType.js";
/**
*
* @param {AttributeSpec} spec
* @returns {number}
*/
export function attribute_spec_to_three_format(spec) {
assert.defined(spec, 'spec');
assert.notNull(spec, 'spec');
const numeric_type = numericTypeFromBinaryDataType(spec.type);
if (spec.normalized || numeric_type === NumericType.Float) {
return channelCountToThreeTextureFormat(spec.itemSize);
} else if (numeric_type === NumericType.Int || numeric_type === NumericType.Uint) {
return channelCountToThreIntegerTextureType(spec.itemSize);
} else {
throw new Error(`Unsupported numeric type '${numeric_type}'`);
}
}