OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <!-- |
| 6 |
| 7 /* |
| 8 ** Copyright (c) 2012 The Khronos Group Inc. |
| 9 ** |
| 10 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 11 ** copy of this software and/or associated documentation files (the |
| 12 ** "Materials"), to deal in the Materials without restriction, including |
| 13 ** without limitation the rights to use, copy, modify, merge, publish, |
| 14 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 15 ** permit persons to whom the Materials are furnished to do so, subject to |
| 16 ** the following conditions: |
| 17 ** |
| 18 ** The above copyright notice and this permission notice shall be included |
| 19 ** in all copies or substantial portions of the Materials. |
| 20 ** |
| 21 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 22 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 23 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 24 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 25 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 26 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 27 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 28 */ |
| 29 |
| 30 --> |
| 31 <link rel="stylesheet" type="text/css" href="../unit.css" /> |
| 32 <script type="application/x-javascript" src="../unit.js"></script> |
| 33 <script type="application/x-javascript" src="../util.js"></script> |
| 34 <script type="application/x-javascript"> |
| 35 |
| 36 var verts = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0]; |
| 37 var normals = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0]; |
| 38 var texcoords = [0.0,0.0, 1.0,0.0, 0.0,1.0]; |
| 39 var indices = [0,1,2] |
| 40 |
| 41 Tests.startUnit = function () { |
| 42 var canvas = document.getElementById('gl'); |
| 43 var gl = wrapGLContext(getGLContext(canvas)); |
| 44 var prog = new Shader(gl, 'vert', 'frag'); |
| 45 prog.use(); |
| 46 var sh = prog.shader.program; |
| 47 var v = gl.getAttribLocation(sh, 'Vertex'); |
| 48 var n = gl.getAttribLocation(sh, 'Normal'); |
| 49 var t = gl.getAttribLocation(sh, 'Tex'); |
| 50 return [gl,prog,v,n,t]; |
| 51 } |
| 52 |
| 53 Tests.setup = function(gl, prog, v,n,t) { |
| 54 assert(0 == gl.getError()); |
| 55 return [gl, prog, v,n,t]; |
| 56 } |
| 57 Tests.teardown = function(gl, prog, v,n,t) { |
| 58 gl.disableVertexAttribArray(v); |
| 59 gl.disableVertexAttribArray(n); |
| 60 gl.disableVertexAttribArray(t); |
| 61 } |
| 62 |
| 63 Tests.endUnit = function(gl, prog, v,n,t) { |
| 64 prog.destroy(); |
| 65 } |
| 66 |
| 67 Tests.testDrawElementsVBO = function(gl, prog, v,n,t) { |
| 68 var vbo = new VBO(gl, |
| 69 {size:3, data:Quad.vertices}, |
| 70 {elements:true, data:Quad.indices}); |
| 71 vbo.draw(v); |
| 72 assert(gl.NO_ERROR == checkError(gl, "vbo.draw")); |
| 73 assertOk(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2);}
); |
| 74 assertOk(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0*2);}
); |
| 75 assertOk(function(){gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_SHORT, 2*1);}
); |
| 76 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2);}
); |
| 77 vbo.destroy(); |
| 78 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy")); |
| 79 } |
| 80 |
| 81 Tests.testDrawElementsVBOMulti = function(gl, prog, v,n,t) { |
| 82 // creates VBOs for the quad arrays, binds them with |
| 83 // vertexAttribPointer and calls drawElements |
| 84 var vbo = new VBO(gl, |
| 85 {size:3, data:Quad.vertices}, |
| 86 {size:3, data:Quad.normals}, |
| 87 {size:2, data:Quad.texcoords}, |
| 88 {elements:true, data:Quad.indices}); |
| 89 vbo.draw(v, n, t); |
| 90 assert(gl.NO_ERROR == checkError(gl, "vbo.draw")); |
| 91 assertOk(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2);}
); |
| 92 assertOk(function(){gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_SHORT, 2*2);}
); |
| 93 assertOk(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0*2);}
); |
| 94 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2);}
); |
| 95 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range", |
| 96 function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 6*2);}); |
| 97 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range 2", |
| 98 function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1*2);}); |
| 99 gl.bindBuffer(gl.ARRAY_BUFFER, null); |
| 100 gl.bindBuffer(gl.ARRAY_BUFFER, vbo.vbos[1]); |
| 101 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0); |
| 102 assertOk(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2);}
); |
| 103 assertOk(function(){gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_SHORT, 2*2);}
); |
| 104 assertOk(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0*2);}
); |
| 105 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2);}
); |
| 106 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range 3", |
| 107 function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 6*2);}); |
| 108 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range 4", |
| 109 function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1*2);}); |
| 110 vbo.destroy(); |
| 111 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy")); |
| 112 } |
| 113 |
| 114 |
| 115 </script> |
| 116 <script id="vert" type="x-shader/x-vertex"> |
| 117 attribute vec3 Vertex; |
| 118 attribute vec3 Normal; |
| 119 attribute vec2 Tex; |
| 120 |
| 121 varying vec4 texCoord0; |
| 122 void main() |
| 123 { |
| 124 gl_Position = vec4(Vertex * Normal, 1.0); |
| 125 texCoord0 = vec4(Tex,0.0,0.0) + gl_Position; |
| 126 } |
| 127 </script> |
| 128 <script id="frag" type="x-shader/x-fragment"> |
| 129 precision mediump float; |
| 130 |
| 131 varying vec4 texCoord0; |
| 132 void main() |
| 133 { |
| 134 vec4 c = texCoord0; |
| 135 gl_FragColor = c; |
| 136 } |
| 137 </script> |
| 138 |
| 139 |
| 140 <style>canvas{ position:absolute; }</style> |
| 141 </head><body> |
| 142 <canvas id="gl" width="1" height="1"></canvas> |
| 143 </body></html> |
OLD | NEW |