Skip to content

Commit

Permalink
Added OES_vertex_array_object tests
Browse files Browse the repository at this point in the history
Change-Id: I2586ad7ea95b463147dbdae95484d70ac602ec67
  • Loading branch information
kakashidinho committed Nov 19, 2019
1 parent 7198b95 commit ab8ca84
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/tests/gl_tests/StateChangeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,88 @@ TEST_P(StateChangeTest, VertexBufferUpdatedAfterDraw)
ASSERT_GL_NO_ERROR();
}

// Test that switching VAOs keeps the disabled "current value" attributes up-to-date.
// OES_vertex_array_object version.
TEST_P(StateChangeTest, VertexArrayObjectAndDisabledAttributes)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_vertex_array_object"));

constexpr char kSingleVS[] = "attribute vec4 position; void main() { gl_Position = position; }";
constexpr char kSingleFS[] = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }";
ANGLE_GL_PROGRAM(singleProgram, kSingleVS, kSingleFS);

constexpr char kDualVS[] =
"attribute vec4 position;\n"
"attribute vec4 color;\n"
"varying vec4 varyColor;\n"
"void main()\n"
"{\n"
" gl_Position = position;\n"
" varyColor = color;\n"
"}";
constexpr char kDualFS[] =
"precision mediump float;\n"
"varying vec4 varyColor;\n"
"void main()\n"
"{\n"
" gl_FragColor = varyColor;\n"
"}";
ANGLE_GL_PROGRAM(dualProgram, kDualVS, kDualFS);
GLint positionLocation = glGetAttribLocation(dualProgram, "position");
ASSERT_NE(-1, positionLocation);
GLint colorLocation = glGetAttribLocation(dualProgram, "color");
ASSERT_NE(-1, colorLocation);

GLint singlePositionLocation = glGetAttribLocation(singleProgram, "position");
ASSERT_NE(-1, singlePositionLocation);

glUseProgram(singleProgram);

// Initialize position vertex buffer.
const auto &quadVertices = GetQuadVertices();

GLBuffer vertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 6, quadVertices.data(), GL_STATIC_DRAW);

// Initialize a VAO. Draw with single program.
GLVertexArrayOES vertexArray;
glBindVertexArrayOES(vertexArray);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexAttribPointer(singlePositionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(singlePositionLocation);

// Should draw red.
glDrawArrays(GL_TRIANGLES, 0, 6);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);

// Draw with a green buffer attribute, without the VAO.
glBindVertexArrayOES(0);
glUseProgram(dualProgram);
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(positionLocation);

std::vector<GLColor> greenColors(6, GLColor::green);
GLBuffer greenBuffer;
glBindBuffer(GL_ARRAY_BUFFER, greenBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLColor) * 6, greenColors.data(), GL_STATIC_DRAW);

glVertexAttribPointer(colorLocation, 4, GL_UNSIGNED_BYTE, GL_FALSE, 4, nullptr);
glEnableVertexAttribArray(colorLocation);

glDrawArrays(GL_TRIANGLES, 0, 6);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);

// Re-bind VAO and try to draw with different program, without changing state.
// Should draw black since current value is not initialized.
glBindVertexArrayOES(vertexArray);
glDrawArrays(GL_TRIANGLES, 0, 6);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
}

// Test that switching VAOs keeps the disabled "current value" attributes up-to-date.
TEST_P(StateChangeTestES3, VertexArrayObjectAndDisabledAttributes)
{
Expand Down
68 changes: 68 additions & 0 deletions src/tests/gl_tests/VertexAttributeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,74 @@ TEST_P(VertexAttributeTestES3, VertexArrayObjectRendering)
ASSERT_GL_NO_ERROR();
}

// Tests that rendering works as expected with VAOs.
// OES_vertex_array_object version
TEST_P(VertexAttributeTest, VertexArrayObjectRendering)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_vertex_array_object"));

constexpr char kVertexShader[] =
"attribute vec4 a_position;\n"
"attribute vec4 a_color;\n"
"varying vec4 v_color;\n"
"void main()\n"
"{\n"
" gl_Position = a_position;\n"
" v_color = a_color;\n"
"}";

constexpr char kFragmentShader[] =
"precision mediump float;\n"
"varying vec4 v_color;\n"
"void main()\n"
"{\n"
" gl_FragColor = v_color;\n"
"}";

ANGLE_GL_PROGRAM(program, kVertexShader, kFragmentShader);

GLint positionLoc = glGetAttribLocation(program, "a_position");
ASSERT_NE(-1, positionLoc);
GLint colorLoc = glGetAttribLocation(program, "a_color");
ASSERT_NE(-1, colorLoc);

GLVertexArrayOES vaos[2];
GLBuffer positionBuffer;
GLBuffer colorBuffers[2];

const auto &quadVertices = GetQuadVertices();

glBindVertexArrayOES(vaos[0]);
glBindBuffer(GL_ARRAY_BUFFER, positionBuffer);
glBufferData(GL_ARRAY_BUFFER, quadVertices.size() * sizeof(Vector3), quadVertices.data(),
GL_STATIC_DRAW);
glEnableVertexAttribArray(positionLoc);
glVertexAttribPointer(positionLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
SetupColorsForUnitQuad(colorLoc, kFloatRed, GL_STREAM_DRAW, &colorBuffers[0]);

glBindVertexArrayOES(vaos[1]);
glBindBuffer(GL_ARRAY_BUFFER, positionBuffer);
glEnableVertexAttribArray(positionLoc);
glVertexAttribPointer(positionLoc, 3, GL_FLOAT, GL_FALSE, 0, 0);
SetupColorsForUnitQuad(colorLoc, kFloatGreen, GL_STATIC_DRAW, &colorBuffers[1]);

glUseProgram(program);
ASSERT_GL_NO_ERROR();

for (int ii = 0; ii < 2; ++ii)
{
glBindVertexArrayOES(vaos[0]);
glDrawArrays(GL_TRIANGLES, 0, 6);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);

glBindVertexArrayOES(vaos[1]);
glDrawArrays(GL_TRIANGLES, 0, 6);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}

ASSERT_GL_NO_ERROR();
}

// Validate that we can support GL_MAX_ATTRIBS attribs
TEST_P(VertexAttributeTest, MaxAttribs)
{
Expand Down
5 changes: 5 additions & 0 deletions src/tests/test_utils/gl_raii.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class GLVertexArray : public GLWrapper
public:
GLVertexArray() : GLWrapper(&glGenVertexArrays, &glDeleteVertexArrays) {}
};
class GLVertexArrayOES : public GLWrapper
{
public:
GLVertexArrayOES() : GLWrapper(&glGenVertexArraysOES, &glDeleteVertexArraysOES) {}
};
class GLBuffer : public GLWrapper
{
public:
Expand Down

0 comments on commit ab8ca84

Please sign in to comment.