1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/misc/shader-precision-format.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 Mozilla Foundation. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<title>WebGL shader precision format test.</title> 1.14 +<link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.15 +<script src="../../resources/js-test-pre.js"></script> 1.16 +<script src="../resources/webgl-test.js"> </script> 1.17 +<script src="../resources/webgl-test-utils.js"> </script> 1.18 +</head> 1.19 +<body> 1.20 +<canvas id="canvas" width="2" height="2" style="width: 40px; height: 40px;"></canvas> 1.21 +<div id="description"></div> 1.22 +<div id="console"></div> 1.23 +<script> 1.24 +var wtu = WebGLTestUtils; 1.25 +description(document.title); 1.26 +debug("Tests that WebGLShaderPrecisionFormat class and getShaderPrecisionFormat work."); 1.27 +debug(""); 1.28 +var gl = wtu.create3DContext("canvas"); 1.29 + 1.30 +function verifyShaderPrecisionFormat(shadertype, precisiontype) { 1.31 + shouldBeTrue('gl.getShaderPrecisionFormat(' + shadertype + ', ' + 1.32 + precisiontype + ') instanceof WebGLShaderPrecisionFormat'); 1.33 +} 1.34 + 1.35 +if (gl.getShaderPrecisionFormat == null || typeof gl.getShaderPrecisionFormat != 'function') { 1.36 + debug("getShaderPrecisionFormat() function not found."); 1.37 +} else { 1.38 + debug(""); 1.39 + debug("Test that getShaderPrecisionFormat returns a WebGLShaderPrecisionFormat object."); 1.40 + debug(""); 1.41 + 1.42 + verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.LOW_FLOAT'); 1.43 + verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.MEDIUM_FLOAT'); 1.44 + verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.HIGH_FLOAT'); 1.45 + verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.LOW_INT'); 1.46 + verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.MEDIUM_INT'); 1.47 + verifyShaderPrecisionFormat('gl.VERTEX_SHADER', 'gl.HIGH_INT'); 1.48 + verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.LOW_FLOAT'); 1.49 + verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.MEDIUM_FLOAT'); 1.50 + verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.HIGH_FLOAT'); 1.51 + verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.LOW_INT'); 1.52 + verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.MEDIUM_INT'); 1.53 + verifyShaderPrecisionFormat('gl.FRAGMENT_SHADER', 'gl.HIGH_INT'); 1.54 + 1.55 + debug(""); 1.56 + debug("Test that getShaderPrecisionFormat throws an error with invalid parameters."); 1.57 + debug(""); 1.58 + 1.59 + shouldGenerateGLError(gl, gl.INVALID_ENUM, 'gl.getShaderPrecisionFormat(gl.HIGH_INT, gl.VERTEX_SHADER)'); 1.60 + 1.61 + debug(""); 1.62 + debug("Test that WebGLShaderPrecisionFormat values are sensible."); 1.63 + debug(""); 1.64 + 1.65 + var shaderPrecisionFormat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT); 1.66 + shouldBeTrue('shaderPrecisionFormat.rangeMin >= 0 && shaderPrecisionFormat.rangeMin <= 128'); 1.67 + shouldBeTrue('shaderPrecisionFormat.rangeMax >= 0 && shaderPrecisionFormat.rangeMax <= 128'); 1.68 + shouldBeTrue('shaderPrecisionFormat.precision >= 0 && shaderPrecisionFormat.precision <= 128'); 1.69 + 1.70 + debug(""); 1.71 + debug("Test that getShaderPrecisionFormat returns the same thing every call."); 1.72 + debug(""); 1.73 + 1.74 + var shaderPrecisionFormat2 = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT); 1.75 + shouldBeTrue('shaderPrecisionFormat.rangeMin == shaderPrecisionFormat2.rangeMin'); 1.76 + shouldBeTrue('shaderPrecisionFormat.rangeMax == shaderPrecisionFormat2.rangeMax'); 1.77 + shouldBeTrue('shaderPrecisionFormat.precision == shaderPrecisionFormat2.precision'); 1.78 +} 1.79 + 1.80 +finishTest(); 1.81 +</script> 1.82 + 1.83 +</body> 1.84 +</html> 1.85 + 1.86 +