| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "media/tools/shader_bench/gpu_painter.h" | 6 #include "media/tools/shader_bench/gpu_painter.h" |
| 7 | 7 |
| 8 // Vertices for a full screen quad. | 8 // Vertices for a full screen quad. |
| 9 static const float kVertices[8] = { | 9 static const float kVertices[8] = { |
| 10 -1.f, 1.f, | 10 -1.f, 1.f, |
| 11 -1.f, -1.f, | 11 -1.f, -1.f, |
| 12 1.f, 1.f, | 12 1.f, 1.f, |
| 13 1.f, -1.f, | 13 1.f, -1.f, |
| 14 }; | 14 }; |
| 15 | 15 |
| 16 // Texture Coordinates mapping the entire texture. | 16 // Texture Coordinates mapping the entire texture. |
| 17 static const float kTextureCoords[8] = { | 17 static const float kTextureCoords[8] = { |
| 18 0, 0, | 18 0, 0, |
| 19 0, 1, | 19 0, 1, |
| 20 1, 0, | 20 1, 0, |
| 21 1, 1, | 21 1, 1, |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 // Buffer size for compile errors. | 24 // Buffer size for compile errors. |
| 25 static const unsigned int kErrorSize = 4096; | 25 static const unsigned int kErrorSize = 4096; |
| 26 | 26 |
| 27 GPUPainter::GPUPainter() | 27 GPUPainter::GPUPainter() |
| 28 : context_(NULL) { | 28 : surface_(NULL), |
| 29 context_(NULL) { |
| 29 } | 30 } |
| 30 | 31 |
| 31 GPUPainter::~GPUPainter() { | 32 GPUPainter::~GPUPainter() { |
| 32 } | 33 } |
| 33 | 34 |
| 34 void GPUPainter::SetGLContext(gfx::GLContext* context) { | 35 void GPUPainter::SetGLContext(gfx::GLSurface* surface, |
| 36 gfx::GLContext* context) { |
| 37 surface_ = surface; |
| 35 context_ = context; | 38 context_ = context; |
| 36 } | 39 } |
| 37 | 40 |
| 38 GLuint GPUPainter::LoadShader(unsigned type, const char* shader_source) { | 41 GLuint GPUPainter::LoadShader(unsigned type, const char* shader_source) { |
| 39 GLuint shader = glCreateShader(type); | 42 GLuint shader = glCreateShader(type); |
| 40 glShaderSource(shader, 1, &shader_source, NULL); | 43 glShaderSource(shader, 1, &shader_source, NULL); |
| 41 glCompileShader(shader); | 44 glCompileShader(shader); |
| 42 int result = GL_FALSE; | 45 int result = GL_FALSE; |
| 43 glGetShaderiv(shader, GL_COMPILE_STATUS, &result); | 46 glGetShaderiv(shader, GL_COMPILE_STATUS, &result); |
| 44 if (!result) { | 47 if (!result) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // Set common vertex parameters. | 83 // Set common vertex parameters. |
| 81 int pos_location = glGetAttribLocation(program, "in_pos"); | 84 int pos_location = glGetAttribLocation(program, "in_pos"); |
| 82 glEnableVertexAttribArray(pos_location); | 85 glEnableVertexAttribArray(pos_location); |
| 83 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); | 86 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); |
| 84 | 87 |
| 85 int tc_location = glGetAttribLocation(program, "in_tc"); | 88 int tc_location = glGetAttribLocation(program, "in_tc"); |
| 86 glEnableVertexAttribArray(tc_location); | 89 glEnableVertexAttribArray(tc_location); |
| 87 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords); | 90 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords); |
| 88 return program; | 91 return program; |
| 89 } | 92 } |
| OLD | NEW |