|
@@ -1,5 +1,5 @@
|
|
/**
|
|
/**
|
|
- * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
|
|
|
+ * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
*
|
|
*
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
*/
|
|
*/
|
|
@@ -19,14 +19,16 @@ const getNextTextureId = idFactory();
|
|
export type TextureKindValue = {
|
|
export type TextureKindValue = {
|
|
'image-uint8': TextureImage<Uint8Array>
|
|
'image-uint8': TextureImage<Uint8Array>
|
|
'image-float32': TextureImage<Float32Array>
|
|
'image-float32': TextureImage<Float32Array>
|
|
|
|
+ 'image-float16': TextureImage<Float32Array>
|
|
'image-depth': TextureImage<Uint8Array> // TODO should be Uint32Array
|
|
'image-depth': TextureImage<Uint8Array> // TODO should be Uint32Array
|
|
'volume-uint8': TextureVolume<Uint8Array>
|
|
'volume-uint8': TextureVolume<Uint8Array>
|
|
'volume-float32': TextureVolume<Float32Array>
|
|
'volume-float32': TextureVolume<Float32Array>
|
|
|
|
+ 'volume-float16': TextureVolume<Float32Array>
|
|
'texture': Texture
|
|
'texture': Texture
|
|
}
|
|
}
|
|
export type TextureValueType = ValueOf<TextureKindValue>
|
|
export type TextureValueType = ValueOf<TextureKindValue>
|
|
export type TextureKind = keyof TextureKindValue
|
|
export type TextureKind = keyof TextureKindValue
|
|
-export type TextureType = 'ubyte' | 'ushort' | 'float'
|
|
|
|
|
|
+export type TextureType = 'ubyte' | 'ushort' | 'float' | 'fp16'
|
|
export type TextureFormat = 'alpha' | 'rgb' | 'rgba' | 'depth'
|
|
export type TextureFormat = 'alpha' | 'rgb' | 'rgba' | 'depth'
|
|
/** Numbers are shortcuts for color attachment */
|
|
/** Numbers are shortcuts for color attachment */
|
|
export type TextureAttachment = 'depth' | 'stencil' | 'color0' | 'color1' | 'color2' | 'color3' | 'color4' | 'color5' | 'color6' | 'color7' | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
|
|
export type TextureAttachment = 'depth' | 'stencil' | 'color0' | 'color1' | 'color2' | 'color3' | 'color4' | 'color5' | 'color6' | 'color7' | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
|
|
@@ -36,12 +38,14 @@ export function getTarget(gl: GLRenderingContext, kind: TextureKind): number {
|
|
switch (kind) {
|
|
switch (kind) {
|
|
case 'image-uint8': return gl.TEXTURE_2D;
|
|
case 'image-uint8': return gl.TEXTURE_2D;
|
|
case 'image-float32': return gl.TEXTURE_2D;
|
|
case 'image-float32': return gl.TEXTURE_2D;
|
|
|
|
+ case 'image-float16': return gl.TEXTURE_2D;
|
|
case 'image-depth': return gl.TEXTURE_2D;
|
|
case 'image-depth': return gl.TEXTURE_2D;
|
|
}
|
|
}
|
|
if (isWebGL2(gl)) {
|
|
if (isWebGL2(gl)) {
|
|
switch (kind) {
|
|
switch (kind) {
|
|
case 'volume-uint8': return gl.TEXTURE_3D;
|
|
case 'volume-uint8': return gl.TEXTURE_3D;
|
|
case 'volume-float32': return gl.TEXTURE_3D;
|
|
case 'volume-float32': return gl.TEXTURE_3D;
|
|
|
|
+ case 'volume-float16': return gl.TEXTURE_3D;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw new Error(`unknown texture kind '${kind}'`);
|
|
throw new Error(`unknown texture kind '${kind}'`);
|
|
@@ -65,16 +69,19 @@ export function getInternalFormat(gl: GLRenderingContext, format: TextureFormat,
|
|
switch (type) {
|
|
switch (type) {
|
|
case 'ubyte': return gl.ALPHA;
|
|
case 'ubyte': return gl.ALPHA;
|
|
case 'float': return gl.R32F;
|
|
case 'float': return gl.R32F;
|
|
|
|
+ case 'fp16': return gl.R16F;
|
|
}
|
|
}
|
|
case 'rgb':
|
|
case 'rgb':
|
|
switch (type) {
|
|
switch (type) {
|
|
case 'ubyte': return gl.RGB;
|
|
case 'ubyte': return gl.RGB;
|
|
case 'float': return gl.RGB32F;
|
|
case 'float': return gl.RGB32F;
|
|
|
|
+ case 'fp16': return gl.RGB16F;
|
|
}
|
|
}
|
|
case 'rgba':
|
|
case 'rgba':
|
|
switch (type) {
|
|
switch (type) {
|
|
case 'ubyte': return gl.RGBA;
|
|
case 'ubyte': return gl.RGBA;
|
|
case 'float': return gl.RGBA32F;
|
|
case 'float': return gl.RGBA32F;
|
|
|
|
+ case 'fp16': return gl.RGBA16F;
|
|
}
|
|
}
|
|
case 'depth':
|
|
case 'depth':
|
|
return gl.DEPTH_COMPONENT16;
|
|
return gl.DEPTH_COMPONENT16;
|
|
@@ -83,11 +90,14 @@ export function getInternalFormat(gl: GLRenderingContext, format: TextureFormat,
|
|
return getFormat(gl, format, type);
|
|
return getFormat(gl, format, type);
|
|
}
|
|
}
|
|
|
|
|
|
-export function getType(gl: GLRenderingContext, type: TextureType): number {
|
|
|
|
|
|
+export function getType(gl: GLRenderingContext, extensions: WebGLExtensions, type: TextureType): number {
|
|
switch (type) {
|
|
switch (type) {
|
|
case 'ubyte': return gl.UNSIGNED_BYTE;
|
|
case 'ubyte': return gl.UNSIGNED_BYTE;
|
|
case 'ushort': return gl.UNSIGNED_SHORT;
|
|
case 'ushort': return gl.UNSIGNED_SHORT;
|
|
case 'float': return gl.FLOAT;
|
|
case 'float': return gl.FLOAT;
|
|
|
|
+ case 'fp16':
|
|
|
|
+ if (extensions.textureHalfFloat) return extensions.textureHalfFloat.HALF_FLOAT;
|
|
|
|
+ else throw new Error('extension "texture_half_float" unavailable');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -169,6 +179,7 @@ export function createTexture(gl: GLRenderingContext, extensions: WebGLExtension
|
|
// check texture kind and type compatability
|
|
// check texture kind and type compatability
|
|
if (
|
|
if (
|
|
(kind.endsWith('float32') && _type !== 'float') ||
|
|
(kind.endsWith('float32') && _type !== 'float') ||
|
|
|
|
+ (kind.endsWith('float16') && _type !== 'fp16') ||
|
|
(kind.endsWith('uint8') && _type !== 'ubyte') ||
|
|
(kind.endsWith('uint8') && _type !== 'ubyte') ||
|
|
(kind.endsWith('depth') && _type !== 'ushort')
|
|
(kind.endsWith('depth') && _type !== 'ushort')
|
|
) {
|
|
) {
|
|
@@ -179,7 +190,7 @@ export function createTexture(gl: GLRenderingContext, extensions: WebGLExtension
|
|
const filter = getFilter(gl, _filter);
|
|
const filter = getFilter(gl, _filter);
|
|
const format = getFormat(gl, _format, _type);
|
|
const format = getFormat(gl, _format, _type);
|
|
const internalFormat = getInternalFormat(gl, _format, _type);
|
|
const internalFormat = getInternalFormat(gl, _format, _type);
|
|
- const type = getType(gl, _type);
|
|
|
|
|
|
+ const type = getType(gl, extensions, _type);
|
|
|
|
|
|
function init() {
|
|
function init() {
|
|
gl.bindTexture(target, texture);
|
|
gl.bindTexture(target, texture);
|