OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style license that can be |
| 4 found in the LICENSE file. |
| 5 --> |
| 6 <!DOCTYPE html> |
| 7 <html> |
| 8 <head> |
| 9 <meta charset="utf-8"> |
| 10 <title>WebGL getActiveUniform conformance test.</title> |
| 11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 12 <script src="../../resources/js-test-pre.js"></script> |
| 13 <script src="../resources/webgl-test.js"> </script> |
| 14 <script src="../resources/webgl-test-utils.js"> </script> |
| 15 </head> |
| 16 <body> |
| 17 <canvas id="example" width="16" height="16"></canvas> |
| 18 <div id="description"></div> |
| 19 <div id="console"></div> |
| 20 <script id="vshader" type="x-shader/x-vertex"> |
| 21 void main() |
| 22 { |
| 23 gl_Position = vec4(0, 0, 0, 1); |
| 24 } |
| 25 </script> |
| 26 <script id="fshader" type="x-shader/x-fragment"> |
| 27 precision mediump float; |
| 28 uniform $type uniform0; |
| 29 void main() |
| 30 { |
| 31 gl_FragColor = vec4(0,$access,0,1); |
| 32 } |
| 33 </script> |
| 34 <script id="fshaderA" type="x-shader/x-fragment"> |
| 35 precision mediump float; |
| 36 uniform float uniform0; |
| 37 void main() |
| 38 { |
| 39 gl_FragColor = vec4(0,uniform0,0,1); |
| 40 } |
| 41 </script> |
| 42 <script id="fshaderB" type="x-shader/x-fragment"> |
| 43 precision mediump float; |
| 44 uniform float uniform0; |
| 45 uniform float uniform1; |
| 46 void main() |
| 47 { |
| 48 gl_FragColor = vec4(0,uniform0,uniform1,1); |
| 49 } |
| 50 </script> |
| 51 <script> |
| 52 description("Tests getActiveUniform for various types"); |
| 53 |
| 54 var wtu = WebGLTestUtils; |
| 55 var canvas = document.getElementById("example"); |
| 56 var gl = wtu.create3DContext(canvas); |
| 57 |
| 58 var tests = [ |
| 59 { glType: gl.FLOAT, size: 1, type: 'float', access: 'uniform0'}, |
| 60 { glType: gl.FLOAT_VEC2, size: 1, type: 'vec2', access: 'uniform0[1]'}, |
| 61 { glType: gl.FLOAT_VEC3, size: 1, type: 'vec3', access: 'uniform0[2]'}, |
| 62 { glType: gl.FLOAT_VEC4, size: 1, type: 'vec4', access: 'uniform0[3]'}, |
| 63 { glType: gl.FLOAT_MAT2, size: 1, type: 'mat2', access: 'uniform0[1][1]'}, |
| 64 { glType: gl.FLOAT_MAT3, size: 1, type: 'mat3', access: 'uniform0[2][2]'}, |
| 65 { glType: gl.FLOAT_MAT3, size: 1, type: 'mat3', access: 'uniform0[2][2]'}, |
| 66 { glType: gl.FLOAT_MAT4, size: 1, type: 'mat4', access: 'uniform0[3][3]'}, |
| 67 { glType: gl.INT, size: 1, type: 'int', access: 'float(uniform0)'}, |
| 68 { glType: gl.INT_VEC2, size: 1, type: 'ivec2', access: 'float(uniform0[1])'}, |
| 69 { glType: gl.INT_VEC3, size: 1, type: 'ivec3', access: 'float(uniform0[2])'}, |
| 70 { glType: gl.INT_VEC4, size: 1, type: 'ivec4', access: 'float(uniform0[3])'}, |
| 71 { glType: gl.BOOL, size: 1, type: 'bool', access: 'float(uniform0)'}, |
| 72 { glType: gl.BOOL_VEC2, size: 1, type: 'bvec2', access: 'float(uniform0[1])'}, |
| 73 { glType: gl.BOOL_VEC3, size: 1, type: 'bvec3', access: 'float(uniform0[2])'}, |
| 74 { glType: gl.BOOL_VEC4, size: 1, type: 'bvec4', access: 'float(uniform0[3])'}, |
| 75 { glType: gl.SAMPLER_2D, |
| 76 size: 1, |
| 77 type: 'sampler2D', |
| 78 access: 'texture2D(uniform0, vec2(0,0)).x' |
| 79 }, |
| 80 { glType: gl.SAMPLER_CUBE, |
| 81 size: 1, |
| 82 type: 'samplerCube', |
| 83 access: 'textureCube(uniform0, vec3(0,1,0)).x' |
| 84 } |
| 85 ]; |
| 86 |
| 87 var vs = wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER); |
| 88 var source = document.getElementById('fshader').text; |
| 89 |
| 90 function createProgram(type, access) { |
| 91 var fs = wtu.loadShader( |
| 92 gl, |
| 93 source.replace('$type', type).replace('$access', access), |
| 94 gl.FRAGMENT_SHADER); |
| 95 var program = wtu.setupProgram(gl, [vs, fs]); |
| 96 glErrorShouldBe(gl, gl.NO_ERROR, "no errors from setup"); |
| 97 return program; |
| 98 } |
| 99 |
| 100 for (var tt = 0; tt < tests.length; ++tt) { |
| 101 var t = tests[tt]; |
| 102 var program = createProgram(t.type, t.access); |
| 103 var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS); |
| 104 var found = false; |
| 105 for (var ii = 0; ii < numUniforms; ++ii) { |
| 106 var info = gl.getActiveUniform(program, ii); |
| 107 if (info.name == 'uniform0') { |
| 108 found = true; |
| 109 assertMsg(info.type == t.glType, |
| 110 "type must be " + wtu.glEnumToString(gl, t.glType) + " was " + |
| 111 wtu.glEnumToString(gl, info.type)); |
| 112 assertMsg(info.size == t.size, |
| 113 "size must be " + t.size + ' was ' + info.size); |
| 114 } |
| 115 } |
| 116 if (!found) { |
| 117 testFailed("uniform 'uniform0' not found"); |
| 118 } |
| 119 } |
| 120 |
| 121 var p1 = wtu.setupProgram( |
| 122 gl, [vs, wtu.loadShaderFromScript(gl, 'fshaderA', gl.FRAGMENT_SHADER)]); |
| 123 glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program A"); |
| 124 var p2 = wtu.setupProgram( |
| 125 gl, [vs, wtu.loadShaderFromScript(gl, 'fshaderB', gl.FRAGMENT_SHADER)]); |
| 126 glErrorShouldBe(gl, gl.NO_ERROR, "no errors from program B"); |
| 127 var l1 = gl.getUniformLocation(p1, 'uniform0'); |
| 128 glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p1"); |
| 129 var l2 = gl.getUniformLocation(p2, 'uniform0'); |
| 130 glErrorShouldBe(gl, gl.NO_ERROR, "no errors getting location of uniform0 p2"); |
| 131 |
| 132 gl.useProgram(p2); |
| 133 gl.uniform1f(l2, 1); |
| 134 glErrorShouldBe(gl, gl.NO_ERROR, "no errors setting uniform 0"); |
| 135 gl.uniform1f(l1, 2); |
| 136 glErrorShouldBe(gl, gl.INVALID_OPERATION, |
| 137 "setting a uniform using a location from another program"); |
| 138 |
| 139 successfullyParsed = true; |
| 140 </script> |
| 141 <script src="../../resources/js-test-post.js"></script> |
| 142 |
| 143 </body> |
| 144 </html> |
| 145 |
| 146 |
OLD | NEW |