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 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame^] | 41 | if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_blend_minmax")) |
Geoff Lang | a809165 | 2015-04-27 10:53:55 -0400 | [diff] [blame] | 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 |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 48 | if (IsIntel() && GetParam() == ES2_OPENGL()) |
Geoff Lang | ddf4d39 | 2015-09-29 13:00:14 -0400 | [diff] [blame] | 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 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame^] | 169 | if (getClientMajorVersion() < 3 || !extensionEnabled("GL_EXT_color_buffer_float")) |
Geoff Lang | a809165 | 2015-04-27 10:53:55 -0400 | [diff] [blame] | 170 | { |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 171 | std::cout << "Test skipped because ES3 and GL_EXT_color_buffer_float are not available." |
| 172 | << std::endl; |
Geoff Lang | a809165 | 2015-04-27 10:53:55 -0400 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 176 | // TODO(jmadill): Figure out why this is broken on Intel |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 177 | if (IsIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9())) |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 178 | { |
| 179 | std::cout << "Test skipped on Intel OpenGL." << std::endl; |
| 180 | return; |
| 181 | } |
| 182 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 183 | // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3 |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 184 | if (IsD3D11_FL93()) |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 185 | { |
| 186 | std::cout << "Test skipped on Feature Level 9_3." << std::endl; |
| 187 | return; |
| 188 | } |
| 189 | |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 190 | runTest(GL_RGBA32F); |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 191 | } |
| 192 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 193 | TEST_P(BlendMinMaxTest, RGBA16F) |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 194 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame^] | 195 | if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_color_buffer_half_float")) |
Geoff Lang | a809165 | 2015-04-27 10:53:55 -0400 | [diff] [blame] | 196 | { |
Austin Kinross | ff318af | 2015-12-22 15:34:45 -0800 | [diff] [blame] | 197 | std::cout << "Test skipped because ES3 or GL_EXT_color_buffer_half_float is not available." |
| 198 | << std::endl; |
Geoff Lang | a809165 | 2015-04-27 10:53:55 -0400 | [diff] [blame] | 199 | return; |
| 200 | } |
| 201 | |
Jamie Madill | 0962fc3 | 2015-09-09 10:40:28 -0400 | [diff] [blame] | 202 | // TODO(jmadill): figure out why this fails |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 203 | if (IsIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9())) |
Jamie Madill | 0962fc3 | 2015-09-09 10:40:28 -0400 | [diff] [blame] | 204 | { |
| 205 | std::cout << "Test skipped on Intel due to failures." << std::endl; |
| 206 | return; |
| 207 | } |
| 208 | |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 209 | // TODO(geofflang): This fails because readpixels with UNSIGNED_BYTE/RGBA does not work with |
| 210 | // half float buffers (http://anglebug.com/1288) |
| 211 | if (GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE) |
| 212 | { |
| 213 | std::cout << "Test skipped on OpenGL ES targets." << std::endl; |
| 214 | return; |
| 215 | } |
| 216 | |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 217 | runTest(GL_RGBA16F); |
Geoff Lang | 496123f | 2014-02-12 11:33:51 -0500 | [diff] [blame] | 218 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 219 | |
| 220 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 221 | ANGLE_INSTANTIATE_TEST(BlendMinMaxTest, |
| 222 | ES2_D3D9(), |
| 223 | ES2_D3D11(), |
| 224 | ES2_D3D11_FL9_3(), |
| 225 | ES2_OPENGL(), |
| 226 | ES2_OPENGLES()); |