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 "gpu/command_buffer/tests/gl_test_utils.h" | 5 #include "gpu/command_buffer/tests/gl_test_utils.h" |
6 #include <string> | 6 #include <string> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 -1.0f, -1.0f, | 101 -1.0f, -1.0f, |
102 1.0f, -1.0f, | 102 1.0f, -1.0f, |
103 }; | 103 }; |
104 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); | 104 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); |
105 glEnableVertexAttribArray(position_location); | 105 glEnableVertexAttribArray(position_location); |
106 glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, 0, 0); | 106 glVertexAttribPointer(position_location, 2, GL_FLOAT, GL_FALSE, 0, 0); |
107 | 107 |
108 return vbo; | 108 return vbo; |
109 } | 109 } |
110 | 110 |
111 GLuint GLTestHelper::SetupColorsForUnitQuad( | |
112 GLint location, const GLfloat color[4], GLenum usage) { | |
113 GLuint vbo = 0; | |
114 glGenBuffers(1, &vbo); | |
115 glBindBuffer(GL_ARRAY_BUFFER, vbo); | |
116 GLfloat vertices[6 * 4]; | |
117 for (int ii = 0; ii < 6; ++ii) { | |
118 for (int jj = 0; jj < 4; ++jj) { | |
119 vertices[ii * 4 + jj] = color[jj]; | |
120 } | |
121 } | |
122 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, usage); | |
123 glEnableVertexAttribArray(location); | |
124 glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, 0, 0); | |
125 | |
126 return vbo; | |
127 } | |
128 | |
129 bool GLTestHelper::CheckPixels( | 111 bool GLTestHelper::CheckPixels( |
130 GLint x, GLint y, GLsizei width, GLsizei height, GLint tolerance, | 112 GLint x, GLint y, GLsizei width, GLsizei height, GLint tolerance, |
131 const uint8* color) { | 113 const uint8* color) { |
132 GLsizei size = width * height * 4; | 114 GLsizei size = width * height * 4; |
133 scoped_array<uint8> pixels(new uint8[size]); | 115 scoped_array<uint8> pixels(new uint8[size]); |
134 memset(pixels.get(), kCheckClearValue, size); | 116 memset(pixels.get(), kCheckClearValue, size); |
135 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); | 117 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); |
136 bool same = true; | 118 bool same = true; |
137 for (GLint yy = 0; yy < height; ++yy) { | 119 for (GLint yy = 0; yy < height; ++yy) { |
138 for (GLint xx = 0; xx < width; ++xx) { | 120 for (GLint xx = 0; xx < width; ++xx) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 fwrite(&bih, sizeof(bih), 1, fp); | 215 fwrite(&bih, sizeof(bih), 1, fp); |
234 fwrite(pixels, size, 1, fp); | 216 fwrite(pixels, size, 1, fp); |
235 fclose(fp); | 217 fclose(fp); |
236 return true; | 218 return true; |
237 } | 219 } |
238 | 220 |
239 int GLTestHelper::RunTests(int argc, char** argv) { | 221 int GLTestHelper::RunTests(int argc, char** argv) { |
240 testing::InitGoogleMock(&argc, argv); | 222 testing::InitGoogleMock(&argc, argv); |
241 return RUN_ALL_TESTS(); | 223 return RUN_ALL_TESTS(); |
242 } | 224 } |
OLD | NEW |