struct-as-out-parameter.html (2983B)
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 as Out Parameter 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="struct-out-parameter-fs" type="x-shader/x-fragment"> 25 struct ColorData { 26 vec3 red; 27 vec3 blue; 28 }; 29 30 void modify(out ColorData colorData) { 31 colorData.red = vec3(1.0, 0.0, 0.0); 32 colorData.blue = vec3(0.0, 0.0, 1.0); 33 } 34 35 void main() { 36 ColorData colorData; 37 38 vec3 red = vec3(1.0, 0.0, 0.0); 39 vec3 green = vec3(0.0, 1.0, 0.0); 40 vec3 blue = vec3(0.0, 0.0, 1.0); 41 vec3 finalColor; 42 43 modify(colorData); 44 45 if (colorData.red == red && colorData.blue == blue) 46 finalColor = green; 47 else 48 finalColor = red; 49 50 gl_FragColor = vec4(finalColor, 1.0); 51 } 52 </script> 53 </head> 54 <body> 55 <div id="description"></div> 56 <div id="console"></div> 57 <script> 58 "use strict"; 59 description("Testing structs as out parameter"); 60 61 debug('Regression test for <a href="http://crbug.com/851873">http://crbug.com/851873</a> / <a href="https://github.com/mrdoob/three.js/issues/14137">https://github.com/mrdoob/three.js/issues/14137</a>'); 62 63 function prepend(floatPrecision) { 64 let source = document.getElementById('struct-out-parameter-fs').text; 65 return 'precision ' + floatPrecision + ' float;\n' + source; 66 } 67 68 let tests = [ 69 { 70 vShaderId: "simple-vs", 71 vShaderSuccess: true, 72 fShaderSource: prepend('lowp'), 73 fShaderSuccess: true, 74 linkSuccess: true, 75 render: true, 76 passMsg: "lowp struct used as out parameter", 77 }, 78 { 79 vShaderId: "simple-vs", 80 vShaderSuccess: true, 81 fShaderSource: prepend('mediump'), 82 fShaderSuccess: true, 83 linkSuccess: true, 84 render: true, 85 passMsg: "mediump struct used as out parameter", 86 }, 87 ]; 88 89 let wtu = WebGLTestUtils; 90 let gl = wtu.create3DContext(); 91 let precision = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT); 92 let highpSupported = (precision.rangeMin >= 62 && precision.rangeMax >= 62 && precision.precision >= 16); 93 debug("highp is" + (highpSupported ? "" : " not") + " supported in fragment shaders"); 94 95 if (highpSupported) { 96 tests.push( 97 { 98 vShaderId: "simple-vs", 99 vShaderSuccess: true, 100 fShaderSource: prepend('highp'), 101 fShaderSuccess: true, 102 linkSuccess: true, 103 render: true, 104 passMsg: "highp struct used as out parameter", 105 } 106 ); 107 } 108 109 GLSLConformanceTester.runTests(tests); 110 debug(""); 111 112 var successfullyParsed = true; 113 </script> 114 </body> 115 </html>