-
Notifications
You must be signed in to change notification settings - Fork 72
greggman merges #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The original code setup to user properties on the WebGLRenderingContext call `gl.viewportWidth` and `gl.viewportHeight`. The issue with these are (1) they end up looking like part of the WebGL spec which is confusing for new users and (2) they are not live so they need to be updated if the canvas changes size. Instead I changed them to `gl.canvas.width` and `gl.canvas.height` where appropriate. Also for the perspective matrix I changed them to `gl.canvas.clientWidth` and `gl.canvas.clientHeight` which means they'll be correct even if the display size of the canvas does not match the size of the canvas' backing store. For example if the canvas is sized using CSS.
The examples were using
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
Which is out-dated. Any browser that supports WebGL supports the newer way.
It's also not very socially aware as it's English only.
Changed to
<meta charset="utf-8">
Which is the modern way as of like 6 years ago and is also internationally
friendly.
1. Got rid of setInterval which is considered bad practice as
it DOSes the user's machine
2. Initialized textured to avoid warning.
Because images are loaded asynchronously and the code does not wait
for the image to load it can start rendering before the image has been
downloaded. In that case a rendering warning appears.
[.WebGLRenderingContext]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering or is not 'texture complete'
Initializing the texture to a single pixel means the code and render with
no warnings and the texture will be uploaded if and when the image is
finally downloaded.
The problem with putting properties on WebGLObjects is your app
will crash if you ever decide to handle WebGLContextLost events.
The reason is all of the gl.createXXX functions will return null
and so code like this
var buffer = gl.createBuffer();
buffer.itemSize = 3;
Will crash because buffer will be null. The simplest solution
is to use JavaScript objects. So for example instead of
var buffer = gl.createBuffer();
buffer.itemSize = 3;
gl.bindBuffer(..., buffer);
We can change it to
var buffer = { id: gl.createBuffer(); };
buffer.itemSize = 3;
gl.bindBuffer(..., buffer.id);
That at least is future proof code.
Stop putting properties on WebGLObjects
Change to utf-8
Remove gl.viewportWidth and gl.viewportHeight
Conflicts: example03/particles-01-noenable.html example03/particles-01.html example03/particles-02.html example03/particles-03.html
All images load asynchronously which means either you should not start rendering until they are loaded or else you need to put something in the textures so you can render immediately. This patch initializes all textures to a 1x1 pixel blue texture. When the image finishes loading the code replaces that contents of that texture with the image. Until then it's free to render with the one pixel texture This gets rid of the rendering warnings from the browser in the JavaScript console.
Fix all image to texture loading to not generate warnings
|
This looks good. I've been learning/following the tutorials and upgrading gl-matrix in each, but this PR makes many more improvements. It seems like the tutorials would need to be updated as well though - perhaps that could be a group effort if the HTML for those are available to be posted? Also - I noticed that, after upgrading gl-matrix to the latest version, the Z-axis translations are much further away than in the original examples. Is that an issue with the old version of gl-matrix? |
|
Hi Brian, Not sure about the Z-axis issues. I will definitely be posting something to the site soon about the upgrade. I was planning on editing the HTML myself but that's a great idea to crowdsource it! I'm slammed this week with conferences but we should talk about this next week. Where are you located? Tony |
|
@tparisi I'm currently in the North East US - let me know when you're thinking for next week and we can set it up. |
No description provided.