var fill3D = function fill3D(vArray, mode, cArray, tArray){
var ctxMode;
if(mode === "TRIANGLES"){
ctxMode = curContext.TRIANGLES;
}
else if(mode === "TRIANGLE_FAN"){
ctxMode = curContext.TRIANGLE_FAN;
}
else{
ctxMode = curContext.TRIANGLE_STRIP;
}
var view = new PMatrix3D();
view.scale(1, -1, 1);
view.apply(modelView.array());
view.transpose();
var proj = new PMatrix3D();
proj.set(projection);
proj.transpose();
curContext.useProgram( programObject3D );
uniformMatrix( programObject3D, "model", false, [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1] );
uniformMatrix( programObject3D, "view", false, view.array() );
uniformMatrix( programObject3D, "projection", false, proj.array() );
curContext.enable( curContext.POLYGON_OFFSET_FILL );
curContext.polygonOffset( 1, 1 );
uniformf(programObject3D, "color", [-1,0,0,0]);
vertexAttribPointer(programObject3D, "Vertex", 3, fillBuffer);
curContext.bufferData(curContext.ARRAY_BUFFER, newWebGLArray(vArray), curContext.STREAM_DRAW);
vertexAttribPointer(programObject3D, "aColor", 4, fillColorBuffer);
curContext.bufferData(curContext.ARRAY_BUFFER, newWebGLArray(cArray), curContext.STREAM_DRAW);
// No support for lights....yet
disableVertexAttribPointer(programObject3D, "Normal");
var i;
if(usingTexture){
if(curTextureMode === p.IMAGE){
for(i = 0; i < tArray.length; i += 2){
tArray[i] = tArray[i]/curTexture.width;
tArray[i+1] /= curTexture.height;
}
}
// hack to handle when users specifies values
// greater than 1.0 for texture coords.
for(i = 0; i < tArray.length; i += 2){
if( tArray[i+0] > 1.0 ){ tArray[i+0] -= (tArray[i+0] - 1.0);}
if( tArray[i+1] > 1.0 ){ tArray[i+1] -= (tArray[i+1] - 1.0);}
}
uniformi(programObject3D, "usingTexture", usingTexture);
vertexAttribPointer(programObject3D, "aTexture", 2, shapeTexVBO);
curContext.bufferData(curContext.ARRAY_BUFFER, newWebGLArray(tArray), curContext.STREAM_DRAW);
}
curContext.drawArrays( ctxMode, 0, vArray.length/3 );
curContext.disable( curContext.POLYGON_OFFSET_FILL );
};