blob: d581f4b18724cb90e75cffdb0d5573bba12b35cc [file] [log] [blame]
Keith Whitwell2884c312009-09-17 12:09:16 +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/**
23 * Measure drawing overhead
24 *
25 * This is the first in a series of simple performance benchmarks.
26 * The code in this file should be as simple as possible to make it
27 * easily portable to other APIs.
28 *
29 * All the window-system stuff should be contained in glmain.c (or TBDmain.c).
30 * All the re-usable, generic code should be in common.c (XXX not done yet).
31 *
32 * Brian Paul
33 * 15 Sep 2009
34 */
35
36#include "glmain.h"
37#include "common.h"
38
39
40int WinWidth = 100, WinHeight = 100;
41
42static GLuint VBO;
43
44struct vertex
45{
46 GLfloat x, y;
47};
48
49static const struct vertex vertices[4] = {
50 { -1.0, -1.0 },
51 { 1.0, -1.0 },
52 { 1.0, 1.0 },
53 { -1.0, 1.0 }
54};
55
56
57/** Called from test harness/main */
58void
59PerfInit(void)
60{
61 /* setup VBO w/ vertex data */
62 glGenBuffersARB(1, &VBO);
63 glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
64 glBufferDataARB(GL_ARRAY_BUFFER_ARB,
65 sizeof(vertices), vertices, GL_STATIC_DRAW_ARB);
66 glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), (void *) 0);
67 glEnableClientState(GL_VERTEX_ARRAY);
68
69 /* misc GL state */
70 glAlphaFunc(GL_ALWAYS, 0.0);
71}
72
73
74static void
75DrawNoStateChange(unsigned count)
76{
77 unsigned i;
78 for (i = 0; i < count; i++) {
79 glDrawArrays(GL_POINTS, 0, 4);
80 }
81 glFinish();
82}
83
84
85static void
86DrawNopStateChange(unsigned count)
87{
88 unsigned i;
89 for (i = 0; i < count; i++) {
90 glDisable(GL_ALPHA_TEST);
91 glDrawArrays(GL_POINTS, 0, 4);
92 }
93 glFinish();
94}
95
96
97static void
98DrawStateChange(unsigned count)
99{
100 unsigned i;
101 for (i = 0; i < count; i++) {
102 if (i & 1)
103 glEnable(GL_TEXTURE_GEN_S);
104 else
105 glDisable(GL_TEXTURE_GEN_S);
106 glDrawArrays(GL_POINTS, 0, 4);
107 }
108 glFinish();
109}
110
111
112/** Called from test harness/main */
113void
114PerfDraw(void)
115{
116 double rate0, rate1, rate2, overhead;
117
118 rate0 = PerfMeasureRate(DrawNoStateChange);
Keith Whitwell25a580c2009-09-21 15:54:28 +0100119 perf_printf(" Draw only: %s draws/second\n",
120 PerfHumanFloat(rate0));
Keith Whitwell2884c312009-09-17 12:09:16 +0100121
Keith Whitwell2884c312009-09-17 12:09:16 +0100122 rate1 = PerfMeasureRate(DrawNopStateChange);
123 overhead = 1000.0 * (1.0 / rate1 - 1.0 / rate0);
Keith Whitwell25a580c2009-09-21 15:54:28 +0100124 perf_printf(" Draw w/ nop state change: %s draws/sec (overhead: %f ms/draw)\n",
125 PerfHumanFloat(rate1), overhead);
Keith Whitwell2884c312009-09-17 12:09:16 +0100126
127 rate2 = PerfMeasureRate(DrawStateChange);
128 overhead = 1000.0 * (1.0 / rate2 - 1.0 / rate0);
Keith Whitwell25a580c2009-09-21 15:54:28 +0100129 perf_printf(" Draw w/ state change: %s draws/sec (overhead: %f ms/draw)\n",
130 PerfHumanFloat(rate2), overhead);
Keith Whitwell2884c312009-09-17 12:09:16 +0100131
132 exit(0);
133}
134