xref: /aosp_15_r20/external/angle/src/tests/gl_tests/DrawElementsIndirectTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2024 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // DrawElementsIndirect tests:
7 // Test issuing DrawElementsIndirect commands.
8 //
9 
10 #include "test_utils/ANGLETest.h"
11 #include "test_utils/gl_raii.h"
12 
13 using namespace angle;
14 
15 namespace
16 {
17 
18 class DrawElementsIndirectTest : public ANGLETest<>
19 {
20   protected:
DrawElementsIndirectTest()21     DrawElementsIndirectTest()
22     {
23         setWindowWidth(64);
24         setWindowHeight(64);
25         setConfigRedBits(8);
26         setConfigGreenBits(8);
27         setConfigBlueBits(8);
28         setConfigAlphaBits(8);
29     }
30 };
31 
32 // Test that DrawElementsIndirect works when count is zero.
TEST_P(DrawElementsIndirectTest,CountIsZero)33 TEST_P(DrawElementsIndirectTest, CountIsZero)
34 {
35     constexpr char kVS[] =
36         "attribute vec3 a_pos;\n"
37         "void main()\n"
38         "{\n"
39         "    gl_Position = vec4(a_pos, 1.0);\n"
40         "}\n";
41 
42     GLProgram program;
43     program.makeRaster(kVS, essl1_shaders::fs::Blue());
44     glUseProgram(program);
45 
46     GLVertexArray va;
47     glBindVertexArray(va);
48 
49     GLBuffer vertexBuffer;
50     glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
51     static float vertexData[3] = {0};
52     glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);
53 
54     GLBuffer indexBuffer;
55     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
56     static GLuint indexData[3] = {0};
57     glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indexData), indexData, GL_STATIC_DRAW);
58 
59     GLBuffer indirectBuffer;
60     glBindBuffer(GL_DRAW_INDIRECT_BUFFER, indirectBuffer);
61     static GLuint indirectData[5] = {0};
62     glBufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(indirectData), indirectData, GL_STATIC_DRAW);
63 
64     GLint posLocation = glGetAttribLocation(program, "a_pos");
65     glEnableVertexAttribArray(posLocation);
66     glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
67 
68     glDrawElementsIndirect(GL_TRIANGLE_FAN, GL_UNSIGNED_INT, nullptr);
69 
70     ASSERT_GL_NO_ERROR();
71 }
72 
73 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DrawElementsIndirectTest);
74 ANGLE_INSTANTIATE_TEST_ES31(DrawElementsIndirectTest);
75 }  // namespace