Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 VMware, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included |
| 12 | * in all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 18 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /** |
Brian Paul | 32979ae | 2009-09-22 07:50:12 -0600 | [diff] [blame] | 23 | * Measure SwapBuffers. |
Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame] | 24 | * |
Brian Paul | 32979ae | 2009-09-22 07:50:12 -0600 | [diff] [blame] | 25 | * Keith Whitwell |
| 26 | * 22 Sep 2009 |
Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include "glmain.h" |
| 30 | #include "common.h" |
| 31 | |
| 32 | |
| 33 | int WinWidth = 100, WinHeight = 100; |
| 34 | int real_WinWidth, real_WinHeight; /* don't know whats going on here */ |
| 35 | |
| 36 | static GLuint VBO; |
| 37 | |
| 38 | struct vertex |
| 39 | { |
| 40 | GLfloat x, y; |
| 41 | }; |
| 42 | |
| 43 | static const struct vertex vertices[4] = { |
| 44 | { -1.0, -1.0 }, |
| 45 | { 1.0, -1.0 }, |
| 46 | { 1.0, 1.0 }, |
| 47 | { -1.0, 1.0 } |
| 48 | }; |
| 49 | |
| 50 | |
| 51 | /** Called from test harness/main */ |
| 52 | void |
| 53 | PerfInit(void) |
| 54 | { |
| 55 | /* setup VBO w/ vertex data */ |
| 56 | glGenBuffersARB(1, &VBO); |
| 57 | glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO); |
| 58 | glBufferDataARB(GL_ARRAY_BUFFER_ARB, |
| 59 | sizeof(vertices), vertices, GL_STATIC_DRAW_ARB); |
| 60 | glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), (void *) 0); |
| 61 | glEnableClientState(GL_VERTEX_ARRAY); |
| 62 | |
| 63 | /* misc GL state */ |
| 64 | glAlphaFunc(GL_ALWAYS, 0.0); |
| 65 | } |
| 66 | |
| 67 | static void |
| 68 | SwapNaked(unsigned count) |
| 69 | { |
| 70 | unsigned i; |
| 71 | for (i = 0; i < count; i++) { |
| 72 | PerfSwapBuffers(); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | |
| 77 | static void |
| 78 | SwapClear(unsigned count) |
| 79 | { |
| 80 | unsigned i; |
| 81 | for (i = 0; i < count; i++) { |
| 82 | glClear(GL_COLOR_BUFFER_BIT); |
| 83 | PerfSwapBuffers(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | static void |
| 88 | SwapClearPoint(unsigned count) |
| 89 | { |
| 90 | unsigned i; |
| 91 | for (i = 0; i < count; i++) { |
| 92 | glClear(GL_COLOR_BUFFER_BIT); |
| 93 | glDrawArrays(GL_POINTS, 0, 4); |
| 94 | PerfSwapBuffers(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | |
| 99 | static const struct { |
| 100 | unsigned w; |
| 101 | unsigned h; |
| 102 | } sizes[] = { |
| 103 | { 320, 240 }, |
| 104 | { 640, 480 }, |
| 105 | { 1024, 768 }, |
| 106 | { 1200, 1024 }, |
| 107 | { 1600, 1200 } |
| 108 | }; |
| 109 | |
| 110 | void |
| 111 | PerfNextRound(void) |
| 112 | { |
| 113 | static unsigned i; |
| 114 | |
Keith Whitwell | bf014d0 | 2009-09-22 11:27:18 +0100 | [diff] [blame] | 115 | if (i < sizeof(sizes) / sizeof(sizes[0]) && |
| 116 | PerfReshapeWindow( sizes[i].w, sizes[i].h )) |
| 117 | { |
Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame] | 118 | perf_printf("Reshape %dx%d\n", sizes[i].w, sizes[i].h); |
Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame] | 119 | real_WinWidth = sizes[i].w; |
| 120 | real_WinHeight = sizes[i].h; |
| 121 | i++; |
| 122 | } |
| 123 | else { |
| 124 | exit(0); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | /** Called from test harness/main */ |
| 132 | void |
| 133 | PerfDraw(void) |
| 134 | { |
| 135 | double rate0; |
| 136 | |
| 137 | rate0 = PerfMeasureRate(SwapNaked); |
Keith Whitwell | bf014d0 | 2009-09-22 11:27:18 +0100 | [diff] [blame] | 138 | perf_printf(" Swapbuffers %dx%d: %s swaps/second", |
Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame] | 139 | real_WinWidth, real_WinHeight, |
| 140 | PerfHumanFloat(rate0)); |
| 141 | perf_printf(" %s pixels/second\n", |
| 142 | PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight)); |
| 143 | |
| 144 | |
| 145 | |
| 146 | rate0 = PerfMeasureRate(SwapClear); |
Keith Whitwell | bf014d0 | 2009-09-22 11:27:18 +0100 | [diff] [blame] | 147 | perf_printf(" Swap/Clear %dx%d: %s swaps/second", |
Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame] | 148 | real_WinWidth, real_WinHeight, |
| 149 | PerfHumanFloat(rate0)); |
| 150 | perf_printf(" %s pixels/second\n", |
| 151 | PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight)); |
| 152 | |
| 153 | |
| 154 | rate0 = PerfMeasureRate(SwapClearPoint); |
Keith Whitwell | bf014d0 | 2009-09-22 11:27:18 +0100 | [diff] [blame] | 155 | perf_printf(" Swap/Clear/Draw %dx%d: %s swaps/second", |
Keith Whitwell | a7b2659 | 2009-09-21 16:55:12 +0100 | [diff] [blame] | 156 | real_WinWidth, real_WinHeight, |
| 157 | PerfHumanFloat(rate0)); |
| 158 | perf_printf(" %s pixels/second\n", |
| 159 | PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight)); |
| 160 | } |
| 161 | |