struct-assign.html (4315B)
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 Assignment 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(0.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 a = b; 36 if (a.f == 1.0) { 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(0.0, 0.0, 0.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 a = b; 53 if (a.v.x == 1.0) { 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(0.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 a = b; 77 if (a.s.f == 1.0) { 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(0.0, 0.0, 0.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 a = b; 101 if (a.s.v.x == 1.0) { 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] = float(i); 121 } 122 123 a = b; 124 if (a.f[1] == 1.0 && a.f[2] == 2.0) { 125 gl_FragColor.y = 1.0; 126 } 127 } 128 </script> 129 <script id="sampler-struct-fs" type="x-shader/x-fragment"> 130 precision mediump float; 131 132 struct my_struct 133 { 134 sampler2D s; 135 }; 136 137 uniform my_struct a; 138 139 void main(void) { 140 gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 141 my_struct b; 142 b = a; 143 } 144 </script> 145 </head> 146 <body> 147 <canvas id="canvas" width="50" height="50"></canvas> 148 <div id="description"></div> 149 <div id="console"></div> 150 <script> 151 "use strict"; 152 description("Testing struct assignment"); 153 154 var wtu = WebGLTestUtils; 155 GLSLConformanceTester.runTests([ 156 { 157 vShaderId: "simple-vs", 158 vShaderSuccess: true, 159 fShaderId: "simple-struct-fs", 160 fShaderSuccess: true, 161 linkSuccess: true, 162 render: true, 163 passMsg: "Simple struct with one float", 164 }, 165 { 166 vShaderId: "simple-vs", 167 vShaderSuccess: true, 168 fShaderId: "vec-struct-fs", 169 fShaderSuccess: true, 170 linkSuccess: true, 171 render: true, 172 passMsg: "Simple struct with a vector", 173 }, 174 { 175 vShaderId: "simple-vs", 176 vShaderSuccess: true, 177 fShaderId: "nested-struct-fs", 178 fShaderSuccess: true, 179 linkSuccess: true, 180 render: true, 181 passMsg: "Nested struct with a float", 182 }, 183 { 184 vShaderId: "simple-vs", 185 vShaderSuccess: true, 186 fShaderId: "nested-vec-struct-fs", 187 fShaderSuccess: true, 188 linkSuccess: true, 189 render: true, 190 passMsg: "Nested struct with a vector", 191 }, 192 { 193 vShaderId: "simple-vs", 194 vShaderSuccess: true, 195 fShaderId: "array-struct-fs", 196 fShaderSuccess: false, 197 linkSuccess: false, 198 passMsg: "Assigning a struct containing an array should not compile", 199 }, 200 { 201 vShaderId: "simple-vs", 202 vShaderSuccess: true, 203 fShaderId: "sampler-struct-fs", 204 fShaderSuccess: false, 205 linkSuccess: false, 206 passMsg: "Assigning a struct containing a sampler should not compile", 207 } 208 ]); 209 debug(""); 210 211 var successfullyParsed = true; 212 </script> 213 </body> 214 </html>