@@ -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.
880962TEST_P (StateChangeTestES3, VertexArrayObjectAndDisabledAttributes)
881963{
0 commit comments