| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2009 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 "gpu/demos/app_framework/gles2_utils.h" | |
| 6 | |
| 7 namespace { | |
| 8 static const int kInfoBufferLength = 1024; | |
| 9 } // namespace | |
| 10 | |
| 11 namespace gpu_demos { | |
| 12 namespace gles2_utils { | |
| 13 | |
| 14 GLuint LoadShader(GLenum type, const char* shader_src) { | |
| 15 GLuint shader = glCreateShader(type); | |
| 16 if (shader == 0) return 0; | |
| 17 | |
| 18 // Load the shader source | |
| 19 glShaderSource(shader, 1, &shader_src, NULL); | |
| 20 // Compile the shader | |
| 21 glCompileShader(shader); | |
| 22 // Check the compile status | |
| 23 GLint value; | |
| 24 glGetShaderiv(shader, GL_COMPILE_STATUS, &value); | |
| 25 if (value == 0) { | |
| 26 char buffer[kInfoBufferLength]; | |
| 27 GLsizei length; | |
| 28 glGetShaderInfoLog(shader, sizeof(buffer), &length, buffer); | |
| 29 std::string log(buffer, length); | |
| 30 DLOG(ERROR) << "Error compiling shader:" << log; | |
| 31 glDeleteShader(shader); | |
| 32 shader = 0; | |
| 33 } | |
| 34 return shader; | |
| 35 } | |
| 36 | |
| 37 GLuint LoadProgram(const char* v_shader_src, const char* f_shader_src) { | |
| 38 GLuint v_shader = LoadShader(GL_VERTEX_SHADER, v_shader_src); | |
| 39 if (v_shader == 0) return 0; | |
| 40 | |
| 41 GLuint f_shader = LoadShader(GL_FRAGMENT_SHADER, f_shader_src); | |
| 42 if (f_shader == 0) return 0; | |
| 43 | |
| 44 // Create the program object | |
| 45 GLuint program_object = glCreateProgram(); | |
| 46 if (program_object == 0) return 0; | |
| 47 | |
| 48 // Link the program and check status. | |
| 49 glAttachShader(program_object, v_shader); | |
| 50 glAttachShader(program_object, f_shader); | |
| 51 glLinkProgram(program_object); | |
| 52 GLint linked = 0; | |
| 53 glGetProgramiv(program_object, GL_LINK_STATUS, &linked); | |
| 54 if (linked == 0) { | |
| 55 char buffer[kInfoBufferLength]; | |
| 56 GLsizei length; | |
| 57 glGetProgramInfoLog(program_object, sizeof(buffer), &length, buffer); | |
| 58 std::string log(buffer, length); | |
| 59 DLOG(ERROR) << "Error linking program:" << log; | |
| 60 glDeleteProgram(program_object); | |
| 61 program_object = 0; | |
| 62 } | |
| 63 return program_object; | |
| 64 } | |
| 65 | |
| 66 } // namespace gles2_utils | |
| 67 } // namespace gpu_demos | |
| OLD | NEW |