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) { |
| 31 const GLint kBytesPerPixel = 4; |
| 32 const GLint kWidth = 2; |
| 33 const GLint kHeight = 2; |
| 34 |
| 35 GLuint b; |
| 36 glClearColor(0.0, 0.0, 1.0, 1.0); |
| 37 glClear(GL_COLOR_BUFFER_BIT); |
| 38 glGenBuffers(1, &b); |
| 39 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, b); |
| 40 glBufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
| 41 kWidth * kHeight * kBytesPerPixel, |
| 42 NULL, |
| 43 GL_STREAM_READ); |
| 44 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 45 unsigned char *data = static_cast<unsigned char *>( |
| 46 glMapBufferCHROMIUM( |
| 47 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
| 48 GL_READ_ONLY)); |
| 49 EXPECT_TRUE(data); |
| 50 EXPECT_EQ(data[0], 0); // red |
| 51 EXPECT_EQ(data[1], 0); // green |
| 52 EXPECT_EQ(data[2], 255); // blue |
| 53 glUnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); |
| 54 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 55 glDeleteBuffers(1, &b); |
| 56 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 57 } |
| 58 |
| 59 TEST_F(GLReadbackTest, ReadPixelsWithPBOAndQuery) { |
| 60 const GLint kBytesPerPixel = 4; |
| 61 const GLint kWidth = 2; |
| 62 const GLint kHeight = 2; |
| 63 |
| 64 GLuint b, q; |
| 65 glClearColor(0.0, 0.0, 1.0, 1.0); |
| 66 glClear(GL_COLOR_BUFFER_BIT); |
| 67 glGenBuffers(1, &b); |
| 68 glGenQueriesEXT(1, &q); |
| 69 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, b); |
| 70 glBufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
| 71 kWidth * kHeight * kBytesPerPixel, |
| 72 NULL, |
| 73 GL_STREAM_READ); |
| 74 glBeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, q); |
| 75 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 76 glEndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
| 77 glFlush(); |
| 78 unsigned int done = 0; |
| 79 while (!done) { |
| 80 glGetQueryObjectuivEXT(q, GL_QUERY_RESULT_AVAILABLE_EXT, &done); |
| 81 } |
| 82 |
| 83 // TODO(hubbe): Check that glMapBufferCHROMIUM does not block here. |
| 84 unsigned char *data = static_cast<unsigned char *>( |
| 85 glMapBufferCHROMIUM( |
| 86 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
| 87 GL_READ_ONLY)); |
| 88 EXPECT_TRUE(data); |
| 89 EXPECT_EQ(data[0], 0); // red |
| 90 EXPECT_EQ(data[1], 0); // green |
| 91 EXPECT_EQ(data[2], 255); // blue |
| 92 glUnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); |
| 93 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 94 glDeleteBuffers(1, &b); |
| 95 glDeleteQueriesEXT(1, &q); |
| 96 GLTestHelper::CheckGLError("no errors", __LINE__); |
| 97 } |
| 98 |
| 99 } // namespace gpu |
OLD | NEW |