Skip to content

Commit

Permalink
smaller footprint webgl feature test, recomended by chrome webgl team.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Jan 26, 2011
1 parent cfa986b commit 9c0ca33
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,7 @@ window.Modernizr = (function(window,document,undefined){


tests['webgl'] = function(){

var elem = document.createElement( 'canvas' );

try {
if (elem.getContext('webgl')){ return true; }
} catch(e){ }

try {
if (elem.getContext('experimental-webgl')){ return true; }
} catch(e){ }

return false;
return !!window.WebGLRenderingContext;
};

/*
Expand Down

8 comments on commit 9c0ca33

@paulirish
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are more details on this test from one of chrome's webgl engineers:

calling canvas.getContext("webgl") does not tell you WebGL is going to succeed either. Your feature detection library might succeed with a 1x1 pixel canvas but the actual page might fail with 1024x1024 canvas with the default anti-aliasing on which takes a lot more memory. You don't know if it's going to succeed until you give it the same parameters the page is going to eventually give it.

A 1024x1024 webgl canvas is

  • 1024x1024x4 color
  • 1024x1024x4 depth
  • 1024x1024x4x4 multi-sample buffer.
  • 2-3 meg for GL/context state.

That's 4+4+16+2 or 24meg minimum.

There's also another problem. We are limiting the number of contexts that can be active. When we hit the limit we will unload a context. So your throw away canvas.getContext call will basically make pages swap even if you don't intend to use the context.

Sorry, I wish I knew an easy answer.

just for reference.

@KuraFire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I have it straight: the new window.WebGLRenderingContext is more reliable, yes? Does it init a context (and make pages swap), or not?

@paulirish
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less reliable as it doesnt init a context.

But less crashy and much faster and doesnt use up 4mb of memory that the normal one does.

So.. currently it's a hint that there may be native support.

And.... that's probably the best we can do for now.

@ryanseddon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about returning "maybe" if that test passes, much like the video codec support works?

@KuraFire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea, Ryan. I'm fine with this being the best we can do for now, even if "for now" ends up being a long-term case. Returning "maybe" sounds great to me because it allows you to decide whether or not to do more determinate testing if you plan to actually use WebGL—which you should do in that case anyway—but it won't interfere or cause unwanted side-effects for all other situations.

@SlexAxton
Copy link
Member

@SlexAxton SlexAxton commented on 9c0ca33 Jun 1, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanseddon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does both I believe, "probably" if it's more confident, and "maybe" if it might be supported.

@paulirish
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think slex was just clarifying the semantics of the possible choices. :) from my experience the canPlayType() api returns probably if it would normally be a maybe but you also specified the codecs...

maybe there is an additional weak test we could do in the future... so thus we'd want to start out with maybe

maybe...

;)

Please sign in to comment.