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.
10 <meta charset=
"utf-8">
11 <title>WebGL Vertex Buffer Updated After Draw Test
</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>
17 <canvas id=
"example" width=
"50" height=
"50">
19 <div id=
"description"></div>
20 <div id=
"console"></div>
21 <script id=
"vshader" type=
"x-shader/x-vertex">
22 attribute vec2 a_position;
23 attribute vec4 a_color;
24 varying vec4 v_outcolor;
26 gl_Position = vec4(a_position,
0,
1);
31 <script id=
"fshader" type=
"x-shader/x-fragment">
32 varying mediump vec4 v_outcolor;
34 gl_FragColor = v_outcolor;
39 // Tests that D3D11 dirty bit updates don't forget about BufferSubData attrib updates.
40 // Based on ANGLE test (StateChangeTest, VertexBufferUpdatedAfterDraw) from https://github.com/google/angle/blob/f7f0b8c3ab21c52cc2915048959361cf628d95f0/src/tests/gl_tests/StateChangeTest.cpp
42 var wtu
= WebGLTestUtils
;
45 var gl
= wtu
.create3DContext("example");
47 var program
= wtu
.setupProgram(gl
, ['vshader', 'fshader']);
49 var colorLoc
= gl
.getAttribLocation(program
, "a_color");
50 var green
= new Uint8Array(4 * 6);
51 var red
= new Uint8Array(4 * 6);
53 for (var i
= 0; i
< 6; ++i
) {
62 green
[ci
+ 2] = red
[ci
+ 2] = 0;
64 green
[ci
+ 3] = red
[ci
+ 3] = 255;
67 var positionLoc
= gl
.getAttribLocation(program
, "a_position");
70 wtu
.setupIndexedQuad(gl
, gridRes
, positionLoc
);
72 var colorBuf
= gl
.createBuffer();
73 gl
.bindBuffer(gl
.ARRAY_BUFFER
, colorBuf
);
74 gl
.bufferData(gl
.ARRAY_BUFFER
, green
, gl
.STATIC_DRAW
);
75 gl
.vertexAttribPointer(colorLoc
, 4, gl
.UNSIGNED_BYTE
, true, 0, 0);
76 gl
.enableVertexAttribArray(colorLoc
);
78 wtu
.clearAndDrawIndexedQuad(gl
, gridRes
);
79 wtu
.checkCanvas(gl
, [0, 255, 0, 255], "should be green");
81 gl
.bufferSubData(gl
.ARRAY_BUFFER
, 0, red
);
83 wtu
.clearAndDrawIndexedQuad(gl
, gridRes
);
84 wtu
.checkCanvas(gl
, [255, 0, 0, 255], "should be red");
86 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "should be no errors");
88 var successfullyParsed
= true;
90 <script src=
"../../js/js-test-post.js"></script>