Skip to content

Commit

Permalink
finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
gleber committed Dec 12, 2011
1 parent b31c576 commit 47413a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 54 deletions.
22 changes: 13 additions & 9 deletions buffer.js
Expand Up @@ -35,24 +35,28 @@ function inferElementType(dt) {
return t;
}

function G3Buffer(c, name, dt, values, stride) {
function G3Buffer(c, name, dt, values, isize) {
this.name = name;
this.buffer = c.createBuffer();
this.buffer_type = c.ARRAY_BUFFER;
this.element_type = inferElementType(dt);

this.stride = stride;
this.length = values.length / stride;
fillAnyBuffer(c, this.buffer_type, this.buffer, values, dt);
this.isize = isize;
this.length = values.length / isize;

c.bindBuffer(this.buffer_type, this.buffer);
c.bufferData(this.buffer_type, new dt(values), c.STATIC_DRAW);
}

function G3ElementBuffer(c, dt, values, stride) {
stride = stride || 1;
function G3ElementBuffer(c, dt, values, isize) {
isize = isize || 1;
this.buffer = c.createBuffer();
this.buffer_type = c.ELEMENT_ARRAY_BUFFER;
this.element_type = inferElementType(dt);

this.stride = stride;
this.length = values.length / stride;
fillAnyBuffer(c, this.buffer_type, this.buffer, values, dt);
this.isize = isize;
this.length = values.length / isize;

c.bindBuffer(this.buffer_type, this.buffer);
c.bufferData(this.buffer_type, new dt(values), c.STATIC_DRAW);
}
33 changes: 0 additions & 33 deletions index.html
Expand Up @@ -10,8 +10,6 @@

<script id="colored-shader-vs" type="x-shader/x-vertex">

uniform bool uTextured;

attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec4 aVertexColor;
Expand All @@ -36,36 +34,6 @@

</script>


<script id="textured-shader-vs" type="x-shader/x-vertex">

attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;

varying vec2 vTextureCoord;
varying vec3 vTransformedNormal;
varying vec3 vNormal;
varying vec3 vPosition;

void main(void)
{
vPosition = vec3(uMVMatrix * vec4(aVertexPosition, 1.0));
vTransformedNormal = uNMatrix * aVertexNormal;
vTextureCoord = aTextureCoord;
vNormal = aVertexNormal;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}

</script>




<script id="colored-shader-fs" type="x-shader/x-fragment">

#ifdef GL_ES
Expand All @@ -85,7 +53,6 @@
uniform vec3 uAmbientColor;

uniform float uMaterialShininess;
uniform sampler2D uSampler;

uniform vec3 uPointLightingLocation;
uniform vec3 uPointLightingSpecularColor;
Expand Down
10 changes: 5 additions & 5 deletions js.js
Expand Up @@ -62,11 +62,11 @@ G3World.mv.pop = function() {
// -4 18 14
// -17 -48

G3World.camera = {'x': 0,
'y': 28,
'z': 0,
'yaw': 0,
'pitch': -90,
G3World.camera = {'x': -4,
'y': 18,
'z': 14,
'yaw': -17,
'pitch': -48,

'yawSpeed': 0,
'pitchSpeed': 0,
Expand Down
15 changes: 8 additions & 7 deletions program.js
Expand Up @@ -21,12 +21,12 @@ function G3Program(c, vs, fs) {
if (info.size != 1) {
throw("arrays of attribs not handled");
}
return function(b) {
c.bindBuffer(c.ARRAY_BUFFER, b.buffer());
c.enableVertexAttribArray(index);
c.vertexAttribPointer(
index, b.numComponents(), b.type(), b.normalize(), b.stride(), b.offset());
};
// return function(b) {
// c.bindBuffer(c.ARRAY_BUFFER, b.buffer());
// c.enableVertexAttribArray(index);
// c.vertexAttribPointer(
// index, b.numComponents(), b.type(), b.normalize(), b.stride(), b.offset());
// };
}

var numAttribs = c.getProgramParameter(program, c.ACTIVE_ATTRIBUTES);
Expand All @@ -40,6 +40,7 @@ function G3Program(c, vs, fs) {
name = name.substr(0, name.length - 3);
}
var index = c.getAttribLocation(program, info.name);
c.enableVertexAttribArray(index);
this.attribLocs[name] = c.getAttribLocation(program, name);
this.attribs[name] = createAttribSetter(info, index);
}
Expand Down Expand Up @@ -169,7 +170,7 @@ function G3Program(c, vs, fs) {
name = b.name || name;
c.bindBuffer(b.buffer_type, b.buffer);
if (b.buffer_type == c.ARRAY_BUFFER) {
c.vertexAttribPointer(this.attribLocs[name], b.stride, b.element_type, false, 0, 0);
c.vertexAttribPointer(this.attribLocs[name], b.isize, b.element_type, false, 0, 0);
}
}

Expand Down

0 comments on commit 47413a7

Please sign in to comment.