blob: 63c7fc06f98096e494e96935fa897d7e343e5b6d [file] [log] [blame]
Keith Whitwella7b26592009-09-21 16:55:12 +01001/*
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 Paul32979ae2009-09-22 07:50:12 -060023 * Measure SwapBuffers.
Keith Whitwella7b26592009-09-21 16:55:12 +010024 *
Brian Paul32979ae2009-09-22 07:50:12 -060025 * Keith Whitwell
26 * 22 Sep 2009
Keith Whitwella7b26592009-09-21 16:55:12 +010027 */
28
29#include "glmain.h"
30#include "common.h"
31
32
33int WinWidth = 100, WinHeight = 100;
34int real_WinWidth, real_WinHeight; /* don't know whats going on here */
35
36static GLuint VBO;
37
38struct vertex
39{
40 GLfloat x, y;
41};
42
43static 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 */
52void
53PerfInit(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
67static void
68SwapNaked(unsigned count)
69{
70 unsigned i;
71 for (i = 0; i < count; i++) {
72 PerfSwapBuffers();
73 }
74}
75
76
77static void
78SwapClear(unsigned count)
79{
80 unsigned i;
81 for (i = 0; i < count; i++) {
82 glClear(GL_COLOR_BUFFER_BIT);
83 PerfSwapBuffers();
84 }
85}
86
87static void
88SwapClearPoint(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
99static 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
110void
111PerfNextRound(void)
112{
113 static unsigned i;
114
Keith Whitwellbf014d02009-09-22 11:27:18 +0100115 if (i < sizeof(sizes) / sizeof(sizes[0]) &&
116 PerfReshapeWindow( sizes[i].w, sizes[i].h ))
117 {
Keith Whitwella7b26592009-09-21 16:55:12 +0100118 perf_printf("Reshape %dx%d\n", sizes[i].w, sizes[i].h);
Keith Whitwella7b26592009-09-21 16:55:12 +0100119 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 */
132void
133PerfDraw(void)
134{
135 double rate0;
136
137 rate0 = PerfMeasureRate(SwapNaked);
Keith Whitwellbf014d02009-09-22 11:27:18 +0100138 perf_printf(" Swapbuffers %dx%d: %s swaps/second",
Keith Whitwella7b26592009-09-21 16:55:12 +0100139 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 Whitwellbf014d02009-09-22 11:27:18 +0100147 perf_printf(" Swap/Clear %dx%d: %s swaps/second",
Keith Whitwella7b26592009-09-21 16:55:12 +0100148 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 Whitwellbf014d02009-09-22 11:27:18 +0100155 perf_printf(" Swap/Clear/Draw %dx%d: %s swaps/second",
Keith Whitwella7b26592009-09-21 16:55:12 +0100156 real_WinWidth, real_WinHeight,
157 PerfHumanFloat(rate0));
158 perf_printf(" %s pixels/second\n",
159 PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight));
160}
161