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

Re: [Public WebGL] WebGL bufferSubData lacks "size" parameter





On Wed, Jan 11, 2012 at 6:32 PM, Mark Callow <callow_mark@hicorp.co.jp> wrote:
On 12/01/2012 05:00, Gregg Tavares (wrk) wrote:
   buf = new Uint8Array(1000);
   gl.bufferSubData(..., someOffset, new Uint8Array(buf, 123, 456));

Uploads 456 bytes of 'buf' starting at byte 123 to someOffset. As others have pointed out there is no copy. The second Uint8Array is just a view into buf.
It might not copy the data but it still generates garbage that has to be collected.

One of the design tenets from applications for previous 3D APIs I've worked with was avoid generating objects, that must be garbage collected, during the application's draw loop. With WebGL's avoidance of length parameters such avoidance is next to impossible. The reason it is bad is because eventually GC will run and the application will hiccup.

I too would like to see variations of the functions that take a source length parameter.

That's just a fact of life in _javascript_ land

A = 0;  // new object
A = 1 + 2;  // new object

A = 1; // new object
B = 2; // new object
C = A + B; // new object
C = A + 1; // new object
C = C + 1; // new object
C++; // new object

want proof

C = A + B;
C.foo = "hello"
console.log(C.foo);  // prints hello
C = A + 1;
console.log(C.foo);  // prints undefined
C.foo = "hello"
console.log(C.foo);  // prints hello
C = C + 1;  // new object
console.log(C.foo);  // prints undefined
C.foo = "hello";
console.log(C.foo);  // prints hello
C++;  // new object
console.log(C.foo);  // prints undefined

So you're not going to get away from object generation in your game loop in _javascript_.

On the other hand a good _javascript_ engine will of course look at your code and optimize away object generation where it can get away with it and it will similarly do the same for the gl.bufferSubData(..., ..., new Uint8Array(buf, offset, length));  Even if it didn't optimize that case if you've go enough calls to gl.bufferSubData in your main loop that object generation is a problem something else is probably wrong.





A good _javascript_ engine can 



 

Regards

    -Mark