1 //
2 // Copyright 2017 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
7 // ClientArraysTest.cpp : Tests of the GL_ANGLE_client_arrays extension.
8
9 #include "test_utils/ANGLETest.h"
10
11 #include "test_utils/gl_raii.h"
12
13 namespace angle
14 {
15
16 class ClientArraysTest : public ANGLETest
17 {
18 protected:
ClientArraysTest()19 ClientArraysTest()
20 {
21 setWindowWidth(128);
22 setWindowHeight(128);
23 setConfigRedBits(8);
24 setConfigGreenBits(8);
25 setConfigBlueBits(8);
26 setConfigAlphaBits(8);
27 setClientArraysEnabled(false);
28 }
29 };
30
31 // Context creation would fail if EGL_ANGLE_create_context_client_arrays was not available so
32 // the GL extension should always be present
TEST_P(ClientArraysTest,ExtensionStringExposed)33 TEST_P(ClientArraysTest, ExtensionStringExposed)
34 {
35 EXPECT_TRUE(IsGLExtensionEnabled("GL_ANGLE_client_arrays"));
36 }
37
38 // Verify that GL_CLIENT_ARRAYS_ANGLE can be queried but not changed
TEST_P(ClientArraysTest,QueryValidation)39 TEST_P(ClientArraysTest, QueryValidation)
40 {
41 GLint intValue = 2;
42 glGetIntegerv(GL_CLIENT_ARRAYS_ANGLE, &intValue);
43 EXPECT_GL_NO_ERROR();
44 EXPECT_GL_FALSE(intValue);
45
46 float floatValue = 2.0f;
47 glGetFloatv(GL_CLIENT_ARRAYS_ANGLE, &floatValue);
48 EXPECT_GL_NO_ERROR();
49 EXPECT_EQ(0.0f, floatValue);
50
51 GLboolean boolValue = GL_TRUE;
52 glGetBooleanv(GL_CLIENT_ARRAYS_ANGLE, &boolValue);
53 EXPECT_GL_NO_ERROR();
54 EXPECT_GL_FALSE(boolValue);
55
56 EXPECT_GL_FALSE(glIsEnabled(GL_CLIENT_ARRAYS_ANGLE));
57 EXPECT_GL_NO_ERROR();
58
59 glEnable(GL_CLIENT_ARRAYS_ANGLE);
60 EXPECT_GL_ERROR(GL_INVALID_ENUM);
61
62 glDisable(GL_CLIENT_ARRAYS_ANGLE);
63 EXPECT_GL_ERROR(GL_INVALID_ENUM);
64 }
65
66 // Test that client-side array buffers are forbidden when client arrays are disabled
TEST_P(ClientArraysTest,ForbidsClientSideArrayBuffer)67 TEST_P(ClientArraysTest, ForbidsClientSideArrayBuffer)
68 {
69 const auto &vertices = GetQuadVertices();
70 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
71 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
72 }
73
74 // Test that client-side element array buffers are forbidden when client arrays are disabled
TEST_P(ClientArraysTest,ForbidsClientSideElementBuffer)75 TEST_P(ClientArraysTest, ForbidsClientSideElementBuffer)
76 {
77 ASSERT_GL_FALSE(glIsEnabled(GL_CLIENT_ARRAYS_ANGLE));
78
79 constexpr char kVS[] =
80 "attribute vec3 a_pos;\n"
81 "void main()\n"
82 "{\n"
83 " gl_Position = vec4(a_pos, 1.0);\n"
84 "}\n";
85
86 ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red());
87
88 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
89 ASSERT_NE(-1, posLocation);
90 glUseProgram(program.get());
91
92 const auto &vertices = GetQuadVertices();
93
94 GLBuffer vertexBuffer;
95 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
96 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
97 GL_STATIC_DRAW);
98
99 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
100 glEnableVertexAttribArray(posLocation);
101
102 const GLubyte indices[] = {0, 1, 2, 3, 4, 5};
103
104 ASSERT_GL_NO_ERROR();
105 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);
106 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
107 }
108
109 // Use this to select which configurations (e.g. which renderer, which GLES major version) these
110 // tests should be run against.
111 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(ClientArraysTest);
112 } // namespace angle
113