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

[Public WebGL] Move flipY and asPremultipliedAlpha parameters out of DOM helpers



On Thu, May 20, 2010 at 06:08, Gregg Tavares <gman@google.com> wrote:
> 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.

(new thread to discuss this particular issue and proposal below)

Do you suggest following signature ?

void texImage2D(GLenum target, GLint level, GLenum internalformat,
GLenum type, HTMLImageElement image, optional GLboolean flipY,
optional GLboolean asPremultipliedAlpha) raises(DOMException);

Makes sense I think. All parameters that cannot be inferred from the
DOM element are then made available to developer.

But I'll go a little farther and propose directly :

void texImage2D(GLenum target, GLint level, GLenum internalformat,
GLenum type, HTMLImageElement image) raises(DOMException);


After looking/playing with the DOM helper signature for a while I
believe that flipY and asPremultipliedAlpha should not be here :
- they are 'alien' to the standard texImage2D signature (one could
argue that this is the case for HTMLImageElement as well - but the
whole point for the helper signatures imho is to help treat the DOM
element parameter as if it was a proper *pixels pointer, this is
easily guessable too even without knowing WebGL but only OpenGL).
- behavior of flipY and asPremultipliedAlpha is not obvious when
reading code, those two booleans after 'element' cannot be guessed
without looking at documentation, worse, it is easy to forget or mix
the order of the two arguments and there won't be any error since both
orders are valid (true,false oops I meant false, true) ; this cannot
happen with the order of GLenum parameters in every other WebGL
function since validation is performed on them.
- if developer wants asPremultipliedAlpha but not flipY, flipY must be
set to false nevertheless, so activating one feature requires knowing
about the other..


In the same spirit of GL's GL_GENERATE_MIPMAP texture parameter, I
propose to remove these parameters from the helper signatures and have
these features activated to the currently bound texture through a
WebGL-specific texture parameter :

gl.TexParameteri(gl.TEXTURE_2D, WEBGL_DOM_FLIP_Y, true);

WEBGL_DOM_FLIP_Y
Specifies a boolean value that indicates if content loaded by a call
to texImage2D or texSubImage2D with a DOM element should be
automatically flipped vertically. The initial value is GL_FALSE.

and

gl.TexParameteri(gl.TEXTURE_2D, WEBGL_DOM_AS_PREMULTIPLIED_ALPHA, true);

WEBGL_AS_PREMULTIPLIED_ALPHA
Specifies a boolean value that indicates if content loaded by a call
to texImage2D or texSubImage2D with a DOM element should automatically
premultiply RGB with ALPHA. The initial value is GL_FALSE.


Advantages :
- simplifies common/frequent API texImage2D helper for _most_ users
(who likely won't need these features - is any current demo using
them?)
- leaves door open for addition of similar features (in core *or*
extensions) usable through the same model, without the usability
nightmare of requiring one new optional parameter every time (e.g
FLIP_X)
- code is more readable than 'true' or 'false', the behavior of the
parameter can be inferred by its name.


Regards,
-----------------------------------------------------------
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: