diff options
Diffstat (limited to 'dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables')
7 files changed, 772 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/00_test_list.txt b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/00_test_list.txt new file mode 100644 index 000000000..31fe0f8f2 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/00_test_list.txt @@ -0,0 +1,6 @@ +gl-fragcoord.html +gl-frontfacing.html +gl-pointcoord.html +--min-version 1.0.2 glsl-built-ins.html +--min-version 1.0.3 gl-fragcoord-xy-values.html +--min-version 1.0.3 gl-fragdata-and-fragcolor.html diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-fragcoord-xy-values.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-fragcoord-xy-values.html new file mode 100644 index 000000000..5c16faea2 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-fragcoord-xy-values.html @@ -0,0 +1,206 @@ +<!-- + +/* +** Copyright (c) 2014 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>gl-fragcoord Test</title> +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> +<script src="../../../js/js-test-pre.js"></script> +<script src="../../../js/webgl-test-utils.js"> </script> +</head> +<body> +<canvas id="canvas" width="32" height="32"> +</canvas> +<div id="description"></div> +<div id="console"></div> +<script id="vshader" type="x-shader/x-vertex"> +// Inputs +attribute vec4 aPosInfo; + +// Outputs +varying vec2 vTargetPixelCoord; + +void main() +{ + vTargetPixelCoord = aPosInfo.zw; + + gl_PointSize = 1.0; + gl_Position = vec4(aPosInfo.xy, 0.0, 1.0); +} +</script> + +<script id="fshader" type="x-shader/x-fragment"> +precision mediump float; + +// Inputs +varying vec2 vTargetPixelCoord; + +// Colors used to signal correctness +const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); +const vec4 green = vec4(0.0, 1.0, 0.0, 1.0); + +void main() +{ + // Check pixel index + bool pixelIxValid = (floor(gl_FragCoord.xy) == vTargetPixelCoord); + + // Check fractional part of coordinates + bool fracCoordValid = all(lessThan(abs(fract(gl_FragCoord.xy) - vec2(0.5)), vec2(0.0001))); + + gl_FragColor = (pixelIxValid && fracCoordValid) ? green : red; +} +</script> + +<script id="test_fshader" type="x-shader/x-fragment"> +// Shader to test if the frame buffer positions within the output pixel are different for the five render passes +// Pass on frame buffer position in varying, change in vertex shader : vTargetPixelCoord = aPosInfo.xy; +// Set test_fshader in setupProgram() + +precision mediump float; + +// Inputs +varying vec2 vTargetPixelCoord; + +const vec2 pixSize = vec2(2.0/32.0, 2.0/32.0); + +void main() +{ + // Coordinates within a framebuffer pixel [0, 1> + vec2 inPixelCoord = fract(vTargetPixelCoord / pixSize); + + // Create different color dependent on the position inside the framebuffer pixel + float r = (inPixelCoord.x < 0.4) ? 0.2 : (inPixelCoord.x > 0.6) ? 0.8 : 0.5; + float g = (inPixelCoord.y < 0.4) ? 0.2 : (inPixelCoord.y > 0.6) ? 0.8 : 0.5; + + gl_FragColor = vec4(r, g, 0.0, 1.0); +} +</script> + +<script> +"use strict"; + +// Test if gl_FragCoord.xy values are always of the form : +// (first framebuffer pixel index + 0.5, second framebuffer pixel index + 0.5) +// (if no multisampling) + +// This is done by rendering a set of points which targets either the center of the +// output pixel or the center of one of the quadrants + +// Constants +var floatsPerAttribute = 4; + +// Globals +var wtu; +var gl; +var program; +var vxBuffer; + +// Set data for one attribute (framebuffer.xy, pixel_index.xy) +function setPixelData(data, dIx, xx, yy, xSize, ySize, xOffset, yOffset) +{ + // Frame buffer first coordinate [-1, 1] + data[dIx++] = (xx + 0.5) * xSize + xOffset - 1; + + // Frame buffer second coordinate [-1, 1] + data[dIx++] = (yy + 0.5) * ySize + yOffset - 1; + + // Frame buffer pixel first index + data[dIx++] = xx; + + // Frame buffer pixel second index + data[dIx++] = yy; + + return dIx; +} + +// Create attribute data +function createAttributeData(xOffset, yOffset) +{ + // Retrieve realised dimensions of viewport + var widthPx = gl.drawingBufferWidth; + var heightPx = gl.drawingBufferHeight; + var pixelCount = widthPx * heightPx; + + // Pixel size in framebuffer coordinates + var pWidth = 2 / widthPx; + var pHeight = 2 / heightPx; + var data = new Float32Array(pixelCount * floatsPerAttribute); + var dIx = 0; + for (var yy = 0; yy < heightPx; ++yy) + for (var xx = 0; xx < widthPx; ++xx) + dIx = setPixelData(data, dIx, xx, yy, pWidth, pHeight, xOffset * pWidth, yOffset * pHeight); + + if (dIx !== data.length) + wtu.error("gl-fragcoord-xy-values.html, createAttributeData(), index not correct at end"); + + return data; +} + +// Initialize test +function init() +{ + description("tests gl_FragCoord.xy values"); + + wtu = WebGLTestUtils; + gl = wtu.create3DContext("canvas", { antialias: false }); + program = wtu.setupProgram(gl, ["vshader", "fshader"], ["aPosInfo"]); + vxBuffer = gl.createBuffer(); + + gl.bindBuffer(gl.ARRAY_BUFFER, vxBuffer); + gl.enableVertexAttribArray(0); + gl.vertexAttribPointer(0, floatsPerAttribute, gl.FLOAT, false, 0, 0); +} + +// Render data +function render(xOffset, yOffset, passMsg) +{ + // Set attribute data + var data = createAttributeData(xOffset, yOffset); + gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW); + + gl.clear(gl.COLOR_BUFFER_BIT); + gl.drawArrays(gl.POINTS, 0, data.length / floatsPerAttribute); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors from draw"); + var green = [0, 255, 0, 255]; + wtu.checkCanvas(gl, green, passMsg); +} + +// Run tests +init(); +render(0, 0, "green : sampling at center of output pixel is correct"); +render(0.25, 0.25, "green : sampling in top right quadrant of output pixel is correct"); +render(-0.25, 0.25, "green : sampling in top left quadrant of output pixel is correct"); +render( 0.25, -0.25, "green : sampling in bottom right quadrant of output pixel is correct"); +render(-0.25, -0.25, "green : sampling in bottom left quadrant of output pixel is correct"); +var successfullyParsed = true; +</script> +<script src="../../../js/js-test-post.js"></script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-fragcoord.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-fragcoord.html new file mode 100644 index 000000000..c9c4ac4b6 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-fragcoord.html @@ -0,0 +1,105 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>gl-fragcoord Test</title> +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> +<script src="../../../js/js-test-pre.js"></script> +<script src="../../../js/webgl-test-utils.js"> </script> +</head> +<body> +<canvas id="example" width="32" height="32"> +</canvas> +<div id="description"></div> +<div id="console"></div> +<script id="vshader" type="x-shader/x-vertex"> +attribute vec4 vPosition; +void main() +{ + gl_Position = vPosition; +} +</script> + +<script id="fshader" type="x-shader/x-fragment"> +precision mediump float; +void main() +{ + gl_FragColor = vec4( + floor(gl_FragCoord.x * 4.0 / 32.0) / 4.0, + floor(gl_FragCoord.y * 4.0 / 32.0) / 4.0, + floor(gl_FragCoord.z * 4.0) / 4.0, + 1); +} +</script> + +<script> +"use strict"; +function init() +{ + description("tests gl_FragCoord"); + + var wtu = WebGLTestUtils; + var gl = wtu.create3DContext("example"); + var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]); + + var vertexObject = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array( + [-1, -1, -1, 1, -1, 0, -1, 1, 0, + -1, 1, 0, 1, -1, 0, 1, 1, 1]), + gl.STATIC_DRAW); + gl.enableVertexAttribArray(0); + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); + + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + gl.drawArrays(gl.TRIANGLES, 0, 6); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors from draw"); + + for (var xx = 0; xx < 32; xx += 4) { + for (var yy = 0; yy < 32; yy += 4) { + var zz = (xx / 64) + (yy / 64); + var color = [ + Math.floor(Math.floor(xx * 4.0 / 32.0) / 4 * 256), + Math.floor(Math.floor(yy * 4.0 / 32.0) / 4 * 256), + Math.floor(Math.floor(zz * 4.0) / 4 * 256) + ]; + var msg = "should be " + color; + wtu.checkCanvasRect(gl, xx, yy, 1, 1, color, msg, 4); + } + } +} + +init(); +var successfullyParsed = true; +</script> +<script src="../../../js/js-test-post.js"></script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-fragdata-and-fragcolor.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-fragdata-and-fragcolor.html new file mode 100644 index 000000000..59f294d36 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-fragdata-and-fragcolor.html @@ -0,0 +1,59 @@ +<!-- + +/* +** Copyright (c) 2014 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>WebGL GLSL Conformance Tests</title> +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> +<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/> +<script src="../../../js/js-test-pre.js"></script> +<script src="../../../js/webgl-test-utils.js"></script> +<script src="../../../js/glsl-conformance-test.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> +<script id="fragmentShader" type="text/something-not-javascript"> +// fragment shader with static assignment to both gl_FragData[0] and gl_FragColor should fail. +// GLES spec section 3.8.2 subsection Shader Outputs. +precision mediump float; + +void main() +{ + gl_FragData[0] = vec4(1, 0, 0, 1); + gl_FragColor = vec4(0, 1, 0, 1); +} +</script> +<script> +"use strict"; +GLSLConformanceTester.runTest(); +var successfullyParsed = true; +</script> +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-frontfacing.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-frontfacing.html new file mode 100644 index 000000000..c944f24ed --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-frontfacing.html @@ -0,0 +1,107 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>gl-fragcoord Test</title> +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> +<script src="../../../js/js-test-pre.js"></script> +<script src="../../../js/webgl-test-utils.js"> </script> +</head> +<body> +<canvas id="example" width="32" height="32"> +</canvas> +<div id="description"></div> +<div id="console"></div> +<script id="vshader" type="x-shader/x-vertex"> +attribute vec4 vPosition; +void main() +{ + gl_Position = vPosition; +} +</script> + +<script id="fshader" type="x-shader/x-fragment"> +precision mediump float; +void main() +{ + gl_FragColor = vec4( + gl_FrontFacing ? 1.0 : 0.0, + gl_FrontFacing ? 0.0 : 1.0, + 0, + 1); +} +</script> + +<script> +"use strict"; +function init() +{ + description("tests gl_FrontFacing"); + + var wtu = WebGLTestUtils; + var gl = wtu.create3DContext("example"); + var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]); + + var gridRes = 4; + wtu.setupIndexedQuad(gl, gridRes, 0, true); + + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + gl.drawElements(gl.TRIANGLES, gridRes * gridRes * 6, gl.UNSIGNED_SHORT, 0); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors from draw"); + + var step = 32 / gridRes; + var halfStep = step / 2; + var quarterStep = halfStep / 2; + for (var xx = 0; xx < 32; xx += step) { + for (var yy = 0; yy < 32; yy += step) { + for (var ii = 0; ii < 2; ++ii) { + var color = [ + ii == 0 ? 255 : 0, + ii == 0 ? 0 : 255, + 0 + ]; + var msg = "should be " + color; + wtu.checkCanvasRect( + gl, + xx + quarterStep + halfStep * ii, + yy + quarterStep + halfStep * ii, + 1, 1, color, msg, 4); + } + } + } +} + +init(); +var successfullyParsed = true; +</script> +<script src="../../../js/js-test-post.js"></script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-pointcoord.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-pointcoord.html new file mode 100644 index 000000000..e7760fc72 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/gl-pointcoord.html @@ -0,0 +1,162 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>gl-pointcoord Test</title> +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> +<script src="../../../js/js-test-pre.js"></script> +<script src="../../../js/webgl-test-utils.js"> </script> +</head> +<body> +<canvas id="example" width="256" height="256"> +</canvas> +<div id="description"></div> +<div id="console"></div> +<script id="vshader" type="x-shader/x-vertex"> +attribute vec4 vPosition; +uniform float uPointSize; +void main() +{ + gl_PointSize = uPointSize; + gl_Position = vPosition; +} +</script> + +<script id="fshader" type="x-shader/x-fragment"> +precision mediump float; +void main() +{ + gl_FragColor = vec4( + gl_PointCoord.x, + gl_PointCoord.y, + 0, + 1); +} +</script> + +<script> +"use strict"; +description("Checks gl_PointCoord and gl_PointSize"); +debug(""); + +// NOTE: I'm not 100% confident in this test. I think it is correct. + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext("example"); +shouldBeNonNull("gl"); +var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["vPosition"]); +shouldBe("gl.getError()", "gl.NO_ERROR"); + +var canvas = gl.canvas; +var width = canvas.width; +var height = canvas.height; +shouldBe("width", "height"); + +var maxPointSize = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE)[1]; +shouldBeTrue("maxPointSize >= 1"); +// The minimum and maximum point sizes may be floating-point numbers. +shouldBeTrue("Math.floor(maxPointSize) >= 1"); +maxPointSize = Math.floor(maxPointSize); +shouldBeTrue("maxPointSize % 1 == 0"); + +maxPointSize = Math.min(maxPointSize, 64); +var pointWidth = maxPointSize / width; +var pointStep = Math.floor(maxPointSize / 4); +var pointStep = Math.max(1, pointStep); + +var pointSizeLoc = gl.getUniformLocation(program, "uPointSize"); +gl.uniform1f(pointSizeLoc, maxPointSize); + +var pixelOffset = (maxPointSize % 2) ? (1 / width) : 0; +var vertexObject = gl.createBuffer(); +gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); +gl.bufferData( + gl.ARRAY_BUFFER, + new Float32Array( + [-0.5 + pixelOffset, -0.5 + pixelOffset, + 0.5 + pixelOffset, -0.5 + pixelOffset, + -0.5 + pixelOffset, 0.5 + pixelOffset, + 0.5 + pixelOffset, 0.5 + pixelOffset]), + gl.STATIC_DRAW); +gl.enableVertexAttribArray(0); +gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0); + +gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + +gl.drawArrays(gl.POINTS, 0, 4); +shouldBe("gl.getError()", "gl.NO_ERROR"); + +function s2p(s) { + return (s + 1.0) * 0.5 * width; +} + +//function print(x, y) { +// var b = new Uint8Array(4); +// gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, b); +// debug("" + x + "," + y + ": " + b[0] + "," + b[1] + "," + b[2]); +//} +// +//for (var ii = 0; ii < 100; ++ii) { +// print(ii, ii); +//} + +for (var py = 0; py < 2; ++py) { + for (var px = 0; px < 2; ++px) { + debug(""); + var pointX = -0.5 + px + pixelOffset; + var pointY = -0.5 + py + pixelOffset; + for (var yy = 0; yy < maxPointSize; yy += pointStep) { + for (var xx = 0; xx < maxPointSize; xx += pointStep) { + // formula for s and t from OpenGL ES 2.0 spec section 3.3 + var xw = s2p(pointX); + var yw = s2p(pointY); + //debug("xw: " + xw + " yw: " + yw); + var u = xx / maxPointSize * 2 - 1; + var v = yy / maxPointSize * 2 - 1; + var xf = Math.floor(s2p(pointX + u * pointWidth)); + var yf = Math.floor(s2p(pointY + v * pointWidth)); + //debug("xf: " + xf + " yf: " + yf); + var s = 0.5 + (xf + 0.5 - xw) / maxPointSize; + var t = 0.5 + (yf + 0.5 - yw) / maxPointSize; + //debug("s: " + s + " t: " + t); + var color = [Math.floor(s * 255), Math.floor((1 - t) * 255), 0]; + var msg = "pixel " + xf + "," + yf + " should be " + color; + wtu.checkCanvasRect(gl, xf, yf, 1, 1, color, msg, 4); + } + } + } +} + +var successfullyParsed = true; +</script> +<script src="../../../js/js-test-post.js"></script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/glsl-built-ins.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/glsl-built-ins.html new file mode 100644 index 000000000..c4c624719 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/variables/glsl-built-ins.html @@ -0,0 +1,127 @@ +<!-- + +/* +** Copyright (c) 2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>WebGL GLSL built in variables Conformance Test</title> +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> +<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/> +<script src="../../../js/js-test-pre.js"></script> +<script src="../../../js/webgl-test-utils.js"></script> +</head> +<body> +<div id="description"></div> +<div id="console"></div> +<canvas id="example" width="2" height="2"> </canvas> +<script id="vshader" type="x-shader/x-vertex"> +attribute vec4 a_position; +void main() +{ + gl_Position = a_position; +} +</script> +<script id="vshaderCheck" type="x-shader/x-vertex"> +attribute vec4 a_position; +varying vec4 v_color; +void main() +{ + gl_Position = a_position; + v_color = (gl_$(name) == $(max)) ? vec4(0,1,0,1) : vec4(1,0,0,1); +} +</script> +<script id="fshader" type="x-shader/x-fragment"> +precision mediump float; +varying vec4 v_color; +void main() +{ + gl_FragColor = v_color; +} +</script> +<script id="fshaderCheck" type="x-shader/x-fragment"> +precision mediump float; +void main() +{ + gl_FragColor = (gl_$(name) == $(max)) ? vec4(0,1,0,1) : vec4(1,0,0,1); +} +</script> +<script> +"use strict"; +description(); +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext("example"); +var contextVersion = wtu.getDefault3DContextVersion(); + +var variables = [ + { name: 'MaxVertexAttribs', min: 8, }, + { name: 'MaxVertexUniformVectors', min: 128, }, + { name: 'MaxVaryingVectors', min: 8, }, + { name: 'MaxVertexTextureImageUnits', min: 0, }, + { name: 'MaxCombinedTextureImageUnits', min: 8, }, + { name: 'MaxTextureImageUnits', min: 8, }, + { name: 'MaxFragmentUniformVectors', min: 16, }, +]; + +if (contextVersion <= 1) { + variables.push({ name: 'MaxDrawBuffers', min: 1, max: 1}); +} else { + variables.push({ name: 'MaxDrawBuffers', min: 1, }); +} + +var toUnderscore = function(str) { + return str.replace(/([a-z])([A-Z])/g, function (g) { return g[0] + "_" + g[1].toUpperCase() }).toUpperCase(); +}; + +var shaderPairs = [ + [wtu.getScript("vshader"), wtu.getScript("fshaderCheck")], + [wtu.getScript("vshaderCheck"), wtu.getScript("fshader")], +]; + +wtu.setupUnitQuad(gl); + +variables.forEach(function(variable) { + debug(""); + debug("Testing gl_" + variable.name); + if (!variable.max) { + variable.max = gl.getParameter(gl[toUnderscore(variable.name)]); + expectTrue(variable.max >= variable.min, "gl.getParameter(gl." + toUnderscore(variable.name) + ") >= " + variable.min); + } + shaderPairs.forEach(function(pair) { + var shaders = [wtu.replaceParams(pair[0], variable), wtu.replaceParams(pair[1], variable)]; + var program = wtu.setupProgram(gl, shaders, ["a_position"], undefined, true); + wtu.clearAndDrawUnitQuad(gl); + wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green"); + }); +}); + +var successfullyParsed = true; +</script> +<script src="../../../js/js-test-post.js"></script> +</body> +</html> + |