summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/misc/struct-as-out-parameter.html
blob: 4190c691e8d9ae1cc07999b9f8a72ee2af48fa30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GLSL Structure as Out Parameter Test</title>
<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
<script src="../../../js/js-test-pre.js"></script>
<script src="../../../js/webgl-test-utils.js"> </script>
<script src="../../../js/glsl-conformance-test.js"></script>

<script id="simple-vs" type="x-shader/x-vertex">
attribute vec4 a_position;
void main(void) {
    gl_Position = a_position;
}
</script>
<script id="struct-out-parameter-fs" type="x-shader/x-fragment">
struct ColorData {
  vec3 red;
  vec3 blue;
};

void modify(out ColorData colorData) {
  colorData.red = vec3(1.0, 0.0, 0.0);
  colorData.blue = vec3(0.0, 0.0, 1.0);
}

void main() {
  ColorData colorData;

  vec3 red = vec3(1.0, 0.0, 0.0);
  vec3 green = vec3(0.0, 1.0, 0.0);
  vec3 blue = vec3(0.0, 0.0, 1.0);
  vec3 finalColor;

  modify(colorData);

  if (colorData.red == red && colorData.blue == blue)
    finalColor = green;
  else
    finalColor = red;

  gl_FragColor = vec4(finalColor, 1.0);
}
</script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Testing structs as out parameter");

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>');

function prepend(floatPrecision) {
  let source = document.getElementById('struct-out-parameter-fs').text;
  return 'precision ' + floatPrecision + ' float;\n' + source;
}

let tests = [
  {
    vShaderId: "simple-vs",
    vShaderSuccess: true,
    fShaderSource: prepend('lowp'),
    fShaderSuccess: true,
    linkSuccess: true,
    render: true,
    passMsg: "lowp struct used as out parameter",
  },
  {
    vShaderId: "simple-vs",
    vShaderSuccess: true,
    fShaderSource: prepend('mediump'),
    fShaderSuccess: true,
    linkSuccess: true,
    render: true,
    passMsg: "mediump struct used as out parameter",
  },
];

let wtu = WebGLTestUtils;
let gl = wtu.create3DContext();
let precision = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
let highpSupported = (precision.rangeMin >= 62 && precision.rangeMax >= 62 && precision.precision >= 16);
debug("highp is" + (highpSupported ? "" : " not") + " supported in fragment shaders");

if (highpSupported) {
  tests.push(
    {
      vShaderId: "simple-vs",
      vShaderSuccess: true,
      fShaderSource: prepend('highp'),
      fShaderSuccess: true,
      linkSuccess: true,
      render: true,
      passMsg: "highp struct used as out parameter",
    }
  );
}

GLSLConformanceTester.runTests(tests);
debug("");

var successfullyParsed = true;
</script>
</body>
</html>