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

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

Issue 1365001: eliminate the non-vbo code path (Closed)
Patch Set: Fixed a CHECK call that failed lint 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 | « no previous file | no next file » | 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 <fcntl.h> 5 #include <fcntl.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 if (Bench(f, &slope, &bias)) { 61 if (Bench(f, &slope, &bias)) {
62 printf("%s: %g\n", name, coefficient * (inverse ? 1.f / slope : slope)); 62 printf("%s: %g\n", name, coefficient * (inverse ? 1.f / slope : slope));
63 } else { 63 } else {
64 printf("# %s is too slow, returning zero.\n", name); 64 printf("# %s is too slow, returning zero.\n", name);
65 printf("%s: 0\n", name); 65 printf("%s: 0\n", name);
66 } 66 }
67 } 67 }
68 } 68 }
69 69
70 static int arg1 = 0; 70 static int arg1 = 0;
71 static void *arg2 = NULL;
72 71
73 void SwapTestFunc(int iter) { 72 void SwapTestFunc(int iter) {
74 for (int i = 0 ; i < iter; ++i) { 73 for (int i = 0 ; i < iter; ++i) {
75 SwapBuffers(); 74 SwapBuffers();
76 } 75 }
77 } 76 }
78 77
79 void SwapTest() { 78 void SwapTest() {
80 RunTest(SwapTestFunc, "us_swap_swap", 1.f, false); 79 RunTest(SwapTestFunc, "us_swap_swap", 1.f, false);
81 } 80 }
(...skipping 27 matching lines...) Expand all
109 RunTest(ClearTestFunc, "mpixels_sec_clear_colordepthstencil", 108 RunTest(ClearTestFunc, "mpixels_sec_clear_colordepthstencil",
110 g_width * g_height, true); 109 g_width * g_height, true);
111 } 110 }
112 111
113 112
114 GLuint SetupVBO(GLenum target, GLsizeiptr size, const GLvoid *data) { 113 GLuint SetupVBO(GLenum target, GLsizeiptr size, const GLvoid *data) {
115 GLuint buf = ~0; 114 GLuint buf = ~0;
116 glGenBuffers(1, &buf); 115 glGenBuffers(1, &buf);
117 glBindBuffer(target, buf); 116 glBindBuffer(target, buf);
118 glBufferData(target, size, data, GL_STATIC_DRAW); 117 glBufferData(target, size, data, GL_STATIC_DRAW);
119 118 CHECK(!glGetError());
Alexey Marinichev 2010/03/25 21:01:57 I personally prefer explicit comparisons for ints
120 return glGetError() == 0 ? buf : 0; 119 return buf;
121 } 120 }
122 121
123 122
124 GLuint SetupTexture(GLsizei size_log2) { 123 GLuint SetupTexture(GLsizei size_log2) {
125 GLsizei size = 1 << size_log2; 124 GLsizei size = 1 << size_log2;
126 GLuint name = ~0; 125 GLuint name = ~0;
127 glGenTextures(1, &name); 126 glGenTextures(1, &name);
128 glBindTexture(GL_TEXTURE_2D, name); 127 glBindTexture(GL_TEXTURE_2D, name);
129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 128 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
130 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 129 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 GLfloat buffer_texture[8] = { 175 GLfloat buffer_texture[8] = {
177 0.f, 0.f, 176 0.f, 0.f,
178 1.f, 0.f, 177 1.f, 0.f,
179 0.f, 1.f, 178 0.f, 1.f,
180 1.f, 1.f, 179 1.f, 1.f,
181 }; 180 };
182 glEnableClientState(GL_VERTEX_ARRAY); 181 glEnableClientState(GL_VERTEX_ARRAY);
183 182
184 GLuint vbo_vertex = SetupVBO(GL_ARRAY_BUFFER, 183 GLuint vbo_vertex = SetupVBO(GL_ARRAY_BUFFER,
185 sizeof(buffer_vertex), buffer_vertex); 184 sizeof(buffer_vertex), buffer_vertex);
186 if (!vbo_vertex) 185 glVertexPointer(2, GL_FLOAT, 0, 0);
187 printf("# Not Using VBO!\n");
188 glVertexPointer(2, GL_FLOAT, 0, vbo_vertex ? 0 : buffer_vertex);
189 186
190 GLuint vbo_texture = SetupVBO(GL_ARRAY_BUFFER, 187 GLuint vbo_texture = SetupVBO(GL_ARRAY_BUFFER,
191 sizeof(buffer_texture), buffer_texture); 188 sizeof(buffer_texture), buffer_texture);
192 glTexCoordPointer(2, GL_FLOAT, 0, vbo_texture ? 0 : buffer_texture); 189 glTexCoordPointer(2, GL_FLOAT, 0, 0);
193 190
194 glColor4f(1.f, 0.f, 0.f, 1.f); 191 glColor4f(1.f, 0.f, 0.f, 1.f);
195 FillRateTestNormal("fill_solid"); 192 FillRateTestNormal("fill_solid");
196 FillRateTestBlendDepth("fill_solid"); 193 FillRateTestBlendDepth("fill_solid");
197 194
198 glColor4f(1.f, 1.f, 1.f, 1.f); 195 glColor4f(1.f, 1.f, 1.f, 1.f);
199 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 196 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
200 glEnable(GL_TEXTURE_2D); 197 glEnable(GL_TEXTURE_2D);
201 198
202 GLuint texture = SetupTexture(9); 199 GLuint texture = SetupTexture(9);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 static void DrawArraysTestFunc(int iter) { 264 static void DrawArraysTestFunc(int iter) {
268 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 265 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
269 glFlush(); 266 glFlush();
270 for (int i = 0; i < iter-1; ++i) { 267 for (int i = 0; i < iter-1; ++i) {
271 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 268 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
272 } 269 }
273 } 270 }
274 271
275 272
276 static void DrawElementsTestFunc(int iter) { 273 static void DrawElementsTestFunc(int iter) {
277 glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, arg2); 274 glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, 0);
278 glFlush(); 275 glFlush();
279 for (int i = 0 ; i < iter-1; ++i) { 276 for (int i = 0 ; i < iter-1; ++i) {
280 glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, arg2); 277 glDrawElements(GL_TRIANGLES, arg1, GL_UNSIGNED_INT, 0);
281 } 278 }
282 } 279 }
283 280
284 // Generates a tautological lattice. 281 // Generates a tautological lattice.
285 static void CreateLattice(GLfloat **vertices, GLsizeiptr *size, 282 static void CreateLattice(GLfloat **vertices, GLsizeiptr *size,
286 GLfloat size_x, GLfloat size_y, 283 GLfloat size_x, GLfloat size_y,
287 int width, int height) 284 int width, int height)
288 { 285 {
289 GLfloat *vptr = *vertices = new GLfloat[2 * (width + 1) * (height + 1)]; 286 GLfloat *vptr = *vertices = new GLfloat[2 * (width + 1) * (height + 1)];
290 for (int j = 0; j <= height; j++) { 287 for (int j = 0; j <= height; j++) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // Larger meshes make this test too slow for devices that do 1 mtri/sec. 335 // Larger meshes make this test too slow for devices that do 1 mtri/sec.
339 GLint width = 64; 336 GLint width = 64;
340 GLint height = 64; 337 GLint height = 64;
341 338
342 GLfloat *vertices = NULL; 339 GLfloat *vertices = NULL;
343 GLsizeiptr vertex_buffer_size = 0; 340 GLsizeiptr vertex_buffer_size = 0;
344 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height, 341 CreateLattice(&vertices, &vertex_buffer_size, 1.f / g_width, 1.f / g_height,
345 width, height); 342 width, height);
346 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER, 343 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER,
347 vertex_buffer_size, vertices); 344 vertex_buffer_size, vertices);
348 glVertexPointer(2, GL_FLOAT, 0, vertex_buffer != 0 ? 0 : vertices); 345 glVertexPointer(2, GL_FLOAT, 0, 0);
349 glEnableClientState(GL_VERTEX_ARRAY); 346 glEnableClientState(GL_VERTEX_ARRAY);
350 347
351 GLuint *indices = NULL; 348 GLuint *indices = NULL;
352 GLuint index_buffer = 0; 349 GLuint index_buffer = 0;
353 GLsizeiptr index_buffer_size = 0; 350 GLsizeiptr index_buffer_size = 0;
354 351
355 { 352 {
356 arg1 = CreateMesh(&indices, &index_buffer_size, width, height, 0); 353 arg1 = CreateMesh(&indices, &index_buffer_size, width, height, 0);
357 354
358 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER, 355 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
359 index_buffer_size, indices); 356 index_buffer_size, indices);
360 arg2 = index_buffer ? 0 : indices;
361
362 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup", arg1 / 3, true); 357 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup", arg1 / 3, true);
363 glEnable(GL_CULL_FACE); 358 glEnable(GL_CULL_FACE);
364 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_all_culled", 359 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_all_culled",
365 arg1 / 3, true); 360 arg1 / 3, true);
366 glDisable(GL_CULL_FACE); 361 glDisable(GL_CULL_FACE);
367 362
368 glDeleteBuffers(1, &index_buffer); 363 glDeleteBuffers(1, &index_buffer);
369 delete[] indices; 364 delete[] indices;
370 } 365 }
371 366
372 { 367 {
373 glColor4f(0.f, 1.f, 1.f, 1.f); 368 glColor4f(0.f, 1.f, 1.f, 1.f);
374 arg1 = CreateMesh(&indices, &index_buffer_size, width, height, 369 arg1 = CreateMesh(&indices, &index_buffer_size, width, height,
375 RAND_MAX / 2); 370 RAND_MAX / 2);
376 371
377 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER, 372 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER,
378 index_buffer_size, indices); 373 index_buffer_size, indices);
379 arg2 = index_buffer ? 0 : indices;
380
381 glEnable(GL_CULL_FACE); 374 glEnable(GL_CULL_FACE);
382 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_half_culled", 375 RunTest(DrawElementsTestFunc, "mtri_sec_triangle_setup_half_culled",
383 arg1 / 3, true); 376 arg1 / 3, true);
384 377
385 glDeleteBuffers(1, &index_buffer); 378 glDeleteBuffers(1, &index_buffer);
386 delete[] indices; 379 delete[] indices;
387 } 380 }
388 381
389 glDeleteBuffers(1, &vertex_buffer); 382 glDeleteBuffers(1, &vertex_buffer);
390 delete[] vertices; 383 delete[] vertices;
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 // Set up the vertex arrays for drawing textured quads later on. 691 // Set up the vertex arrays for drawing textured quads later on.
699 glEnableClientState(GL_VERTEX_ARRAY); 692 glEnableClientState(GL_VERTEX_ARRAY);
700 GLfloat buffer_vertex[8] = { 693 GLfloat buffer_vertex[8] = {
701 -1.f, -1.f, 694 -1.f, -1.f,
702 1.f, -1.f, 695 1.f, -1.f,
703 -1.f, 1.f, 696 -1.f, 1.f,
704 1.f, 1.f, 697 1.f, 1.f,
705 }; 698 };
706 GLuint vbo_vertex = SetupVBO(GL_ARRAY_BUFFER, 699 GLuint vbo_vertex = SetupVBO(GL_ARRAY_BUFFER,
707 sizeof(buffer_vertex), buffer_vertex); 700 sizeof(buffer_vertex), buffer_vertex);
708 if (!vbo_vertex) 701 glVertexPointer(2, GL_FLOAT, 0, 0);
709 printf("# Not Using VBO!\n");
710 glVertexPointer(2, GL_FLOAT, 0, vbo_vertex ? 0 : buffer_vertex);
711 702
712 GLfloat buffer_texture[8] = { 703 GLfloat buffer_texture[8] = {
713 0.f, 0.f, 704 0.f, 0.f,
714 1.f, 0.f, 705 1.f, 0.f,
715 0.f, 1.f, 706 0.f, 1.f,
716 1.f, 1.f, 707 1.f, 1.f,
717 }; 708 };
718 GLuint vbo_texture = SetupVBO(GL_ARRAY_BUFFER, 709 GLuint vbo_texture = SetupVBO(GL_ARRAY_BUFFER,
719 sizeof(buffer_texture), buffer_texture); 710 sizeof(buffer_texture), buffer_texture);
720 for (int i = 0; i < 3; i++) { 711 for (int i = 0; i < 3; i++) {
721 glClientActiveTexture(GL_TEXTURE0 + i); 712 glClientActiveTexture(GL_TEXTURE0 + i);
722 glTexCoordPointer(2, GL_FLOAT, 0, vbo_texture ? 0 : buffer_texture); 713 glTexCoordPointer(2, GL_FLOAT, 0, 0);
723 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 714 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
724 } 715 }
725 716
726 // Set up the static background textures. 717 // Set up the static background textures.
727 UpdateTexture(); 718 UpdateTexture();
728 UpdateTexture(); 719 UpdateTexture();
729 UpdateTexture(); 720 UpdateTexture();
730 // Load these textures into bound texture ids and keep using them 721 // Load these textures into bound texture ids and keep using them
731 // from there to avoid having to reload this texture every frame 722 // from there to avoid having to reload this texture every frame
732 glActiveTexture(GL_TEXTURE0); 723 glActiveTexture(GL_TEXTURE0);
(...skipping 20 matching lines...) Expand all
753 compositing_background_program = 744 compositing_background_program =
754 TripleTextureBlendShaderProgram(vbo_vertex, 745 TripleTextureBlendShaderProgram(vbo_vertex,
755 vbo_texture, vbo_texture, vbo_texture); 746 vbo_texture, vbo_texture, vbo_texture);
756 compositing_foreground_program = 747 compositing_foreground_program =
757 BasicTextureShaderProgram(vbo_vertex, vbo_texture); 748 BasicTextureShaderProgram(vbo_vertex, vbo_texture);
758 if ((!compositing_background_program) || 749 if ((!compositing_background_program) ||
759 (!compositing_foreground_program)) { 750 (!compositing_foreground_program)) {
760 printf("# Could not set up compositing shader.\n"); 751 printf("# Could not set up compositing shader.\n");
761 } 752 }
762 753
763 if (!vbo_vertex) 754 glVertexPointer(2, GL_FLOAT, 0, 0);
764 printf("# Not Using VBO!\n");
765 glVertexPointer(2, GL_FLOAT, 0, vbo_vertex ? 0 : buffer_vertex);
766 } 755 }
767 756
768 void TeardownCompositing() { 757 void TeardownCompositing() {
769 glDeleteProgram(compositing_background_program); 758 glDeleteProgram(compositing_background_program);
770 glDeleteProgram(compositing_foreground_program); 759 glDeleteProgram(compositing_foreground_program);
771 } 760 }
772 761
773 // Notes on the window manager compositing test: 762 // Notes on the window manager compositing test:
774 // Depth 763 // Depth
775 // Depth complexity = 3: background, active window, static window 764 // Depth complexity = 3: background, active window, static window
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 test[i](); 842 test[i]();
854 GLenum err = glGetError(); 843 GLenum err = glGetError();
855 if (err != 0) 844 if (err != 0)
856 printf("# glGetError returned non-zero: 0x%x\n", err); 845 printf("# glGetError returned non-zero: 0x%x\n", err);
857 DestroyContext(); 846 DestroyContext();
858 } 847 }
859 } while (GetUTime() < done); 848 } while (GetUTime() < done);
860 849
861 return 0; 850 return 0;
862 } 851 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698