2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL uniform values are per program conformance test.
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <script id=
"vshader" type=
"x-shader/x-vertex">
18 attribute vec4 a_position;
20 gl_Position = a_position;
23 <script id=
"fshader" type=
"x-shader/x-fragment">
24 precision mediump float;
27 gl_FragColor = v_color;
30 <script id=
"vshaderTest" type=
"x-shader/x-vertex">
31 attribute vec4 a_position;
32 uniform $(type) $(name1);
33 uniform $(type) $(name2);
34 uniform bool u_select;
37 $(type) value = u_select ? $(name2) : $(name1);
38 v_color = $(conversion);
39 gl_Position = a_position;
42 <script id=
"fshaderTest" type=
"x-shader/x-fragment">
43 precision mediump float;
44 uniform $(type) $(name1);
45 uniform $(type) $(name2);
46 uniform bool u_select;
48 $(type) value = u_select ? $(name2) : $(name1);
49 gl_FragColor = $(conversion);
52 <canvas id=
"example" width=
"2" height=
"2" style=
"width: 40px; height: 40px;"></canvas>
53 <div id=
"description"></div>
54 <div id=
"console"></div>
60 var console
= document
.getElementById("console");
61 var wtu
= WebGLTestUtils
;
62 var gl
= wtu
.create3DContext("example");
63 wtu
.setupUnitQuad(gl
);
64 var vtemplate
= wtu
.getScript("vshader");
65 var ftemplate
= wtu
.getScript("fshader");
66 var vtemplateTest
= wtu
.getScript("vshaderTest");
67 var ftemplateTest
= wtu
.getScript("fshaderTest");
70 [vtemplate
, ftemplateTest
],
71 [vtemplateTest
, ftemplate
],
75 ["u_value1", "u_value2"],
84 conversion
: "vec4(value, 0, 0, 0)",
85 values
: [[64], [128]],
89 conversion
: "vec4(value, 0, 0)",
90 values
: [[64, 128], [128, 64]],
94 conversion
: "vec4(value, 0)",
95 values
: [[64, 128, 192], [192, 128, 64]],
99 conversion
: "vec4(value)",
100 values
: [[64, 128, 192, 255], [255, 192, 128, 64]],
105 var clone = function(obj
) {
107 for (var $key
in obj
) {
114 names
.forEach(function(namePair
) {
115 testList
.forEach(function(test
) {
117 t
.name1
= namePair
[0];
118 t
.name2
= namePair
[1];
123 var runTest = function(test
) {
125 debug("testing: " + test
.type
);
126 shaders
.forEach(function(shaderPair
) {
128 for (var ii
= 0; ii
< 2; ++ii
) {
129 var vsource
= wtu
.replaceParams(shaderPair
[0], test
);
130 var fsource
= wtu
.replaceParams(shaderPair
[1], test
);
132 wtu
.addShaderSource(console
, "vertex shader: type = " + test
.type
+ " with names " + test
.name1
+ ", " + test
.name2
, vsource
);
133 wtu
.addShaderSource(console
, "fragment shader: type = " + test
.type
+ " with names " + test
.name1
+ ", " + test
.name2
, fsource
);
135 var program
= wtu
.setupProgram(gl
, [vsource
, fsource
], ["a_position"]);
138 valueLocs
: [gl
.getUniformLocation(program
, test
.name1
),
139 gl
.getUniformLocation(program
, test
.name2
)],
140 selectLoc
: gl
.getUniformLocation(program
, "u_select"),
142 var v1
= test
.values
[0];
143 var v2
= test
.values
[1];
149 info
.expect
= [v1
, v2
];
150 for (var jj
= 0; jj
< 2; ++jj
) {
151 var input
= info
.expect
[jj
].map(function(v
) { return v
/ 255; });
152 gl
[test
.func
](info
.valueLocs
[jj
], input
);
156 for (var ii
= 0; ii
< 2; ++ii
) {
157 progs
.forEach(function(info
) {
158 gl
.useProgram(info
.program
);
159 gl
.uniform1i(info
.selectLoc
, ii
);
160 wtu
.clearAndDrawUnitQuad(gl
);
161 wtu
.checkCanvas(gl
, info
.expect
[ii
], undefined, 1);
164 progs
.forEach(function(info
) {
165 gl
.deleteProgram(info
.program
);
169 tests
.forEach(function(test
){
174 var successfullyParsed
= true;
176 <script src=
"../../js/js-test-post.js"></script>