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

[Public WebGL] Spec Comments

I skimmed the spec and here's some random comments I hope are useful.

Section 2.2: The Drawing Buffer

Which image do toDataURL and drawImage use? The spec talks about "WebGL presents its drawing buffer to the HTML page compositor immediately before a compositing operation, but only if the drawing buffer has been modified since the last compositing operation."  It's not obvious from the spec if toDataURL and drawImage also get the result of all draw commands or only the last image available to the page compositor.

Section 3: WebGL Resources

Maybe this should go under losing the context but it seems like the spec should say that

If the OpenGL context is lost, all WebGLObjects that were created from that context are invalid and what that means in terms of ctx.bindXXX and functions related to setting the state of those objects.

Section 4.1: WebGLArrayBuffer

Should we choose 1 way to handle accessing out of range values?  Or can we at least make it consistent from a programming point of view? I think the idea was that some systems can enforce this in hardware so we didn't want to dictate a solution. In that case it seems the spec should say disallow throwing an exception so that from the programmers point of view he doesn't have to put try {} catch {} around every access if he's excepting user data. 

Section 4.2: Resource restrictions.

Similar to 4.1 ... for drawArrrays and drawElements the spec should state whether all implementations are required to generate an error or required to NOT generate an error regardless of how they enforce the restrictions.

Section 5.2.1

premultipliedAlpha  This currently specifies stuff about page composition. Does this setting effect canvas.toDataURL or canvas2Dcontext.drawImage(canvas3d)?  Given that they all seem easily related at an implementation level, it seems like the spec should be explicit about this.

5.15.8 Texture Objects

OpenGL ES 2.0 has the idea of default textures. There is a default 2D texture and a default 3D texture.  Both textures can be modified as in

glBindTexture(GL_TEXTURE_2D, 0);
glTexImage2D(GL_TEXTURE_2D, 4, 4, etc.....);

Should the WebGL spec be changed to be the same as OpenGL?  For example the OpenGL ES 2.0 conformance tests require this behavior. And I know I've personally used it in my OpenGL programs by setting the default to 1,0,1,1 and then if I see any magenta in my scene I know I forgot something.

Right now WebGL explicitly generates INVALID_OPERATION if no texture is bound or if any texture functions are called after ctx.bindTexture(GL_TEXTURE_2D, null).  It seems like WebGL should be the same as OpenGL here. 

5.15.3 getParameter

The spec should probably be explicit whether ctx.getParameter(ctx.TEXTURE_BINDING_2D) and similar texture related enums should return null or a WebGLTexture for the default texture (id = 0). I'd pick null I think.

5.15.10 getActiveAttrib and getActiveUniform

getActiveAttrib and getActiveUniform need to do something that will not fail cause a program to have an exception when the context is lost. If null is returned then any code that does

info = ctx.getActiveAttrib(...);

Will fail with an exception during context lost.  Either that or it seems like we need to put a big warning that doing this

info = ctx.getActiveAttrib(indexKnowExistsInMyShader);

is discouraged and that instead all returns from ctx.getActiveAttrib and ctx.getUniformAttrib must be checked for null.

var numAttribs = ctx.getProgramParameter(prg, gtx.NUM_ATTRIBS);
for (var ii = 0; ii < numAttibs; ++ii) {
   var info = gtx.getActiveAttrib(prg, ii);
   if (info) {    // This check must be here so that a program doesn't stop executing do to JS exception during lost context.
      // work with info.

5.15.10 uniformXXX

Assuming we stick to the OpenGL ES spec, all the uniform functions need to silently do nothing if location is null

5.15.12 ReadPixels

The spec needs to specify that out of range pixels must be 0,0,0,0 and that a lost context will still return a pixels, all of which are 0,0,0,0

5.15.14 extension strings case-insensitive? 

The spec here is unclear. It seems like what it means to say is extension strings passed to getExtension are case-insensitive. What it currently says suggests that the strings passed back by getSupportedExtensions() are case-insensitive which suggests something like this would be possible.

var extensions = ctx.getSupportedExtensions();
if (extensions["SoMeRaNdOmExTeNtIoN") !== undefined) {
  // this extension exists.

This that really the intended behavior? There's some special CaseInsensitiveString objects passed back from getSupportedExtensions?

As it is, it also suggests that some implementations can return "floating_point_texture_extension" and others can return "Floating_Point_Texture_Extension" and that code that does this

if (extension["floating_point_texture_extensions"))

will not work and instead the user has to do this

for (var ii = 0; ii < extensions.length; ++ii) {
   if (extension[ii].tolower() == "floating_point_texture_extensions") {

It seems like they should be case-sensitive which avoids all of these issues.

5.16 Lost context

We still haven't decided how context lost is handed. Assuming it's handled as written, it seems like the spec needs to point out that a context can be lost BEFORE the WebGLContextLostEvent is delivered and that all WebGLObjects created in the context that was lost are invalid.

Polling for context.resetContext() == true seems bad so it still seems like we need either WebGLContextRestored or WebGLContextResetable. I'd prefer if my hidden tab on my smartphone was not running _javascript_ trying to restore itself constantly. Developers won't choose polling every 500ms because if they do their app, when brought to the foreground, will sit there doing nothing for 1/2 a second. More likely they'll choose 1ms to get the fastest response.

Also, all get functions, getParamter, getProgramiv, getFramebuffer???, getUniform, getVertexAttrib etc need to be speced what they will return for each pname with a lost context

This is important for the same reason as getActiveAttrib above.

var v = ctx.getVertexAttrib(12, ctx.CURRENT_VERTEX_ATTRIB);
var b = v[0] * v[1]; // This line will stop execution because of a JS exception
                          // if getVertexAttrib does not return a 4 element array with a lost context.

The spec already says that ctx.getVertexAttrib with ctx.CURRENT_VERTEX_ATTRIB will return a WebGLFloatArray with 4 elements. What it doesn't say is what values will be in those 4 elements during a lost context.

It needs to be spelled out what various functions do like ctx.createBuffer, etc do with a lost context.