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

Side by Side Diff: client/deps/glbench/src/shaders.cc

Issue 1282001: Added window manager graphics performance tests to gl_Bench. (Closed)
Patch Set: Implemented requested name change, retested Created 10 years, 9 months 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
« no previous file with comments | « client/deps/glbench/src/shaders.h ('k') | client/deps/glbench/src/xlib_window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 <stdio.h> 5 #include <stdio.h>
6 #include <sys/mman.h> 6 #include <sys/mman.h>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 #include "main.h" 10 #include "main.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 attribute[1] = '1' + i; 73 attribute[1] = '1' + i;
74 int attribute_index = glGetAttribLocation(program, attribute); 74 int attribute_index = glGetAttribLocation(program, attribute);
75 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffers[i]); 75 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffers[i]);
76 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL); 76 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
77 glEnableVertexAttribArray(attribute_index); 77 glEnableVertexAttribArray(attribute_index);
78 } 78 }
79 79
80 return program; 80 return program;
81 } 81 }
82 82
83
84 #define I915_WORKAROUND 1 83 #define I915_WORKAROUND 1
85 84
86 #if I915_WORKAROUND 85 #if I915_WORKAROUND
87 #define V1 "gl_TexCoord[0]" 86 #define V1 "gl_TexCoord[0]"
88 #define V2 "gl_TexCoord[1]" 87 #define V2 "gl_TexCoord[1]"
89 #define V3 "gl_TexCoord[2]" 88 #define V3 "gl_TexCoord[2]"
90 #define V4 "gl_TexCoord[3]" 89 #define V4 "gl_TexCoord[3]"
91 #define V5 "gl_TexCoord[4]" 90 #define V5 "gl_TexCoord[4]"
92 #define V6 "gl_TexCoord[5]" 91 #define V6 "gl_TexCoord[5]"
93 #define V7 "gl_TexCoord[6]" 92 #define V7 "gl_TexCoord[6]"
94 #define V8 "gl_TexCoord[7]" 93 #define V8 "gl_TexCoord[7]"
95 #define DDX "dFdx" 94 #define DDX "dFdx"
96 #define DDY "dFdy" 95 #define DDY "dFdy"
97 #else 96 #else
98 #define V1 "v1" 97 #define V1 "v1"
99 #define V2 "v2" 98 #define V2 "v2"
100 #define V3 "v3" 99 #define V3 "v3"
101 #define V4 "v4" 100 #define V4 "v4"
102 #define V5 "v5" 101 #define V5 "v5"
103 #define V6 "v6" 102 #define V6 "v6"
104 #define V7 "v7" 103 #define V7 "v7"
105 #define V8 "v8" 104 #define V8 "v8"
106 #define DDX "ddx" 105 #define DDX "ddx"
107 #define DDY "ddy" 106 #define DDY "ddy"
108 #endif 107 #endif
109 108
109 const char *basic_texture_vertex_shader =
110 "attribute vec4 c1;"
111 "attribute vec4 c2;"
112 "varying vec2 v1;"
113 "void main() {"
114 " gl_Position = c1;"
115 " " V1 " = c2;"
116 "}";
117
118 const char *basic_texture_fragment_shader =
119 "uniform sampler2D texture_sampler;"
120 "varying vec2 v1;"
121 "void main() {"
122 " gl_FragColor = texture2D(texture_sampler, " V1 ".xy);"
123 "}";
124
125 ShaderProgram BasicTextureShaderProgram(GLuint vertex_buffer,
126 GLuint texture_buffer) {
127 ShaderProgram program =
128 InitShaderProgram(basic_texture_vertex_shader,
129 basic_texture_fragment_shader);
130
131 // Set up the texture sampler
132 int textureSampler = glGetUniformLocation(program, "texture_sampler");
133 glUniform1i(textureSampler, 0);
134
135 // Set up vertex attribute
136 int attribute_index = glGetAttribLocation(program, "c1");
137 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
138 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
139 glEnableVertexAttribArray(attribute_index);
140
141 // Set up texture attribute
142 attribute_index = glGetAttribLocation(program, "c2");
143 glBindBuffer(GL_ARRAY_BUFFER, texture_buffer);
144 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
145 glEnableVertexAttribArray(attribute_index);
146
147 return program;
148 }
149
150 const char *double_texture_blend_vertex_shader =
151 "attribute vec4 c1;"
152 "attribute vec4 c2;"
153 "attribute vec4 c3;"
154 "varying vec2 v1;"
155 "varying vec2 v2;"
156 "void main() {"
157 " gl_Position = c1;"
158 " " V1 " = c2;"
159 " " V2 " = c3;"
160 "}";
161
162 const char *double_texture_blend_fragment_shader =
163 "uniform sampler2D texture_sampler_0;"
164 "uniform sampler2D texture_sampler_1;"
165 "varying vec2 v1;"
166 "varying vec2 v2;"
167 "void main() {"
168 " vec4 one = texture2D(texture_sampler_0, " V1 ".xy);"
169 " vec4 two = texture2D(texture_sampler_1, " V2 ".xy);"
170 " gl_FragColor = mix(one, two, 0.5);"
171 "}";
172
173 // This shader blends the three textures
174 ShaderProgram DoubleTextureBlendShaderProgram(GLuint vertex_buffer,
175 GLuint texture_buffer_0,
176 GLuint texture_buffer_1) {
177 ShaderProgram program =
178 InitShaderProgram(double_texture_blend_vertex_shader,
179 double_texture_blend_fragment_shader);
180
181 // Set up the texture sampler
182 int textureSampler0 = glGetUniformLocation(program, "texture_sampler_0");
183 glUniform1i(textureSampler0, 0);
184 int textureSampler1 = glGetUniformLocation(program, "texture_sampler_1");
185 glUniform1i(textureSampler1, 1);
186
187 // Set up vertex attribute
188 int attribute_index = glGetAttribLocation(program, "c1");
189 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
190 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
191 glEnableVertexAttribArray(attribute_index);
192
193 // Set up texture attributes
194 attribute_index = glGetAttribLocation(program, "c2");
195 glBindBuffer(GL_ARRAY_BUFFER, texture_buffer_0);
196 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
197 glEnableVertexAttribArray(attribute_index);
198
199 attribute_index = glGetAttribLocation(program, "c3");
200 glBindBuffer(GL_ARRAY_BUFFER, texture_buffer_1);
201 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
202 glEnableVertexAttribArray(attribute_index);
203
204 return program;
205 }
206
207 const char *triple_texture_blend_vertex_shader =
208 "attribute vec4 c1;"
209 "attribute vec4 c2;"
210 "attribute vec4 c3;"
211 "attribute vec4 c4;"
212 "varying vec2 v1;"
213 "varying vec2 v2;"
214 "varying vec2 v3;"
215 "void main() {"
216 " gl_Position = c1;"
217 " " V1 " = c2;"
218 " " V2 " = c3;"
219 " " V3 " = c4;"
220 "}";
221
222 const char *triple_texture_blend_fragment_shader =
223 "uniform sampler2D texture_sampler_0;"
224 "uniform sampler2D texture_sampler_1;"
225 "uniform sampler2D texture_sampler_2;"
226 "varying vec2 v1;"
227 "varying vec2 v2;"
228 "varying vec2 v3;"
229 "void main() {"
230 " vec4 one = texture2D(texture_sampler_0, " V1 ".xy);"
231 " vec4 two = texture2D(texture_sampler_1, " V2 ".xy);"
232 " vec4 three = texture2D(texture_sampler_2, " V3 ".xy);"
233 " gl_FragColor = mix(mix(one, two, 0.5), three, 0.5);"
234 "}";
235
236 // This shader blends the three textures
237 ShaderProgram TripleTextureBlendShaderProgram(GLuint vertex_buffer,
238 GLuint texture_buffer_0,
239 GLuint texture_buffer_1,
240 GLuint texture_buffer_2) {
241 ShaderProgram program =
242 InitShaderProgram(triple_texture_blend_vertex_shader,
243 triple_texture_blend_fragment_shader);
244
245 // Set up the texture sampler
246 int textureSampler0 = glGetUniformLocation(program, "texture_sampler_0");
247 glUniform1i(textureSampler0, 0);
248 int textureSampler1 = glGetUniformLocation(program, "texture_sampler_1");
249 glUniform1i(textureSampler1, 1);
250 int textureSampler2 = glGetUniformLocation(program, "texture_sampler_2");
251 glUniform1i(textureSampler2, 2);
252
253 // Set up vertex attribute
254 int attribute_index = glGetAttribLocation(program, "c1");
255 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
256 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
257 glEnableVertexAttribArray(attribute_index);
258
259 // Set up texture attributes
260 attribute_index = glGetAttribLocation(program, "c2");
261 glBindBuffer(GL_ARRAY_BUFFER, texture_buffer_0);
262 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
263 glEnableVertexAttribArray(attribute_index);
264
265 attribute_index = glGetAttribLocation(program, "c3");
266 glBindBuffer(GL_ARRAY_BUFFER, texture_buffer_1);
267 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
268 glEnableVertexAttribArray(attribute_index);
269
270 attribute_index = glGetAttribLocation(program, "c4");
271 glBindBuffer(GL_ARRAY_BUFFER, texture_buffer_2);
272 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL);
273 glEnableVertexAttribArray(attribute_index);
274
275 return program;
276 }
277
110 const char *vertex_shader_1_varying = 278 const char *vertex_shader_1_varying =
111 "attribute vec4 c;" 279 "attribute vec4 c;"
112 "varying vec4 v1;" 280 "varying vec4 v1;"
113 "void main() {" 281 "void main() {"
114 " gl_Position = c;" 282 " gl_Position = c;"
115 V1 "= c;" 283 V1 "= c;"
116 "}"; 284 "}";
117 285
118 const char *vertex_shader_2_varying = 286 const char *vertex_shader_2_varying =
119 "attribute vec4 c;" 287 "attribute vec4 c;"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 glEnableVertexAttribArray(attribute_index); 459 glEnableVertexAttribArray(attribute_index);
292 return program; 460 return program;
293 } 461 }
294 462
295 463
296 done: 464 done:
297 munmap(yuv_to_rgb_fragment, size_fragment); 465 munmap(yuv_to_rgb_fragment, size_fragment);
298 munmap(yuv_to_rgb_fragment, size_vertex); 466 munmap(yuv_to_rgb_fragment, size_vertex);
299 return program; 467 return program;
300 } 468 }
OLDNEW
« no previous file with comments | « client/deps/glbench/src/shaders.h ('k') | client/deps/glbench/src/xlib_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698