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 buffer size change test for bindBufferBase/bindBufferRange
</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 <div id=
"description"></div>
18 <div id=
"console"></div>
21 description("WebGL buffer size change for bindings through bindBufferBase/bindBufferRange");
23 // This test verifies the ES3 behavior, that the bound buffer range (offset, size) is not
24 // limited by the actual buffer size, and the driver is responsible that no out-of-range
27 var wtu
= WebGLTestUtils
;
29 var gl
= wtu
.create3DContext(undefined, undefined, 2);
32 debug("bindBufferBase with TRANSFORM_FEEDBACK_BUFFER target");
33 var buffer1
= gl
.createBuffer();
34 gl
.bindBufferBase(gl
.TRANSFORM_FEEDBACK_BUFFER
, 0, buffer1
);
35 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
36 "Calling bindBufferBase on a buffer where no storage is allocated should succeed.");
37 shouldBe("gl.getParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING)", "buffer1");
38 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0)", "buffer1");
39 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0)", "0");
40 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0)", "0");
42 gl
.bufferData(gl
.TRANSFORM_FEEDBACK_BUFFER
, 4, gl
.STATIC_DRAW
);
43 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0)", "buffer1");
44 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0)", "0");
45 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0)", "0");
47 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
50 debug("bindBufferBase with UNIFORM_BUFFER target");
51 var buffer2
= gl
.createBuffer();
52 gl
.bindBufferBase(gl
.UNIFORM_BUFFER
, 1, buffer2
);
53 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
54 "Calling bindBufferBase on a buffer where no storage is allocated should succeed.");
55 shouldBe("gl.getParameter(gl.UNIFORM_BUFFER_BINDING)", "buffer2");
56 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1)", "buffer2");
57 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1)", "0");
58 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1)", "0");
60 gl
.bufferData(gl
.UNIFORM_BUFFER
, 8, gl
.STATIC_DRAW
);
61 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1)", "buffer2");
62 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1)", "0");
63 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1)", "0");
65 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
68 debug("bindBufferRange with TRANSFORM_FEEDBACK_BUFFER target");
69 var buffer3
= gl
.createBuffer();
70 gl
.bindBufferRange(gl
.TRANSFORM_FEEDBACK_BUFFER
, 0, buffer3
, 4, 8);
71 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
72 "Calling bindBufferRange on a buffer where no storage is allocated should succeed.");
73 shouldBe("gl.getParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING)", "buffer3");
74 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0)", "buffer3");
75 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0)", "8");
76 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0)", "4");
78 gl
.bufferData(gl
.TRANSFORM_FEEDBACK_BUFFER
, 4, gl
.STATIC_DRAW
);
79 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0)", "buffer3");
80 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0)", "8");
81 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0)", "4");
83 gl
.bufferData(gl
.TRANSFORM_FEEDBACK_BUFFER
, 12, gl
.STATIC_DRAW
);
84 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_BINDING, 0)", "buffer3");
85 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_SIZE, 0)", "8");
86 shouldBe("gl.getIndexedParameter(gl.TRANSFORM_FEEDBACK_BUFFER_START, 0)", "4");
88 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
91 debug("bindBufferRange with UNIFORM_BUFFER target");
92 var buffer4
= gl
.createBuffer();
93 var offset
= gl
.getParameter(gl
.UNIFORM_BUFFER_OFFSET_ALIGNMENT
);
94 gl
.bindBufferRange(gl
.UNIFORM_BUFFER
, 1, buffer4
, offset
, 12);
95 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
,
96 "Calling bindBufferRange on a buffer where no storage is allocated should succeed.");
97 shouldBe("gl.getParameter(gl.UNIFORM_BUFFER_BINDING)", "buffer4");
98 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1)", "buffer4");
99 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1)", "12");
100 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1)", "offset");
102 gl
.bufferData(gl
.UNIFORM_BUFFER
, offset
+ 8, gl
.STATIC_DRAW
);
103 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1)", "buffer4");
104 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1)", "12");
105 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1)", "offset");
107 gl
.bufferData(gl
.UNIFORM_BUFFER
, offset
+ 12, gl
.STATIC_DRAW
);
108 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_BINDING, 1)", "buffer4");
109 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_SIZE, 1)", "12");
110 shouldBe("gl.getIndexedParameter(gl.UNIFORM_BUFFER_START, 1)", "offset");
112 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
115 var successfullyParsed
= true;
117 <script src=
"../../js/js-test-post.js"></script>