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

Re: [Public WebGL] Re: WEBGL_get_buffer_sub_data_async



I guess you're suggesting this right?

var ext = gl.getExtension('WEBGL_get_buffer_sub_data_async');
var buffer = new Float32Array(1234);
var sync = null;

function readBuffer(){
    extension.getBufferSubDataAsync(target, 0, buffer);
    if(sync !== null){
      gl.deleteSync(sync);
    }
    sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE);
}

function bufferReady(){
   return gl.clientWaitSync(sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0) != gl.TIMEOUT_EXPIRED
}

readBuffer();
function raf(){
    if(bufferReady()){
      doSomethingWithData();
      readBuffer();
    }
    requestAnimationFrame(raf);  
}
raf();

I think I'd have reservations about it because you cannot pre-allocate the list of sync objects you'd wish to use, and because in WebGL they're unfortunately JS objects (and not integers) you need to store them in an Array rather than a TypedArray, which means that you'll end up setting list entries all the time (or even worse resizing lists with push/unshift). Other than that, I don't think there's anything wrong with that.