{"record":{"id":"aecee9fbd9ab12d2","repo":"mrdoob/three.js","slug":"three-depthtexture-format-must-be-either-three-de","errorCode":null,"errorMessage":"THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat","messagePattern":"THREE\\.DepthTexture: format must be either THREE\\.DepthFormat or THREE\\.DepthStencilFormat","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/textures/DepthTexture.js","lineNumber":32,"sourceCode":"\t * Constructs a new depth texture.\n\t *\n\t * @param {number} width - The width of the texture.\n\t * @param {number} height - The height of the texture.\n\t * @param {number} [type=UnsignedIntType] - The texture type.\n\t * @param {number} [mapping=Texture.DEFAULT_MAPPING] - The texture mapping.\n\t * @param {number} [wrapS=ClampToEdgeWrapping] - The wrapS value.\n\t * @param {number} [wrapT=ClampToEdgeWrapping] - The wrapT value.\n\t * @param {number} [magFilter=LinearFilter] - The mag filter value.\n\t * @param {number} [minFilter=LinearFilter] - The min filter value.\n\t * @param {number} [anisotropy=Texture.DEFAULT_ANISOTROPY] - The anisotropy value.\n\t * @param {number} [format=DepthFormat] - The texture format.\n\t * @param {number} [depth=1] - The depth of the texture.\n\t */\n\tconstructor( width, height, type = UnsignedIntType, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, format = DepthFormat, depth = 1 ) {\n\n\t\tif ( format !== DepthFormat && format !== DepthStencilFormat ) {\n\n\t\t\tthrow new Error( 'THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );\n\n\t\t}\n\n\t\tconst image = { width: width, height: height, depth: depth };\n\n\t\tsuper( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );\n\n\t\t/**\n\t\t * This flag can be used for type testing.\n\t\t *\n\t\t * @type {boolean}\n\t\t * @readonly\n\t\t * @default true\n\t\t */\n\t\tthis.isDepthTexture = true;\n\n\t\t/**\n\t\t * If set to `true`, the texture is flipped along the vertical axis when","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/textures/DepthTexture.js#L14-L50","documentation":"Thrown by the DepthTexture constructor when the format argument is neither THREE.DepthFormat nor THREE.DepthStencilFormat. A depth texture's GPU resource must be a depth or depth-stencil image; color formats (RGBAFormat, RedFormat, etc.) are meaningless for depth attachment, so the constructor rejects them eagerly. Note format is the 10th positional parameter with a default of DepthFormat, so a misaligned argument list is the most frequent real cause.","triggerScenarios":"Constructing new THREE.DepthTexture(width, height, ...) with format set to a color format constant. Misaligning the 11 positional parameters (width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format, depth) so that a value intended for an earlier slot lands in the format slot. Passing a string or a stale constant from a different THREE version.","commonSituations":"Copying a Texture constructor call and assuming DepthTexture accepts the same format set. Passing format as the 3rd argument (where type belongs) because that ordering is familiar from other textures. Upgrading three.js across a version where DepthTexture became strict about format. Needing stencil and forgetting to switch from the DepthFormat default to DepthStencilFormat (or vice-versa, that case works fine, but passing RGBAFormat for stencil fails).","solutions":["Pass THREE.DepthFormat (depth-only) or THREE.DepthStencilFormat (depth + stencil) explicitly as the format argument.","Count positional arguments against the signature (width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format, depth); prefer relying on defaults and passing only the trailing format you need.","Use object-spread / default-friendly call sites (e.g. new THREE.DepthTexture(w, h, THREE.UnsignedIntType, undefined, undefined, undefined, undefined, undefined, undefined, THREE.DepthStencilFormat)) to keep the slot alignment explicit.","If a color-format depth attachment was intended, that is not supported; switch to a regular Texture for color data."],"exampleFix":"// before: format landed in the wrong positional slot (type's slot)\nconst dt = new THREE.DepthTexture( 1024, 1024, THREE.RGBAFormat ); // throws\n\n// after: depth-only with correct slots, or depth+stencil\nconst depthOnly = new THREE.DepthTexture( 1024, 1024, THREE.UnsignedIntType );\nconst depthStencil = new THREE.DepthTexture(\n  1024, 1024, THREE.UnsignedInt248Type,\n  undefined, undefined, undefined, undefined, undefined, undefined,\n  THREE.DepthStencilFormat\n);","handlingStrategy":"validation","validationCode":"import { DepthFormat, DepthStencilFormat } from 'three';\n\nconst ALLOWED_DEPTH_FORMATS = new Set( [ DepthFormat, DepthStencilFormat ] );\n\nfunction assertDepthFormat( format ) {\n  if ( ! ALLOWED_DEPTH_FORMATS.has( format ) ) {\n    throw new Error(\n      `DepthTexture format must be THREE.DepthFormat or THREE.DepthStencilFormat (got ${ format })`\n    );\n  }\n}\n\nassertDepthFormat( myFormat );\nconst depthTexture = new THREE.DepthTexture( w, h, type, undefined, undefined, undefined, undefined, undefined, undefined, myFormat );","typeGuard":"import { DepthFormat, DepthStencilFormat } from 'three';\n\nfunction isValidDepthFormat( format ) {\n  return format === DepthFormat || format === DepthStencilFormat;\n}","tryCatchPattern":null,"preventionTips":["Always pass format explicitly as the 10th positional argument; do not rely on positional memory for an 11-parameter constructor.","Use THREE.DepthFormat for depth-only render targets and THREE.DepthStencilFormat when stencil is required.","Never reuse a color-format constant (RGBAFormat, RedFormat, ...) for DepthTexture.","Validate the format constant once at module load to catch stale or renamed imports across three.js versions."],"tags":["texture","depth-texture","format","constructor","webgl","webgpu"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}