content/canvas/test/webgl-conformance/conformance/attribs/gl-vertex-attrib-zero-issues.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 <!--
     2 // Copyright (c) 2011 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 Enable Vertex Attrib Zero 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="50" height="50">
    18 </canvas>
    19 <div id="description"></div>
    20 <div id="console"></div>
    21 <script id="vshader" type="x-shader/x-vertex">
    22     attribute vec4 vPosition;
    23     void main()
    24     {
    25         gl_Position = vPosition;
    26     }
    27 </script>
    29 <script id="fshader" type="x-shader/x-fragment">
    30     void main()
    31     {
    32         gl_FragColor = vec4(0.0,0.0,0.0,0.0);
    33     }
    34 </script>
    36 <script>
    37 description("Test some of the issues of the difference between attrib 0 on OpenGL vs WebGL");
    38 debug("");
    39 var wtu = WebGLTestUtils;
    40 var gl = wtu.create3DContext("example");
    42 function setup(numVerts, attribIndex) {
    43   var program = wtu.setupProgram(
    44       gl, ['vshader', 'fshader'], ['vPosition'], [attribIndex]);
    45   // draw with something on attrib zero with a small number of vertices
    46   var vertexObject = gl.createBuffer();
    47   g_program = program;
    48   g_attribLocation = attribIndex;
    49   shouldBe("g_attribLocation", "gl.getAttribLocation(g_program, 'vPosition')");
    50   gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
    51   gl.bufferData(
    52       gl.ARRAY_BUFFER, new Float32Array(numVerts * 3), gl.STATIC_DRAW);
    53   gl.vertexAttribPointer(attribIndex, 3, gl.FLOAT, false, 0, 0);
    54   var indices = new Uint16Array(numVerts);
    55   for (var ii = 0; ii < numVerts; ++ii) {
    56     indices[ii] = ii;
    57   }
    58   var indexBuffer = gl.createBuffer();
    59   gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
    60   gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
    61   return program;
    62 }
    64 var p1 = setup(3, 0);
    65 var p2 = setup(60000, 3);
    67 for (var ii = 0; ii < 5; ++ii) {
    68   gl.useProgram(p1);
    69   gl.enableVertexAttribArray(0);
    70   gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0);
    71   glErrorShouldBe(
    72       gl, gl.NO_ERROR,
    73       "drawing using attrib 0 with 3 verts");
    75   gl.useProgram(p2);
    76   gl.enableVertexAttribArray(3);
    77   gl.drawArrays(gl.LINES, 0, 60000);
    78   glErrorShouldBe(
    79       gl, gl.NO_ERROR,
    80       "drawing using attrib 3 with 60000 verts");
    81 }
    83 wtu.checkCanvas(gl, [0, 0, 0, 0], "canvas should be 0, 0, 0, 0");
    85 successfullyParsed = true;
    86 </script>
    87 <script>finishTest();</script>
    89 </body>
    90 </html>

mercurial