blob: 6f788e13a34d993ad9fe2a5368f6e46391584b98 [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
Geoff Langd1913172013-10-18 16:15:10 -04007#include "ANGLETest.h"
8
Jamie Madillfa05f602015-05-07 13:47:11 -04009using namespace angle;
Jamie Madill94203b32014-10-02 10:44:16 -040010
Jamie Madill94203b32014-10-02 10:44:16 -040011class ClearTestBase : public ANGLETest
Geoff Langd1913172013-10-18 16:15:10 -040012{
Jamie Madill94203b32014-10-02 10:44:16 -040013 protected:
Jamie Madillfa05f602015-05-07 13:47:11 -040014 ClearTestBase()
Geoff Langd1913172013-10-18 16:15:10 -040015 {
16 setWindowWidth(128);
17 setWindowHeight(128);
Geoff Langefc551f2013-10-31 10:20:28 -040018 setConfigRedBits(8);
19 setConfigGreenBits(8);
20 setConfigBlueBits(8);
21 setConfigAlphaBits(8);
22 setConfigDepthBits(24);
Geoff Langd1913172013-10-18 16:15:10 -040023 }
24
25 virtual void SetUp()
26 {
27 ANGLETest::SetUp();
28
29 const std::string vertexShaderSource = SHADER_SOURCE
30 (
31 precision highp float;
32 attribute vec4 position;
33
34 void main()
35 {
36 gl_Position = position;
37 }
38 );
39
40 const std::string fragmentShaderSource = SHADER_SOURCE
41 (
42 precision highp float;
43
44 void main()
45 {
46 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
47 }
48 );
49
Jamie Madill5599c8f2014-08-26 13:16:39 -040050 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Geoff Langd1913172013-10-18 16:15:10 -040051 if (mProgram == 0)
52 {
53 FAIL() << "shader compilation failed.";
54 }
Jamie Madilla09403c2014-07-21 10:03:36 -040055
56 glGenFramebuffers(1, &mFBO);
57
58 ASSERT_GL_NO_ERROR();
Geoff Langd1913172013-10-18 16:15:10 -040059 }
60
61 virtual void TearDown()
62 {
63 glDeleteProgram(mProgram);
Jamie Madilla09403c2014-07-21 10:03:36 -040064 glDeleteFramebuffers(1, &mFBO);
Geoff Langd1913172013-10-18 16:15:10 -040065
66 ANGLETest::TearDown();
67 }
68
69 GLuint mProgram;
Jamie Madilla09403c2014-07-21 10:03:36 -040070 GLuint mFBO;
Geoff Langd1913172013-10-18 16:15:10 -040071};
72
Jamie Madillfa05f602015-05-07 13:47:11 -040073class ClearTest : public ClearTestBase {};
74class ClearTestES3 : public ClearTestBase {};
Jamie Madill94203b32014-10-02 10:44:16 -040075
Jamie Madillfa05f602015-05-07 13:47:11 -040076TEST_P(ClearTest, ClearIssue)
Geoff Langd1913172013-10-18 16:15:10 -040077{
Geoff Lang463cdea2015-04-28 13:22:31 -040078 // TODO(geofflang): Figure out why this is broken on Intel OpenGL
79 if (isIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
80 {
81 std::cout << "Test skipped on Intel OpenGL." << std::endl;
82 return;
83 }
84
Geoff Langd1913172013-10-18 16:15:10 -040085 glEnable(GL_DEPTH_TEST);
86 glDepthFunc(GL_LEQUAL);
87
88 glClearColor(0.0, 1.0, 0.0, 1.0);
89 glClearDepthf(0.0);
90 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
91
92 EXPECT_GL_NO_ERROR();
93
Jamie Madilla09403c2014-07-21 10:03:36 -040094 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
Geoff Langd1913172013-10-18 16:15:10 -040095
96 GLuint rbo;
97 glGenRenderbuffers(1, &rbo);
98 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
99 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
100
101 EXPECT_GL_NO_ERROR();
102
103 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
104
105 EXPECT_GL_NO_ERROR();
106
107 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
108 glClearDepthf(1.0f);
109 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
110
111 EXPECT_GL_NO_ERROR();
112
113 glBindFramebuffer(GL_FRAMEBUFFER, 0);
114 glBindBuffer(GL_ARRAY_BUFFER, 0);
115
116 drawQuad(mProgram, "position", 0.5f);
117
118 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
119}
Jamie Madilla09403c2014-07-21 10:03:36 -0400120
121// Requires ES3
122// This tests a bug where in a masked clear when calling "ClearBuffer", we would
123// mistakenly clear every channel (including the masked-out ones)
Jamie Madillfa05f602015-05-07 13:47:11 -0400124TEST_P(ClearTestES3, MaskedClearBufferBug)
Jamie Madilla09403c2014-07-21 10:03:36 -0400125{
126 unsigned char pixelData[] = { 255, 255, 255, 255 };
127
128 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
129
130 GLuint textures[2];
131 glGenTextures(2, &textures[0]);
132
133 glBindTexture(GL_TEXTURE_2D, textures[0]);
134 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
135 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
136
137 glBindTexture(GL_TEXTURE_2D, textures[1]);
138 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
139 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
140
141 ASSERT_GL_NO_ERROR();
142 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
143
144 float clearValue[] = { 0, 0.5f, 0.5f, 1.0f };
145 GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 };
146 glDrawBuffers(2, drawBuffers);
147 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
148 glClearBufferfv(GL_COLOR, 1, clearValue);
149
150 ASSERT_GL_NO_ERROR();
151 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
152
153 // TODO: glReadBuffer support
154 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
155 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
Jamie Madill9abdc2d2014-11-05 16:13:22 -0500156
157 //TODO(jmadill): Robust handling of pixel test error ranges
158 EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1);
Jamie Madillc4833262014-09-18 16:18:26 -0400159
160 glDeleteTextures(2, textures);
161}
162
Jamie Madillfa05f602015-05-07 13:47:11 -0400163TEST_P(ClearTestES3, BadFBOSerialBug)
Jamie Madillc4833262014-09-18 16:18:26 -0400164{
165 // First make a simple framebuffer, and clear it to green
166 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
167
168 GLuint textures[2];
169 glGenTextures(2, &textures[0]);
170
171 glBindTexture(GL_TEXTURE_2D, textures[0]);
172 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
173 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
174
175 GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
176 glDrawBuffers(1, drawBuffers);
177
178 float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
179 glClearBufferfv(GL_COLOR, 0, clearValues1);
180
181 ASSERT_GL_NO_ERROR();
182 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
183
184 // Next make a second framebuffer, and draw it to red
185 // (Triggers bad applied render target serial)
186 GLuint fbo2;
187 glGenFramebuffers(1, &fbo2);
188 ASSERT_GL_NO_ERROR();
189
190 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
191
192 glBindTexture(GL_TEXTURE_2D, textures[1]);
193 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
194 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
195
196 glDrawBuffers(1, drawBuffers);
197
198 drawQuad(mProgram, "position", 0.5f);
199
200 ASSERT_GL_NO_ERROR();
201 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
202
203 // Check that the first framebuffer is still green.
204 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
205 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
206
207 glDeleteTextures(2, textures);
208 glDeleteFramebuffers(1, &fbo2);
Jamie Madilla09403c2014-07-21 10:03:36 -0400209}
Jamie Madillfa05f602015-05-07 13:47:11 -0400210
211// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
212ANGLE_INSTANTIATE_TEST(ClearTest, ES2_D3D9(), ES2_D3D11(), ES3_D3D11(), ES2_OPENGL(), ES3_OPENGL());
213ANGLE_INSTANTIATE_TEST(ClearTestES3, ES3_D3D11());