content/canvas/test/webgl-conformance/conformance/glsl/misc/re-compile-re-link.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!--
     2 Copyright (c) 2012 The Chromium Authors. All rights reserved.
     3 Use of this source code is governed by a BSD-style license that can be
     4 found in the LICENSE file.
     5  -->
     6 <!DOCTYPE html>
     7 <html>
     8 <head>
     9 <meta charset="utf-8">
    10 <title>WebGL Re-Compile and Re-link Shader conformance test.</title>
    11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
    12 <script src="../../../resources/js-test-pre.js"></script>
    13 <script src="../../resources/webgl-test.js"> </script>
    14 <script src="../../resources/webgl-test-utils.js"> </script>
    15 </head>
    16 <body>
    17 <canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas>
    18 <div id="description"></div>
    19 <div id="console"></div>
    20 <script id="vshader" type="x-shader/x-vertex">
    21 attribute float column;
    22 attribute float height;
    23 uniform float position;
    24 void main() {
    25   gl_Position = vec4(mod(column - position, 1.0) * 2.0 - 1.0, height, 0, 1);
    26 }
    27 </script>
    29 <script id="fshader1" type="x-shader/x-fragment">
    30 precision mediump float;
    31 void main() {
    32   gl_FragColor = vec4(1,0,0,1);
    33 }
    34 </script>
    35 <script id="fshader2" type="x-shader/x-fragment">
    36 precision mediump float;
    37 uniform float foobar;
    38 void main() {
    39   gl_FragColor = vec4(1,0,foobar,1);
    40 }
    41 </script>
    42 <script id="vshaderB" type="not-js">
    43 attribute vec2 position;
    44 varying vec2 v_texCoord;
    45 void main() {
    46   gl_Position = vec4(position, 0, 1);
    47   v_texCoord = vec2(position * 0.5 + 0.5);
    48 }
    49 </script>
    50 <script id="fshaderB" type="not-js">
    51 precision mediump float;
    52 varying vec2 v_texCoord;
    53 uniform sampler2D tex;
    54 void main() {
    55   gl_FragColor = texture2D(tex, v_texCoord);
    56 }
    57 </script>
    59 <script>
    60 description(document.title);
    61 var wtu = WebGLTestUtils;
    62 var gl = wtu.create3DContext("example");
    64 var vsSource = document.getElementById("vshader").text;
    65 var fs1Source = document.getElementById("fshader1").text;
    66 var fs2Source = document.getElementById("fshader2").text;
    68 var vsSourceB = document.getElementById("vshaderB").text;
    69 var fsSourceB = document.getElementById("fshaderB").text;
    71 var vShader = gl.createShader(gl.VERTEX_SHADER);
    72 var fShader = gl.createShader(gl.FRAGMENT_SHADER);
    74 var vShaderB = gl.createShader(gl.VERTEX_SHADER);
    75 var fShaderB = gl.createShader(gl.FRAGMENT_SHADER);
    77 var program = gl.createProgram();
    78 var programB = gl.createProgram();
    80 gl.attachShader(program, vShader);
    81 gl.attachShader(program, fShader);
    83 gl.attachShader(programB, vShaderB);
    84 gl.attachShader(programB, fShaderB);
    86 var success;
    87 var shader;
    89 function checkShaderStatus(s) {
    90   shader = s;
    91   shouldBeTrue("success = gl.getShaderParameter(shader, gl.COMPILE_STATUS)");
    92   if (!success) {
    93     debug("error: " + gl.getShaderInfoLog());
    94   }
    95 }
    97 var prg;
    98 function checkProgramStatus(p) {
    99   prg = p;
   100   shouldBeTrue("success = gl.getProgramParameter(prg, gl.LINK_STATUS)");
   101   if (!success) {
   102     debug("error: " + gl.getProgramInfoLog(prg));
   103   }
   104 }
   106 for (var i = 0; i < 10; ++i) {
   107   gl.shaderSource(vShader, vsSource);
   108   gl.compileShader(vShader);
   109   checkShaderStatus(vShader)
   110   gl.shaderSource(fShader, fs1Source);
   111   gl.compileShader(fShader);
   112   checkShaderStatus(fShader)
   114   gl.linkProgram(program);
   115   checkProgramStatus(program)
   116   gl.useProgram(program);
   118   gl.shaderSource(vShaderB, vsSourceB);
   119   gl.compileShader(vShaderB);
   120   checkShaderStatus(vShaderB)
   121   gl.shaderSource(fShaderB, fsSourceB);
   122   gl.compileShader(fShaderB);
   123   checkShaderStatus(fShaderB)
   125   gl.linkProgram(programB);
   126   checkProgramStatus(programB)
   128   gl.useProgram(programB);
   129 }
   131 for (var i = 0; i < 10; ++i) {
   132   // Now change the fragment shader
   133   gl.shaderSource(fShader, fs2Source);
   134   gl.compileShader(fShader);
   135   checkShaderStatus(fShader)
   137   // And re-link
   138   gl.linkProgram(program);
   139   checkProgramStatus(program)
   140 }
   142 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
   144 successfullyParsed = true;
   145 </script>
   146 <script>finishTest();</script>
   148 </body>
   149 </html>

mercurial