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 0 /* should be GL_STREAM_READ, but that is not defined in | |
greggman
2013/03/21 23:18:13
Maybe add GL_STREAM_READ to gpu/GLES2/gl2extchromi
hubbe
2013/03/21 23:36:51
Done.
| |
44 GLES2, and the code currently doesn't care */); | |
45 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
46 unsigned char *data = static_cast<unsigned char *>( | |
47 glMapBufferCHROMIUM( | |
48 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | |
49 GL_READ_ONLY)); | |
50 EXPECT_TRUE(data); | |
51 EXPECT_EQ(data[0], 0); // red | |
52 EXPECT_EQ(data[1], 0); // green | |
53 EXPECT_EQ(data[2], 255); // blue | |
54 glUnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); | |
55 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
56 glDeleteBuffers(1, &b); | |
57 GLTestHelper::CheckGLError("no errors", __LINE__); | |
58 } | |
59 | |
60 TEST_F(GLReadbackTest, ReadPixelsWithPBOAndQuery) { | |
61 const GLint kBytesPerPixel = 4; | |
62 const GLint kWidth = 2; | |
63 const GLint kHeight = 2; | |
64 | |
65 GLuint b, q; | |
66 glClearColor(0.0, 0.0, 1.0, 1.0); | |
67 glClear(GL_COLOR_BUFFER_BIT); | |
68 glGenBuffers(1, &b); | |
69 glGenQueriesEXT(1, &q); | |
70 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, b); | |
71 glBufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | |
72 kWidth * kHeight * kBytesPerPixel, | |
73 NULL, | |
74 0 /* should be GL_STREAM_READ, but that is not defined in | |
75 GLES2, and the code currently doesn't care */); | |
76 glBeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, q); | |
77 glReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); | |
78 glEndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | |
79 glFlush(); | |
80 unsigned int done = 0; | |
81 while (!done) { | |
82 glGetQueryObjectuivEXT(q, GL_QUERY_RESULT_AVAILABLE_EXT, &done); | |
83 } | |
84 | |
85 // TODO(hubbe): Check that glMapBufferCHROMIUM does not block here. | |
86 unsigned char *data = static_cast<unsigned char *>( | |
87 glMapBufferCHROMIUM( | |
88 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | |
89 GL_READ_ONLY)); | |
90 EXPECT_TRUE(data); | |
91 EXPECT_EQ(data[0], 0); // red | |
92 EXPECT_EQ(data[1], 0); // green | |
93 EXPECT_EQ(data[2], 255); // blue | |
94 glUnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); | |
95 glBindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
96 glDeleteBuffers(1, &b); | |
97 glDeleteQueriesEXT(1, &q); | |
98 GLTestHelper::CheckGLError("no errors", __LINE__); | |
99 } | |
100 | |
101 } // namespace gpu | |
OLD | NEW |