OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright (C) 2011 Apple Computer, Inc. All rights reserved. |
| 3 |
| 4 Redistribution and use in source and binary forms, with or without |
| 5 modification, are permitted provided that the following conditions |
| 6 are met: |
| 7 1. Redistributions of source code must retain the above copyright |
| 8 notice, this list of conditions and the following disclaimer. |
| 9 2. Redistributions in binary form must reproduce the above copyright |
| 10 notice, this list of conditions and the following disclaimer in the |
| 11 documentation and/or other materials provided with the distribution. |
| 12 |
| 13 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. AS IS AND ANY |
| 14 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 --> |
| 25 <!DOCTYPE html> |
| 26 <html> |
| 27 <head> |
| 28 <meta charset="utf-8"> |
| 29 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 30 <script src="../../resources/js-test-pre.js"></script> |
| 31 <script src="../resources/webgl-test.js"></script> |
| 32 </head> |
| 33 <body> |
| 34 <div id="description"></div> |
| 35 <div id="console"></div> |
| 36 |
| 37 <script> |
| 38 description("Test of get calls against GL objects like getBufferParameter, etc."
); |
| 39 |
| 40 function sizeInBytes(type) { |
| 41 switch (type) { |
| 42 case gl.BYTE: |
| 43 case gl.UNSIGNED_BYTE: |
| 44 return 1; |
| 45 case gl.SHORT: |
| 46 case gl.UNSIGNED_SHORT: |
| 47 return 2; |
| 48 case gl.INT: |
| 49 case gl.UNSIGNED_INT: |
| 50 case gl.FLOAT: |
| 51 return 4; |
| 52 default: |
| 53 throw "unknown type"; |
| 54 } |
| 55 } |
| 56 |
| 57 var gl = create3DContext(); |
| 58 |
| 59 var standardVert = loadStandardVertexShader(gl); |
| 60 var standardFrag = loadStandardFragmentShader(gl); |
| 61 var standardProgram = gl.createProgram(); |
| 62 gl.attachShader(standardProgram, standardVert); |
| 63 gl.attachShader(standardProgram, standardFrag); |
| 64 gl.linkProgram(standardProgram); |
| 65 var shaders = gl.getAttachedShaders(standardProgram); |
| 66 shouldBe('shaders.length', '2'); |
| 67 shouldBeTrue('shaders[0] == standardVert && shaders[1] == standardFrag || shader
s[1] == standardVert && shaders[0] == standardFrag'); |
| 68 glErrorShouldBe(gl, gl.NO_ERROR); |
| 69 shouldBeNull('gl.getAttachedShaders(null)'); |
| 70 glErrorShouldBe(gl, gl.INVALID_VALUE); |
| 71 shouldThrow('gl.getAttachedShaders(standardVert)'); |
| 72 glErrorShouldBe(gl, gl.NO_ERROR); |
| 73 |
| 74 // Test getBufferParameter |
| 75 var buffer = gl.createBuffer(); |
| 76 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); |
| 77 gl.bufferData(gl.ARRAY_BUFFER, 16, gl.DYNAMIC_DRAW); |
| 78 shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)', '16'); |
| 79 shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_USAGE)', 'gl.DYNAMIC_
DRAW'); |
| 80 |
| 81 // Test getFramebufferAttachmentParameter |
| 82 var texture = gl.createTexture(); |
| 83 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 84 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, |
| 85 new Uint8Array([ |
| 86 0, 0, 0, 255, |
| 87 255, 255, 255, 255, |
| 88 255, 255, 255, 255, |
| 89 0, 0, 0, 255])); |
| 90 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); |
| 91 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
| 92 gl.bindTexture(gl.TEXTURE_2D, null); |
| 93 var framebuffer = gl.createFramebuffer(); |
| 94 gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); |
| 95 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex
ture, 0); |
| 96 var renderbuffer = gl.createRenderbuffer(); |
| 97 glErrorShouldBe(gl, gl.NO_ERROR); |
| 98 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); |
| 99 glErrorShouldBe(gl, gl.NO_ERROR); |
| 100 gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 2, 2); |
| 101 glErrorShouldBe(gl, gl.NO_ERROR); |
| 102 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER,
renderbuffer); |
| 103 // FIXME: on some machines (in particular the WebKit commit bots) the |
| 104 // framebuffer status is FRAMEBUFFER_UNSUPPORTED; more investigation |
| 105 // is needed why this is the case, because the FBO allocated |
| 106 // internally by the WebKit implementation has almost identical |
| 107 // parameters to this one. See https://bugs.webkit.org/show_bug.cgi?id=31843. |
| 108 shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE')
; |
| 109 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHME
NT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.TEXTURE'); |
| 110 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHME
NT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)', 'texture'); |
| 111 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHME
NT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL)', '0'); |
| 112 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHME
NT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE)', '0'); |
| 113 |
| 114 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHME
NT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.RENDERBUFFER'); |
| 115 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHME
NT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)', 'renderbuffer'); |
| 116 |
| 117 // Test getProgramParameter |
| 118 shouldBe('gl.getProgramParameter(standardProgram, gl.DELETE_STATUS)', 'false'); |
| 119 shouldBe('gl.getProgramParameter(standardProgram, gl.LINK_STATUS)', 'true'); |
| 120 shouldBe('typeof gl.getProgramParameter(standardProgram, gl.VALIDATE_STATUS)', '
"boolean"'); |
| 121 shouldBe('gl.getProgramParameter(standardProgram, gl.ATTACHED_SHADERS)', '2'); |
| 122 shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_ATTRIBUTES)', '2'); |
| 123 shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_UNIFORMS)', '1'); |
| 124 |
| 125 // Test getRenderbufferParameter |
| 126 shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)',
'2'); |
| 127 shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_HEIGHT)',
'2'); |
| 128 // Note: we can't test the actual value of the internal format since |
| 129 // the implementation is allowed to change it. |
| 130 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_IN
TERNAL_FORMAT)'); |
| 131 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_DE
PTH_SIZE)'); |
| 132 var colorbuffer = gl.createRenderbuffer(); |
| 133 glErrorShouldBe(gl, gl.NO_ERROR); |
| 134 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); |
| 135 glErrorShouldBe(gl, gl.NO_ERROR); |
| 136 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 2, 2); |
| 137 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_RE
D_SIZE)'); |
| 138 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_GR
EEN_SIZE)'); |
| 139 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_BL
UE_SIZE)'); |
| 140 shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_AL
PHA_SIZE)'); |
| 141 |
| 142 // Test getShaderParameter |
| 143 shouldBe('gl.getShaderParameter(standardVert, gl.SHADER_TYPE)', 'gl.VERTEX_SHADE
R'); |
| 144 shouldBe('gl.getShaderParameter(standardVert, gl.DELETE_STATUS)', 'false'); |
| 145 shouldBe('gl.getShaderParameter(standardVert, gl.COMPILE_STATUS)', 'true'); |
| 146 |
| 147 // Test getTexParameter |
| 148 gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); |
| 149 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 150 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 151 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 152 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 153 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 154 shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER)', 'gl.NEAREST
'); |
| 155 shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER)', 'gl.NEAREST
'); |
| 156 shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)', 'gl.CLAMP_TO_ED
GE'); |
| 157 shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T)', 'gl.CLAMP_TO_ED
GE'); |
| 158 |
| 159 // Test getUniform with all variants of data types |
| 160 // Boolean uniform variables |
| 161 var boolProgram = loadProgram(gl, "../resources/boolUniformShader.vert", "../res
ources/noopUniformShader.frag"); |
| 162 shouldBe('gl.getProgramParameter(boolProgram, gl.LINK_STATUS)', 'true'); |
| 163 var bvalLoc = gl.getUniformLocation(boolProgram, "bval"); |
| 164 var bval2Loc = gl.getUniformLocation(boolProgram, "bval2"); |
| 165 var bval3Loc = gl.getUniformLocation(boolProgram, "bval3"); |
| 166 var bval4Loc = gl.getUniformLocation(boolProgram, "bval4"); |
| 167 gl.useProgram(boolProgram); |
| 168 gl.uniform1i(bvalLoc, 1); |
| 169 gl.uniform2i(bval2Loc, 1, 0); |
| 170 gl.uniform3i(bval3Loc, 1, 0, 1); |
| 171 gl.uniform4i(bval4Loc, 1, 0, 1, 0); |
| 172 glErrorShouldBe(gl, gl.NO_ERROR); |
| 173 shouldBe('gl.getUniform(boolProgram, bvalLoc)', 'true'); |
| 174 shouldBe('gl.getUniform(boolProgram, bval2Loc)', '[true, false]'); |
| 175 shouldBe('gl.getUniform(boolProgram, bval3Loc)', '[true, false, true]'); |
| 176 shouldBe('gl.getUniform(boolProgram, bval4Loc)', '[true, false, true, false]'); |
| 177 // Integer uniform variables |
| 178 var intProgram = loadProgram(gl, "../resources/intUniformShader.vert", "../resou
rces/noopUniformShader.frag"); |
| 179 shouldBe('gl.getProgramParameter(intProgram, gl.LINK_STATUS)', 'true'); |
| 180 var ivalLoc = gl.getUniformLocation(intProgram, "ival"); |
| 181 var ival2Loc = gl.getUniformLocation(intProgram, "ival2"); |
| 182 var ival3Loc = gl.getUniformLocation(intProgram, "ival3"); |
| 183 var ival4Loc = gl.getUniformLocation(intProgram, "ival4"); |
| 184 gl.useProgram(intProgram); |
| 185 gl.uniform1i(ivalLoc, 1); |
| 186 gl.uniform2i(ival2Loc, 2, 3); |
| 187 gl.uniform3i(ival3Loc, 4, 5, 6); |
| 188 gl.uniform4i(ival4Loc, 7, 8, 9, 10); |
| 189 glErrorShouldBe(gl, gl.NO_ERROR); |
| 190 shouldBe('gl.getUniform(intProgram, ivalLoc)', '1'); |
| 191 shouldBe('gl.getUniform(intProgram, ival2Loc)', '[2, 3]'); |
| 192 shouldBe('gl.getUniform(intProgram, ival3Loc)', '[4, 5, 6]'); |
| 193 shouldBe('gl.getUniform(intProgram, ival4Loc)', '[7, 8, 9, 10]'); |
| 194 // Float uniform variables |
| 195 var floatProgram = loadProgram(gl, "../resources/floatUniformShader.vert", "../r
esources/noopUniformShader.frag"); |
| 196 shouldBe('gl.getProgramParameter(floatProgram, gl.LINK_STATUS)', 'true'); |
| 197 var fvalLoc = gl.getUniformLocation(floatProgram, "fval"); |
| 198 var fval2Loc = gl.getUniformLocation(floatProgram, "fval2"); |
| 199 var fval3Loc = gl.getUniformLocation(floatProgram, "fval3"); |
| 200 var fval4Loc = gl.getUniformLocation(floatProgram, "fval4"); |
| 201 gl.useProgram(floatProgram); |
| 202 gl.uniform1f(fvalLoc, 11); |
| 203 gl.uniform2f(fval2Loc, 12, 13); |
| 204 gl.uniform3f(fval3Loc, 14, 15, 16); |
| 205 gl.uniform4f(fval4Loc, 17, 18, 19, 20); |
| 206 glErrorShouldBe(gl, gl.NO_ERROR); |
| 207 shouldBe('gl.getUniform(floatProgram, fvalLoc)', '11'); |
| 208 shouldBe('gl.getUniform(floatProgram, fval2Loc)', '[12, 13]'); |
| 209 shouldBe('gl.getUniform(floatProgram, fval3Loc)', '[14, 15, 16]'); |
| 210 shouldBe('gl.getUniform(floatProgram, fval4Loc)', '[17, 18, 19, 20]'); |
| 211 // Sampler uniform variables |
| 212 var samplerProgram = loadProgram(gl, "../resources/noopUniformShader.vert", "../
resources/samplerUniformShader.frag"); |
| 213 shouldBe('gl.getProgramParameter(samplerProgram, gl.LINK_STATUS)', 'true'); |
| 214 var s2DValLoc = gl.getUniformLocation(samplerProgram, "s2D"); |
| 215 var sCubeValLoc = gl.getUniformLocation(samplerProgram, "sCube"); |
| 216 gl.useProgram(samplerProgram); |
| 217 gl.uniform1i(s2DValLoc, 0); |
| 218 gl.uniform1i(sCubeValLoc, 1); |
| 219 glErrorShouldBe(gl, gl.NO_ERROR); |
| 220 shouldBe('gl.getUniform(samplerProgram, s2DValLoc)', '0'); |
| 221 shouldBe('gl.getUniform(samplerProgram, sCubeValLoc)', '1'); |
| 222 // Matrix uniform variables |
| 223 var matProgram = loadProgram(gl, "../resources/matUniformShader.vert", "../resou
rces/noopUniformShader.frag"); |
| 224 shouldBe('gl.getProgramParameter(matProgram, gl.LINK_STATUS)', 'true'); |
| 225 var mval2Loc = gl.getUniformLocation(matProgram, "mval2"); |
| 226 var mval3Loc = gl.getUniformLocation(matProgram, "mval3"); |
| 227 var mval4Loc = gl.getUniformLocation(matProgram, "mval4"); |
| 228 gl.useProgram(matProgram); |
| 229 gl.uniformMatrix2fv(mval2Loc, false, [1, 2, 3, 4]); |
| 230 gl.uniformMatrix3fv(mval3Loc, false, [5, 6, 7, 8, 9, 10, 11, 12, 13]); |
| 231 gl.uniformMatrix4fv(mval4Loc, false, [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
, 25, 26, 27, 28, 29]); |
| 232 glErrorShouldBe(gl, gl.NO_ERROR); |
| 233 shouldBe('gl.getUniform(matProgram, mval2Loc)', '[1, 2, 3, 4]'); |
| 234 shouldBe('gl.getUniform(matProgram, mval3Loc)', '[5, 6, 7, 8, 9, 10, 11, 12, 13]
'); |
| 235 shouldBe('gl.getUniform(matProgram, mval4Loc)', '[14, 15, 16, 17, 18, 19, 20, 21
, 22, 23, 24, 25, 26, 27, 28, 29]'); |
| 236 |
| 237 // Test getVertexAttrib |
| 238 var array = new Float32Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16]); |
| 239 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); |
| 240 gl.bufferData(gl.ARRAY_BUFFER, array, gl.DYNAMIC_DRAW); |
| 241 // Vertex attribute 0 is special in that it has no current state, so |
| 242 // fetching GL_CURRENT_VERTEX_ATTRIB generates an error. Use attribute |
| 243 // 1 for these tests instead. |
| 244 gl.enableVertexAttribArray(1); |
| 245 gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 0, 0); |
| 246 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)', 'buffer
'); |
| 247 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'true'); |
| 248 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_SIZE)', '4'); |
| 249 // Stride MUST be the value the user put in. |
| 250 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE)', '0'); |
| 251 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_TYPE)', 'gl.FLOAT'); |
| 252 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED)', 'false'); |
| 253 gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 36, 12); |
| 254 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE)', '36'); |
| 255 shouldBe('gl.getVertexAttribOffset(1, gl.VERTEX_ATTRIB_ARRAY_POINTER)', '12'); |
| 256 gl.disableVertexAttribArray(1); |
| 257 shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'false'); |
| 258 gl.vertexAttrib4f(1, 5, 6, 7, 8); |
| 259 shouldBe('gl.getVertexAttrib(1, gl.CURRENT_VERTEX_ATTRIB)', '[5, 6, 7, 8]'); |
| 260 glErrorShouldBe(gl, gl.NO_ERROR); |
| 261 |
| 262 // Test cases where name == 0 |
| 263 gl.deleteTexture(texture); |
| 264 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHME
NT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.NONE'); |
| 265 gl.deleteRenderbuffer(renderbuffer); |
| 266 shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHME
NT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.NONE'); |
| 267 gl.deleteBuffer(buffer); |
| 268 shouldBeNull('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)'); |
| 269 glErrorShouldBe(gl, gl.NO_ERROR); |
| 270 |
| 271 successfullyParsed = true; |
| 272 </script> |
| 273 |
| 274 <script src="../../resources/js-test-post.js"></script> |
| 275 </body> |
| 276 </html> |
OLD | NEW |