Chromium Code Reviews| Index: gpu/command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc |
| diff --git a/gpu/command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc b/gpu/command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc |
| index c1d3c9885c6a8e1da9a9ea78086ec546066fe88a..95fc84313e5de5cd2c3ace11bdc67a3935c80b87 100644 |
| --- a/gpu/command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc |
| +++ b/gpu/command_buffer/tests/gl_chromium_framebuffer_multisample_unittest.cc |
| @@ -47,5 +47,114 @@ TEST_F(GLChromiumFramebufferMultisampleTest, CachedBindingsTest) { |
| GLTestHelper::CheckGLError("no errors", __LINE__); |
| } |
| +TEST_F(GLChromiumFramebufferMultisampleTest, DrawAndResolve) { |
| + if (!GLTestHelper::HasExtension("GL_CHROMIUM_framebuffer_multisample")) { |
| + return; |
| + } |
| + |
| + static const char* v_shader_str = |
| + "attribute vec4 a_Position;\n" |
| + "void main()\n" |
| + "{\n" |
| + " gl_Position = a_Position;\n" |
| + "}\n"; |
| + static const char* f_shader_str = |
| + "precision mediump float;\n" |
| + "void main()\n" |
| + "{\n" |
| + " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" |
| + "}\n"; |
| + |
| + GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); |
| + glUseProgram(program); |
| + GLuint position_loc = glGetAttribLocation(program, "a_Position"); |
| + |
| + GLTestHelper::SetupUnitQuad(position_loc); |
| + |
| + const GLuint width = 100; |
| + const GLuint height = 100; |
| + |
| + // Create a sample buffer. |
| + GLsizei num_samples = 4, max_samples = 0; |
| + glGetIntegerv(GL_MAX_SAMPLES, &max_samples); |
| + num_samples = std::min(num_samples, max_samples); |
| + |
| + GLuint sample_fbo, sample_rb; |
| + glGenRenderbuffers(1, &sample_rb); |
| + glBindRenderbuffer(GL_RENDERBUFFER, sample_rb); |
| + glRenderbufferStorageMultisampleEXT( |
| + GL_RENDERBUFFER, num_samples, GL_RGBA8_OES, width, height); |
| + GLint param = 0; |
| + glGetRenderbufferParameteriv( |
| + GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, ¶m); |
| + EXPECT_GE(param, num_samples); |
| + |
| + glGenFramebuffers(1, &sample_fbo); |
| + glBindFramebuffer(GL_FRAMEBUFFER, sample_fbo); |
| + glFramebufferRenderbuffer(GL_FRAMEBUFFER, |
| + GL_COLOR_ATTACHMENT0, |
| + GL_RENDERBUFFER, |
| + sample_rb); |
| + EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| + glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| + |
| + // Create another FBO to resolve the multisample buffer into. |
| + GLuint resolve_fbo, resolve_tex; |
| + glGenTextures(1, &resolve_tex); |
| + glBindTexture(GL_TEXTURE_2D, resolve_tex); |
| + glTexImage2D(GL_TEXTURE_2D, |
| + 0, |
| + GL_RGBA, |
| + width, |
| + height, |
| + 0, |
| + GL_RGBA, |
| + GL_UNSIGNED_BYTE, |
| + NULL); |
| + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
Sami
2013/10/29 16:31:16
Pet peeve: glTexParameteri :)
no sievers
2013/10/29 18:45:48
Done.
|
| + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| + glGenFramebuffers(1, &resolve_fbo); |
| + glBindFramebuffer(GL_FRAMEBUFFER, resolve_fbo); |
| + glFramebufferTexture2D(GL_FRAMEBUFFER, |
| + GL_COLOR_ATTACHMENT0, |
| + GL_TEXTURE_2D, |
| + resolve_tex, |
| + 0); |
| + EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| + glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| + |
| + // Draw one triangle (bottom left half). |
| + glViewport(0, 0, width, height); |
| + glBindFramebuffer(GL_FRAMEBUFFER, sample_fbo); |
| + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| + glClear(GL_COLOR_BUFFER_BIT); |
| + glDrawArrays(GL_TRIANGLES, 0, 3); |
| + |
| + // Resolve. |
| + glBindFramebuffer(GL_READ_FRAMEBUFFER, sample_fbo); |
| + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolve_fbo); |
| + glClearColor(1.0f, 0.0f, 0.0f, 0.0f); |
| + glClear(GL_COLOR_BUFFER_BIT); |
| + glBlitFramebufferEXT(0, |
| + 0, |
| + width, |
| + height, |
| + 0, |
| + 0, |
| + width, |
| + height, |
| + GL_COLOR_BUFFER_BIT, |
| + GL_NEAREST); |
| + |
| + // Verify. |
| + const uint8 green[] = {0, 255, 0, 255}; |
| + const uint8 black[] = {0, 0, 0, 0}; |
| + glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo); |
| + EXPECT_TRUE(GLTestHelper::CheckPixels(0, height - 1, 1, 1, 0, green)); |
|
Sami
2013/10/29 16:31:16
I wonder if this part could be a little flaky sinc
no sievers
2013/10/29 18:45:48
Done.
|
| + EXPECT_TRUE(GLTestHelper::CheckPixels(width - 1, 0, 1, 1, 0, black)); |
| +} |
| + |
| } // namespace gpu |