Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 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 | |
Corentin Wallez | ac3ab88 | 2015-05-12 13:31:28 -0400 | [diff] [blame] | 7 | #include "end2end_tests/ANGLETest.h" |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 8 | |
Brandon Jones | 993d08d | 2014-10-10 14:32:57 -0700 | [diff] [blame] | 9 | #include <memory> |
| 10 | #include <stdint.h> |
Jamie Madill | 7a29e4a | 2014-05-02 10:41:48 -0400 | [diff] [blame] | 11 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 12 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 13 | |
Jamie Madill | 7a29e4a | 2014-05-02 10:41:48 -0400 | [diff] [blame] | 14 | class ProgramBinaryTest : public ANGLETest |
| 15 | { |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 16 | protected: |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 17 | ProgramBinaryTest() |
Jamie Madill | 7a29e4a | 2014-05-02 10:41:48 -0400 | [diff] [blame] | 18 | { |
| 19 | setWindowWidth(128); |
| 20 | setWindowHeight(128); |
| 21 | setConfigRedBits(8); |
| 22 | setConfigGreenBits(8); |
| 23 | setConfigBlueBits(8); |
| 24 | setConfigAlphaBits(8); |
| 25 | } |
| 26 | |
| 27 | virtual void SetUp() |
| 28 | { |
| 29 | ANGLETest::SetUp(); |
| 30 | |
| 31 | const std::string vertexShaderSource = SHADER_SOURCE |
| 32 | ( |
| 33 | attribute vec4 inputAttribute; |
| 34 | void main() |
| 35 | { |
| 36 | gl_Position = inputAttribute; |
| 37 | } |
| 38 | ); |
| 39 | |
| 40 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 41 | ( |
| 42 | void main() |
| 43 | { |
| 44 | gl_FragColor = vec4(1,0,0,1); |
| 45 | } |
| 46 | ); |
| 47 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 48 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | 7a29e4a | 2014-05-02 10:41:48 -0400 | [diff] [blame] | 49 | if (mProgram == 0) |
| 50 | { |
| 51 | FAIL() << "shader compilation failed."; |
| 52 | } |
| 53 | |
| 54 | glGenBuffers(1, &mBuffer); |
| 55 | glBindBuffer(GL_ARRAY_BUFFER, mBuffer); |
| 56 | glBufferData(GL_ARRAY_BUFFER, 128, NULL, GL_STATIC_DRAW); |
| 57 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 58 | |
| 59 | ASSERT_GL_NO_ERROR(); |
| 60 | } |
| 61 | |
| 62 | virtual void TearDown() |
| 63 | { |
| 64 | glDeleteProgram(mProgram); |
| 65 | glDeleteBuffers(1, &mBuffer); |
| 66 | |
| 67 | ANGLETest::TearDown(); |
| 68 | } |
| 69 | |
| 70 | GLuint mProgram; |
| 71 | GLuint mBuffer; |
| 72 | }; |
| 73 | |
| 74 | // This tests the assumption that float attribs of different size |
| 75 | // should not internally cause a vertex shader recompile (for conversion). |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 76 | TEST_P(ProgramBinaryTest, FloatDynamicShaderSize) |
Jamie Madill | 7a29e4a | 2014-05-02 10:41:48 -0400 | [diff] [blame] | 77 | { |
| 78 | glUseProgram(mProgram); |
| 79 | glBindBuffer(GL_ARRAY_BUFFER, mBuffer); |
| 80 | |
| 81 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 8, NULL); |
| 82 | glEnableVertexAttribArray(0); |
| 83 | glDrawArrays(GL_POINTS, 0, 1); |
| 84 | |
| 85 | GLint programLength; |
| 86 | glGetProgramiv(mProgram, GL_PROGRAM_BINARY_LENGTH_OES, &programLength); |
| 87 | |
| 88 | EXPECT_GL_NO_ERROR(); |
| 89 | |
| 90 | for (GLsizei size = 1; size <= 3; size++) |
| 91 | { |
| 92 | glVertexAttribPointer(0, size, GL_FLOAT, GL_FALSE, 8, NULL); |
| 93 | glEnableVertexAttribArray(0); |
| 94 | glDrawArrays(GL_POINTS, 0, 1); |
| 95 | |
| 96 | GLint newProgramLength; |
| 97 | glGetProgramiv(mProgram, GL_PROGRAM_BINARY_LENGTH_OES, &newProgramLength); |
| 98 | EXPECT_GL_NO_ERROR(); |
| 99 | EXPECT_EQ(programLength, newProgramLength); |
| 100 | } |
| 101 | } |
Brandon Jones | 993d08d | 2014-10-10 14:32:57 -0700 | [diff] [blame] | 102 | |
| 103 | // This tests the ability to successfully save and load a program binary. |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 104 | TEST_P(ProgramBinaryTest, SaveAndLoadBinary) |
Brandon Jones | 993d08d | 2014-10-10 14:32:57 -0700 | [diff] [blame] | 105 | { |
| 106 | GLint programLength = 0; |
| 107 | GLint writtenLength = 0; |
| 108 | GLenum binaryFormat = 0; |
| 109 | |
| 110 | glGetProgramiv(mProgram, GL_PROGRAM_BINARY_LENGTH_OES, &programLength); |
| 111 | EXPECT_GL_NO_ERROR(); |
| 112 | |
| 113 | std::vector<uint8_t> binary(programLength); |
| 114 | glGetProgramBinaryOES(mProgram, programLength, &writtenLength, &binaryFormat, binary.data()); |
| 115 | EXPECT_GL_NO_ERROR(); |
| 116 | |
| 117 | // The lengths reported by glGetProgramiv and glGetProgramBinaryOES should match |
| 118 | EXPECT_EQ(programLength, writtenLength); |
| 119 | |
| 120 | if (writtenLength) |
| 121 | { |
| 122 | GLuint program2 = glCreateProgram(); |
| 123 | glProgramBinaryOES(program2, binaryFormat, binary.data(), writtenLength); |
| 124 | |
| 125 | EXPECT_GL_NO_ERROR(); |
| 126 | |
| 127 | GLint linkStatus; |
| 128 | glGetProgramiv(program2, GL_LINK_STATUS, &linkStatus); |
| 129 | if (linkStatus == 0) |
| 130 | { |
| 131 | GLint infoLogLength; |
| 132 | glGetProgramiv(program2, GL_INFO_LOG_LENGTH, &infoLogLength); |
| 133 | |
Geoff Lang | 981afd7 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 134 | if (infoLogLength > 0) |
| 135 | { |
| 136 | std::vector<GLchar> infoLog(infoLogLength); |
| 137 | glGetProgramInfoLog(program2, infoLog.size(), NULL, &infoLog[0]); |
| 138 | FAIL() << "program link failed: " << &infoLog[0]; |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | FAIL() << "program link failed."; |
| 143 | } |
Brandon Jones | 993d08d | 2014-10-10 14:32:57 -0700 | [diff] [blame] | 144 | } |
| 145 | else |
| 146 | { |
| 147 | glUseProgram(program2); |
| 148 | glBindBuffer(GL_ARRAY_BUFFER, mBuffer); |
| 149 | |
| 150 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 8, NULL); |
| 151 | glEnableVertexAttribArray(0); |
| 152 | glDrawArrays(GL_POINTS, 0, 1); |
| 153 | |
| 154 | EXPECT_GL_NO_ERROR(); |
| 155 | } |
| 156 | |
| 157 | glDeleteProgram(program2); |
| 158 | } |
| 159 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 160 | |
| 161 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 162 | ANGLE_INSTANTIATE_TEST(ProgramBinaryTest, ES2_D3D9(), ES2_D3D11()); |