struct-equals.html (4266B)
1 <!-- 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. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>GLSL Structure Equals Test</title> 12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> 13 <link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/> 14 <script src="../../../js/js-test-pre.js"></script> 15 <script src="../../../js/webgl-test-utils.js"> </script> 16 <script src="../../../js/glsl-conformance-test.js"></script> 17 18 <script id="simple-vs" type="x-shader/x-vertex"> 19 attribute vec4 a_position; 20 void main(void) { 21 gl_Position = a_position; 22 } 23 </script> 24 <script id="simple-struct-fs" type="x-shader/x-fragment"> 25 precision mediump float; 26 struct my_struct { 27 float f; 28 }; 29 30 my_struct a = my_struct(1.0); 31 my_struct b = my_struct(1.0); 32 33 void main(void) { 34 gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 35 36 if (a == b) { 37 gl_FragColor.y = 1.0; 38 } 39 } 40 </script> 41 <script id="vec-struct-fs" type="x-shader/x-fragment"> 42 precision mediump float; 43 struct my_struct { 44 vec3 v; 45 }; 46 47 my_struct a = my_struct(vec3(1.0, 2.0, 3.0)); 48 my_struct b = my_struct(vec3(1.0, 2.0, 3.0)); 49 50 void main(void) { 51 gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 52 53 if (a == b) { 54 gl_FragColor.y = 1.0; 55 } 56 } 57 </script> 58 <script id="nested-struct-fs" type="x-shader/x-fragment"> 59 precision mediump float; 60 61 struct s1 62 { 63 float f; 64 }; 65 66 struct s2 67 { 68 s1 s; 69 }; 70 71 s2 a = s2(s1(1.0)); 72 s2 b = s2(s1(1.0)); 73 74 void main(void) { 75 gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 76 77 if (a == b) { 78 gl_FragColor.y = 1.0; 79 } 80 } 81 </script> 82 <script id="nested-vec-struct-fs" type="x-shader/x-fragment"> 83 precision mediump float; 84 85 struct s1 86 { 87 vec3 v; 88 }; 89 90 struct s2 91 { 92 s1 s; 93 }; 94 95 s2 a = s2(s1(vec3(1.0, 2.0, 3.0))); 96 s2 b = s2(s1(vec3(1.0, 2.0, 3.0))); 97 98 void main(void) { 99 gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 100 101 if (a == b) { 102 gl_FragColor.y = 1.0; 103 } 104 } 105 </script> 106 <script id="array-struct-fs" type="x-shader/x-fragment"> 107 precision mediump float; 108 109 struct my_struct 110 { 111 float f[3]; 112 }; 113 114 void main(void) { 115 gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 116 my_struct a; 117 my_struct b; 118 for (int i = 0; i < 3; ++i) { 119 a.f[i] = 0.0; 120 b.f[i] = 1.0; 121 } 122 123 if (a == b) { 124 gl_FragColor.x = 1.0; 125 } 126 } 127 </script> 128 <script id="sampler-struct-fs" type="x-shader/x-fragment"> 129 precision mediump float; 130 131 struct my_struct 132 { 133 sampler2D s; 134 }; 135 136 uniform my_struct a; 137 uniform my_struct b; 138 139 void main(void) { 140 gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 141 142 if (a == b) { 143 gl_FragColor.x = 1.0; 144 } 145 } 146 </script> 147 </head> 148 <body> 149 <canvas id="canvas" width="50" height="50"></canvas> 150 <div id="description"></div> 151 <div id="console"></div> 152 <script> 153 "use strict"; 154 description("Testing struct equals"); 155 156 var wtu = WebGLTestUtils; 157 GLSLConformanceTester.runTests([ 158 { 159 vShaderId: "simple-vs", 160 vShaderSuccess: true, 161 fShaderId: "simple-struct-fs", 162 fShaderSuccess: true, 163 linkSuccess: true, 164 render: true, 165 passMsg: "Simple struct with one float", 166 }, 167 { 168 vShaderId: "simple-vs", 169 vShaderSuccess: true, 170 fShaderId: "vec-struct-fs", 171 fShaderSuccess: true, 172 linkSuccess: true, 173 render: true, 174 passMsg: "Simple struct with a vector", 175 }, 176 { 177 vShaderId: "simple-vs", 178 vShaderSuccess: true, 179 fShaderId: "nested-struct-fs", 180 fShaderSuccess: true, 181 linkSuccess: true, 182 render: true, 183 passMsg: "Nested struct with a float", 184 }, 185 { 186 vShaderId: "simple-vs", 187 vShaderSuccess: true, 188 fShaderId: "nested-vec-struct-fs", 189 fShaderSuccess: true, 190 linkSuccess: true, 191 render: true, 192 passMsg: "Nested struct with a vector", 193 }, 194 { 195 vShaderId: "simple-vs", 196 vShaderSuccess: true, 197 fShaderId: "array-struct-fs", 198 fShaderSuccess: false, 199 linkSuccess: false, 200 passMsg: "Comparing a struct containing an array should not compile", 201 }, 202 { 203 vShaderId: "simple-vs", 204 vShaderSuccess: true, 205 fShaderId: "sampler-struct-fs", 206 fShaderSuccess: false, 207 linkSuccess: false, 208 passMsg: "Comparing a struct containing a sampler should not compile", 209 } 210 ]); 211 debug(""); 212 213 var successfullyParsed = true; 214 </script> 215 </body> 216 </html>