1 #include "ANGLETest.h" 2 3 class ProgramBinaryTest : public ANGLETest 4 { 5 protected: 6 ProgramBinaryTest() 7 { 8 setWindowWidth(128); 9 setWindowHeight(128); 10 setConfigRedBits(8); 11 setConfigGreenBits(8); 12 setConfigBlueBits(8); 13 setConfigAlphaBits(8); 14 } 15 16 virtual void SetUp() 17 { 18 ANGLETest::SetUp(); 19 20 const std::string vertexShaderSource = SHADER_SOURCE 21 ( 22 attribute vec4 inputAttribute; 23 void main() 24 { 25 gl_Position = inputAttribute; 26 } 27 ); 28 29 const std::string fragmentShaderSource = SHADER_SOURCE 30 ( 31 void main() 32 { 33 gl_FragColor = vec4(1,0,0,1); 34 } 35 ); 36 37 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); 38 if (mProgram == 0) 39 { 40 FAIL() << "shader compilation failed."; 41 } 42 43 glGenBuffers(1, &mBuffer); 44 glBindBuffer(GL_ARRAY_BUFFER, mBuffer); 45 glBufferData(GL_ARRAY_BUFFER, 128, NULL, GL_STATIC_DRAW); 46 glBindBuffer(GL_ARRAY_BUFFER, 0); 47 48 ASSERT_GL_NO_ERROR(); 49 } 50 51 virtual void TearDown() 52 { 53 glDeleteProgram(mProgram); 54 glDeleteBuffers(1, &mBuffer); 55 56 ANGLETest::TearDown(); 57 } 58 59 GLuint mProgram; 60 GLuint mBuffer; 61 }; 62 63 // This tests the assumption that float attribs of different size 64 // should not internally cause a vertex shader recompile (for conversion). 65 TEST_F(ProgramBinaryTest, FloatDynamicShaderSize) 66 { 67 glUseProgram(mProgram); 68 glBindBuffer(GL_ARRAY_BUFFER, mBuffer); 69 70 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 8, NULL); 71 glEnableVertexAttribArray(0); 72 glDrawArrays(GL_POINTS, 0, 1); 73 74 GLint programLength; 75 glGetProgramiv(mProgram, GL_PROGRAM_BINARY_LENGTH_OES, &programLength); 76 77 EXPECT_GL_NO_ERROR(); 78 79 for (GLsizei size = 1; size <= 3; size++) 80 { 81 glVertexAttribPointer(0, size, GL_FLOAT, GL_FALSE, 8, NULL); 82 glEnableVertexAttribArray(0); 83 glDrawArrays(GL_POINTS, 0, 1); 84 85 GLint newProgramLength; 86 glGetProgramiv(mProgram, GL_PROGRAM_BINARY_LENGTH_OES, &newProgramLength); 87 EXPECT_GL_NO_ERROR(); 88 EXPECT_EQ(programLength, newProgramLength); 89 } 90 } 91