uniform-buffers-state-restoration.html (2934B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>WebGL Uniform Buffers State Restoration Conformance Tests</title> 12 <link rel="stylesheet" href="../../resources/js-test-style.css"/> 13 <script src="../../js/js-test-pre.js"></script> 14 <script src="../../js/webgl-test-utils.js"></script> 15 <script id='vshader' type='x-shader/x-vertex'>#version 300 es 16 layout(location=0) in vec3 p; 17 void main() 18 { 19 gl_Position = vec4(p.xyz, 1.0); 20 } 21 </script> 22 <script id='fshader' type='x-shader/x-fragment'>#version 300 es 23 precision mediump float; 24 layout(location=0) out vec4 oColor; 25 26 uniform UBOData { 27 vec4 uboColor; 28 }; 29 30 void main() 31 { 32 oColor = uboColor; 33 } 34 </script> 35 </head> 36 <body> 37 <div id="description"></div> 38 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas> 39 <div id="console"></div> 40 <script> 41 "use strict"; 42 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>"); 43 44 debug(""); 45 46 var wtu = WebGLTestUtils; 47 var canvas = document.getElementById("canvas"); 48 var gl = wtu.create3DContext(canvas, null, 2); 49 var greenBuf = null; 50 var throwawayBuf = null; 51 var red = new Float32Array([1, 0, 0, 1]); 52 var green = new Float32Array([0, 1, 0, 1]); 53 var frame = 0; 54 55 if (!gl) { 56 testFailed("WebGL context does not exist"); 57 } else { 58 testPassed("WebGL context exists"); 59 60 initTest(); 61 wtu.waitForComposite(runTest); 62 } 63 64 function initTest() { 65 wtu.setupUnitQuad(gl); 66 67 var program = wtu.setupProgram(gl, ['vshader', 'fshader']); 68 if (!program) { 69 testFailed("Could not compile shader with uniform blocks without error"); 70 return; 71 } 72 var uboLocation = gl.getUniformBlockIndex(program, "UBOData"); 73 gl.uniformBlockBinding(program, uboLocation, 0); 74 75 greenBuf = gl.createBuffer(); 76 throwawayBuf = gl.createBuffer(); 77 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "createBuffer should not set an error"); 78 79 // Bind uniform buffer (both index 0 AND generic binding points) to greenBuf 80 gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, greenBuf); 81 gl.bufferData(gl.UNIFORM_BUFFER, green, gl.STATIC_DRAW); 82 // Bind throwaray uniform buffer (from only the generic binding point) 83 gl.bindBuffer(gl.UNIFORM_BUFFER, throwawayBuf); 84 } 85 86 function runTest() { 87 // ONLY the binding point at index 0 (not the generic binding point) should be greenBuf. 88 // (The generic binding point should point at throwawayBuf.) 89 // So this bufferData should go into throwawayBuf. 90 gl.bufferData(gl.UNIFORM_BUFFER, red, gl.STATIC_DRAW); 91 wtu.clearAndDrawUnitQuad(gl); 92 wtu.checkCanvas(gl, [0, 255, 0, 255], "draw call should set canvas to green", 2); 93 finishTest(); 94 } 95 96 debug(""); 97 var successfullyParsed = true; 98 </script> 99 100 </body> 101 </html>