WebGL
Khronos
 

WebGL WEBGL_subscribe_uniform Extension Rejected Specification

Name

WEBGL_subscribe_uniform

Contact

WebGL working group (public_webgl 'at' khronos.org)

Contributors

Owen Glofcheski, Google

Members of the WebGL working group

Version

Last modified date: April 14, 2016
Revision: 2

Number

WebGL extension #NN

Dependencies

Written against the WebGL API 1.0 specification.

Overview

This extension exposes the ability to subscribe to a set of uniform targets which can be used to populate uniforms within shader programs. This extension is generic, but currently only supports mouse position as a subscription target.

Background:

The depth of the web pipeline makes it difficult to support low latency interaction as event information retrieved via javascript is outdated by the time it's displayed to clients. By populating event information later in the pipeline one can reduce perceived input latency.

This extension creates a new buffer type 'Valuebuffer' to maintain the active state for predefined subscription targets. Since a mechanism for buffering uniform information isn't available pre 2.0 (UBOs) an additional data type was needed. See 'New Types' for additional information.

When this extension is enabled:

IDL

[NoInterfaceObject]
interface WEBGL_subscribe_uniform {
  const GLenum SUBSCRIBED_VALUES_BUFFER = 0x924B;

  // subscription targets
  const GLenum MOUSE_POSITION = 0x924C;

  WebGLValuebuffer? createValuebuffer();
  void deleteValuebuffer(WebGLValuebuffer? buffer);
  void isValuebuffer(WebGLValuebuffer? buffer);
  void bindValuebuffer(GLenum target, WebGLValuebuffer? buffer);

  void subscribeValue(GLenum traget, GLenum subscription);
  void populateSubscribedValues(GLenum target);
  void uniformValuebuffer(WebGLUniformLocation? location, GLenum target, GLenum subscription);
}; // interface WEBGL_subscribe_uniform
  

New Functions

WebGLValuebuffer createValuebuffer()
Creates and returns a Valuebuffer object.
void deleteValuebuffer(WebGLValuebuffer buffer)
Deletes a Valuebuffer object.
bool isValuebuffer(WebGLValuebuffer buffer)
Returns whether an object is a Valuebuffer object.
void bindValuebuffer(GLenum target, WebGLValuebuffer buffer)
Lets you use a named Valuebuffer object.
void subscribeValuebuffer(GLenum target, GLenum subscription)
Subscribes the currently bound Valuebuffer object to a subscription target.
void populateSubscribedValues(GLenum target)
Populates the currently bound Valuebuffer object with the state of the subscriptions to which it is subscribed.
void uniformValuebuffer(WebGLUniformLocation location, GLenum target, GLenum subscription)
Modifies the value of a uniform variable or uniform variable array using the state of the subscription target in the currently bound Valuebuffer object.

New Types

A Valuebuffer abstracts the mapping of subscription targets to internal state and acts as a single storage object for subscription information (e.g. current mouse position). Clients can then use the objects data to populate uniform variables.

Post WebGL API 2.0, this abstraction could exist as a layer ontop of UBOs which managers the mapping of subscription targets to internal state and the mapping of subscription targets to offsets within the buffer. The UBO would be used to store the active buffer state as well as the uniform location mapping. Clients would be required to state all their subscription targets at once to allocate the appropriate amount of memory. Aside from this small change the implementation is essentially the same, with UBOs replacing Valuebuffers and relevant create, delete, bind methods being replaced. Additionally, the inclusion of UBOs would replace the need for uniformValueBuffer(...).

[NoInterfaceObject]
interface WebGLValuebuffer {
};

This interface is used to maintain a reference to internal Valuebuffer subscription states.

New Tokens

any bindValuebuffer(GLenum target, WebGLValuebuffer buffer)

SUBSCRIBED_VALUES_BUFFER is accepted as the target parameter to bindValuebuffer

void subscribeValuebuffer(GLenum target, GLenum subscription)

SUBSCRIBED_VALUES_BUFFER is accepted as the target parameter to subscribeValuebuffer

MOUSE_POSITION is accepted as the subscription parameter to subscribeValuebuffer

void populateSubscribedValues(GLenum target)

SUBSCRIBED_VALUES_BUFFER is accepted as the target parameter to populateSubscribedValues

void uniformValuebuffer(WebGLUniformLocation location, GLenum target, GLenum subscription)

SUBSCRIBED_VALUES_BUFFER is accepted as the target parameter to uniformValuebuffer

MOUSE_POSITION is accepted as the subscription parameter to uniformValuebuffer

Sample Code

<script id="vshader" type="x-shader/x-vertex">
  uniform ivec2 uMousePosition;

  void main()
  {
    gl_Position = vec4(uMousePosition, 0, 1);
  }
</script>

function init(gl) {
  shader.uMousePosition = gl.getUniformLocation(shader, "uMousePosition");
  ...

  var ext = gl.getExtension('WEBGL_subscribe_uniform');
    
  // Create the value buffer and subscribe.
  var valuebuffer = ext.createValuebuffer();
  ext.bindValuebuffer(SUBSCRIBED_VALUES_BUFFER, valuebuffer);
  ext.subscribeValue(MOUSE_POSITION);
  ...
}
     
function draw(gl) {   
  // Populate buffer and populate uniform
  ext.bindValuebuffer(SUBSCRIBED_VALUES_BUFFER, valuebuffer);
  ext.populateSubscribedValues(SUBSCRIBED_VALUES_BUFFER);
  ext.uniformValuebuffer(shader.uMousePosition,
                         SUBSCRIBED_VALUES_BUFFER,
                         MOUSE_POSITION);

  gl.drawElements(...);
}
  

Issues

Revision History

Revision 1, 2014/11/13

Revision 2, 2016/04/14