webgl-tools

changeset 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 06d05a65bd77
files glass.js sanegl.js
diffstat 2 files changed, 27 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/glass.js	Thu Jun 16 07:13:20 2011 +0300
     1.2 +++ b/glass.js	Sat Jun 18 05:13:01 2011 +0300
     1.3 @@ -197,6 +197,15 @@
     1.4  	return prog;
     1.5  }
     1.6  
     1.7 +function set_uniform1i(p, name, v)
     1.8 +{
     1.9 +	var loc = gl.getUniformLocation(p, name);
    1.10 +	if(loc != -1) {
    1.11 +		gl.useProgram(p);
    1.12 +		gl.uniform1i(loc, v);
    1.13 +	}
    1.14 +}
    1.15 +
    1.16  function set_uniform1f(p, name, v)
    1.17  {
    1.18  	var loc = gl.getUniformLocation(p, name);
     2.1 --- a/sanegl.js	Thu Jun 16 07:13:20 2011 +0300
     2.2 +++ b/sanegl.js	Sat Jun 18 05:13:01 2011 +0300
     2.3 @@ -31,8 +31,7 @@
     2.4  		[new Float32Array(gl_ident_val)],
     2.5  		[new Float32Array(gl_ident_val)]);
     2.6  
     2.7 -/* XXX change after debugging */
     2.8 -const GL_MAX_VERTS = 32;
     2.9 +const GL_MAX_VERTS = 512;
    2.10  
    2.11  var gl_prim = 0;
    2.12  var gl_vbuf = null, gl_nbuf = null, gl_cbuf = null, gl_tbuf = null;
    2.13 @@ -156,6 +155,12 @@
    2.14  	glMultMatrixf(xform);
    2.15  }
    2.16  
    2.17 +function gluPerspective(vfov, aspect, near, far)
    2.18 +{
    2.19 +	var x = near * Math.tan(vfov / 2.0);
    2.20 +	glFrustum(-aspect * x, aspect * x, -x, x, near, far);
    2.21 +}
    2.22 +
    2.23  function gl_apply_xform(prog)
    2.24  {
    2.25  	var mvtop = gl_mat[GL_MODELVIEW].length - 1;
    2.26 @@ -383,7 +388,17 @@
    2.27  	}
    2.28  
    2.29  	gl_vert_calls++;
    2.30 -	if(++gl_nverts >= GL_MAX_VERTS) {
    2.31 +	gl_nverts++;
    2.32 +
    2.33 +	var buffer_full;
    2.34 +	if(gl_prim == GL_QUADS) {
    2.35 +		/* leave space for 6 more worst-case and don't allow flushes mid-quad */
    2.36 +		buffer_full = gl_nverts >= GL_MAX_VERTS - 6 && gl_vert_calls % 4 == 0;
    2.37 +	} else {
    2.38 +		buffer_full = gl_nverts >= GL_MAX_VERTS - gl_prim;
    2.39 +	}
    2.40 +
    2.41 +	if(buffer_full) {
    2.42  		gl_draw_immediate();
    2.43  		glBegin(gl_prim);	/* reset everything */
    2.44  	}