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 <title>WebGL BindAttribLocation Long Names Conformance Tests</title> |
| 33 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 34 <script src="../../resources/js-test-pre.js"></script> |
| 35 <script src="../resources/webgl-test.js"></script> |
| 36 <script src="../resources/webgl-test-utils.js"></script> |
| 37 </head> |
| 38 <body> |
| 39 <div id="description"></div> |
| 40 <div id="console"></div> |
| 41 <canvas style="border: 1px solid black;" id="canvas" width="50" height="50"></ca
nvas> |
| 42 <script id="vshader" type="text/something-not-javascript"> |
| 43 attribute vec4 vPosition$(suffix); |
| 44 attribute vec4 vColor$(suffix); |
| 45 varying vec4 color; |
| 46 void main() |
| 47 { |
| 48 gl_Position = vPosition$(suffix); |
| 49 color = vColor$(suffix); |
| 50 } |
| 51 </script> |
| 52 <script id="fshader" type="text/something-not-javascript"> |
| 53 precision mediump float; |
| 54 |
| 55 varying vec4 color; |
| 56 void main() |
| 57 { |
| 58 gl_FragColor = color; |
| 59 } |
| 60 </script> |
| 61 <script> |
| 62 description("This test checks using long names with bindAttribLocation work."); |
| 63 |
| 64 debug(""); |
| 65 debug("Canvas.getContext"); |
| 66 |
| 67 var wtu = WebGLTestUtils; |
| 68 var gl = create3DContext(document.getElementById("canvas")); |
| 69 shouldBeNonNull("gl"); |
| 70 |
| 71 function fail(x,y, buf, shouldBe) |
| 72 { |
| 73 var i = (y*50+x) * 4; |
| 74 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+",
"+buf[i+3]+"), should be "+shouldBe; |
| 75 testFailed(reason); |
| 76 } |
| 77 |
| 78 function pass() |
| 79 { |
| 80 testPassed("drawing is correct"); |
| 81 } |
| 82 |
| 83 debug(""); |
| 84 debug("Checking gl.bindAttribLocation with long names."); |
| 85 |
| 86 var program = gl.createProgram(); |
| 87 |
| 88 var suffix = "long"; |
| 89 for (var ii = 0; ii < 5; ++ii) { |
| 90 suffix = suffix + suffix; |
| 91 } |
| 92 var replacements = { |
| 93 suffix: suffix |
| 94 }; |
| 95 |
| 96 var vsrc = wtu.replaceParams(wtu.getScript("vshader"), replacements); |
| 97 var fsrc = wtu.replaceParams(wtu.getScript("fshader"), replacements); |
| 98 |
| 99 var vs = wtu.loadShader(gl, vsrc, gl.VERTEX_SHADER); |
| 100 var fs = wtu.loadShader(gl, fsrc, gl.FRAGMENT_SHADER); |
| 101 |
| 102 var attribs = { |
| 103 vPosition: "vPosition" + suffix, |
| 104 vColor: "vColor" + suffix |
| 105 }; |
| 106 |
| 107 gl.attachShader(program, vs); |
| 108 gl.attachShader(program, fs); |
| 109 |
| 110 var positions = gl.createBuffer(); |
| 111 gl.bindBuffer(gl.ARRAY_BUFFER, positions); |
| 112 gl.bufferData( |
| 113 gl.ARRAY_BUFFER, |
| 114 new Float32Array( |
| 115 [ 1.0, 1.0, 0.0, |
| 116 -1.0, 1.0, 0.0, |
| 117 -1.0, -1.0, 0.0, |
| 118 1.0, 1.0, 0.0, |
| 119 -1.0, -1.0, 0.0, |
| 120 1.0, -1.0, 0.0]), |
| 121 gl.STATIC_DRAW); |
| 122 |
| 123 var colors = gl.createBuffer(); |
| 124 gl.bindBuffer(gl.ARRAY_BUFFER, colors); |
| 125 gl.bufferData( |
| 126 gl.ARRAY_BUFFER, |
| 127 new Float32Array( |
| 128 [ 0,1,0,1, |
| 129 0,1,0,1, |
| 130 0,1,0,1, |
| 131 0,1,0,1, |
| 132 0,1,0,1, |
| 133 0,1,0,1]), |
| 134 gl.STATIC_DRAW); |
| 135 |
| 136 function setBindLocations(colorLocation, positionLocation) { |
| 137 gl.bindAttribLocation(program, positionLocation, attribs.vPosition); |
| 138 gl.bindAttribLocation(program, colorLocation, attribs.vColor); |
| 139 gl.linkProgram(program); |
| 140 gl.useProgram(program); |
| 141 var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0); |
| 142 assertMsg(linked, "program linked successfully"); |
| 143 |
| 144 debug("vPosition:" + gl.getAttribLocation(program, attribs.vPosition)) |
| 145 debug("vColor :" + gl.getAttribLocation(program, attribs.vColor)) |
| 146 assertMsg(gl.getAttribLocation(program, attribs.vPosition) == positionLocation
, |
| 147 "location of vPosition should be " + positionLocation); |
| 148 assertMsg(gl.getAttribLocation(program, attribs.vColor) == colorLocation, |
| 149 "location of vColor should be " + colorLocation); |
| 150 |
| 151 var ploc = gl.getAttribLocation(program, attribs.vPosition); |
| 152 var cloc = gl.getAttribLocation(program, attribs.vColor); |
| 153 gl.bindBuffer(gl.ARRAY_BUFFER, positions); |
| 154 gl.enableVertexAttribArray(positionLocation); |
| 155 gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0); |
| 156 gl.bindBuffer(gl.ARRAY_BUFFER, colors); |
| 157 gl.enableVertexAttribArray(colorLocation); |
| 158 gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0); |
| 159 } |
| 160 |
| 161 function checkDraw(colorLocation, positionLocation, r, g, b, a) { |
| 162 wtu.drawQuad(gl); |
| 163 wtu.checkCanvas(gl, [r, g, b, a], "should be green"); |
| 164 |
| 165 gl.disableVertexAttribArray(positionLocation); |
| 166 gl.disableVertexAttribArray(colorLocation); |
| 167 } |
| 168 |
| 169 setBindLocations(2, 3); |
| 170 checkDraw(2, 3, 0, 255, 0, 255); |
| 171 |
| 172 setBindLocations(0, 3); |
| 173 gl.disableVertexAttribArray(0); |
| 174 gl.vertexAttrib4f(0, 1, 0, 0, 1); |
| 175 checkDraw(0, 3, 255, 0, 0, 255); |
| 176 |
| 177 glErrorShouldBe(gl, gl.NO_ERROR); |
| 178 |
| 179 debug(""); |
| 180 successfullyParsed = true; |
| 181 |
| 182 </script> |
| 183 <script src="../../resources/js-test-post.js"></script> |
| 184 |
| 185 </body> |
| 186 </html> |
OLD | NEW |