<!--Copyright (c) 2019 The Khronos Group Inc.Use of this source code is governed by an MIT-style license that can befound in the LICENSE.txt file.--><!DOCTYPE html><html><head><metacharset="utf-8"><title>WebGL draw with uniform blocks conformance tests</title><linkrel="stylesheet"href="../../resources/js-test-style.css"/><scriptsrc="../../js/js-test-pre.js"></script><scriptsrc="../../js/webgl-test-utils.js"></script><scriptid="vshader"type="x-shader/x-vertex">#version300esinvec4a_vertex;voidmain(void){gl_Position=a_vertex;}</script><scriptid="fshader"type="x-shader/x-fragment">#version300esprecisionmediumpfloat;layout(std140)uniformcolor_ubo{vec4color;};outvec4fragColor;voidmain(void){fragColor=color;}</script></head><body><canvasid="example"width="100",height="100"></canvas><divid="description"></div><divid="console"></div><script>"use strict";debug("");// Ported from: https://github.com/google/angle/blob/master/src/tests/gl_tests/UniformBufferTest.cpp#L1463description("Regression test for https://bugs.chromium.org/p/chromium/issues/detail?id=792966");varwtu=WebGLTestUtils;vargl=wtu.create3DContext("example",undefined,2);functionrunTest(){varprogram=wtu.setupProgram(gl,['vshader','fshader'],['a_vertex']);varuboIndex=gl.INVALID_INDEX;if(program)uboIndex=gl.getUniformBlockIndex(program,"color_ubo");if(!program||uboIndex==gl.INVALID_INDEX){testFailed("Loading program failed");return;}testPassed("Loading program succeeded");varvertices=newFloat32Array([-1,-1,0,1,-1,0,-1,1,0,1,1,0]);varvertexBuf=gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER,vertexBuf);gl.bufferData(gl.ARRAY_BUFFER,vertices,gl.STATIC_DRAW);gl.enableVertexAttribArray(0);gl.vertexAttribPointer(0,3,gl.FLOAT,false,0,0);varindexBuf=gl.createBuffer();gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,indexBuf);gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,newInt16Array([0,1,2,2,1,3]),gl.STATIC_DRAW);varuboDataSize=gl.getActiveUniformBlockParameter(program,uboIndex,gl.UNIFORM_BLOCK_DATA_SIZE);if(uboDataSize==0){testFailed("uniform block data size invalid");return;}wtu.glErrorShouldBe(gl,gl.NO_ERROR,"No errors from setup");debug("draw lower triangle - should be red");varuboBuf1=gl.createBuffer();gl.bindBufferBase(gl.UNIFORM_BUFFER,0,uboBuf1);gl.bufferData(gl.UNIFORM_BUFFER,uboDataSize,gl.STATIC_DRAW);gl.bufferSubData(gl.UNIFORM_BUFFER,0,newFloat32Array([1,0,0,1]));gl.uniformBlockBinding(program,uboIndex,0);gl.drawElements(gl.TRIANGLES,3,gl.UNSIGNED_SHORT,0);wtu.glErrorShouldBe(gl,gl.NO_ERROR,"No errors from draw");// Bind a second buffer to the same binding point (0). This should set to draw green.debug("draw upper triangle - should be green");varuboBuf2=gl.createBuffer();gl.bindBufferBase(gl.UNIFORM_BUFFER,0,uboBuf2);gl.bufferData(gl.UNIFORM_BUFFER,uboDataSize,gl.STATIC_DRAW);gl.bufferSubData(gl.UNIFORM_BUFFER,0,newFloat32Array([0,1,0,1]));gl.drawElements(gl.TRIANGLES,3,gl.UNSIGNED_SHORT,6);wtu.glErrorShouldBe(gl,gl.NO_ERROR,"No errors from draw");varwidth=100,height=100;wtu.checkCanvasRectColor(gl,0,0,width/2-5,height/2-5,[255,0,0,255],2,function(){testPassed("lower left should be red");},function(){testFailed("lower left should be red");});wtu.checkCanvasRectColor(gl,width/2+5,height/2+5,width/2-5,height/2-5,[0,255,0,255],2,function(){testPassed("top right should be green");},function(){testFailed("top right should be green");});}if(!gl){testFailed("WebGL context creation failed");}else{testPassed("WebGL context creation succeeded");runTest();}debug("");varsuccessfullyParsed=true;</script><scriptsrc="../../js/js-test-post.js"></script></body></html>