Skip to content

Commit ab8ca84

Browse files
committed
Added OES_vertex_array_object tests
Change-Id: I2586ad7ea95b463147dbdae95484d70ac602ec67
1 parent 7198b95 commit ab8ca84

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

src/tests/gl_tests/StateChangeTest.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,88 @@ TEST_P(StateChangeTest, VertexBufferUpdatedAfterDraw)
876876
ASSERT_GL_NO_ERROR();
877877
}
878878

879+
// Test that switching VAOs keeps the disabled "current value" attributes up-to-date.
880+
// OES_vertex_array_object version.
881+
TEST_P(StateChangeTest, VertexArrayObjectAndDisabledAttributes)
882+
{
883+
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_vertex_array_object"));
884+
885+
constexpr char kSingleVS[] = "attribute vec4 position; void main() { gl_Position = position; }";
886+
constexpr char kSingleFS[] = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }";
887+
ANGLE_GL_PROGRAM(singleProgram, kSingleVS, kSingleFS);
888+
889+
constexpr char kDualVS[] =
890+
"attribute vec4 position;\n"
891+
"attribute vec4 color;\n"
892+
"varying vec4 varyColor;\n"
893+
"void main()\n"
894+
"{\n"
895+
" gl_Position = position;\n"
896+
" varyColor = color;\n"
897+
"}";
898+
constexpr char kDualFS[] =
899+
"precision mediump float;\n"
900+
"varying vec4 varyColor;\n"
901+
"void main()\n"
902+
"{\n"
903+
" gl_FragColor = varyColor;\n"
904+
"}";
905+
ANGLE_GL_PROGRAM(dualProgram, kDualVS, kDualFS);
906+
GLint positionLocation = glGetAttribLocation(dualProgram, "position");
907+
ASSERT_NE(-1, positionLocation);
908+
GLint colorLocation = glGetAttribLocation(dualProgram, "color");
909+
ASSERT_NE(-1, colorLocation);
910+
911+
GLint singlePositionLocation = glGetAttribLocation(singleProgram, "position");
912+
ASSERT_NE(-1, singlePositionLocation);
913+
914+
glUseProgram(singleProgram);
915+
916+
// Initialize position vertex buffer.
917+
const auto &quadVertices = GetQuadVertices();
918+
919+
GLBuffer vertexBuffer;
920+
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
921+
glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 6, quadVertices.data(), GL_STATIC_DRAW);
922+
923+
// Initialize a VAO. Draw with single program.
924+
GLVertexArrayOES vertexArray;
925+
glBindVertexArrayOES(vertexArray);
926+
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
927+
glVertexAttribPointer(singlePositionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
928+
glEnableVertexAttribArray(singlePositionLocation);
929+
930+
// Should draw red.
931+
glDrawArrays(GL_TRIANGLES, 0, 6);
932+
ASSERT_GL_NO_ERROR();
933+
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
934+
935+
// Draw with a green buffer attribute, without the VAO.
936+
glBindVertexArrayOES(0);
937+
glUseProgram(dualProgram);
938+
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
939+
glEnableVertexAttribArray(positionLocation);
940+
941+
std::vector<GLColor> greenColors(6, GLColor::green);
942+
GLBuffer greenBuffer;
943+
glBindBuffer(GL_ARRAY_BUFFER, greenBuffer);
944+
glBufferData(GL_ARRAY_BUFFER, sizeof(GLColor) * 6, greenColors.data(), GL_STATIC_DRAW);
945+
946+
glVertexAttribPointer(colorLocation, 4, GL_UNSIGNED_BYTE, GL_FALSE, 4, nullptr);
947+
glEnableVertexAttribArray(colorLocation);
948+
949+
glDrawArrays(GL_TRIANGLES, 0, 6);
950+
ASSERT_GL_NO_ERROR();
951+
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
952+
953+
// Re-bind VAO and try to draw with different program, without changing state.
954+
// Should draw black since current value is not initialized.
955+
glBindVertexArrayOES(vertexArray);
956+
glDrawArrays(GL_TRIANGLES, 0, 6);
957+
ASSERT_GL_NO_ERROR();
958+
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
959+
}
960+
879961
// Test that switching VAOs keeps the disabled "current value" attributes up-to-date.
880962
TEST_P(StateChangeTestES3, VertexArrayObjectAndDisabledAttributes)
881963
{

src/tests/gl_tests/VertexAttributeTest.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,74 @@ TEST_P(VertexAttributeTestES3, VertexArrayObjectRendering)
10711071
ASSERT_GL_NO_ERROR();
10721072
}
10731073

