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

Re: [Public WebGL] Adding internalformat param to all texImage2d variants

On Wed, May 19, 2010 at 10:47 AM, Chris Marrin <cmarrin@apple.com> wrote:

On May 19, 2010, at 10:36 AM, Gregg Tavares wrote:

> ...I'm not sure how it's any more alien than flipy and premultipliedAlpha. We might as well argue that naming these functions texImage2D is inappropriate. Perhaps it would be better to have conversion functions that take in one of the image element types and the convertTo, flipy and premultipliedAlpha params and return a filled in ArrayBuffer. I don't particularly like that idea because it would not allow optimizations that might be possible on some platforms, such as directly writing the image to GPU memory using some non-OpenGL mechanism.
> Personally I think this is the better solution.
> We're trying to add all kinds of conversion stuff to texImage2D that may or may not make sense.
> How do the types UNSIGNED_SHORT_5_6_5, UNSIGNED_SHORT_4_4_4_4 and UNSIGNED_SHORT_5_5_5_1 fit into these conversions? For example one of the arguments for supporting conversion to LUMINANCE and ALPHA formats was space savings but if that's the argument for supporting conversions then it applies to these types as well.

> It really seems all this conversion belongs outside of texImage2D.  add ArrayBuffer ctx.convertTo(img, format, ....) or something like that.

First, let me note that these formats are not supported in the OpeGL ES 2.0, nor will they be supported in WebGL 1.0.

All of those formats ARE supported in OpenGL ES 2.0 and in WebGL. There are even conformance tests for them.

There's a bigger problem though.

In OpenGL (not ES) the 3 parameters, internalFormat, format and type.

internalFormat specifies the internal format. The format of the texture texImage2D will create.

format and type specify in source format. The format of the data being passed in to texImage2D.

In OpenGL ES 2.0 these are conflated. type specifies BOTH the internal and source formats.

To see where this happens see http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt

In OpenGL to make a floating point texture you do

glTexImage2D(GL_TEXURE_2D, level, GL_RGBA32F_ARB, width, height, border, GL_RGBA, GL_UNSIGNED_BYTE, data);

The final format, floating point RGBA is completely separate from the input format.

In OpenGL ES 2.0 though these are conflated. Since it assumes no conversions. To make a floating point texture there you do

glTexImage2D(GL_TEXURE_2D, level, GL_RGBA width, height, border, GL_RGBA, GL_FLOAT, data);

The OpenGL way is far more flexible than the OpenGL ES way. It seems like we should take some inspiration from there which will leave things open for more conversions such has IMG -> 5_6_5 or IMG->4_4_4_4 etc instead of just IMG to only 8 bit formats.

But supporting these formats in the future seems like a perfect reason to keep the conversion in texImage2D. Requiring the data to be placed in a ArrayBuffer takes away the opportunity to optimize the conversions to these formats. What if your graphics hardware had the ability to convert RGB888 to RGB565? If you had to put the result in an ArrayBuffer on the CPU, you couldn't use that hardware, or at best you would have to do a slow GPU to CPU copy.