blob: 8ccaf9274495151f3db910f4f38c9909b412ecc0 [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
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 Wallezd3970de2015-05-14 11:07:48 -04007#include "test_utils/ANGLETest.h"
Geoff Lang496123f2014-02-12 11:33:51 -05008
Jamie Madillfa05f602015-05-07 13:47:11 -04009using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070010
Geoff Lang496123f2014-02-12 11:33:51 -050011class BlendMinMaxTest : public ANGLETest
12{
Jamie Madillfa05f602015-05-07 13:47:11 -040013 protected:
14 BlendMinMaxTest()
Geoff Lang496123f2014-02-12 11:33:51 -050015 {
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;
Sami Väisänenc4433f42016-07-12 16:56:43 +030026 mFramebuffer = 0;
27 mColorRenderbuffer = 0;
Geoff Lang496123f2014-02-12 11:33:51 -050028 }
29
30 struct Color
31 {
32 float values[4];
33 };
34
35 static GLubyte getExpected(bool blendMin, float curColor, GLubyte prevColor)
36 {
Minmin Gong794e0002015-04-07 18:31:54 -070037 GLubyte curAsUbyte = static_cast<GLubyte>((curColor * std::numeric_limits<GLubyte>::max()) + 0.5f);
Geoff Lang496123f2014-02-12 11:33:51 -050038 return blendMin ? std::min<GLubyte>(curAsUbyte, prevColor) : std::max<GLubyte>(curAsUbyte, prevColor);
39 }
40
Geoff Langf34d1db2015-05-20 14:10:46 -040041 void runTest(GLenum colorFormat)
Geoff Lang496123f2014-02-12 11:33:51 -050042 {
Martin Radev1be913c2016-07-11 17:59:16 +030043 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_blend_minmax"))
Geoff Langa8091652015-04-27 10:53:55 -040044 {
45 std::cout << "Test skipped because ES3 or GL_EXT_blend_minmax is not available." << std::endl;
46 return;
47 }
48
Geoff Langddf4d392015-09-29 13:00:14 -040049 // TODO(geofflang): figure out why this fails
Jamie Madill518b9fa2016-03-02 11:26:02 -050050 if (IsIntel() && GetParam() == ES2_OPENGL())
Geoff Langddf4d392015-09-29 13:00:14 -040051 {
52 std::cout << "Test skipped on OpenGL Intel due to flakyness." << std::endl;
53 return;
54 }
55
Geoff Langf34d1db2015-05-20 14:10:46 -040056 SetUpFramebuffer(colorFormat);
57
Geoff Lang496123f2014-02-12 11:33:51 -050058 const size_t colorCount = 1024;
59 Color colors[colorCount];
60 for (size_t i = 0; i < colorCount; i++)
61 {
62 for (size_t j = 0; j < 4; j++)
63 {
64 colors[i].values[j] = (rand() % 255) / 255.0f;
65 }
66 }
67
68 GLubyte prevColor[4];
69 for (size_t i = 0; i < colorCount; i++)
70 {
71 const Color &color = colors[i];
72 glUseProgram(mProgram);
73 glUniform4f(mColorLocation, color.values[0], color.values[1], color.values[2], color.values[3]);
74
75 bool blendMin = (rand() % 2 == 0);
76 glBlendEquation(blendMin ? GL_MIN : GL_MAX);
77
78 drawQuad(mProgram, "aPosition", 0.5f);
79
80 if (i > 0)
81 {
82 EXPECT_PIXEL_EQ(0, 0,
83 getExpected(blendMin, color.values[0], prevColor[0]),
84 getExpected(blendMin, color.values[1], prevColor[1]),
85 getExpected(blendMin, color.values[2], prevColor[2]),
86 getExpected(blendMin, color.values[3], prevColor[3]));
87 }
88
89 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, prevColor);
90 }
91 }
92
93 virtual void SetUp()
94 {
95 ANGLETest::SetUp();
96
97 const std::string testVertexShaderSource = SHADER_SOURCE
98 (
99 attribute highp vec4 aPosition;
100
101 void main(void)
102 {
103 gl_Position = aPosition;
104 }
105 );
106
107 const std::string testFragmentShaderSource = SHADER_SOURCE
108 (
109 uniform highp vec4 color;
110 void main(void)
111 {
112 gl_FragColor = color;
113 }
114 );
115
Jamie Madill5599c8f2014-08-26 13:16:39 -0400116 mProgram = CompileProgram(testVertexShaderSource, testFragmentShaderSource);
Geoff Lang496123f2014-02-12 11:33:51 -0500117 if (mProgram == 0)
118 {
119 FAIL() << "shader compilation failed.";
120 }
121
122 mColorLocation = glGetUniformLocation(mProgram, "color");
123
124 glUseProgram(mProgram);
125
126 glClearColor(0, 0, 0, 0);
127 glClearDepthf(0.0);
128 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
129
130 glEnable(GL_BLEND);
131 glDisable(GL_DEPTH_TEST);
132 }
133
134 void SetUpFramebuffer(GLenum colorFormat)
135 {
136 glGenFramebuffers(1, &mFramebuffer);
137 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer);
138 glBindFramebuffer(GL_READ_FRAMEBUFFER, mFramebuffer);
139
140 glGenRenderbuffers(1, &mColorRenderbuffer);
141 glBindRenderbuffer(GL_RENDERBUFFER, mColorRenderbuffer);
142 glRenderbufferStorage(GL_RENDERBUFFER, colorFormat, getWindowWidth(), getWindowHeight());
143 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, mColorRenderbuffer);
144
145 ASSERT_GL_NO_ERROR();
146 }
147
148 virtual void TearDown()
149 {
150 glDeleteProgram(mProgram);
151 glDeleteFramebuffers(1, &mFramebuffer);
152 glDeleteRenderbuffers(1, &mColorRenderbuffer);
153
154 ANGLETest::TearDown();
155 }
156
157 GLuint mProgram;
158 GLint mColorLocation;
159
160 GLuint mFramebuffer;
161 GLuint mColorRenderbuffer;
162};
163
Jamie Madillfa05f602015-05-07 13:47:11 -0400164TEST_P(BlendMinMaxTest, RGBA8)
Geoff Lang496123f2014-02-12 11:33:51 -0500165{
Geoff Langf34d1db2015-05-20 14:10:46 -0400166 runTest(GL_RGBA8);
Geoff Lang496123f2014-02-12 11:33:51 -0500167}
168
Jamie Madillfa05f602015-05-07 13:47:11 -0400169TEST_P(BlendMinMaxTest, RGBA32f)
Geoff Lang496123f2014-02-12 11:33:51 -0500170{
Martin Radev1be913c2016-07-11 17:59:16 +0300171 if (getClientMajorVersion() < 3 || !extensionEnabled("GL_EXT_color_buffer_float"))
Geoff Langa8091652015-04-27 10:53:55 -0400172 {
Geoff Lange0cc2a42016-01-20 10:58:17 -0500173 std::cout << "Test skipped because ES3 and GL_EXT_color_buffer_float are not available."
174 << std::endl;
Geoff Langa8091652015-04-27 10:53:55 -0400175 return;
176 }
177
Jamie Madill1ea9aaa2015-10-07 11:13:55 -0400178 // TODO(jmadill): Figure out why this is broken on Intel
Jamie Madill518b9fa2016-03-02 11:26:02 -0500179 if (IsIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9()))
Jamie Madill1ea9aaa2015-10-07 11:13:55 -0400180 {
181 std::cout << "Test skipped on Intel OpenGL." << std::endl;
182 return;
183 }
184
Austin Kinrossd544cc92016-01-11 15:26:42 -0800185 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -0500186 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -0800187 {
188 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
189 return;
190 }
191
Geoff Langf34d1db2015-05-20 14:10:46 -0400192 runTest(GL_RGBA32F);
Geoff Lang496123f2014-02-12 11:33:51 -0500193}
194
Jamie Madillfa05f602015-05-07 13:47:11 -0400195TEST_P(BlendMinMaxTest, RGBA16F)
Geoff Lang496123f2014-02-12 11:33:51 -0500196{
Martin Radev1be913c2016-07-11 17:59:16 +0300197 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_color_buffer_half_float"))
Geoff Langa8091652015-04-27 10:53:55 -0400198 {
Austin Kinrossff318af2015-12-22 15:34:45 -0800199 std::cout << "Test skipped because ES3 or GL_EXT_color_buffer_half_float is not available."
200 << std::endl;
Geoff Langa8091652015-04-27 10:53:55 -0400201 return;
202 }
203
Jamie Madill0962fc32015-09-09 10:40:28 -0400204 // TODO(jmadill): figure out why this fails
Jamie Madill518b9fa2016-03-02 11:26:02 -0500205 if (IsIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9()))
Jamie Madill0962fc32015-09-09 10:40:28 -0400206 {
207 std::cout << "Test skipped on Intel due to failures." << std::endl;
208 return;
209 }
210
Geoff Lange0cc2a42016-01-20 10:58:17 -0500211 // TODO(geofflang): This fails because readpixels with UNSIGNED_BYTE/RGBA does not work with
212 // half float buffers (http://anglebug.com/1288)
213 if (GetParam().getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
214 {
215 std::cout << "Test skipped on OpenGL ES targets." << std::endl;
216 return;
217 }
218
Geoff Langf34d1db2015-05-20 14:10:46 -0400219 runTest(GL_RGBA16F);
Geoff Lang496123f2014-02-12 11:33:51 -0500220}
Jamie Madillfa05f602015-05-07 13:47:11 -0400221
222// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -0500223ANGLE_INSTANTIATE_TEST(BlendMinMaxTest,
224 ES2_D3D9(),
225 ES2_D3D11(),
226 ES2_D3D11_FL9_3(),
227 ES2_OPENGL(),
228 ES2_OPENGLES());