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 VBO upload speed.
24 * That is, measure glBufferDataARB() and glBufferSubDataARB().
35 int WinWidth
= 100, WinHeight
= 100;
39 static GLsizei VBOSize
= 0;
40 static GLubyte
*VBOData
= NULL
;
42 static const GLboolean DrawPoint
= GL_TRUE
;
43 static const GLboolean BufferSubDataInHalves
= GL_TRUE
;
45 static const GLfloat Vertex0
[2] = { 0.0, 0.0 };
48 /** Called from test harness/main */
53 glGenBuffersARB(1, &VBO
);
54 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, VBO
);
55 glVertexPointer(2, GL_FLOAT
, sizeof(Vertex0
), (void *) 0);
56 glEnableClientState(GL_VERTEX_ARRAY
);
61 UploadVBO(unsigned count
)
64 for (i
= 0; i
< count
; i
++) {
65 glBufferDataARB(GL_ARRAY_BUFFER
, VBOSize
, VBOData
, GL_STREAM_DRAW_ARB
);
68 glDrawArrays(GL_POINTS
, 0, 1);
75 UploadSubVBO(unsigned count
)
78 for (i
= 0; i
< count
; i
++) {
79 if (BufferSubDataInHalves
) {
80 GLsizei half
= VBOSize
/ 2;
81 glBufferSubDataARB(GL_ARRAY_BUFFER
, 0, half
, VBOData
);
82 glBufferSubDataARB(GL_ARRAY_BUFFER
, half
, half
, VBOData
+ half
);
85 glBufferSubDataARB(GL_ARRAY_BUFFER
, 0, VBOSize
, VBOData
);
89 glDrawArrays(GL_POINTS
, 0, 1);
95 static const GLsizei Sizes
[] = {
106 /** Called from test harness/main */
110 double rate
, mbPerSec
;
113 /* loop over whole/sub buffer upload */
114 for (sub
= 0; sub
< 2; sub
++) {
116 /* loop over VBO sizes */
117 for (sz
= 0; Sizes
[sz
]; sz
++) {
120 VBOData
= malloc(VBOSize
);
121 memcpy(VBOData
, Vertex0
, sizeof(Vertex0
));
124 rate
= PerfMeasureRate(UploadSubVBO
);
126 rate
= PerfMeasureRate(UploadVBO
);
128 mbPerSec
= rate
* VBOSize
/ (1024.0 * 1024.0);
130 perf_printf(" glBuffer%sDataARB(size = %d): %.1f MB/sec\n",
131 (sub
? "Sub" : ""), VBOSize
, mbPerSec
);