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

[Public WebGL] Heads Up: WebGL API changes coming soon

Hi all,

The are two large changes that are coming to the public WebGL implementations fairly soon.  They involve enabling mandatory GLSL ES shader validation, and a change to the texImage2D API that takes a DOM object for data.  The bad news is that these changes will likely break all existing WebGL content.  The good news is that you can test code with these changes today, and that it's possible to write code such that it will work both before and after the changes.

== GLSL ES Shader Validation ==

The first change, mandatory GLSL ES shader validation.  Thanks to Google & Transgaming's efforts, the ANGLE project now implements a full GLSL ES shader parser, and performs the necessary translation to desktop GLSL.  The three public implementations are all using the same shader valiator, and it's already been integrated in such a way that it can be enabled for testing.  To do so:

  In Minefield/Firefox:
    - open about:config
    - change "webgl.shader_validator" from false to true

  In Chromium:
    - pass --enable-glsl-translator on the command line

  In WebKit:
    - instructions coming soon :)

The biggest impact of this change is that fragment shaders will have a mandatory precision specifier, as per the GLSL ES spec.  However, the precision specifier is invalid in desktop GLSL without a #version pragma.  So, a fix that will enable fragment shaders to work both with and without validation is to place:

  #ifdef GL_ES
  precision highp float;

at the start of every fragment shader.  The GL_ES define is not present on desktop, so that line is ignored; however it is present when running under validation, because the translator implements GLSL ES.  Note that the precision qualifiers will have no effect on the desktop (I believe they're just ignored by the translator), but may have an impact on mobile.  Note that the #ifdefs should be considered temporary here, as the correct/valid shader must include a precision qualifier.  If you wish you can also explicitly specify qualifiers on every float variable.

Another common problem is implicit type casting, as no such feature exists in GLSL ES.  Most commonly, floating point constants must be specified as floating point.  For example, the following will fail:

  float a = 1.0 * 2;
  vec3 v2 = v * 2;

The 2 must be written as "2.0" or float(2).

The shader validator will also impose additional spec issues that are sometimes ignored or relaxed by drivers.  The shader compilation log should provide the necessary information to fix these.

Should you run into GLSL ES programs that you believe are correct but that the shader validator is either rejecting or translating incorrectly, please report these!

== Obsolete TexImage2D API Removal ==

The second change is the removing of the now-obsolete form of texImage2D calls.  The WebGL spec originally had a form of texImage2D that looked like this (for HTMLImageElement and other DOM elements):

  texImage2D(target, level, HTMLImageElement, [optional] flipY, [optional] premultiplyAlpha)

This caused a number of problems once we looked at specifying what should happen when going from HTML image data to a texture given various source formats.  The new form of this call looks like the standard buffer-taking texImage2D call:

  texImage2D(target, level, internalformat, format, type, HTMLImageElement)

As described in the spec, the opaque image data provided by the DOM object will first be internally converted into the given format and type before being uploaded to GL.  Additionally, two new PixelStore parameters replace the previous optional flipY and premultiplyAlpha parameters:


More details on these can be found in the spec at https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/WebGL-spec.html#PIXEL_STORAGE_PARAMETERS .

Currently, all implementations support both the new form of this API call, as well as the old legacy form.  You should be able to change to the new form of the calls and have content continue to work on recent nightly builds of any implementation, with the obsolete form slated for removal shortly.

We expect that enabling shader validation and removing the obsolete texImage2D calls will happen simultaneously, and within the next two weeks.

    - Vlad
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: