Skip to content

Commit

Permalink
feat(core): Add float64 VertexType and VertexFormat values
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Feb 28, 2024
1 parent 3ff710e commit 3ef316a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions modules/core/src/adapter/type-utils/decode-data-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const TYPE_MAP: Record<NormalizedDataType, DataType> = {
snorm16: 'sint16',
float16: 'float16',
float32: 'float32',
float64: 'float64',
uint32: 'uint32',
sint32: 'sint32'
};
Expand All @@ -61,6 +62,7 @@ const TYPE_SIZES: Record<DataType, number> = {
sint16: 2,
float16: 2,
float32: 4,
float64: 8,
uint32: 4,
sint32: 4
};
12 changes: 9 additions & 3 deletions modules/core/src/adapter/types/vertex-formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export type DataType =
| 'uint32'
| 'sint32'
| 'float16'
| 'float32';
| 'float32'
| 'float64';

/** Vertex and Pixel data types. Include normalized integers */
export type NormalizedDataType =
Expand All @@ -28,8 +29,9 @@ export type NormalizedDataType =
// WebGPU does not support normalized 32 bit integer attributes...
// | 'unorm32'
// | 'snorm32'
| 'float16'
| 'float32'
| 'float16';
| 'float64';

/** Describes the type (without number of components) of a vertex format */
export type VertexType = NormalizedDataType;
Expand Down Expand Up @@ -87,4 +89,8 @@ export type VertexFormat =
| 'float32'
| 'float32x2'
| 'float32x3'
| 'float32x4';
| 'float32x4'
| 'float64'
| 'float64x2'
| 'float64x3'
| 'float64x4';
8 changes: 6 additions & 2 deletions modules/webgl/src/adapter/converters/vertex-formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type GLDataType =
| GL.UNSIGNED_INT
| GL.INT
| GL.HALF_FLOAT
| GL.FLOAT;
| GL.FLOAT
| GL.DOUBLE;

/** Get vertex format from GL constants */
export function getVertexFormatFromGL(type: GLDataType, components: 1 | 2 | 3 | 4): VertexFormat {
Expand Down Expand Up @@ -42,6 +43,7 @@ export function getVertexTypeFromGL(type: GLDataType, normalized = false): Verte
case GL.UNSIGNED_SHORT: return normalized ? 'uint16' : 'unorm16';
case GL.BYTE: return normalized ? 'sint8' : 'snorm16';
case GL.UNSIGNED_BYTE: return normalized ? 'uint8' : 'unorm8';
case GL.DOUBLE: return 'float64';
case GL.FLOAT: return 'float32';
case GL.HALF_FLOAT: return 'float16';
}
Expand All @@ -59,7 +61,8 @@ export function getGLFromVertexType(
| GL.UNSIGNED_INT
| GL.INT
| GL.HALF_FLOAT
| GL.FLOAT {
| GL.FLOAT
| GL.DOUBLE {
// prettier-ignore
switch (dataType) {
case 'uint8': return GL.UNSIGNED_BYTE;
Expand All @@ -77,6 +80,7 @@ export function getGLFromVertexType(
// case 'snorm32': return GL.INT;
case 'float16': return GL.HALF_FLOAT;
case 'float32': return GL.FLOAT;
case 'float64': return GL.DOUBLE;
}
// @ts-ignore unreachable
throw new Error(String(dataType));
Expand Down

0 comments on commit 3ef316a

Please sign in to comment.