blob: 5b1035c74eb904cfdae77c93e33b26e1d54a437c [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;
26 }
27
28 struct Color
29 {
30 float values[4];
31 };
32
33 static GLubyte getExpected(bool blendMin, float curColor, GLubyte prevColor)
34 {
Minmin Gong794e0002015-04-07 18:31:54 -070035 GLubyte curAsUbyte = static_cast<GLubyte>((curColor * std::numeric_limits<GLubyte>::max()) + 0.5f);
Geoff Lang496123f2014-02-12 11:33:51 -050036 return blendMin ? std::min<GLubyte>(curAsUbyte, prevColor) : std::max<GLubyte>(curAsUbyte, prevColor);
37 }
38
Geoff Langf34d1db2015-05-20 14:10:46 -040039 void runTest(GLenum colorFormat)
Geoff Lang496123f2014-02-12 11:33:51 -050040 {
Martin Radev1be913c2016-07-11 17:59:16 +030041 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_blend_minmax"))
Geoff Langa8091652015-04-27 10:53:55 -040042 {
43 std::cout << "Test skipped because ES3 or GL_EXT_blend_minmax is not available." << std::endl;
44 return;
45 }
46
Geoff Langddf4d392015-09-29 13:00:14 -040047 // TODO(geofflang): figure out why this fails
Jamie Madill518b9fa2016-03-02 11:26:02 -050048 if (IsIntel() && GetParam() == ES2_OPENGL())
Geoff Langddf4d392015-09-29 13:00:14 -040049 {
50 std::cout << "Test skipped on OpenGL Intel due to flakyness." << std::endl;
51 return;
52 }
53
Geoff Langf34d1db2015-05-20 14:10:46 -040054 SetUpFramebuffer(colorFormat);
55
Geoff Lang496123f2014-02-12 11:33:51 -050056 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 Madill5599c8f2014-08-26 13:16:39 -0400114 mProgram = CompileProgram(testVertexShaderSource, testFragmentShaderSource);
Geoff Lang496123f2014-02-12 11:33:51 -0500115 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 Madillfa05f602015-05-07 13:47:11 -0400162TEST_P(BlendMinMaxTest, RGBA8)
Geoff Lang496123f2014-02-12 11:33:51 -0500163{
Geoff Langf34d1db2015-05-20 14:10:46 -0400164 runTest(GL_RGBA8);
Geoff Lang496123f2014-02-12 11:33:51 -0500165}
166
Jamie Madillfa05f602015-05-07 13:47:11 -0400167TEST_P(BlendMinMaxTest, RGBA32f)
Geoff Lang496123f2014-02-12 11:33:51 -0500168{
Martin Radev1be913c2016-07-11 17:59:16 +0300169 if (getClientMajorVersion() < 3 || !extensionEnabled("GL_EXT_color_buffer_float"))
Geoff Langa8091652015-04-27 10:53:55 -0400170 {
Geoff Lange0cc2a42016-01-20 10:58:17 -0500171 std::cout << "Test skipped because ES3 and GL_EXT_color_buffer_float are not available."
172 << std::endl;
Geoff Langa8091652015-04-27 10:53:55 -0400173 return;
174 }
175
Jamie Madill1ea9aaa2015-10-07 11:13:55 -0400176 // TODO(jmadill): Figure out why this is broken on Intel
Jamie Madill518b9fa2016-03-02 11:26:02 -0500177 if (IsIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9()))
Jamie Madill1ea9aaa2015-10-07 11:13:55 -0400178 {
179 std::cout << "Test skipped on Intel OpenGL." << std::endl;
180 return;
181 }
182
Austin Kinrossd544cc92016-01-11 15:26:42 -0800183 // TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
Jamie Madill518b9fa2016-03-02 11:26:02 -0500184 if (IsD3D11_FL93())
Austin Kinrossd544cc92016-01-11 15:26:42 -0800185 {
186 std::cout << "Test skipped on Feature Level 9_3." << std::endl;
187 return;
188 }
189
Geoff Langf34d1db2015-05-20 14:10:46 -0400190 runTest(GL_RGBA32F);
Geoff Lang496123f2014-02-12 11:33:51 -0500191}
192
Jamie Madillfa05f602015-05-07 13:47:11 -0400193TEST_P(BlendMinMaxTest, RGBA16F)
Geoff Lang496123f2014-02-12 11:33:51 -0500194{
Martin Radev1be913c2016-07-11 17:59:16 +0300195 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_color_buffer_half_float"))
Geoff Langa8091652015-04-27 10:53:55 -0400196 {
Austin Kinrossff318af2015-12-22 15:34:45 -0800197 std::cout << "Test skipped because ES3 or GL_EXT_color_buffer_half_float is not available."
198 << std::endl;
Geoff Langa8091652015-04-27 10:53:55 -0400199 return;
200 }
201
Jamie Madill0962fc32015-09-09 10:40:28 -0400202 // TODO(jmadill): figure out why this fails
Jamie Madill518b9fa2016-03-02 11:26:02 -0500203 if (IsIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9()))
Jamie Madill0962fc32015-09-09 10:40:28 -0400204 {
205 std::cout << "Test skipped on Intel due to failures." << std::endl;
206 return;
207 }
208
Geoff Lange0cc2a42016-01-20 10:58:17 -0500209 // 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 Langf34d1db2015-05-20 14:10:46 -0400217 runTest(GL_RGBA16F);
Geoff Lang496123f2014-02-12 11:33:51 -0500218}
Jamie Madillfa05f602015-05-07 13:47:11 -0400219
220// 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 -0500221ANGLE_INSTANTIATE_TEST(BlendMinMaxTest,
222 ES2_D3D9(),
223 ES2_D3D11(),
224 ES2_D3D11_FL9_3(),
225 ES2_OPENGL(),
226 ES2_OPENGLES());