So I decided to wait

Until webgl was more advanced, and I’m glad I did. The new Google Chrome Beta and Firefox Beta 7 are both amazingly good for webgl, and they now both support arraybuffers over xhr. Thanks to Alan Chaney for help with this.

function getDisplayable(disp) {
    disp.xhr.onreadystatechange = function() {
	if (disp.xhr.readyState == 4 && disp.xhr.status == 200
	    && disp.ready!=true) {
	    if (disp.xhr.responseType=="arraybuffer")
        else if (disp.xhr.mozResponseArrayBuffer != null)
        else if (disp.xhr.responseText != null ) {
	        var data = new String(disp.xhr.responseText);
		    var ary = new Array(data.length);
		    for (var i = 0; i <data.length; i++) 
                {ary[i] = data.charCodeAt(i) & 0xff;}
		    var uint8ay = new Uint8Array(ary); = uint8ay.buffer;
	}}"GET", disp.url, true);
        {disp.xhr.overrideMimeType('text/plain; charset=x-user-defined');}
This entry was posted in Uncategorized and tagged , , , , , , . Bookmark the permalink.

4 Responses to So I decided to wait

  1. Ram says:

    Hi! Great post.

    Can you fill me in on how exactly you got the returned binary data into a webGL buffer?
    I can get the buffer returned correctly when using xhr.response in Chrome, but I get errors when I try to use it as a GL buffer.

  2. disp.buffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, disp.buffer);
    gl.bufferData(gl.ARRAY_BUFFER,, gl.STATIC_DRAW);
    And then to draw
    gl.vertexAttribPointer(shader.variables[‘position’],3,gl.UNSIGNED_BYTE,gl.FALSE,6,0); and so on.

  3. Vjeux says:


    Thanks for the tip, I made a jQuery patch in order to use it more easily.

    Also you may want to take a look at a DataView wrapper I made to read binary files.

  4. Pingback: Javascript – jQuery Binary Ajax | Vjeux

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s