Advertisement
Guest User

fill3D()

a guest
Aug 3rd, 2010
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var fill3D = function fill3D(vArray, mode, cArray, tArray){
  2.   var ctxMode;
  3.   if(mode === "TRIANGLES"){
  4.     ctxMode = curContext.TRIANGLES;
  5.   }
  6.   else if(mode === "TRIANGLE_FAN"){
  7.     ctxMode = curContext.TRIANGLE_FAN;
  8.   }
  9.   else{
  10.     ctxMode = curContext.TRIANGLE_STRIP;
  11.   }
  12.  
  13.   var view = new PMatrix3D();
  14.   view.scale(1, -1, 1);
  15.   view.apply(modelView.array());
  16.   view.transpose();
  17.  
  18.   var proj = new PMatrix3D();
  19.   proj.set(projection);
  20.   proj.transpose();
  21.  
  22.   curContext.useProgram( programObject3D );
  23.   uniformMatrix( programObject3D, "model", false,  [1,0,0,0,  0,1,0,0,   0,0,1,0,   0,0,0,1] );
  24.   uniformMatrix( programObject3D, "view", false, view.array() );
  25.   uniformMatrix( programObject3D, "projection", false, proj.array() );
  26.  
  27.   curContext.enable( curContext.POLYGON_OFFSET_FILL );
  28.   curContext.polygonOffset( 1, 1 );
  29.  
  30.   uniformf(programObject3D, "color", [-1,0,0,0]);
  31.  
  32.   vertexAttribPointer(programObject3D, "Vertex", 3, fillBuffer);
  33.   curContext.bufferData(curContext.ARRAY_BUFFER, newWebGLArray(vArray), curContext.STREAM_DRAW);
  34.  
  35.   vertexAttribPointer(programObject3D, "aColor", 4, fillColorBuffer);
  36.   curContext.bufferData(curContext.ARRAY_BUFFER, newWebGLArray(cArray), curContext.STREAM_DRAW);
  37.  
  38.   // No support for lights....yet
  39.   disableVertexAttribPointer(programObject3D, "Normal");
  40.  
  41.   var i;
  42.  
  43.   if(usingTexture){
  44.     if(curTextureMode === p.IMAGE){
  45.       for(i = 0; i < tArray.length; i += 2){
  46.         tArray[i] = tArray[i]/curTexture.width;
  47.         tArray[i+1] /= curTexture.height;
  48.       }
  49.     }
  50.  
  51.     // hack to handle when users specifies values
  52.     // greater than 1.0 for texture coords.
  53.     for(i = 0; i < tArray.length; i += 2){
  54.       if( tArray[i+0] > 1.0 ){ tArray[i+0] -= (tArray[i+0] - 1.0);}
  55.       if( tArray[i+1] > 1.0 ){ tArray[i+1] -= (tArray[i+1] - 1.0);}
  56.     }
  57.  
  58.     uniformi(programObject3D, "usingTexture", usingTexture);
  59.     vertexAttribPointer(programObject3D, "aTexture", 2, shapeTexVBO);
  60.     curContext.bufferData(curContext.ARRAY_BUFFER, newWebGLArray(tArray), curContext.STREAM_DRAW);
  61.   }
  62.  
  63.   curContext.drawArrays( ctxMode, 0, vArray.length/3 );
  64.   curContext.disable( curContext.POLYGON_OFFSET_FILL );
  65. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement