Fix type of CompressedTexture.mipmaps
#1024
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently
CompressedTexture
andCompressedArrayTexture
represent mipmaps using the browser'sImageData
. This is actually inaccurate to three.js's implementation in a few ways:ImageData#colorSpace
is unused by three.js.ImageData#data
is the incorrect type. It isUint8ClampedArray
however, usingUint8ClampedArray
will sometimes cause runtime breakages in three.js (see below for details)Of these two, (2) is the real problem.
ImageData#data
is defined asUint8ClampedArray
, however, mipmap data is regularly used by threejs intexSubImage2D
andcompressedTexSubImage2D
which both require that the source data array view matches the texture type. For example, if I have a texture usingRGIntegerFormat
withFloatType
thencompressedTexSubImage2D
must be passed aFloat32Array
. As currently written, clients would be forced to useUint8ClampedArray
which will cause a runtime error due to misalignment between the source data and texture type. This is documented bytexSubImage2D
which specifiesThe fix here is to replace the current usage of
ImageData
with a new typeMipmapImageData
which better aligns to three.js's internal usage, and importantly allows thedata
field to be populated by anyTypedArray
.