<!--

/*
** Copyright (c) 2014 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/

-->

<!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",
  },
  // The following tests have been removed as they were enforcing a rule contradictory to the ESSL 1.0
  // specification. The tests are removed and not changed to preserve any implementations that
  // pass this snapshot instead of trunk.
  /*
  // Changed on trunk in #2878
  {
    vShaderId: "vertexShaderVariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderGlobalInvariant",
    fShaderSuccess: true,
    linkSuccess: false,
    passMsg: "vertex shader with variant varying and fragment shader with invariant (global setting) varying must fail",
  },
  // Changed on trunk in #2908
  {
    vShaderId: "vertexShaderInvariant",
    vShaderSuccess: true,
    fShaderId: "fragmentShaderGlobalInvariant",
    fShaderSuccess: true,
    linkSuccess: true,
    passMsg: "vertex shader with invariant varying and fragment shader with invariant (global setting) varying must succeed",
  }
  */
];

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