1074+
// Tests that rendering works as expected with VAOs.
1075+
// OES_vertex_array_object version
1076+
TEST_P(VertexAttributeTest, VertexArrayObjectRendering)
1077+
{
1078+
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_vertex_array_object"));
1079+
1080+
constexpr char kVertexShader[] =
1081+
"attribute vec4 a_position;\n"
1082+
"attribute vec4 a_color;\n"
1083+
"varying vec4 v_color;\n"
1084+
"void main()\n"
1085+
"{\n"
1086+
" gl_Position = a_position;\n"
1087+
" v_color = a_color;\n"
1088+
"}";
1089+
1090+
constexpr char kFragmentShader[] =
1091+
"precision mediump float;\n"
1092+
"varying vec4 v_color;\n"
1093+
"void main()\n"
1094+
"{\n"
1095+
" gl_FragColor = v_color;\n"
1096+
"}";
1097+
1098+
ANGLE_GL_PROGRAM(program, kVertexShader, kFragmentShader);
1099+
1100+
GLint positionLoc = glGetAttribLocation(program, "a_position");
1101+
ASSERT_NE(-1, positionLoc);
1102+
GLint colorLoc = glGetAttribLocation(program, "a_color");
1103+
ASSERT_NE(-1, colorLoc);
1104+
1105+
GLVertexArrayOES vaos[2];
1106+
GLBuffer positionBuffer;
1107+
GLBuffer colorBuffers[2];
1108+
1109+
const auto &quadVertices = GetQuadVertices();
1110+
1111+
glBindVertexArrayOES(vaos[0]);
1112+
glBindBuffer(GL_ARRAY_BUFFER, positionBuffer);
1113+
glBufferData(GL_ARRAY_BUFFER, quadVertices.size() * sizeof(Vector3), quadVertices.data(),
1114+
GL_STATIC_DRAW);
1115+
glEnableVertexAttribArray(positionLoc);
1116+
glVertexAttribPointer(positionLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
1117+
SetupColorsForUnitQuad(colorLoc, kFloatRed, GL_STREAM_DRAW, &colorBuffers[0]);
1118+
1119+
glBindVertexArrayOES(vaos[1]);
1120+
glBindBuffer(GL_ARRAY_BUFFER, positionBuffer);
1121+
glEnableVertexAttribArray(positionLoc);
1122+
glVertexAttribPointer(positionLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
1123+
SetupColorsForUnitQuad(colorLoc, kFloatGreen, GL_STATIC_DRAW, &colorBuffers[1]);
1124+
1125+
glUseProgram(program);
1126+
ASSERT_GL_NO_ERROR();
1127+
1128+
for (int ii = 0; ii < 2; ++ii)
1129+
{
1130+
glBindVertexArrayOES(vaos[0]);
1131+
glDrawArrays(GL_TRIANGLES, 0, 6);
1132+
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1133+
1134+
glBindVertexArrayOES(vaos[1]);
1135+
glDrawArrays(GL_TRIANGLES, 0, 6);
1136+
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1137+
}
1138+
1139+
ASSERT_GL_NO_ERROR();
1140+
}
1141+
10741142
// Validate that we can support GL_MAX_ATTRIBS attribs
10751143
TEST_P(VertexAttributeTest, MaxAttribs)
10761144
{

src/tests/test_utils/gl_raii.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class GLVertexArray : public GLWrapper
7777
public:
7878
GLVertexArray() : GLWrapper(&glGenVertexArrays, &glDeleteVertexArrays) {}
7979
};
80+
class GLVertexArrayOES : public GLWrapper
81+
{
82+
public:
83+
GLVertexArrayOES() : GLWrapper(&glGenVertexArraysOES, &glDeleteVertexArraysOES) {}
84+
};
8085
class GLBuffer : public GLWrapper
8186
{
8287
public:

0 commit comments

Comments
 (0)