webgl-tools
diff sanegl.js @ 3:56ae66e32998
glass.js:
- added set_uniform1i
sanegl.js:
- GL_QUAD handling was broken
- added gluPerspective
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 18 Jun 2011 05:13:01 +0300 |
parents | 9eb4c37ce415 |
children | b215a8d38818 |
line diff
1.1 --- a/sanegl.js Thu Jun 16 07:13:20 2011 +0300 1.2 +++ b/sanegl.js Sat Jun 18 05:13:01 2011 +0300 1.3 @@ -31,8 +31,7 @@ 1.4 [new Float32Array(gl_ident_val)], 1.5 [new Float32Array(gl_ident_val)]); 1.6 1.7 -/* XXX change after debugging */ 1.8 -const GL_MAX_VERTS = 32; 1.9 +const GL_MAX_VERTS = 512; 1.10 1.11 var gl_prim = 0; 1.12 var gl_vbuf = null, gl_nbuf = null, gl_cbuf = null, gl_tbuf = null; 1.13 @@ -156,6 +155,12 @@ 1.14 glMultMatrixf(xform); 1.15 } 1.16 1.17 +function gluPerspective(vfov, aspect, near, far) 1.18 +{ 1.19 + var x = near * Math.tan(vfov / 2.0); 1.20 + glFrustum(-aspect * x, aspect * x, -x, x, near, far); 1.21 +} 1.22 + 1.23 function gl_apply_xform(prog) 1.24 { 1.25 var mvtop = gl_mat[GL_MODELVIEW].length - 1; 1.26 @@ -383,7 +388,17 @@ 1.27 } 1.28 1.29 gl_vert_calls++; 1.30 - if(++gl_nverts >= GL_MAX_VERTS) { 1.31 + gl_nverts++; 1.32 + 1.33 + var buffer_full; 1.34 + if(gl_prim == GL_QUADS) { 1.35 + /* leave space for 6 more worst-case and don't allow flushes mid-quad */ 1.36 + buffer_full = gl_nverts >= GL_MAX_VERTS - 6 && gl_vert_calls % 4 == 0; 1.37 + } else { 1.38 + buffer_full = gl_nverts >= GL_MAX_VERTS - gl_prim; 1.39 + } 1.40 + 1.41 + if(buffer_full) { 1.42 gl_draw_immediate(); 1.43 glBegin(gl_prim); /* reset everything */ 1.44 }