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

Re: [Public WebGL] Behavior of WebGL canvas when it can't make a backbuffer of the requested size?



Â

Regards

-Mark





On 10/11/2010 04:00, Vladimir Vukicevic wrote:

----- Original Message -----
One common pattern that I can see is:

  canvas.width = large_value;
  canvas.height = large_value;
  cx = canvas.getContext("webgl");
  size = cx.getDrawingBufferDimensions();
  if (size.width < canvas.width)
    canvas.width = size.width;
  if (size.height < canvas.height)
    canvas.height = size.height;

  The two .width/.height sets to size.* shouldn't cause a resize (since the backbuffer is already that size), and from that point on the developer can continue to use canvas.width/canvas.height just like they normally would have.  (Or just store the right values in local variables, to avoid having to get dom attributes for this!)

I think the above is by far the simplest thing to implement, describe, and use.  Let's say instead we went with throwing an exception:

ok = false;
desired_w = large_value;
desired_h = large_value;
while (!ok) {
  try {
    canvas.width = desired_w;
    canvas.height = desired_h;
  } catch (e) {
    // what now? You have no GL context yet, so can't query the viewport dimensions.  So..
    canvas.width = 1;
    canvas.height = 1;
    cx = canvas.getContext("webgl");
    new_dim = cx.getParameter(MAX_VIEWPORT_...);
    if (desired_w == new_dim) {
      alert("failed");
      break;
    }

    desired_w = new_dim;
    desired_h = new_dim;
  }
}

That's awful, and has zero advantages that I can see.
I agree the first looks easier.

I think WebGL needs to say something about the minimum required value of MAX_VIEWPORT_DIMENSION. The GL spec. says something like "it must be at least as large as the display". When written, display == device screen. As I pointed out the other day at the native level, you can't rely on this to tell you the maximum size of an FBO renderbuffer or texture render target. So if WebGL simply returns the native value, it is not useful for checking the maximum permissible size of the drawing buffer.

Regards

ÂÂÂ -Mark

begin:vcard
fn:Mark Callow
n:Callow;Mark
org:HI Corporation;Graphics Lab, Research & Development
adr:Higashiyama 1-4-4, Meguro-ku;;Meguro Higashiyama Bldg 5F;Tokyo;;153-0043;Japan
email;internet:callow_mark@hicorp.co.jp
title:Chief Architect
tel;work:+81 3 3710 9367 x228
tel;fax:+81 3 5773 8660
x-mozilla-html:TRUE
url:http://www.hicorp.co.jp,  http://www.mascotcapsule.com
version:2.1
end:vcard