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

Re: [Public WebGL] Extension mechanism for WebGL



On Thu, Feb 11, 2010 at 4:47 PM, Chris Marrin <cmarrin@apple.com> wrote:
>
> We decided at the F2F to add an extension mechanism. Even though we don't plan on having any extensions included in the first release it was believed that it will give browser vendors a standard way to add extensions as needed.
>
> There are a few illustrative examples of existing OpenGL ES 2.0 extensions. One is OES_texture_float (http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt). This extension provides no new function calls and no new enums. It simply allows data of type FLOAT to be passed to texImage2D. Another is OES_point_sprite (http://www.khronos.org/registry/gles/extensions/OES/OES_point_sprite.txt), which adds no new functions, but has a couple of new enums. The last is OES_texture_3D (http://www.khronos.org/registry/gles/extensions/OES/OES_texture_3D.txt), which has both new functions and enums.
>
> There are 3 steps to using an extension: discovery, enabling and access. There are a few ways to do discovery:
>
> - Provide a call to return a list of all supported extensions.
>
> -  Provide a call that returns true or false given an extension string.
>
> -  Provide no way to do discovery, simply fail when an attempt is made to access the extension.
>
> We've decided that we want to disallow the use of an extension unless it is enabled. So an enable API is needed. This could be explicit (enableExtension(name)) or implicit in the attempt to access the extension.
>
> The last step is access. There are a couple of choices here as well:
>
> 1) Have the enums and API calls part of the returned context, using the OpenGL mechanism of adding a suffix to them to disambiguate the namespace. So, for instance:
>
>        var context.haveTex3D = context.enableExtension("OES_texture_3D")
>        if (context.haveTex3D)
>                context.texSubImage3DOES(context.TEXTURE_3D_OES, ...);
>
>
> , context.TEXTURE_3D_OES would be an enum name and context.texSubImage3DOES() would be a function call. The function call would throw if an attempt is made to use it without first calling an enableExtension(name) method.
>
> 2) Add a getExtension(name) method and have it return a new object which would contain any enums or API calls in the extension. For instance:
>
>        context.tex3D = context.getExtension("OES_texture_3D");
>        if (context.tex3D)
>                context.tex3D.texSubImage3D(context.tex3D.TEXTURE_3D, ...);
>
> Both of these options assume that enabling and detecting the presence of an extension are included in the call (enableExtension in the first case, getExtension in the second). We could still provide an explicit hasExtension(name) or getExtensionList() call. But I don't think it adds any value.
>
> I prefer choice (2) because:
>
> a) It allows us to express each extension as a standalone WebIDL interface rather than snippets to be added to the context.
>
> b) It uses the object oriented mechanisms at our disposal for disambiguation of names rather than "C style" name mangling.
>
> c) It avoids the problem of "undocumented" property pollution of the WebGLRenderingContext. What if the user places a property on the context object. They have chosen a property name that is not in the WebGL spec, so it seems safe. But if that name clashes with a name used by an extension then behavior will be different depending on whether or not an implementation has that extension and how it is implemented.
>
> Other comments?

I prefer choice (2) as well for all of the reasons you mention above.

I believe it would also work better if a WebGL binding to a statically
typed language such as Java is ever created. In such an environment it
is undesirable to have methods disappear on a class such as
WebGLRenderingContext, which would occur if a user's newer code were
run on an older browser that doesn't yet declare a particular
extension's entry points.

-Ken

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