Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <GLES2/gl2.h> | |
| 6 #include <GLES2/gl2ext.h> | |
| 7 #include <GLES2/gl2extchromium.h> | |
| 8 | |
| 9 #include "gpu/command_buffer/tests/gl_manager.h" | |
| 10 #include "gpu/command_buffer/tests/gl_test_utils.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace gpu { | |
| 15 | |
| 16 class GLReadbackTest : public testing::Test { | |
| 17 protected: | |
| 18 virtual void SetUp() { | |
| 19 gl_.Initialize(GLManager::Options()); | |
| 20 } | |
| 21 | |
| 22 virtual void TearDown() { | |
| 23 gl_.Destroy(); | |
| 24 } | |
| 25 | |
| 26 GLManager gl_; | |
| 27 }; | |
| 28 | |
| 29 | |
| 30 TEST_F(GLReadbackTest, ReadPixelsWithPBO) { | |
|
apatrick_chromium
2013/03/21 22:51:27
Can you clear the FBO to a particular color and th
hubbe
2013/03/21 23:00:58
Done.
| |
| 31 const GLint kBytesPerPixel = 4; | |
| 32 const GLint kWidth = 2; | |
| 33 const GLint kHeight = 2; | |
| 34 | |
| 35 GLuint b; | |
| 36 glGenBuffers(1, &b); | |
| 37 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, b); | |
| 38 glBufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | |
| 39 kWidth * kHeight * kBytesPerPixel, | |
| 40 NULL, | |
| 41 0 /* should be GL_STREAM_READ, but that is not defined in | |
| 42 GLES2, and the code currently doesn't care */); | |
| 43 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| 44 glFlush(); | |
|
apatrick_chromium
2013/03/21 22:51:27
You shouldn't need this glFlush() because glMapBuf
hubbe
2013/03/21 23:00:58
Done.
| |
| 45 EXPECT_TRUE(glMapBufferCHROMIUM( | |
| 46 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | |
| 47 GL_READ_ONLY)); | |
| 48 glUnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); | |
| 49 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
| 50 glDeleteBuffers(1, &b); | |
| 51 GLTestHelper::CheckGLError("no errors", __LINE__); | |
| 52 } | |
| 53 | |
| 54 TEST_F(GLReadbackTest, ReadPixelsWithPBOAndQuery) { | |
| 55 const GLint kBytesPerPixel = 4; | |
| 56 const GLint kWidth = 2; | |
| 57 const GLint kHeight = 2; | |
| 58 | |
| 59 GLuint b, q; | |
| 60 glGenBuffers(1, &b); | |
| 61 glGenQueriesEXT(1, &q); | |
|
apatrick_chromium
2013/03/21 22:51:27
The query object leaks.
hubbe
2013/03/21 23:00:58
Done.
| |
| 62 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, b); | |
| 63 glBufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | |
| 64 kWidth * kHeight * kBytesPerPixel, | |
| 65 NULL, | |
| 66 0 /* should be GL_STREAM_READ, but that is not defined in | |
| 67 GLES2, and the code currently doesn't care */); | |
| 68 glBeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, q); | |
| 69 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
| 70 glEndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | |
| 71 unsigned int done = 0; | |
| 72 while (!done) { | |
|
apatrick_chromium
2013/03/21 22:51:27
I think you need a glFlush before this loop.
hubbe
2013/03/21 23:00:58
Done.
| |
| 73 glGetQueryObjectuivEXT(q, GL_QUERY_RESULT_AVAILABLE_EXT, &done); | |
| 74 } | |
| 75 | |
| 76 // TODO(hubbe): Check that glMapBufferCHROMIUM does not block here. | |
| 77 EXPECT_TRUE(glMapBufferCHROMIUM( | |
| 78 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | |
| 79 GL_READ_ONLY)); | |
| 80 glUnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); | |
| 81 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
| 82 glDeleteBuffers(1, &b); | |
| 83 GLTestHelper::CheckGLError("no errors", __LINE__); | |
| 84 } | |
| 85 | |
| 86 } // namespace gpu | |
| OLD | NEW |