[Public WebGL] WebGLArray iterator proposal

Patrick Baggett [email protected]
Sun Jan 10 01:40:20 PST 2010


My understanding was that the constructors would create a copy of the
buffer:

5.13.3.1 Shared ConstructorsConstructor(array)
Create a new WebGL*TypeName*Array object with a new underlying
WebGLArrayBuffer large enough to hold the given data, then copy the passed
data into the buffer.

If so, that kills your example. =(

If not, I think the wording on 5.13.3.1 needs to be *seriously *changed.

Patrick Baggett

On Sun, Jan 10, 2010 at 3:25 AM, Kenneth Russell <[email protected]> wrote:

> 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/aa321cc5/attachment.html>


More information about the public_webgl mailing list