Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: media/tools/shader_bench/gpu_painter.cc

Issue 4873002: Benchmark tool for GPU-accelerated video rendering (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fixes, added comments to headers Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/tools/shader_bench/gpu_painter.h"
6
7 // Vertices for a full screen quad.
8 static const float kVertices[8] = {
9 -1.f, 1.f,
10 -1.f, -1.f,
11 1.f, 1.f,
12 1.f, -1.f,
13 };
14
15 // Texture Coordinates mapping the entire texture.
16 static const float kTextureCoords[8] = {
17 0, 0,
18 0, 1,
19 1, 0,
20 1, 1,
21 };
22
23 // Buffer size for compile errors.
24 static const unsigned int kErrorSize = 4096;
25
26 GPUPainter::GPUPainter()
27 : context_(NULL) {
scherkus (not reviewing) 2010/11/30 23:36:10 indent by extra 2 spaces
vrk (LEFT CHROMIUM) 2010/12/01 02:46:11 Done.
28 }
29
30 void GPUPainter::SetGLContext(gfx::GLContext* context) {
31 context_ = context;
32 }
33
34 GLuint GPUPainter::LoadShader(gfx::GLContext* context, unsigned type,
35 const char* shader_source) {
36 GLuint shader = glCreateShader(type);
37 glShaderSource(shader, 1, &shader_source, NULL);
38 glCompileShader(shader);
39 int result = GL_FALSE;
40 glGetShaderiv(shader, GL_COMPILE_STATUS, &result);
41 if (!result) {
42 char log[kErrorSize];
43 int len;
44 glGetShaderInfoLog(shader, kErrorSize - 1, &len, log);
45 log[kErrorSize - 1] = 0;
46 printf("Shader did not compile: %s\n", log);
scherkus (not reviewing) 2010/11/30 23:36:10 LOG(ERROR)?
vrk (LEFT CHROMIUM) 2010/12/01 02:46:11 Done.
47 }
48 return shader;
49 }
50
51 GLuint GPUPainter::CreateShaderProgram(
52 gfx::GLContext* context, const char* vertex_shader_source,
53 const char* fragment_shader_source) {
54
55 // Create vertex and pixel shaders.
56 GLuint vertex_shader =
57 LoadShader(context, GL_VERTEX_SHADER, vertex_shader_source);
58 GLuint fragment_shader =
59 LoadShader(context, GL_FRAGMENT_SHADER, fragment_shader_source);
60
61 // Create program and attach shaders.
62 GLuint program = glCreateProgram();
63 glAttachShader(program, vertex_shader);
64 glAttachShader(program, fragment_shader);
65 glDeleteShader(vertex_shader);
66 glDeleteShader(fragment_shader);
67 glLinkProgram(program);
68 int result = GL_FALSE;
69 glGetProgramiv(program, GL_LINK_STATUS, &result);
70 if (!result) {
71 char log[kErrorSize];
72 int len;
73 glGetProgramInfoLog(program, kErrorSize - 1, &len, log);
74 log[kErrorSize - 1] = 0;
75 printf("Program did not link: %s\n", log);
scherkus (not reviewing) 2010/11/30 23:36:10 LOG(ERROR)?
vrk (LEFT CHROMIUM) 2010/12/01 02:46:11 Done.
76 }
77 glUseProgram(program);
78
79 // Set common vertex parameters.
80 int pos_location = glGetAttribLocation(program, "in_pos");
81 glEnableVertexAttribArray(pos_location);
82 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices);
83
84 int tc_location = glGetAttribLocation(program, "in_tc");
85 glEnableVertexAttribArray(tc_location);
86 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0,
87 kTextureCoords);
88 return program;
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698