<!--
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>WebGL GLSL Conformance Tests</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>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="vertexShaderVariant" type="text/something-not-javascript">
varying vec4 v_varying;

void main()
{
    gl_PointSize = 1.0;
    gl_Position = v_varying;
}
</script>
<script id="vertexShaderInvariant" type="text/something-not-javascript">
invariant varying vec4 v_varying;

void main()
{
    gl_Position = v_varying;
}
</script>
<script id="vertexShaderSeparateInvariant" type="text/something-not-javascript">
varying vec4 v_varying;
invariant v_varying;

void main()
{
    gl_Position = v_varying;
}
</script>
<script id="vertexShaderSeparateInvariantWrongOrder" type="text/something-not-javascript">
invariant v_varying;
varying vec4 v_varying;

void main()
{
    gl_Position = v_varying;
}
</script>
<script id="vertexShaderGlobalInvariant" type="text/something-not-javascript">
#pragma STDGL invariant(all)
varying vec4 v_varying;

void main()
{
    gl_Position = v_varying;
}
</script>
<script id="vertexShaderInvariantGlPosition" type="text/something-not-javascript">
invariant gl_Position;

void main()
{
    gl_Position = vec4(0, 0, 0, 0);
}
</script>
<script id="vertexShaderInvariantGlPointSize" type="text/something-not-javascript">
invariant gl_PointSize;

void main()
{
    gl_PointSize = 1.0;
    gl_Position = vec4(0, 0, 0, 0);
}
</script>
<script id="fragmentShaderVariant" type="text/something-not-javascript">
precision mediump float;

varying vec4 v_varying;

void main()
{
    gl_FragColor = v_varying;
}
</script>
<script id="fragmentShaderInvariant" type="text/something-not-javascript">
precision mediump float;

invariant varying vec4 v_varying;

void main()
{
    gl_FragColor = v_varying;
}
</script>
<script id="fragmentShaderSeparateInvariant" type="text/something-not-javascript">
precision mediump float;

varying vec4 v_varying;
invariant v_varying;

void main()
{
    gl_FragColor = v_varying;
}
</script>
<script id="fragmentShaderSeparateInvariantWrongOrder" type="text/something-not-javascript">
precision mediump float;

invariant v_varying;
varying vec4 v_varying;

void main()
{
    gl_FragColor = v_varying;
}
</script>
<script id="fragmentShaderGlobalInvariant" type="text/something-not-javascript">
#pragma STDGL invariant(all)
precision mediump float;

varying vec4 v_varying;

void main()
{
    gl_FragColor = v_varying;
}
</script>
<script id="fragmentShaderInvariantGlFragCoord" type="text/something-not-javascript">
invariant gl_FragCoord;

void main()
{
    gl_FragColor = gl_FragCoord;
}
</script>
<script id="fragmentShaderVariantGlFragCoord" type="text/something-not-javascript">
void main()
{
    gl_FragColor = gl_FragCoord;
}
</script>
<script id="fragmentShaderInvariantGlPointCoord" type="text/something-not-javascript">
invariant gl_PointCoord;

void main()
{
    gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);
}
</script>
<script id="fragmentShaderVariantGlPointCoord" type="text/something-not-javascript">
void main()
{
    gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);
}
</script>
<script id="fragmentShaderInvariantGlFrontFacing" type="text/something-not-javascript">
invariant gl_FrontFacing;

