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 | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 7 | #include "test_utils/ANGLETest.h" |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 8 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 9 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 10 | |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 11 | class BlendMinMaxTest : public ANGLETest |
| 12 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 13 | protected: |
| 14 | BlendMinMaxTest() |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 15 | { |
| 16 | setWindowWidth(128); |
| 17 | setWindowHeight(128); |
| 18 | setConfigRedBits(8); |
| 19 | setConfigGreenBits(8); |
| 20 | setConfigBlueBits(8); |
| 21 | setConfigAlphaBits(8); |
| 22 | setConfigDepthBits(24); |
| 23 | |
| 24 | mProgram = 0; |
| 25 | mColorLocation = -1; |
| 26 | } |
| 27 | |
| 28 | struct Color |
| 29 | { |
| 30 | float values[4]; |
| 31 | }; |
| 32 | |
| 33 | static GLubyte getExpected(bool blendMin, float curColor, GLubyte prevColor) |
| 34 | { |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 35 | GLubyte curAsUbyte = static_cast<GLubyte>((curColor * std::numeric_limits<GLubyte>::max()) + 0.5f); |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 36 | return blendMin ? std::min<GLubyte>(curAsUbyte, prevColor) : std::max<GLubyte>(curAsUbyte, prevColor); |
| 37 | } |
| 38 | |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 39 | void runTest(GLenum colorFormat) |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 40 | { |
Geoff Lang | a809165 | 2015-04-27 10:53:55 -0400 | [diff] [blame] | 41 | if (getClientVersion() < 3 && !extensionEnabled("GL_EXT_blend_minmax")) |
| 42 | { |
| 43 | std::cout << "Test skipped because ES3 or GL_EXT_blend_minmax is not available." << std::endl; |
| 44 | return; |
| 45 | } |
| 46 | |
Geoff Lang | ddf4d39 | 2015-09-29 13:00:14 -0400 | [diff] [blame] | 47 | // TODO(geofflang): figure out why this fails |
| 48 | if (isIntel() && GetParam() == ES2_OPENGL()) |
| 49 | { |
| 50 | std::cout << "Test skipped on OpenGL Intel due to flakyness." << std::endl; |
| 51 | return; |
| 52 | } |
| 53 | |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 54 | SetUpFramebuffer(colorFormat); |
| 55 | |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 56 | const size_t colorCount = 1024; |
| 57 | Color colors[colorCount]; |
| 58 | for (size_t i = 0; i < colorCount; i++) |
| 59 | { |
| 60 | for (size_t j = 0; j < 4; j++) |
| 61 | { |
| 62 | colors[i].values[j] = (rand() % 255) / 255.0f; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | GLubyte prevColor[4]; |
| 67 | for (size_t i = 0; i < colorCount; i++) |
| 68 | { |
| 69 | const Color &color = colors[i]; |
| 70 | glUseProgram(mProgram); |
| 71 | glUniform4f(mColorLocation, color.values[0], color.values[1], color.values[2], color.values[3]); |
| 72 | |
| 73 | bool blendMin = (rand() % 2 == 0); |
| 74 | glBlendEquation(blendMin ? GL_MIN : GL_MAX); |
| 75 | |
| 76 | drawQuad(mProgram, "aPosition", 0.5f); |
| 77 | |
| 78 | if (i > 0) |
| 79 | { |
| 80 | EXPECT_PIXEL_EQ(0, 0, |
| 81 | getExpected(blendMin, color.values[0], prevColor[0]), |
| 82 | getExpected(blendMin, color.values[1], prevColor[1]), |
| 83 | getExpected(blendMin, color.values[2], prevColor[2]), |
| 84 | getExpected(blendMin, color.values[3], prevColor[3])); |
| 85 | } |
| 86 | |
| 87 | glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, prevColor); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | virtual void SetUp() |
| 92 | { |
| 93 | ANGLETest::SetUp(); |
| 94 | |
| 95 | const std::string testVertexShaderSource = SHADER_SOURCE |
| 96 | ( |
| 97 | attribute highp vec4 aPosition; |
| 98 | |
| 99 | void main(void) |
| 100 | { |
| 101 | gl_Position = aPosition; |
| 102 | } |
| 103 | ); |
| 104 | |
| 105 | const std::string testFragmentShaderSource = SHADER_SOURCE |
| 106 | ( |
| 107 | uniform highp vec4 color; |
| 108 | void main(void) |
| 109 | { |
| 110 | gl_FragColor = color; |
| 111 | } |
| 112 | ); |
| 113 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 114 | mProgram = CompileProgram(testVertexShaderSource, testFragmentShaderSource); |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 115 | if (mProgram == 0) |
| 116 | { |
| 117 | FAIL() << "shader compilation failed."; |
| 118 | } |
| 119 | |
| 120 | mColorLocation = glGetUniformLocation(mProgram, "color"); |
| 121 | |
| 122 | glUseProgram(mProgram); |
| 123 | |
| 124 | glClearColor(0, 0, 0, 0); |
| 125 | glClearDepthf(0.0); |
| 126 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 127 | |
| 128 | glEnable(GL_BLEND); |
| 129 | glDisable(GL_DEPTH_TEST); |
| 130 | } |
| 131 | |
| 132 | void SetUpFramebuffer(GLenum colorFormat) |
| 133 | { |
| 134 | glGenFramebuffers(1, &mFramebuffer); |
| 135 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer); |
| 136 | glBindFramebuffer(GL_READ_FRAMEBUFFER, mFramebuffer); |
| 137 | |
| 138 | glGenRenderbuffers(1, &mColorRenderbuffer); |
| 139 | glBindRenderbuffer(GL_RENDERBUFFER, mColorRenderbuffer); |
| 140 | glRenderbufferStorage(GL_RENDERBUFFER, colorFormat, getWindowWidth(), getWindowHeight()); |
| 141 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, mColorRenderbuffer); |
| 142 | |
| 143 | ASSERT_GL_NO_ERROR(); |
| 144 | } |
| 145 | |
| 146 | virtual void TearDown() |
| 147 | { |
| 148 | glDeleteProgram(mProgram); |
| 149 | glDeleteFramebuffers(1, &mFramebuffer); |
| 150 | glDeleteRenderbuffers(1, &mColorRenderbuffer); |
| 151 | |
| 152 | ANGLETest::TearDown(); |
| 153 | } |
| 154 | |
| 155 | GLuint mProgram; |
| 156 | GLint mColorLocation; |
| 157 | |
| 158 | GLuint mFramebuffer; |
| 159 | GLuint mColorRenderbuffer; |
| 160 | }; |
| 161 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 162 | TEST_P(BlendMinMaxTest, RGBA8) |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 163 | { |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 164 | runTest(GL_RGBA8); |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 165 | } |
| 166 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 167 | TEST_P(BlendMinMaxTest, RGBA32f) |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 168 | { |
Geoff Lang | a809165 | 2015-04-27 10:53:55 -0400 | [diff] [blame] | 169 | if (getClientVersion() < 3 && !extensionEnabled("GL_OES_texture_float")) |
| 170 | { |
| 171 | std::cout << "Test skipped because ES3 or GL_OES_texture_float is not available." << std::endl; |
| 172 | return; |
| 173 | } |
| 174 | |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 175 | // TODO(jmadill): Figure out why this is broken on Intel |
| 176 | if (isIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9())) |
| 177 | { |
| 178 | std::cout << "Test skipped on Intel OpenGL." << std::endl; |
| 179 | return; |
| 180 | } |
| 181 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame^] | 182 | // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3 |
| 183 | if (isD3D11_FL93()) |
| 184 | { |
| 185 | std::cout << "Test skipped on Feature Level 9_3." << std::endl; |
| 186 | return; |
| 187 | } |
| 188 | |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 189 | runTest(GL_RGBA32F); |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 190 | } |
| 191 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 192 | TEST_P(BlendMinMaxTest, RGBA16F) |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 193 | { |
Austin Kinross | ff318af | 2015-12-22 15:34:45 -0800 | [diff] [blame] | 194 | if (getClientVersion() < 3 && !extensionEnabled("GL_EXT_color_buffer_half_float")) |
Geoff Lang | a809165 | 2015-04-27 10:53:55 -0400 | [diff] [blame] | 195 | { |
Austin Kinross | ff318af | 2015-12-22 15:34:45 -0800 | [diff] [blame] | 196 | std::cout << "Test skipped because ES3 or GL_EXT_color_buffer_half_float is not available." |
| 197 | << std::endl; |
Geoff Lang | a809165 | 2015-04-27 10:53:55 -0400 | [diff] [blame] | 198 | return; |
| 199 | } |
| 200 | |
Jamie Madill | 0962fc3 | 2015-09-09 10:40:28 -0400 | [diff] [blame] | 201 | // TODO(jmadill): figure out why this fails |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 202 | if (isIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9())) |
Jamie Madill | 0962fc3 | 2015-09-09 10:40:28 -0400 | [diff] [blame] | 203 | { |
| 204 | std::cout << "Test skipped on Intel due to failures." << std::endl; |
| 205 | return; |
| 206 | } |
| 207 | |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 208 | runTest(GL_RGBA16F); |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 209 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 210 | |
| 211 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Austin Kinross | ff318af | 2015-12-22 15:34:45 -0800 | [diff] [blame] | 212 | ANGLE_INSTANTIATE_TEST(BlendMinMaxTest, ES2_D3D9(), ES2_D3D11(), ES2_D3D11_FL9_3(), ES2_OPENGL()); |