Update getTextureByteLength to handle compressed textures and external textures.#1560
Update getTextureByteLength to handle compressed textures and external textures.#1560castano wants to merge 5 commits intoNASA-AMMOS:masterfrom
Conversation
Extend getTextureByteLength and avoid throwing when the size cannot be determined: - CompressedTexture: sum the mip-chain buffers already attached to the texture. - Unknown formats, missing images, or missing dimensions now return UNKNOWN_TEXTURE_BYTE_LENGTH (0) instead of raising. - ExternalTexture without a userData.byteLength falls back to the same unknown-size sentinel rather than silently taking the generic path.
gkjohnson
left a comment
There was a problem hiding this comment.
Thanks! I've made a couple comments - and we'll likely need to handle texture disposal correctly, too (see #1497 (comment))
|
Just trying to be extra careful to handle unexpected texture objects, but I can remove that if you think there's no need to. The |
…ovements # Conflicts: # src/three/renderer/utils/MemoryUtils.js
|
Thanks!
Disposal handling is that last step, I think. Let me know if there's anything I can help clarify on that.
I definitely understand the inclination but have found that in order to keep the code manageable, especially in javascript, it's best to assume that data is coming in well-shaped. Otherwise the amount of error handling and data checking will be a bit too much |
|
Thanks. I think registering dispose event handlers from Spark's glTF loader might be the right approach, but I'm not sure whether that should live in the loader or be left to the application. What do you think? Either way, I think that's independent of this PR. Here's a possible implementation: Ludicon/spark.js#31 |
getTextureByteLengthassumed thetexargument is a regular uncompressed texture backed by an image. When using compressed textures or external textures the code would throw an exception.This PR extends it to handle
CompressedTexture(summing the attached mip-chain buffers) andExternalTexture(readinguserData.byteLength), and returnsUNKNOWN_TEXTURE_BYTE_LENGTH(0) when the size can't be determined (missing image, missing dimensions, or unknown format) instead of throwing.Originally discussed in #1497; splitting out as a standalone fix with no Spark dependencies.