Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 8 |
| 9 #include "gpu/command_buffer/tests/gl_manager.h" | 9 #include "gpu/command_buffer/tests/gl_manager.h" |
| 10 #include "gpu/command_buffer/tests/gl_test_utils.h" | 10 #include "gpu/command_buffer/tests/gl_test_utils.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 // If the caching is bad the second call to glBindFramebuffer will do nothing. | 40 // If the caching is bad the second call to glBindFramebuffer will do nothing. |
| 41 // which means the draw buffer is bad and will not return | 41 // which means the draw buffer is bad and will not return |
| 42 // GL_FRAMEBUFFER_COMPLETE and rendering will generate an error. | 42 // GL_FRAMEBUFFER_COMPLETE and rendering will generate an error. |
| 43 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | 43 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 44 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | 44 glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 45 | 45 |
| 46 glClear(GL_COLOR_BUFFER_BIT); | 46 glClear(GL_COLOR_BUFFER_BIT); |
| 47 GLTestHelper::CheckGLError("no errors", __LINE__); | 47 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 48 } | 48 } |
| 49 | 49 |
| 50 TEST_F(GLChromiumFramebufferMultisampleTest, DrawAndResolve) { | |
| 51 if (!GLTestHelper::HasExtension("GL_CHROMIUM_framebuffer_multisample")) { | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 static const char* v_shader_str = | |
| 56 "attribute vec4 a_Position;\n" | |
| 57 "void main()\n" | |
| 58 "{\n" | |
| 59 " gl_Position = a_Position;\n" | |
| 60 "}\n"; | |
| 61 static const char* f_shader_str = | |
| 62 "precision mediump float;\n" | |
| 63 "void main()\n" | |
| 64 "{\n" | |
| 65 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" | |
| 66 "}\n"; | |
| 67 | |
| 68 GLuint program = GLTestHelper::LoadProgram(v_shader_str, f_shader_str); | |
| 69 glUseProgram(program); | |
| 70 GLuint position_loc = glGetAttribLocation(program, "a_Position"); | |
| 71 | |
| 72 GLTestHelper::SetupUnitQuad(position_loc); | |
| 73 | |
| 74 const GLuint width = 100; | |
| 75 const GLuint height = 100; | |
| 76 | |
| 77 // Create a sample buffer. | |
| 78 GLsizei num_samples = 4, max_samples = 0; | |
| 79 glGetIntegerv(GL_MAX_SAMPLES, &max_samples); | |
| 80 num_samples = std::min(num_samples, max_samples); | |
| 81 | |
| 82 GLuint sample_fbo, sample_rb; | |
| 83 glGenRenderbuffers(1, &sample_rb); | |
| 84 glBindRenderbuffer(GL_RENDERBUFFER, sample_rb); | |
| 85 glRenderbufferStorageMultisampleEXT( | |
| 86 GL_RENDERBUFFER, num_samples, GL_RGBA8_OES, width, height); | |
| 87 GLint param = 0; | |
| 88 glGetRenderbufferParameteriv( | |
| 89 GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, ¶m); | |
| 90 EXPECT_GE(param, num_samples); | |
| 91 | |
| 92 glGenFramebuffers(1, &sample_fbo); | |
| 93 glBindFramebuffer(GL_FRAMEBUFFER, sample_fbo); | |
| 94 glFramebufferRenderbuffer(GL_FRAMEBUFFER, | |
| 95 GL_COLOR_ATTACHMENT0, | |
| 96 GL_RENDERBUFFER, | |
| 97 sample_rb); | |
| 98 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | |
| 99 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
| 100 | |
| 101 // Create another FBO to resolve the multisample buffer into. | |
| 102 GLuint resolve_fbo, resolve_tex; | |
| 103 glGenTextures(1, &resolve_tex); | |
| 104 glBindTexture(GL_TEXTURE_2D, resolve_tex); | |
| 105 glTexImage2D(GL_TEXTURE_2D, | |
| 106 0, | |
| 107 GL_RGBA, | |
| 108 width, | |
| 109 height, | |
| 110 0, | |
| 111 GL_RGBA, | |
| 112 GL_UNSIGNED_BYTE, | |
| 113 NULL); | |
| 114 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.
| |
| 115 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
| 116 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| 117 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 118 glGenFramebuffers(1, &resolve_fbo); | |
| 119 glBindFramebuffer(GL_FRAMEBUFFER, resolve_fbo); | |
| 120 glFramebufferTexture2D(GL_FRAMEBUFFER, | |
| 121 GL_COLOR_ATTACHMENT0, | |
| 122 GL_TEXTURE_2D, | |
| 123 resolve_tex, | |
| 124 0); | |
| 125 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), | |
| 126 glCheckFramebufferStatus(GL_FRAMEBUFFER)); | |
| 127 | |
| 128 // Draw one triangle (bottom left half). | |
| 129 glViewport(0, 0, width, height); | |
| 130 glBindFramebuffer(GL_FRAMEBUFFER, sample_fbo); | |
| 131 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |
| 132 glClear(GL_COLOR_BUFFER_BIT); | |
| 133 glDrawArrays(GL_TRIANGLES, 0, 3); | |
| 134 | |
| 135 // Resolve. | |
| 136 glBindFramebuffer(GL_READ_FRAMEBUFFER, sample_fbo); | |
| 137 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolve_fbo); | |
| 138 glClearColor(1.0f, 0.0f, 0.0f, 0.0f); | |
| 139 glClear(GL_COLOR_BUFFER_BIT); | |
| 140 glBlitFramebufferEXT(0, | |
| 141 0, | |
| 142 width, | |
| 143 height, | |
| 144 0, | |
| 145 0, | |
| 146 width, | |
| 147 height, | |
| 148 GL_COLOR_BUFFER_BIT, | |
| 149 GL_NEAREST); | |
| 150 | |
| 151 // Verify. | |
| 152 const uint8 green[] = {0, 255, 0, 255}; | |
| 153 const uint8 black[] = {0, 0, 0, 0}; | |
| 154 glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo); | |
| 155 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.
| |
| 156 EXPECT_TRUE(GLTestHelper::CheckPixels(width - 1, 0, 1, 1, 0, black)); | |
| 157 } | |
| 158 | |
| 50 } // namespace gpu | 159 } // namespace gpu |
| 51 | 160 |
| OLD | NEW |