mrdoob/three.js · error · Error

THREE.WebGLTextureUtils: Unsupported WebGL type: ${glType}

Error message

THREE.WebGLTextureUtils: Unsupported WebGL type: ${glType}

What it means

Thrown by WebGLTextureUtils._getTypedArrayType() when a WebGL pixel type (glType) does not match any of the supported readback types (UNSIGNED_BYTE, UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_5_5_5_1, UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT, UNSIGNED_INT, HALF_FLOAT, FLOAT). The method picks a JS typed array to receive readback pixels; if the texture's GL type isn't in the table, it can't choose a destination array.

Source

Thrown at src/renderers/webgl-fallback/utils/WebGLTextureUtils.js:1312

	 * @param {GLenum} glType - The WebGL data type.
	 * @return {TypedArray.constructor} The typed array type.
	 */
	_getTypedArrayType( glType ) {

		const { gl } = this;

		if ( glType === gl.UNSIGNED_BYTE ) return Uint8Array;

		if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) return Uint16Array;
		if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) return Uint16Array;
		if ( glType === gl.UNSIGNED_SHORT_5_6_5 ) return Uint16Array;
		if ( glType === gl.UNSIGNED_SHORT ) return Uint16Array;
		if ( glType === gl.UNSIGNED_INT ) return Uint32Array;

		if ( glType === gl.HALF_FLOAT ) return Uint16Array;
		if ( glType === gl.FLOAT ) return Float32Array;

		throw new Error( `THREE.WebGLTextureUtils: Unsupported WebGL type: ${glType}` );

	}

	/**
	 * Returns the bytes-per-texel value for the given WebGL data type and texture format.
	 *
	 * @private
	 * @param {GLenum} glType - The WebGL data type.
	 * @param {GLenum} glFormat - The WebGL texture format.
	 * @return {number} The bytes-per-texel.
	 */
	_getBytesPerTexel( glType, glFormat ) {

		const { gl } = this;

		let bytesPerComponent = 0;

		if ( glType === gl.UNSIGNED_BYTE ) bytesPerComponent = 1;

View on GitHub (pinned to da05705fa3)

Solutions

  1. Read back from a render target whose color attachment uses a supported type ( UNSIGNED_BYTE / FLOAT / HALF_FLOAT ).
  2. Blit/copy the unusual-format texture into a standard RGBA8/RGBA16F target and read back from that.
  3. Avoid pixel readback for compressed or integer textures; use a buffer readback instead where supported.
  4. Update three.js — newer versions may extend the supported glType table.

Example fix

// before - reading back from an integer-format target
renderer.readbackPixels(intFormatRT); // throws via _getTypedArrayType

// after - blit to a standard RGBA8 target first
renderer.setRenderTarget(rgba8RT);
renderer.render(scene, orthoCam);
const pixels = renderer.readbackPixels(rgba8RT);
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_GL_TYPES = new Set(['UNSIGNED_BYTE','UNSIGNED_SHORT_4_4_4_4','UNSIGNED_SHORT_5_5_5_1','UNSIGNED_SHORT_5_6_5','UNSIGNED_SHORT','UNSIGNED_INT','HALF_FLOAT','FLOAT']);
function canReadbackType(gl, glType) {
  return [...SUPPORTED_GL_TYPES].some(k => glType === gl[k]);
}

Type guard

function isReadableTextureType(gl, glType) {
  return [gl.UNSIGNED_BYTE, gl.UNSIGNED_SHORT_4_4_4_4, gl.UNSIGNED_SHORT_5_5_5_1, gl.UNSIGNED_SHORT_5_6_5, gl.UNSIGNED_SHORT, gl.UNSIGNED_INT, gl.HALF_FLOAT, gl.FLOAT].includes(glType);
}

Try / catch

try {
  pixels = renderer.readbackPixels(rt);
} catch (e) {
  if (/Unsupported WebGL type/.test(e.message)) { /* blit to RGBA8/RGBA16F target, then readback */ }
  else throw e;
}

Prevention

When it happens

Trigger: Reading back pixels (e.g. via renderer.readback / renderTarget readback) from a texture whose GL type is an integer/signed format or an extension type not in the supported list (e.g. signed normalized formats, certain compressed formats).

Common situations: Readback from a render target using an unusual internal format (e.g. RG16I, RGBA32I, depth). Using a compressed texture format and trying to readback raw pixels. Browser/driver exposing a glType constant not anticipated by three's mapping table. Mismatched format between write and readback.

Related errors


AI-assisted analysis of mrdoob/three.js@da05705fa3 (2026-08-12). Data as JSON: /api/errors/b605c80eee9d54d4. Report an issue: GitHub.