-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Texture compression #4758
Texture compression #4758
Conversation
Just document that these are not supported in the reference doc. Later, as the glTF spec for this stabilizes, we'll add whatever features we need to be fully conformant. |
Is the plan to also add ASTC to this PR? |
Source/Renderer/Context.js
Outdated
@@ -271,7 +271,10 @@ define([ | |||
this._depthTexture = !!getExtension(gl, ['WEBGL_depth_texture', 'WEBKIT_WEBGL_depth_texture']); | |||
this._textureFloat = !!getExtension(gl, ['OES_texture_float']); | |||
this._fragDepth = !!getExtension(gl, ['EXT_frag_depth']); | |||
this._debugShaders = getExtension(gl, ['WEBGL_debug_shaders']); | |||
this._debugShaders = !!getExtension(gl, ['WEBGL_debug_shaders']); | |||
this._s3tc = !!getExtension(gl, ['WEBGL_compressed_s3tc', 'MOZ_WEBGL_compressed_texture_s3tc', 'WEBKIT_WEBGL_compressed_texture_s3tc']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below, do you know if the 'MOZ_
and WEBKIT_
prefixes are in widespread use? If this is just for older browsers, we can drop them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the MOZ_
prefix, but the WEBKIT_
prefix was on the iPad I tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What the WEBKIT_
prefix the only option? If so, just leave these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it was the only one.
Source/Scene/Model.js
Outdated
@@ -1395,6 +1399,21 @@ define([ | |||
}; | |||
} | |||
|
|||
function ktxLoad(model, id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? Because of internalFormat
? Could this be combined with imageLoad
?
Can you please provide a summary of the current glTF changes you made, e.g., can now reference .ktx, how it works with binary glTF, how it works when embedded, etc.? |
Source/Core/loadKTX.js
Outdated
var endianness = view.getUint32(byteOffset, true); | ||
byteOffset += sizeOfUint32; | ||
if (endianness !== endiannessTest) { | ||
// TODO: Switch endianness? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually given how trivial this will be, I would just do it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to ignore this for now. I couldn't find a big endian file to test with without generating one from the same code. The KTX library has an issue to add tests as well: KhronosGroup/KTX-Software#26
var fakeXHR; | ||
|
||
beforeEach(function() { | ||
fakeXHR = jasmine.createSpyObj('XMLHttpRequest', ['send', 'open', 'setRequestHeader', 'abort', 'getAllResponseHeaders']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this copy and pasted a few times in the tests? Perhaps it should be a utility in the Specs
root directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, all of the load*
functions have similar tests. Since many of them are slightly different, I'm not going to do it in this PR.
@bagnell wow, this looks really good. Once we have the summary, #4758 (comment), I can start discussing with the glTF folks. |
I added it but couldn't test it. I have the extension on my Galaxy S6 but it isn't reported by WebGL Report. It also isn't on WebGL stats. Is it a draft extension? https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/ |
The KTX files must be a single 2D texture. The texture can be compressed or uncompressed. |
… them from KTX files.
6020a01
to
4cc7559
Compare
@pjcozzi This is ready for another look. I squashed the commits to remove all of the binary test data from the history during implementation. |
These three ShaderProgram tests fail in this branch and pass in master:
|
* @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} | ||
* @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} | ||
*/ | ||
function loadKTX(urlOrBuffer, headers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bagnell we should encourage users to use this broadly. What do you think about adding this to a Sandcastle example? Perhaps the materials one? Just use a small simple KTX file like the Cesium logo.
Source/Core/loadKTX.js
Outdated
texture = new Uint8Array(texture.buffer, 0, levelSize); | ||
} | ||
|
||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we document this type? Even if it is a trivial constructor + readonly properties?
I don't know if there is an easier way to document this (other than making the type) like how we can document callback functions.
} | ||
|
||
if (!PixelFormat.validate(glInternalFormat)) { | ||
throw new RuntimeError('glInternalFormat is not a valid format.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document all exceptions. Are you sure these are runtime errors? I think they are developer errors. For example: https://github.com/AnalyticalGraphicsInc/cesium/blob/3d-tiles/Source/Scene/Batched3DModel3DTileContent.js#L215
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't all file loading/parsing be a runtime error? The developer might not have control over the file. KML and GeoJSON work this way. Shouldn't parsing a 3D tile also throw runtime errors when they fail to parse?
Source/Core/loadKTX.js
Outdated
throw new RuntimeError('3D textures are unsupported.'); | ||
} | ||
|
||
// TODO: support texture arrays and cubemaps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the TODO
here and below, and just add bullets for the limitations to the reference doc.
Source/Core/loadKTX.js
Outdated
var bytesOfKeyValueByteSize = view.getUint32(byteOffset, true); | ||
byteOffset += sizeOfUint32; | ||
|
||
// TODO: read metadata? At least need to check for KTXorientation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TODO
as well.
@bagnell just those comments. Can you please also open a separate PR to merge this into |
Add crunch compressed texture support
* @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} | ||
* @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} | ||
*/ | ||
function loadCRN(urlOrBuffer, headers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to bump my question in the other PR about if we can implement some of these in terms of a generic @private
load*
function to avoid some duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep them separate. The only thing that is the same is checking if the parameter is a url or array buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
Sandcastle.declare(applyCompressedTextureMaterial); // For highlighting in Sandcastle. | ||
|
||
var compressedImageUrl; | ||
var context = scene.context; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context
is not part of the public API. You could expose these on Scene
or perhaps a scene.getTextureFormatSupported(String)
function. Whatever you think is clean.
Really nice job, just those comments @bagnell. We'll also have to park this PR while we work on the glTF spec, but this branch should come into master well before |
Related glTF Pipeline changes: CesiumGS/gltf-pipeline#204 |
@bagnell given that this is cleanly going into a glTF |
@pjcozzi This has been updated. Just waiting of the gltf-pipeline changes to generate the binary and embedded test models. |
@pjcozzi This is ready for another look. |
Source/Scene/Model.js
Outdated
@@ -1419,8 +1419,8 @@ define([ | |||
var gltfImage = images[textures[id].source]; | |||
var extras = gltfImage.extras; | |||
|
|||
var binary; | |||
var uri; | |||
var binary = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Also merged into |
Adds support for:
There are a few features of KTX files that I didn't implement, but if they are important I can add support in this PR:
TODO: