[Public WebGL] WebGLArray iterator proposal

Kenneth Russell [email protected]
Sun Jan 10 01:25:02 PST 2010


A crucial piece you're missing is the fact that multiple WebGLArrays can
refer to the same region of memory. To do so, use the WebGL[T]Array
constructor taking a WebGLArrayBuffer. You can either create the
WebGLArrayBuffer separately, or fetch it from a previously created
WebGLArray.

To implement your first example, you would do something like

  var numVertices = 100; // for example
  var floatSize = gl.sizeInBytes(gl.FLOAT);
  var vertexSize = 3 * floatSize + 4 * gl.sizeInBytes(gl.UNSIGNED_BYTE);
  // Round up to sizeInBytes(gl.FLOAT) -- just in case it isn't 4 on some
platforms
  vertexSize = ((vertexSize + floatSize - 1) / floatSize) * floatSize;
  var vertexSizeInFloats = vertexSize / floatSize;
  var buf = new WebGLArrayBuffer(numVertices * vertexSize);
  var floatArray = new WebGLFloatArray(buf);
  var byteArray = new WebGLUnsignedByteArray(buf);
  var floatIdx = 0;
  // Set up the initial offset of the bytes within the vertex data
  var byteIdx = 3 * floatSize;
  for (var i = 0; i < numVertices; i++) {
    floatArray[floatIdx] = ...;
    floatArray[floatIdx + 1] = ...;
    floatArray[floatIdx + 2] = ...;
    byteArray[byteIdx] = ...;
    byteArray[byteIdx + 1] = ...;
    byteArray[byteIdx + 2] = ...;
    byteArray[byteIdx + 3] = ...;
    floatIdx += vertexSizeInFloats;
    byteIdx += vertexSize;
  }

We certainly need to provide examples of this. Right now I don't think there
are any examples of heterogeneous interleaved data in the demos.

You should be able to implement the sort of iterators you have in mind in
pure JavaScript, hiding these details from the casual programmer. Please
take another look at the spec and give it a try.

-Ken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://khronos.org/pipermail/public_webgl_khronos.org/attachments/20100110/93f27e9a/attachment.html>


More information about the public_webgl mailing list