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.
11 <meta charset=
"utf-8">
12 <title>Passing a struct containing a sampler to a function.
</title>
13 <link rel=
"stylesheet" href=
"../../../resources/js-test-style.css"/>
14 <script src=
"../../../js/js-test-pre.js"></script>
15 <script src=
"../../../js/webgl-test-utils.js"></script>
19 <canvas id=
"output" style=
"border: none;" width=
"64" height=
"64"></canvas>
20 <div id=
"description"></div>
21 <div id=
"console"></div>
23 <script id=
"shader-fs" type=
"x-shader/x-fragment">
24 precision mediump float;
30 vec4 fun(SomeStruct s){
31 return texture2D(s.source, vec2(
0.5));
34 uniform SomeStruct green;
36 gl_FragColor = fun(green);
40 <script id=
"shader-fs-array" type=
"x-shader/x-fragment">
41 precision mediump float;
47 vec4 fun(SomeStruct s[
2]){
48 return texture2D(s[
0].source, vec2(
0.5));
51 uniform SomeStruct green[
2];
53 gl_FragColor = fun(green);
61 debug("If the test passes correctly the viewport will be green.");
63 var wtu
= WebGLTestUtils
;
64 var canvas
= document
.getElementById("output");
65 var gl
= wtu
.create3DContext(canvas
);
69 var createGreenTexture = function() {
70 var texture
= gl
.createTexture();
71 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
72 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.LINEAR
);
73 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.LINEAR
);
74 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, gl
.CLAMP_TO_EDGE
);
75 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, gl
.CLAMP_TO_EDGE
);
76 wtu
.fillTexture(gl
, texture
, 1, 1, [0, 255, 0, 255]);
77 gl
.bindTexture(gl
.TEXTURE_2D
, null);
81 var test = function(fragShaderId
, texUniformName
) {
82 var program
= wtu
.setupProgram(gl
, [wtu
.simpleVertexShader
, fragShaderId
], ["a_position"], [0], true);
85 testFailed("Shader compilation/link failed");
88 var uniformMap
= wtu
.getUniformMap(gl
, program
);
89 gl
.activeTexture(gl
.TEXTURE0
);
90 gl
.bindTexture(gl
.TEXTURE_2D
, textureGreen
);
91 gl
.uniform1i(uniformMap
[texUniformName
].location
, 0);
94 wtu
.clearAndDrawUnitQuad(gl
);
97 wtu
.checkCanvasRect(gl
, 0, 128, 256, 128, [0, 255,0, 255], "should be green", 1);
102 testFailed("context does not exist");
104 wtu
.setupUnitQuad(gl
, 0, 1);
105 textureGreen
= createGreenTexture();
106 test("shader-fs", "green.source");
107 test("shader-fs-array", "green[0].source");
109 var successfullyParsed
= true;
111 <script src=
"../../../js/js-test-post.js"></script>