| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <GLES2/gl2.h> | 5 #include <GLES2/gl2.h> |
| 6 #include <GLES2/gl2ext.h> | 6 #include <GLES2/gl2ext.h> |
| 7 #include <GLES2/gl2extchromium.h> | 7 #include <GLES2/gl2extchromium.h> |
| 8 #include <stdint.h> |
| 8 | 9 |
| 9 #include "gpu/command_buffer/tests/gl_manager.h" | 10 #include "gpu/command_buffer/tests/gl_manager.h" |
| 10 #include "gpu/command_buffer/tests/gl_test_utils.h" | 11 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| 11 #include "gpu/config/gpu_test_config.h" | 12 #include "gpu/config/gpu_test_config.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 #define SHADER0(Src) #Src | 15 #define SHADER0(Src) #Src |
| 15 | 16 |
| 16 namespace gpu { | 17 namespace gpu { |
| 17 | 18 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 147 } |
| 147 | 148 |
| 148 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f}; | 149 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f}; |
| 149 static const float kGreen[] = {0.0f, 1.0f, 0.0f, 1.0f}; | 150 static const float kGreen[] = {0.0f, 1.0f, 0.0f, 1.0f}; |
| 150 static const float kRed[] = {1.0f, 0.0f, 0.0f, 1.0f}; | 151 static const float kRed[] = {1.0f, 0.0f, 0.0f, 1.0f}; |
| 151 | 152 |
| 152 // Different drivers seem to behave differently with respect to resulting | 153 // Different drivers seem to behave differently with respect to resulting |
| 153 // values. These might be due to different MSAA sample counts causing | 154 // values. These might be due to different MSAA sample counts causing |
| 154 // different samples to hit. Other option is driver bugs. Just test that | 155 // different samples to hit. Other option is driver bugs. Just test that |
| 155 // disabling multisample causes a difference. | 156 // disabling multisample causes a difference. |
| 156 scoped_ptr<uint8[]> results[3]; | 157 scoped_ptr<uint8_t[]> results[3]; |
| 157 const GLint kResultSize = kWidth * kHeight * 4; | 158 const GLint kResultSize = kWidth * kHeight * 4; |
| 158 for (int pass = 0; pass < 3; pass++) { | 159 for (int pass = 0; pass < 3; pass++) { |
| 159 PrepareForDraw(); | 160 PrepareForDraw(); |
| 160 // Green: from top right to bottom left. | 161 // Green: from top right to bottom left. |
| 161 glUniform4fv(color_loc_, 1, kGreen); | 162 glUniform4fv(color_loc_, 1, kGreen); |
| 162 glDrawArrays(GL_TRIANGLES, 0, 3); | 163 glDrawArrays(GL_TRIANGLES, 0, 3); |
| 163 | 164 |
| 164 // Blue: from top left to bottom right. | 165 // Blue: from top left to bottom right. |
| 165 glUniform4fv(color_loc_, 1, kBlue); | 166 glUniform4fv(color_loc_, 1, kBlue); |
| 166 glDrawArrays(GL_TRIANGLES, 3, 3); | 167 glDrawArrays(GL_TRIANGLES, 3, 3); |
| 167 | 168 |
| 168 // Red, with and without MSAA: from bottom left to top right. | 169 // Red, with and without MSAA: from bottom left to top right. |
| 169 if (pass == 1) { | 170 if (pass == 1) { |
| 170 glDisable(GL_MULTISAMPLE_EXT); | 171 glDisable(GL_MULTISAMPLE_EXT); |
| 171 } | 172 } |
| 172 glUniform4fv(color_loc_, 1, kRed); | 173 glUniform4fv(color_loc_, 1, kRed); |
| 173 glDrawArrays(GL_TRIANGLES, 6, 3); | 174 glDrawArrays(GL_TRIANGLES, 6, 3); |
| 174 if (pass == 1) { | 175 if (pass == 1) { |
| 175 glEnable(GL_MULTISAMPLE_EXT); | 176 glEnable(GL_MULTISAMPLE_EXT); |
| 176 } | 177 } |
| 177 PrepareForVerify(); | 178 PrepareForVerify(); |
| 178 results[pass].reset(new uint8[kResultSize]); | 179 results[pass].reset(new uint8_t[kResultSize]); |
| 179 memset(results[pass].get(), GLTestHelper::kCheckClearValue, kResultSize); | 180 memset(results[pass].get(), GLTestHelper::kCheckClearValue, kResultSize); |
| 180 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, | 181 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, |
| 181 results[pass].get()); | 182 results[pass].get()); |
| 182 } | 183 } |
| 183 EXPECT_NE(0, memcmp(results[0].get(), results[1].get(), kResultSize)); | 184 EXPECT_NE(0, memcmp(results[0].get(), results[1].get(), kResultSize)); |
| 184 // Verify that rendering is deterministic, so that the pass above does not | 185 // Verify that rendering is deterministic, so that the pass above does not |
| 185 // come from non-deterministic rendering. | 186 // come from non-deterministic rendering. |
| 186 EXPECT_EQ(0, memcmp(results[0].get(), results[2].get(), kResultSize)); | 187 EXPECT_EQ(0, memcmp(results[0].get(), results[2].get(), kResultSize)); |
| 187 } | 188 } |
| 188 | 189 |
| 189 TEST_F(EXTMultisampleCompatibilityTest, DrawAlphaOneAndResolve) { | 190 TEST_F(EXTMultisampleCompatibilityTest, DrawAlphaOneAndResolve) { |
| 190 // Test that enabling GL_SAMPLE_ALPHA_TO_ONE_EXT affects rendering. | 191 // Test that enabling GL_SAMPLE_ALPHA_TO_ONE_EXT affects rendering. |
| 191 if (!IsApplicable()) { | 192 if (!IsApplicable()) { |
| 192 return; | 193 return; |
| 193 } | 194 } |
| 194 | 195 |
| 195 // SAMPLE_ALPHA_TO_ONE is specified to transform alpha values of | 196 // SAMPLE_ALPHA_TO_ONE is specified to transform alpha values of |
| 196 // covered samples to 1.0. In order to detect it, we use non-1.0 | 197 // covered samples to 1.0. In order to detect it, we use non-1.0 |
| 197 // alpha. | 198 // alpha. |
| 198 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 0.5f}; | 199 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 0.5f}; |
| 199 static const float kGreen[] = {0.0f, 1.0f, 0.0f, 0.5f}; | 200 static const float kGreen[] = {0.0f, 1.0f, 0.0f, 0.5f}; |
| 200 static const float kRed[] = {1.0f, 0.0f, 0.0f, 0.5f}; | 201 static const float kRed[] = {1.0f, 0.0f, 0.0f, 0.5f}; |
| 201 | 202 |
| 202 // Different drivers seem to behave differently with respect to resulting | 203 // Different drivers seem to behave differently with respect to resulting |
| 203 // alpha value. These might be due to different MSAA sample counts causing | 204 // alpha value. These might be due to different MSAA sample counts causing |
| 204 // different samples to hit. Other option is driver bugs. Testing exact or | 205 // different samples to hit. Other option is driver bugs. Testing exact or |
| 205 // even approximate sample values is not that easy. Thus, just test | 206 // even approximate sample values is not that easy. Thus, just test |
| 206 // representative positions which have fractional pixels, inspecting that | 207 // representative positions which have fractional pixels, inspecting that |
| 207 // normal rendering is different to SAMPLE_ALPHA_TO_ONE rendering. | 208 // normal rendering is different to SAMPLE_ALPHA_TO_ONE rendering. |
| 208 scoped_ptr<uint8[]> results[3]; | 209 scoped_ptr<uint8_t[]> results[3]; |
| 209 const GLint kResultSize = kWidth * kHeight * 4; | 210 const GLint kResultSize = kWidth * kHeight * 4; |
| 210 | 211 |
| 211 for (int pass = 0; pass < 3; ++pass) { | 212 for (int pass = 0; pass < 3; ++pass) { |
| 212 PrepareForDraw(); | 213 PrepareForDraw(); |
| 213 if (pass == 1) { | 214 if (pass == 1) { |
| 214 glEnable(GL_SAMPLE_ALPHA_TO_ONE_EXT); | 215 glEnable(GL_SAMPLE_ALPHA_TO_ONE_EXT); |
| 215 } | 216 } |
| 216 glEnable(GL_MULTISAMPLE_EXT); | 217 glEnable(GL_MULTISAMPLE_EXT); |
| 217 glUniform4fv(color_loc_, 1, kGreen); | 218 glUniform4fv(color_loc_, 1, kGreen); |
| 218 glDrawArrays(GL_TRIANGLES, 0, 3); | 219 glDrawArrays(GL_TRIANGLES, 0, 3); |
| 219 | 220 |
| 220 glUniform4fv(color_loc_, 1, kBlue); | 221 glUniform4fv(color_loc_, 1, kBlue); |
| 221 glDrawArrays(GL_TRIANGLES, 3, 3); | 222 glDrawArrays(GL_TRIANGLES, 3, 3); |
| 222 | 223 |
| 223 glDisable(GL_MULTISAMPLE_EXT); | 224 glDisable(GL_MULTISAMPLE_EXT); |
| 224 glUniform4fv(color_loc_, 1, kRed); | 225 glUniform4fv(color_loc_, 1, kRed); |
| 225 glDrawArrays(GL_TRIANGLES, 6, 3); | 226 glDrawArrays(GL_TRIANGLES, 6, 3); |
| 226 | 227 |
| 227 PrepareForVerify(); | 228 PrepareForVerify(); |
| 228 results[pass].reset(new uint8[kResultSize]); | 229 results[pass].reset(new uint8_t[kResultSize]); |
| 229 memset(results[pass].get(), GLTestHelper::kCheckClearValue, kResultSize); | 230 memset(results[pass].get(), GLTestHelper::kCheckClearValue, kResultSize); |
| 230 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, | 231 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, |
| 231 results[pass].get()); | 232 results[pass].get()); |
| 232 if (pass == 1) { | 233 if (pass == 1) { |
| 233 glDisable(GL_SAMPLE_ALPHA_TO_ONE_EXT); | 234 glDisable(GL_SAMPLE_ALPHA_TO_ONE_EXT); |
| 234 } | 235 } |
| 235 } | 236 } |
| 236 EXPECT_NE(0, memcmp(results[0].get(), results[1].get(), kResultSize)); | 237 EXPECT_NE(0, memcmp(results[0].get(), results[1].get(), kResultSize)); |
| 237 // Verify that rendering is deterministic, so that the pass above does not | 238 // Verify that rendering is deterministic, so that the pass above does not |
| 238 // come from non-deterministic rendering. | 239 // come from non-deterministic rendering. |
| 239 EXPECT_EQ(0, memcmp(results[0].get(), results[2].get(), kResultSize)); | 240 EXPECT_EQ(0, memcmp(results[0].get(), results[2].get(), kResultSize)); |
| 240 } | 241 } |
| 241 | 242 |
| 242 } // namespace gpu | 243 } // namespace gpu |
| OLD | NEW |