void main()
{
    gl_FragColor = gl_FrontFacing ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1);
}
</script>
<script id="fragmentShaderVariantGlFrontFacing" type="text/something-not-javascript">
void main()
{
    gl_FragColor = gl_FrontFacing ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1);
}
</script>
<script>
// GLSL 1.0.17 4.3.5
"use strict";
// See GLSL ES spec 1.0.17 section 4.6.4 "Invariance and linkage".
var cases = [
  {
    vShaderId: "vertexShaderVariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderInvariant",
    fShaderSuccess: true,
    linkSuccess: false,
    passMsg: "vertex shader with variant varying and fragment shader with invariant varying must fail",
  },
  {
    vShaderId: "vertexShaderInvariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderVariant",
    fShaderSuccess: true,
    linkSuccess: false,
    passMsg: "vertex shader with invariant varying and fragment shader with variant varying must fail",
  },
  {
    vShaderId: "vertexShaderGlobalInvariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderVariant",
    fShaderSuccess: true,
    linkSuccess: false,
    passMsg: "vertex shader with invariant (global setting) varying and fragment shader with variant varying must fail",
  },
  {
    vShaderId: "vertexShaderGlobalInvariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderInvariant",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "vertex shader with invariant (global setting) varying and fragment shader with invariant varying must succeed",
  },
  {
    vShaderId: "vertexShaderSeparateInvariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderInvariant",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "vertex shader with invariant (separately set) varying and fragment shader with invariant varying must succeed",
  },
  {
    vShaderId: "vertexShaderInvariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderSeparateInvariant",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "vertex shader with invariant varying and fragment shader with invariant (separately set) varying must succeed",
  },
  {
    vShaderId: "vertexShaderSeparateInvariantWrongOrder",
    vShaderSuccess: false,
    fShaderId: "fragmentShaderInvariant",
    fShaderSuccess: true,
    linkSuccess: false,
    passMsg: "vertex shader with invariant (separately set in wrong order) varying must fail",
  },
  {
    vShaderId: "vertexShaderInvariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderSeparateInvariantWrongOrder",
    fShaderSuccess: false,
    linkSuccess: false,
    passMsg: "fragment shader with invariant (separately set in wrong order) varying must fail",
  },
  {
    vShaderId: "vertexShaderInvariantGlPosition",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderInvariantGlFragCoord",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "vertex shader with invariant gl_Position and fragment shader with invariant gl_FragCoord must succeed",
  },
  {
    vShaderId: "vertexShaderVariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderInvariantGlFragCoord",
    fShaderSuccess: true,
    linkSuccess: false,
    passMsg: "vertex shader with variant gl_Position and fragment shader with invariant gl_FragCoord must fail",
  },
  {
    vShaderId: "vertexShaderInvariantGlPosition",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderVariantGlFragCoord",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "vertex shader with invariant gl_Position and fragment shader with variant gl_FragCoord must succeed",
  },
  {
    vShaderId: "vertexShaderInvariantGlPointSize",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderInvariantGlPointCoord",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "vertex shader with invariant gl_PointSize and fragment shader with invariant gl_PointCoord must succeed",
  },
  {
    vShaderId: "vertexShaderVariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderInvariantGlPointCoord",
    fShaderSuccess: true,
    linkSuccess: false,
    passMsg: "vertex shader with variant gl_PointSize and fragment shader with invariant gl_PointCoord must fail",
  },
  {
    vShaderId: "vertexShaderInvariantGlPointSize",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderVariantGlPointCoord",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "vertex shader with invariant gl_PointSize and fragment shader with variant gl_PointCoord must succeed",
  },
  {
    vShaderId: "vertexShaderVariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderVariantGlFrontFacing",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "fragment shader with variant gl_FrontFacing must succeed compilation",
  },
  {
    vShaderId: "vertexShaderVariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderInvariantGlFrontFacing",
    fShaderSuccess: false,
    linkSuccess: false,
    passMsg: "fragment shader with invariant gl_FrontFacing must fail compilation",
  },
  {
    vShaderId: "vertexShaderVariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderGlobalInvariant",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "vertex shader with variant varying and fragment shader with invariant (global setting) varying must succeed",
  },
  {
    vShaderId: "vertexShaderInvariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderGlobalInvariant",
    fShaderSuccess: true,
    linkSuccess: false,
    passMsg: "vertex shader with invariant varying and fragment shader with invariant (global setting) varying must fail",
  }
];

GLSLConformanceTester.runTests(cases);
var successfullyParsed = true;
</script>
</body>
</html>
