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

[Public WebGL] WebGL context resize / canvas redraw


context resize

I noticed some differences in the WebGL implementations in Webkit and Minefield.

When you resize the canvas the following instructions are enough to resize the 
rendering context in Webkit.

    canvas.width   = canvas.clientWidth;
    canvas.height  = canvas.clientHeight;
I think in Minefield you lose the shaders and other buffers because it only works
when I recreate the shader program and buffers. What behavior is supposed to
happen when you change the canvas size?

canvas redraw
What action triggers the compositing of the canvas on the screen? In Webkit I see 
the following problem. 

I have an WebGL canvas that is rendered once in the body.onload function and
also when you resize the browser window.

The first time the render is OK but when I push the reload button of the browser 
several times, sometimes the render appears and sometimes it does not. 
When you resize the window the render always appears.

  canvas.render = function()
    var gl = this.gl;
    var scene = this.scene;


    // Set the viewport
    gl.viewport(0, 0, this.width, this.height);
    gl.clearColor(0, 0, 0, 0);
    // Clear the canvas
    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

I found the following workaround. If I add the following line at the end of the
body.onload instead of calling the above render function. 

  window.setTimeout(window.onresize, 10);

Adding the following line doesn't work please explain.


Best regards,

Carl van Heezik