WIP - port to Mali EGL
[mesa-demos/mali.git] / src / perf / swapbuffers.c
blob63c7fc06f98096e494e96935fa897d7e343e5b6d
1 /*
2 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
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.
22 /**
23 * Measure SwapBuffers.
25 * Keith Whitwell
26 * 22 Sep 2009
29 #include "glmain.h"
30 #include "common.h"
33 int WinWidth = 100, WinHeight = 100;
34 int real_WinWidth, real_WinHeight; /* don't know whats going on here */
36 static GLuint VBO;
38 struct vertex
40 GLfloat x, y;
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 }
51 /** Called from test harness/main */
52 void
53 PerfInit(void)
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);
63 /* misc GL state */
64 glAlphaFunc(GL_ALWAYS, 0.0);
67 static void
68 SwapNaked(unsigned count)
70 unsigned i;
71 for (i = 0; i < count; i++) {
72 PerfSwapBuffers();
77 static void
78 SwapClear(unsigned count)
80 unsigned i;
81 for (i = 0; i < count; i++) {
82 glClear(GL_COLOR_BUFFER_BIT);
83 PerfSwapBuffers();
87 static void
88 SwapClearPoint(unsigned count)
90 unsigned i;
91 for (i = 0; i < count; i++) {
92 glClear(GL_COLOR_BUFFER_BIT);
93 glDrawArrays(GL_POINTS, 0, 4);
94 PerfSwapBuffers();
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 }
110 void
111 PerfNextRound(void)
113 static unsigned i;
115 if (i < sizeof(sizes) / sizeof(sizes[0]) &&
116 PerfReshapeWindow( sizes[i].w, sizes[i].h ))
118 perf_printf("Reshape %dx%d\n", sizes[i].w, sizes[i].h);
119 real_WinWidth = sizes[i].w;
120 real_WinHeight = sizes[i].h;
121 i++;
123 else {
124 exit(0);
131 /** Called from test harness/main */
132 void
133 PerfDraw(void)
135 double rate0;
137 rate0 = PerfMeasureRate(SwapNaked);
138 perf_printf(" Swapbuffers %dx%d: %s swaps/second",
139 real_WinWidth, real_WinHeight,
140 PerfHumanFloat(rate0));
141 perf_printf(" %s pixels/second\n",
142 PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight));
146 rate0 = PerfMeasureRate(SwapClear);
147 perf_printf(" Swap/Clear %dx%d: %s swaps/second",
148 real_WinWidth, real_WinHeight,
149 PerfHumanFloat(rate0));
150 perf_printf(" %s pixels/second\n",
151 PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight));
154 rate0 = PerfMeasureRate(SwapClearPoint);
155 perf_printf(" Swap/Clear/Draw %dx%d: %s swaps/second",
156 real_WinWidth, real_WinHeight,
157 PerfHumanFloat(rate0));
158 perf_printf(" %s pixels/second\n",
159 PerfHumanFloat(rate0 * real_WinWidth * real_WinHeight));