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

Re: [Public WebGL] Proposed change to WebGL Event definition




On Aug 20, 2010, at 8:35 PM, Cedric Vivier wrote:

On Sat, Aug 21, 2010 at 00:57, Chris Marrin <cmarrin@apple.com> wrote:
Currently the spec shows two event interfaces: WebGLContextLostEvent and WebGLContextRestoredEvent. Other Event generators in HTML tend to use a single Event object with many event types. For instance, there is a MouseEvent object with event types like "click", "mousedown", "mouseup", etc.


Looks good but I think event type and status code should be separated into two different fields.
Consider using one handler for all three events, the context creation error case would require 3 comparisons instead of one, it's confusing and error-prone (easy to forget one) when you only care about context creation error itself.

unsigned short type - one of CONTEXT_LOST, CONTEXT_RESTORED or CONTEXT_ERROR
unsigned short statusCode - when type is CONTEXT_ERROR, one of NOT_AVAILABLE, NOT_ENABLED or OTHER_ERROR

In DOM events the type is always the DOMString of the event type (e.g., "webglcontextlost"), so you do get what you're looking for, right?



CONTEXT_ERROR wording has the advantage of being a little bit more general than creation-time only error. For instance such error event could be raised when a context could not be restored or the user just disabled WebGL.

Yes, we could make the names more general.


Having a separate statusCode also has the advantage that we can use the same organization wrt statusCode to deliver advanced status information about context loss/restoration in a future revision of the spec where we might support partial context restoration (eg. statusCode PARTIAL vs FULL, we discussed this few months ago, case where some GL resources are still available thus it's not necessary to re-upload everything).

There is a separate status code. You don't see the 'type' property in the WebGLContextEvent is because it's in the parent Event interface.

-----
~Chris