1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/state/gl-object-get-calls.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,276 @@ 1.4 +<!-- 1.5 +Copyright (C) 2011 Apple Computer, Inc. All rights reserved. 1.6 + 1.7 +Redistribution and use in source and binary forms, with or without 1.8 +modification, are permitted provided that the following conditions 1.9 +are met: 1.10 +1. Redistributions of source code must retain the above copyright 1.11 + notice, this list of conditions and the following disclaimer. 1.12 +2. Redistributions in binary form must reproduce the above copyright 1.13 + notice, this list of conditions and the following disclaimer in the 1.14 + documentation and/or other materials provided with the distribution. 1.15 + 1.16 +THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. AS IS AND ANY 1.17 +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.18 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.19 +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 1.20 +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.21 +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.22 +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.23 +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 1.24 +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.25 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.26 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.27 +--> 1.28 +<!DOCTYPE html> 1.29 +<html> 1.30 +<head> 1.31 +<meta charset="utf-8"> 1.32 +<link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.33 +<script src="../../resources/js-test-pre.js"></script> 1.34 +<script src="../resources/webgl-test.js"></script> 1.35 +</head> 1.36 +<body> 1.37 +<div id="description"></div> 1.38 +<div id="console"></div> 1.39 + 1.40 +<script> 1.41 +description("Test of get calls against GL objects like getBufferParameter, etc."); 1.42 + 1.43 +function sizeInBytes(type) { 1.44 + switch (type) { 1.45 + case gl.BYTE: 1.46 + case gl.UNSIGNED_BYTE: 1.47 + return 1; 1.48 + case gl.SHORT: 1.49 + case gl.UNSIGNED_SHORT: 1.50 + return 2; 1.51 + case gl.INT: 1.52 + case gl.UNSIGNED_INT: 1.53 + case gl.FLOAT: 1.54 + return 4; 1.55 + default: 1.56 + throw "unknown type"; 1.57 + } 1.58 +} 1.59 + 1.60 +var gl = create3DContext(); 1.61 + 1.62 +var standardVert = loadStandardVertexShader(gl); 1.63 +var standardFrag = loadStandardFragmentShader(gl); 1.64 +var standardProgram = gl.createProgram(); 1.65 +gl.attachShader(standardProgram, standardVert); 1.66 +gl.attachShader(standardProgram, standardFrag); 1.67 +gl.linkProgram(standardProgram); 1.68 +var shaders = gl.getAttachedShaders(standardProgram); 1.69 +shouldBe('shaders.length', '2'); 1.70 +shouldBeTrue('shaders[0] == standardVert && shaders[1] == standardFrag || shaders[1] == standardVert && shaders[0] == standardFrag'); 1.71 +glErrorShouldBe(gl, gl.NO_ERROR); 1.72 +shouldBeNull('gl.getAttachedShaders(null)'); 1.73 +glErrorShouldBe(gl, gl.INVALID_VALUE); 1.74 +shouldThrow('gl.getAttachedShaders(standardVert)'); 1.75 +glErrorShouldBe(gl, gl.NO_ERROR); 1.76 + 1.77 +// Test getBufferParameter 1.78 +var buffer = gl.createBuffer(); 1.79 +gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 1.80 +gl.bufferData(gl.ARRAY_BUFFER, 16, gl.DYNAMIC_DRAW); 1.81 +shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)', '16'); 1.82 +shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_USAGE)', 'gl.DYNAMIC_DRAW'); 1.83 + 1.84 +// Test getFramebufferAttachmentParameter 1.85 +var texture = gl.createTexture(); 1.86 +gl.bindTexture(gl.TEXTURE_2D, texture); 1.87 +gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, 1.88 + new Uint8Array([ 1.89 + 0, 0, 0, 255, 1.90 + 255, 255, 255, 255, 1.91 + 255, 255, 255, 255, 1.92 + 0, 0, 0, 255])); 1.93 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); 1.94 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); 1.95 +gl.bindTexture(gl.TEXTURE_2D, null); 1.96 +var framebuffer = gl.createFramebuffer(); 1.97 +gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); 1.98 +gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); 1.99 +var renderbuffer = gl.createRenderbuffer(); 1.100 +glErrorShouldBe(gl, gl.NO_ERROR); 1.101 +gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); 1.102 +glErrorShouldBe(gl, gl.NO_ERROR); 1.103 +gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 2, 2); 1.104 +glErrorShouldBe(gl, gl.NO_ERROR); 1.105 +gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuffer); 1.106 +// FIXME: on some machines (in particular the WebKit commit bots) the 1.107 +// framebuffer status is FRAMEBUFFER_UNSUPPORTED; more investigation 1.108 +// is needed why this is the case, because the FBO allocated 1.109 +// internally by the WebKit implementation has almost identical 1.110 +// parameters to this one. See https://bugs.webkit.org/show_bug.cgi?id=31843. 1.111 +shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE'); 1.112 +shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.TEXTURE'); 1.113 +shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)', 'texture'); 1.114 +shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL)', '0'); 1.115 +shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE)', '0'); 1.116 + 1.117 +shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.RENDERBUFFER'); 1.118 +shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)', 'renderbuffer'); 1.119 + 1.120 +// Test getProgramParameter 1.121 +shouldBe('gl.getProgramParameter(standardProgram, gl.DELETE_STATUS)', 'false'); 1.122 +shouldBe('gl.getProgramParameter(standardProgram, gl.LINK_STATUS)', 'true'); 1.123 +shouldBe('typeof gl.getProgramParameter(standardProgram, gl.VALIDATE_STATUS)', '"boolean"'); 1.124 +shouldBe('gl.getProgramParameter(standardProgram, gl.ATTACHED_SHADERS)', '2'); 1.125 +shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_ATTRIBUTES)', '2'); 1.126 +shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_UNIFORMS)', '1'); 1.127 + 1.128 +// Test getRenderbufferParameter 1.129 +shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)', '2'); 1.130 +shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_HEIGHT)', '2'); 1.131 +// Note: we can't test the actual value of the internal format since 1.132 +// the implementation is allowed to change it. 1.133 +shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_INTERNAL_FORMAT)'); 1.134 +shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_DEPTH_SIZE)'); 1.135 +var colorbuffer = gl.createRenderbuffer(); 1.136 +glErrorShouldBe(gl, gl.NO_ERROR); 1.137 +gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); 1.138 +glErrorShouldBe(gl, gl.NO_ERROR); 1.139 +gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 2, 2); 1.140 +shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_RED_SIZE)'); 1.141 +shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_GREEN_SIZE)'); 1.142 +shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_BLUE_SIZE)'); 1.143 +shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_ALPHA_SIZE)'); 1.144 + 1.145 +// Test getShaderParameter 1.146 +shouldBe('gl.getShaderParameter(standardVert, gl.SHADER_TYPE)', 'gl.VERTEX_SHADER'); 1.147 +shouldBe('gl.getShaderParameter(standardVert, gl.DELETE_STATUS)', 'false'); 1.148 +shouldBe('gl.getShaderParameter(standardVert, gl.COMPILE_STATUS)', 'true'); 1.149 + 1.150 +// Test getTexParameter 1.151 +gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); 1.152 +gl.bindTexture(gl.TEXTURE_2D, texture); 1.153 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 1.154 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 1.155 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 1.156 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 1.157 +shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER)', 'gl.NEAREST'); 1.158 +shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER)', 'gl.NEAREST'); 1.159 +shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)', 'gl.CLAMP_TO_EDGE'); 1.160 +shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T)', 'gl.CLAMP_TO_EDGE'); 1.161 + 1.162 +// Test getUniform with all variants of data types 1.163 +// Boolean uniform variables 1.164 +var boolProgram = loadProgram(gl, "../resources/boolUniformShader.vert", "../resources/noopUniformShader.frag"); 1.165 +shouldBe('gl.getProgramParameter(boolProgram, gl.LINK_STATUS)', 'true'); 1.166 +var bvalLoc = gl.getUniformLocation(boolProgram, "bval"); 1.167 +var bval2Loc = gl.getUniformLocation(boolProgram, "bval2"); 1.168 +var bval3Loc = gl.getUniformLocation(boolProgram, "bval3"); 1.169 +var bval4Loc = gl.getUniformLocation(boolProgram, "bval4"); 1.170 +gl.useProgram(boolProgram); 1.171 +gl.uniform1i(bvalLoc, 1); 1.172 +gl.uniform2i(bval2Loc, 1, 0); 1.173 +gl.uniform3i(bval3Loc, 1, 0, 1); 1.174 +gl.uniform4i(bval4Loc, 1, 0, 1, 0); 1.175 +glErrorShouldBe(gl, gl.NO_ERROR); 1.176 +shouldBe('gl.getUniform(boolProgram, bvalLoc)', 'true'); 1.177 +shouldBe('gl.getUniform(boolProgram, bval2Loc)', '[true, false]'); 1.178 +shouldBe('gl.getUniform(boolProgram, bval3Loc)', '[true, false, true]'); 1.179 +shouldBe('gl.getUniform(boolProgram, bval4Loc)', '[true, false, true, false]'); 1.180 +// Integer uniform variables 1.181 +var intProgram = loadProgram(gl, "../resources/intUniformShader.vert", "../resources/noopUniformShader.frag"); 1.182 +shouldBe('gl.getProgramParameter(intProgram, gl.LINK_STATUS)', 'true'); 1.183 +var ivalLoc = gl.getUniformLocation(intProgram, "ival"); 1.184 +var ival2Loc = gl.getUniformLocation(intProgram, "ival2"); 1.185 +var ival3Loc = gl.getUniformLocation(intProgram, "ival3"); 1.186 +var ival4Loc = gl.getUniformLocation(intProgram, "ival4"); 1.187 +gl.useProgram(intProgram); 1.188 +gl.uniform1i(ivalLoc, 1); 1.189 +gl.uniform2i(ival2Loc, 2, 3); 1.190 +gl.uniform3i(ival3Loc, 4, 5, 6); 1.191 +gl.uniform4i(ival4Loc, 7, 8, 9, 10); 1.192 +glErrorShouldBe(gl, gl.NO_ERROR); 1.193 +shouldBe('gl.getUniform(intProgram, ivalLoc)', '1'); 1.194 +shouldBe('gl.getUniform(intProgram, ival2Loc)', '[2, 3]'); 1.195 +shouldBe('gl.getUniform(intProgram, ival3Loc)', '[4, 5, 6]'); 1.196 +shouldBe('gl.getUniform(intProgram, ival4Loc)', '[7, 8, 9, 10]'); 1.197 +// Float uniform variables 1.198 +var floatProgram = loadProgram(gl, "../resources/floatUniformShader.vert", "../resources/noopUniformShader.frag"); 1.199 +shouldBe('gl.getProgramParameter(floatProgram, gl.LINK_STATUS)', 'true'); 1.200 +var fvalLoc = gl.getUniformLocation(floatProgram, "fval"); 1.201 +var fval2Loc = gl.getUniformLocation(floatProgram, "fval2"); 1.202 +var fval3Loc = gl.getUniformLocation(floatProgram, "fval3"); 1.203 +var fval4Loc = gl.getUniformLocation(floatProgram, "fval4"); 1.204 +gl.useProgram(floatProgram); 1.205 +gl.uniform1f(fvalLoc, 11); 1.206 +gl.uniform2f(fval2Loc, 12, 13); 1.207 +gl.uniform3f(fval3Loc, 14, 15, 16); 1.208 +gl.uniform4f(fval4Loc, 17, 18, 19, 20); 1.209 +glErrorShouldBe(gl, gl.NO_ERROR); 1.210 +shouldBe('gl.getUniform(floatProgram, fvalLoc)', '11'); 1.211 +shouldBe('gl.getUniform(floatProgram, fval2Loc)', '[12, 13]'); 1.212 +shouldBe('gl.getUniform(floatProgram, fval3Loc)', '[14, 15, 16]'); 1.213 +shouldBe('gl.getUniform(floatProgram, fval4Loc)', '[17, 18, 19, 20]'); 1.214 +// Sampler uniform variables 1.215 +var samplerProgram = loadProgram(gl, "../resources/noopUniformShader.vert", "../resources/samplerUniformShader.frag"); 1.216 +shouldBe('gl.getProgramParameter(samplerProgram, gl.LINK_STATUS)', 'true'); 1.217 +var s2DValLoc = gl.getUniformLocation(samplerProgram, "s2D"); 1.218 +var sCubeValLoc = gl.getUniformLocation(samplerProgram, "sCube"); 1.219 +gl.useProgram(samplerProgram); 1.220 +gl.uniform1i(s2DValLoc, 0); 1.221 +gl.uniform1i(sCubeValLoc, 1); 1.222 +glErrorShouldBe(gl, gl.NO_ERROR); 1.223 +shouldBe('gl.getUniform(samplerProgram, s2DValLoc)', '0'); 1.224 +shouldBe('gl.getUniform(samplerProgram, sCubeValLoc)', '1'); 1.225 +// Matrix uniform variables 1.226 +var matProgram = loadProgram(gl, "../resources/matUniformShader.vert", "../resources/noopUniformShader.frag"); 1.227 +shouldBe('gl.getProgramParameter(matProgram, gl.LINK_STATUS)', 'true'); 1.228 +var mval2Loc = gl.getUniformLocation(matProgram, "mval2"); 1.229 +var mval3Loc = gl.getUniformLocation(matProgram, "mval3"); 1.230 +var mval4Loc = gl.getUniformLocation(matProgram, "mval4"); 1.231 +gl.useProgram(matProgram); 1.232 +gl.uniformMatrix2fv(mval2Loc, false, [1, 2, 3, 4]); 1.233 +gl.uniformMatrix3fv(mval3Loc, false, [5, 6, 7, 8, 9, 10, 11, 12, 13]); 1.234 +gl.uniformMatrix4fv(mval4Loc, false, [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]); 1.235 +glErrorShouldBe(gl, gl.NO_ERROR); 1.236 +shouldBe('gl.getUniform(matProgram, mval2Loc)', '[1, 2, 3, 4]'); 1.237 +shouldBe('gl.getUniform(matProgram, mval3Loc)', '[5, 6, 7, 8, 9, 10, 11, 12, 13]'); 1.238 +shouldBe('gl.getUniform(matProgram, mval4Loc)', '[14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]'); 1.239 + 1.240 +// Test getVertexAttrib 1.241 +var array = new Float32Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); 1.242 +gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 1.243 +gl.bufferData(gl.ARRAY_BUFFER, array, gl.DYNAMIC_DRAW); 1.244 +// Vertex attribute 0 is special in that it has no current state, so 1.245 +// fetching GL_CURRENT_VERTEX_ATTRIB generates an error. Use attribute 1.246 +// 1 for these tests instead. 1.247 +gl.enableVertexAttribArray(1); 1.248 +gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 0, 0); 1.249 +shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)', 'buffer'); 1.250 +shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'true'); 1.251 +shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_SIZE)', '4'); 1.252 +// Stride MUST be the value the user put in. 1.253 +shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE)', '0'); 1.254 +shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_TYPE)', 'gl.FLOAT'); 1.255 +shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED)', 'false'); 1.256 +gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 36, 12); 1.257 +shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE)', '36'); 1.258 +shouldBe('gl.getVertexAttribOffset(1, gl.VERTEX_ATTRIB_ARRAY_POINTER)', '12'); 1.259 +gl.disableVertexAttribArray(1); 1.260 +shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'false'); 1.261 +gl.vertexAttrib4f(1, 5, 6, 7, 8); 1.262 +shouldBe('gl.getVertexAttrib(1, gl.CURRENT_VERTEX_ATTRIB)', '[5, 6, 7, 8]'); 1.263 +glErrorShouldBe(gl, gl.NO_ERROR); 1.264 + 1.265 +// Test cases where name == 0 1.266 +gl.deleteTexture(texture); 1.267 +shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.NONE'); 1.268 +gl.deleteRenderbuffer(renderbuffer); 1.269 +shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.NONE'); 1.270 +gl.deleteBuffer(buffer); 1.271 +shouldBeNull('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)'); 1.272 +glErrorShouldBe(gl, gl.NO_ERROR); 1.273 + 1.274 +successfullyParsed = true; 1.275 +</script> 1.276 + 1.277 +<script>finishTest();</script> 1.278 +</body> 1.279 +</html>