summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/buffers/uniform-buffers-state-restoration.html
blob: 51edd6ec0726d4172830cf7347c7cb2d515d9bfe (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
<!--
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 Uniform Buffers State Restoration Conformance Tests</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script id='vshader' type='x-shader/x-vertex'>#version 300 es
layout(location=0) in vec3 p;
void main()
{
    gl_Position = vec4(p.xyz, 1.0);
}
</script>
<script id='fshader' type='x-shader/x-fragment'>#version 300 es
precision mediump float;
layout(location=0) out vec4 oColor;

uniform UBOData {
    vec4 uboColor;
};

void main()
{
    oColor = uboColor;
}
</script>
</head>
<body>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<script>
"use strict";
description("This is a regression test verifying that uniform buffer bindings persist correctly across frames: <a href='http://crbug.com/722060'>crbug.com/722060</a>");

debug("");

var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, null, 2);
var greenBuf = null;
var throwawayBuf = null;
var red = new Float32Array([1, 0, 0, 1]);
var green = new Float32Array([0, 1, 0, 1]);
var frame = 0;

if (!gl) {
    testFailed("WebGL context does not exist");
} else {
    testPassed("WebGL context exists");

    initTest();
    wtu.waitForComposite(runTest);
}

function initTest() {
    wtu.setupUnitQuad(gl);

    var program = wtu.setupProgram(gl, ['vshader', 'fshader']);
    if (!program) {
        testFailed("Could not compile shader with uniform blocks without error");
        return;
    }
    var uboLocation = gl.getUniformBlockIndex(program, "UBOData");
    gl.uniformBlockBinding(program, uboLocation, 0);

    greenBuf = gl.createBuffer();
    throwawayBuf = gl.createBuffer();
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "createBuffer should not set an error");

    // Bind uniform buffer (both index 0 AND generic binding points) to greenBuf
    gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, greenBuf);
    gl.bufferData(gl.UNIFORM_BUFFER, green, gl.STATIC_DRAW);
    // Bind throwaray uniform buffer (from only the generic binding point)
    gl.bindBuffer(gl.UNIFORM_BUFFER, throwawayBuf);
}

function runTest() {
    // ONLY the binding point at index 0 (not the generic binding point) should be greenBuf.
    // (The generic binding point should point at throwawayBuf.)
    // So this bufferData should go into throwawayBuf.
    gl.bufferData(gl.UNIFORM_BUFFER, red, gl.STATIC_DRAW);
    wtu.clearAndDrawUnitQuad(gl);
    wtu.checkCanvas(gl, [0, 255, 0, 255], "draw call should set canvas to green", 2);
    finishTest();
}

debug("");
var successfullyParsed = true;
</script>

</body>
</html>