OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 6 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 7 ** copy of this software and/or associated documentation files (the |
| 8 ** "Materials"), to deal in the Materials without restriction, including |
| 9 ** without limitation the rights to use, copy, modify, merge, publish, |
| 10 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 11 ** permit persons to whom the Materials are furnished to do so, subject to |
| 12 ** the following conditions: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 */ |
| 25 |
| 26 --> |
| 27 |
| 28 <!DOCTYPE html> |
| 29 <html> |
| 30 <head> |
| 31 <meta charset="utf-8"> |
| 32 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 33 <script src="../../resources/js-test-pre.js"></script> |
| 34 <script src="../resources/webgl-test.js"></script> |
| 35 <script id='vshader' type='x-shader'> |
| 36 attribute vec4 a; |
| 37 attribute vec2 p; |
| 38 void main() { |
| 39 gl_Position = vec4(p.x + a.x + a.y + a.z + a.w, p.y, 0.0, 1.0); |
| 40 } |
| 41 </script> |
| 42 <script id='fshader' type='x-shader'> |
| 43 precision mediump float; |
| 44 void main() { |
| 45 gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); |
| 46 } |
| 47 </script> |
| 48 <script> |
| 49 function checkRedPortion(gl, w, low, high) { |
| 50 var buf = new Uint8Array(w * w * 4); |
| 51 gl.readPixels(0, 0, w, w, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
| 52 var i = 0; |
| 53 for (; i < w; ++i) { |
| 54 if (buf[i * 4 + 0] != 255 || buf[i * 4 + 1] != 0 || buf[i *
4 + 2] != 0 || buf[i * 4 + 3] != 255) { |
| 55 break; |
| 56 } |
| 57 } |
| 58 return low <= i && i <= high; |
| 59 } |
| 60 |
| 61 function runTest() { |
| 62 var gl = initWebGL('testbed', { preserveDrawingBuffer : true }); |
| 63 if (!gl) { |
| 64 testFailed('initWebGL(..) failed'); |
| 65 return; |
| 66 } |
| 67 var program = setupProgram(gl, 'vshader', 'fshader', ['p', 'a']) |
| 68 |
| 69 gl.enableVertexAttribArray(gl.p); |
| 70 var pos = gl.createBuffer(); |
| 71 pos.type = gl.FLOAT; |
| 72 pos.size = 2; |
| 73 pos.num = 4; |
| 74 gl.bindBuffer(gl.ARRAY_BUFFER, pos); |
| 75 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1,
-1, 1, 1, 1]), gl.STATIC_DRAW); |
| 76 |
| 77 gl.vertexAttribPointer(0, pos.size, pos.type, false, 0, 0); |
| 78 |
| 79 debug('Test vertexAttrib[1..4]fv by setting different combinatio
ns that add up to 1.5 and use that when rendering.'); |
| 80 var vals = [[0.5], [0.1,0.4], [0.2,-0.2,0.5], [-1.0,0.3,0.2,2.0]
]; |
| 81 |
| 82 for (var j = 0; j < 4; ++j) { |
| 83 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 84 gl['vertexAttrib' + (j+1) + 'fv'](1, vals[j]); |
| 85 gl.drawArrays(gl.TRIANGLE_STRIP, 0, pos.num); |
| 86 |
| 87 if (checkRedPortion(gl, 50, 50 * 0.7, 50 * 0.8)) { |
| 88 testPassed('Attribute of size ' + (j+1) + ' was set corr
ectly'); |
| 89 } else { |
| 90 testFailed('Attribute of size ' + (j+1) + ' was not set
correctly'); |
| 91 } |
| 92 } |
| 93 } |
| 94 </script> |
| 95 </head> |
| 96 <body> |
| 97 <canvas id="testbed" width="50" height="50"></canvas> |
| 98 <div id="description"></div> |
| 99 <div id="console"></div> |
| 100 <script> |
| 101 description('Verify that using constant attributes works.'); |
| 102 runTest(); |
| 103 successfullyParsed = true; |
| 104 </script> |
| 105 <script src="../../resources/js-test-post.js"></script> |
| 106 </body> |
| 107 </html> |
OLD | NEW |