[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Public WebGL] Compressed texture support in WebGL 1.0.1




Today WebGL doesn't support compressed texture formats, as per section 6.16. But we do include the enumerants COMPRESSED_TEXTURE_FORMATS and NUM_COMPRESSED_TEXTURE_FORMATS, which always return 0. There is a proposed extension, WEBGL_texture_compression which aims at adding support. The issue with this extension is that it doesn't allow you to discover which of the several compressed texture formats are supported on the current hardware. There are several ways we could solve this:

1) Add compressedTexImage2D and compressedTexSubImage2D into the core 1.0.1 spec. Use the current COMPRESSED_TEXTURE_FORMATS enumerant to discover the set of supported formats.

	example:
		var formats = ctx.getParameter(ctx.COMPRESSED_TEXTURE_FORMATS);
		if (hasFormat(formats, "ETC1_RGB8_OES") // hasFormat is some local function that looks through the list for the desired format
			ctx.compressedTexImage2D(..., ctx.ETC1_RGB8_OES, ...);

2) The same as (1), but add one extension per compressed texture format (e.g, WEBGL_texture_compression_etc1, WEBGL_texture_compression_dxt1) to discover which formats are supported.

	example:
		var comp = ctx.getExtension("WEBGL_texture_compression_etc1");
		if (comp)
			ctx.compressedTexImage2D(..., comp.ETC1_RGB8_OES, ...);

3) Have one extension per compressed texture format as in (2), but put the compressedTexImage2D and compressedTexSubImage2D calls in the object returned for each extension. 

	example:
		var comp = ctx.getExtension("WEBGL_texture_compression_etc1");
		if (comp)
			comp.compressedTexImage2D(..., comp.ETC1_RGB8_OES, ...);

4) Have a single extension for compressed textures and use COMPRESSED_TEXTURE_FORMATS to discover support for a given texture

	example:
		var comp = ctx.getExtension("WEBGL_texture_compression");
		if (comp) {
			var formats = ctx.getParameter(ctx.COMPRESSED_TEXTURE_FORMATS);
			if (hasFormat(formats, "ETC1_RGB8_OES") // hasFormat is some local function that looks through the list for the desired format
				comp.compressedTexImage2D(..., comp.ETC1_RGB8_OES, ...);

5) The same as (4), but add a function to the extension to discover supported formats

	example:
		var comp = ctx.getExtension("WEBGL_texture_compression");
		if (comp) {
			if (comp.compressedTexSupported("ETC1_RGB8_OES")
				comp.compressedTexImage2D(..., comp.ETC1_RGB8_OES, ...);

I prefer (5) since it puts all the functionality into the extension and doesn't require that anything be added to the current spec. Tim will argue that this gives authors a different way to discover which formats are supported from discovering whether or not compressed textures are supported at all. But I don't think that's a bad thing. You're asking WebGL whether or not it supports the concept of compressed textures, but you're asking the extension itself for details about that support. This sort of hierarchical approach will make it much easier to pull this functionality into the core when it comes time.

I really dislike the idea of one extension per format because it pollutes the extension namespace the worst. So I like (2) and (3) the least. I also don't like the idea of using the COMPRESSED_TEXTURE_FORMATS, since it adds functionality to the core spec. For that same reason, I dislike (1) and (2). 

I really think we need to finish the 1.0.1 spec, so I think we need to stop adding API. Adding is getShaderPrecisionFormat() is an unfortunate, but I believe necessary exception to this. But I think the compressed texture functions can easily stay in an extension for now. When it comes time to pull this extension into the core (1.1, 1.2, 2.0 ?) then we can just pull in the 3 calls that make up the extension.

We really should think about how we bring this into the core when it comes time. If you look at approach (2) you have:

		var comp = ctx.getExtension("WEBGL_texture_compression_etc1");
		if (comp)
			ctx.compressedTexImage2D(..., comp.ETC1_RGB8_OES, ...);

when brought into the core, how do you discover support for a given texture format? Presumably you'd use the existing COMPRESSED_TEXTURE_FORMATS mechanism, so you'd basically switch over to example (1):

		var formats = ctx.getParameter(ctx.COMPRESSED_TEXTURE_FORMATS);
		if (hasFormat(formats, "ETC1_RGB8_OES") // hasFormat is some local function that looks through the list for the desired format
			ctx.compressedTexImage2D(..., ctx.ETC1_RGB8_OES, ...);

which isn't bad, except that it's a completely different technique, one in which we suddenly start using a dormant core feature, which feels weird. For approach (5), you have:

		var comp = ctx.getExtension("WEBGL_texture_compression");
		if (comp) {
			if (comp.compressedTexSupported("ETC1_RGB8_OES")
				comp.compressedTexImage2D(..., comp.ETC1_RGB8_OES, ...);

when it comes time to move it into the core, you simply add the 3 functions from the extensions and are left with:

		if (ctx.compressedTexSupported("ETC1_RGB8_OES")
			ctx.compressedTexImage2D(..., ctx.ETC1_RGB8_OES, ...);

which is the same technique, just without the getExtension call. That seems much cleaner to me.

-----
~Chris
cmarrin@apple.com





-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl
-----------------------------------------------------------