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/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 bool success = true; | 24 bool success = true; |
25 GLenum error = GL_NO_ERROR; | 25 GLenum error = GL_NO_ERROR; |
26 while ((error = glGetError()) != GL_NO_ERROR) { | 26 while ((error = glGetError()) != GL_NO_ERROR) { |
27 success = false; | 27 success = false; |
28 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), error) | 28 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), error) |
29 << "GL ERROR in " << msg << " at line " << line << " : " << error; | 29 << "GL ERROR in " << msg << " at line " << line << " : " << error; |
30 } | 30 } |
31 return success; | 31 return success; |
32 } | 32 } |
33 | 33 |
34 GLuint GLTestHelper::LoadShader(GLenum type, const char* shaderSrc) { | 34 GLuint GLTestHelper::CompileShader(GLenum type, const char* shaderSrc) { |
35 GLuint shader = glCreateShader(type); | 35 GLuint shader = glCreateShader(type); |
36 // Load the shader source | 36 // Load the shader source |
37 glShaderSource(shader, 1, &shaderSrc, NULL); | 37 glShaderSource(shader, 1, &shaderSrc, NULL); |
38 // Compile the shader | 38 // Compile the shader |
39 glCompileShader(shader); | 39 glCompileShader(shader); |
| 40 |
| 41 return shader; |
| 42 } |
| 43 |
| 44 GLuint GLTestHelper::LoadShader(GLenum type, const char* shaderSrc) { |
| 45 GLuint shader = CompileShader(type, shaderSrc); |
| 46 |
40 // Check the compile status | 47 // Check the compile status |
41 GLint value = 0; | 48 GLint value = 0; |
42 glGetShaderiv(shader, GL_COMPILE_STATUS, &value); | 49 glGetShaderiv(shader, GL_COMPILE_STATUS, &value); |
43 if (value == 0) { | 50 if (value == 0) { |
44 char buffer[1024]; | 51 char buffer[1024]; |
45 GLsizei length = 0; | 52 GLsizei length = 0; |
46 glGetShaderInfoLog(shader, sizeof(buffer), &length, buffer); | 53 glGetShaderInfoLog(shader, sizeof(buffer), &length, buffer); |
47 std::string log(buffer, length); | 54 std::string log(buffer, length); |
48 EXPECT_EQ(1, value) << "Error compiling shader: " << log; | 55 EXPECT_EQ(1, value) << "Error compiling shader: " << log; |
49 glDeleteShader(shader); | 56 glDeleteShader(shader); |
50 shader = 0; | 57 shader = 0; |
51 } | 58 } |
52 return shader; | 59 return shader; |
53 } | 60 } |
54 | 61 |
55 GLuint GLTestHelper::SetupProgram( | 62 GLuint GLTestHelper::LinkProgram( |
56 GLuint vertex_shader, GLuint fragment_shader) { | 63 GLuint vertex_shader, GLuint fragment_shader) { |
57 // Create the program object | 64 // Create the program object |
58 GLuint program = glCreateProgram(); | 65 GLuint program = glCreateProgram(); |
59 glAttachShader(program, vertex_shader); | 66 glAttachShader(program, vertex_shader); |
60 glAttachShader(program, fragment_shader); | 67 glAttachShader(program, fragment_shader); |
61 // Link the program | 68 // Link the program |
62 glLinkProgram(program); | 69 glLinkProgram(program); |
| 70 |
| 71 return program; |
| 72 } |
| 73 |
| 74 GLuint GLTestHelper::SetupProgram( |
| 75 GLuint vertex_shader, GLuint fragment_shader) { |
| 76 GLuint program = LinkProgram(vertex_shader, fragment_shader); |
63 // Check the link status | 77 // Check the link status |
64 GLint linked = 0; | 78 GLint linked = 0; |
65 glGetProgramiv(program, GL_LINK_STATUS, &linked); | 79 glGetProgramiv(program, GL_LINK_STATUS, &linked); |
66 if (linked == 0) { | 80 if (linked == 0) { |
67 char buffer[1024]; | 81 char buffer[1024]; |
68 GLsizei length = 0; | 82 GLsizei length = 0; |
69 glGetProgramInfoLog(program, sizeof(buffer), &length, buffer); | 83 glGetProgramInfoLog(program, sizeof(buffer), &length, buffer); |
70 std::string log(buffer, length); | 84 std::string log(buffer, length); |
71 EXPECT_EQ(1, linked) << "Error linking program: " << log; | 85 EXPECT_EQ(1, linked) << "Error linking program: " << log; |
72 glDeleteProgram(program); | 86 glDeleteProgram(program); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 Set32BitValue(bih.y_pels_per_meter, 0); | 246 Set32BitValue(bih.y_pels_per_meter, 0); |
233 Set32BitValue(bih.clr_used, 0); | 247 Set32BitValue(bih.clr_used, 0); |
234 Set32BitValue(bih.clr_important, 0); | 248 Set32BitValue(bih.clr_important, 0); |
235 | 249 |
236 fwrite(&bhf, sizeof(bhf), 1, fp); | 250 fwrite(&bhf, sizeof(bhf), 1, fp); |
237 fwrite(&bih, sizeof(bih), 1, fp); | 251 fwrite(&bih, sizeof(bih), 1, fp); |
238 fwrite(pixels, size, 1, fp); | 252 fwrite(pixels, size, 1, fp); |
239 fclose(fp); | 253 fclose(fp); |
240 return true; | 254 return true; |
241 } | 255 } |
OLD | NEW |