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

Re: [Public WebGL] Buffer size and viewport

On Jun 7, 2010, at 8:14 AM, Alan Chaney wrote:

> Hi
> Desktop GL programming frequently requires that the user sets the window size as part of the game/application setup. This means that normally the viewport can be set to (0, 0, displaybufferwidth, displaybufferheight). However, in a WebGL application it is likely to be very common that the window size will change due to use input.
> The default with WebGL is to set the buffer size to that of the canvas element and the viewport to that as well. This means that if the window is resized to greater dimensions than the original canvas size the display buffer must be discarded and a new buffer initialized - this takes time. One option that I can see is to make the display buffer considerably bigger than the canvas element - perhaps by doing some calculation based upon my UI layout and the underlying screen size and setting this value when creating the context.
> Then as the canvas is resized  I simply set the viewport size to match the size of the canvas element, until, of course, it exceeds the underlying buffer size.
> Does anyone have any feel to the relationship between viewport size and buffer size and performance? In other words, if I allocate a larger buffer than I actually display in the view port, is this likely to cause a significant performance issue?

I'm not sure what the issue is here. The width and height of the Canvas are attributes of the Canvas element. As such there is no "automatic" way to change them. For instance, if you wanted to change the Canvas size when the user resized the window, you'd have to listen for Window size changes and then use JS to set the size attributes on the Canvas. So you have complete control over when and if you change the size and force the expensive reinitialization. I think there will be many games which use fixed size Canvases so there will not be an issue. You could also delay the Canvas resize to let the use settle on a new window size before changing the Canvas size. Incidentally, you can change the apparent Canvas size by setting it's CSS width and height properties. This will scale the Canvas to fit that width and height and will not reinitialize the Canvas. You could use this scaling while the user is resizing the Window and then resize the Canvas itself a few seconds after the resizing is done. 


You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email: