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.
23 * Measure simple vertex processing rate via:
28 * - VBO glDrawElements
29 * - glDrawRangeElements
30 * - VBO glDrawRangeElements
42 #define MAX_VERTS (100 * 100)
44 /** glVertex2/3/4 size */
47 int WinWidth
= 500, WinHeight
= 500;
49 static GLuint VertexBO
, ElementBO
;
51 static unsigned NumVerts
= MAX_VERTS
;
52 static unsigned VertBytes
= VERT_SIZE
* sizeof(float);
53 static float *VertexData
= NULL
;
55 static unsigned NumElements
= MAX_VERTS
;
56 static GLuint
*Elements
= NULL
;
60 * Load VertexData buffer with a 2-D grid of points in the range [-1,1]^2.
63 InitializeVertexData(void)
66 float x
= -1.0, y
= -1.0;
70 VertexData
= (float *) malloc(NumVerts
* VertBytes
);
72 for (i
= 0; i
< NumVerts
; i
++) {
73 VertexData
[i
* VERT_SIZE
+ 0] = x
;
74 VertexData
[i
* VERT_SIZE
+ 1] = y
;
75 VertexData
[i
* VERT_SIZE
+ 2] = 0.0;
76 VertexData
[i
* VERT_SIZE
+ 3] = 1.0;
84 Elements
= (GLuint
*) malloc(NumVerts
* sizeof(GLuint
));
86 for (i
= 0; i
< NumVerts
; i
++) {
87 Elements
[i
] = NumVerts
- i
- 1;
92 /** Called from test harness/main */
96 InitializeVertexData();
99 glGenBuffersARB(1, &VertexBO
);
100 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, VertexBO
);
101 glBufferDataARB(GL_ARRAY_BUFFER_ARB
,
102 NumVerts
* VertBytes
, VertexData
, GL_STATIC_DRAW_ARB
);
103 glEnableClientState(GL_VERTEX_ARRAY
);
105 /* setup ElementBO */
106 glGenBuffersARB(1, &ElementBO
);
107 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
, ElementBO
);
108 glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB
,
109 NumElements
* sizeof(GLuint
), Elements
, GL_STATIC_DRAW_ARB
);
114 DrawImmediate(unsigned count
)
117 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER
, 0);
118 glBindBufferARB(GL_ARRAY_BUFFER
, 0);
119 for (i
= 0; i
< count
; i
++) {
122 for (j
= 0; j
< NumVerts
; j
++) {
124 glVertex4fv(VertexData
+ j
* 4);
126 glVertex3fv(VertexData
+ j
* 3);
128 glVertex2fv(VertexData
+ j
* 2);
141 DrawArraysMem(unsigned count
)
144 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER
, 0);
145 glBindBufferARB(GL_ARRAY_BUFFER
, 0);
146 glVertexPointer(VERT_SIZE
, GL_FLOAT
, VertBytes
, VertexData
);
147 for (i
= 0; i
< count
; i
++) {
148 glDrawArrays(GL_POINTS
, 0, NumVerts
);
156 DrawArraysVBO(unsigned count
)
159 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER
, 0);
160 glBindBufferARB(GL_ARRAY_BUFFER
, VertexBO
);
161 glVertexPointer(VERT_SIZE
, GL_FLOAT
, VertBytes
, (void *) 0);
162 for (i
= 0; i
< count
; i
++) {
163 glDrawArrays(GL_POINTS
, 0, NumVerts
);
171 DrawElementsMem(unsigned count
)
174 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER
, 0);
175 glBindBufferARB(GL_ARRAY_BUFFER
, 0);
176 glVertexPointer(VERT_SIZE
, GL_FLOAT
, VertBytes
, VertexData
);
177 for (i
= 0; i
< count
; i
++) {
178 glDrawElements(GL_POINTS
, NumVerts
, GL_UNSIGNED_INT
, Elements
);
186 DrawElementsBO(unsigned count
)
189 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER
, ElementBO
);
190 glBindBufferARB(GL_ARRAY_BUFFER
, VertexBO
);
191 glVertexPointer(VERT_SIZE
, GL_FLOAT
, VertBytes
, (void *) 0);
192 for (i
= 0; i
< count
; i
++) {
193 glDrawElements(GL_POINTS
, NumVerts
, GL_UNSIGNED_INT
, (void *) 0);
201 DrawRangeElementsMem(unsigned count
)
204 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER
, 0);
205 glBindBufferARB(GL_ARRAY_BUFFER
, 0);
206 glVertexPointer(VERT_SIZE
, GL_FLOAT
, VertBytes
, VertexData
);
207 for (i
= 0; i
< count
; i
++) {
208 glDrawRangeElements(GL_POINTS
, 0, NumVerts
- 1,
209 NumVerts
, GL_UNSIGNED_INT
, Elements
);
217 DrawRangeElementsBO(unsigned count
)
220 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER
, ElementBO
);
221 glBindBufferARB(GL_ARRAY_BUFFER
, VertexBO
);
222 glVertexPointer(VERT_SIZE
, GL_FLOAT
, VertBytes
, (void *) 0);
223 for (i
= 0; i
< count
; i
++) {
224 glDrawRangeElements(GL_POINTS
, 0, NumVerts
- 1,
225 NumVerts
, GL_UNSIGNED_INT
, (void *) 0);
237 /** Called from test harness/main */
243 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
245 perf_printf("Vertex rate (%d x Vertex%df)\n", NumVerts
, VERT_SIZE
);
247 rate
= PerfMeasureRate(DrawImmediate
);
249 perf_printf(" Immediate mode: %s verts/sec\n", PerfHumanFloat(rate
));
251 rate
= PerfMeasureRate(DrawArraysMem
);
253 perf_printf(" glDrawArrays: %s verts/sec\n", PerfHumanFloat(rate
));
255 rate
= PerfMeasureRate(DrawArraysVBO
);
257 perf_printf(" VBO glDrawArrays: %s verts/sec\n", PerfHumanFloat(rate
));
259 rate
= PerfMeasureRate(DrawElementsMem
);
261 perf_printf(" glDrawElements: %s verts/sec\n", PerfHumanFloat(rate
));
263 rate
= PerfMeasureRate(DrawElementsBO
);
265 perf_printf(" VBO glDrawElements: %s verts/sec\n", PerfHumanFloat(rate
));
267 rate
= PerfMeasureRate(DrawRangeElementsMem
);
269 perf_printf(" glDrawRangeElements: %s verts/sec\n", PerfHumanFloat(rate
));
271 rate
= PerfMeasureRate(DrawRangeElementsBO
);
273 perf_printf(" VBO glDrawRangeElements: %s verts/sec\n", PerfHumanFloat(rate
));