1import { ValueType } from './value-type' 2 3export function isInline(value: ValueType): boolean { 4 return value === ValueType.BOOL 5 || value <= ValueType.FLOAT; 6} 7 8export function isNumber(value: ValueType): boolean { 9 return value >= ValueType.INT 10 && value <= ValueType.FLOAT; 11} 12 13export function isIndirectNumber(value: ValueType): boolean { 14 return value >= ValueType.INDIRECT_INT 15 && value <= ValueType.INDIRECT_FLOAT; 16} 17 18export function isTypedVectorElement(value: ValueType): boolean { 19 return value === ValueType.BOOL 20 || (value >= ValueType.INT 21 && value <= ValueType.STRING); 22} 23 24export function isTypedVector(value: ValueType): boolean { 25 return value === ValueType.VECTOR_BOOL 26 || (value >= ValueType.VECTOR_INT 27 && value <= ValueType.VECTOR_STRING_DEPRECATED); 28} 29 30export function isFixedTypedVector(value: ValueType): boolean { 31 return value >= ValueType.VECTOR_INT2 32 && value <= ValueType.VECTOR_FLOAT4; 33} 34 35export function isAVector(value: ValueType): boolean { 36 return isTypedVector(value) 37 || isFixedTypedVector(value) 38 || value === ValueType.VECTOR; 39} 40 41export function toTypedVector(valueType: ValueType, length: number): ValueType { 42 if (length === 0) return valueType - ValueType.INT + ValueType.VECTOR_INT; 43 if (length === 2) return valueType - ValueType.INT + ValueType.VECTOR_INT2; 44 if (length === 3) return valueType - ValueType.INT + ValueType.VECTOR_INT3; 45 if (length === 4) return valueType - ValueType.INT + ValueType.VECTOR_INT4; 46 throw "Unexpected length " + length; 47} 48 49export function typedVectorElementType(valueType: ValueType): ValueType { 50 return valueType - ValueType.VECTOR_INT + ValueType.INT; 51} 52 53export function fixedTypedVectorElementType(valueType: ValueType): ValueType { 54 return ((valueType - ValueType.VECTOR_INT2) % 3) + ValueType.INT; 55} 56 57export function fixedTypedVectorElementSize(valueType: ValueType): ValueType { 58 // The x / y >> 0 trick is to have an int division. Suppose to be faster than Math.floor() 59 return (((valueType - ValueType.VECTOR_INT2) / 3) >> 0) + 2; 60} 61 62export function packedType(valueType: ValueType, bitWidth: number): ValueType { 63 return bitWidth | (valueType << 2); 64}