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 glReadPixels speed.
24 * XXX also read into a PBO?
25 * XXX also read from FBOs?
36 int WinWidth
= 1000, WinHeight
= 1000;
40 static const GLboolean DrawPoint
= GL_TRUE
;
41 static const GLboolean BufferSubDataInHalves
= GL_TRUE
;
43 static const GLfloat Vertex0
[2] = { 0.0, 0.0 };
45 static GLenum HaveDepthStencil
;
47 static GLenum ReadFormat
, ReadType
;
48 static GLint ReadWidth
, ReadHeight
;
49 static GLvoid
*ReadBuffer
;
52 /** Called from test harness/main */
57 glGenBuffersARB(1, &VBO
);
58 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, VBO
);
59 glBufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(Vertex0
), Vertex0
, GL_STATIC_DRAW_ARB
);
60 glVertexPointer(2, GL_FLOAT
, sizeof(Vertex0
), (void *) 0);
61 glEnableClientState(GL_VERTEX_ARRAY
);
63 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
65 HaveDepthStencil
= PerfExtensionSupported("GL_EXT_packed_depth_stencil");
67 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
68 glEnable(GL_DEPTH_TEST
);
69 glEnable(GL_STENCIL_TEST
);
74 ReadPixels(unsigned count
)
77 for (i
= 0; i
< count
; i
++) {
78 /* read from random pos */
81 x
= WinWidth
- ReadWidth
;
82 y
= WinHeight
- ReadHeight
;
89 glDrawArrays(GL_POINTS
, 0, 1);
91 glReadPixels(x
, y
, ReadWidth
, ReadHeight
,
92 ReadFormat
, ReadType
, ReadBuffer
);
98 static const GLsizei Sizes
[] = {
107 static const struct {
113 { GL_RGBA
, GL_UNSIGNED_BYTE
, "RGBA/ubyte", 4 },
114 { GL_BGRA
, GL_UNSIGNED_BYTE
, "BGRA/ubyte", 4 },
115 { GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, "RGB/565", 2 },
116 { GL_LUMINANCE
, GL_UNSIGNED_BYTE
, "L/ubyte", 1 },
117 { GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, "Z/uint", 4 },
118 { GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, "Z+S/uint", 4 },
124 /** Called from test harness/main */
131 /** Called from test harness/main */
135 double rate
, mbPerSec
;
138 /* loop over formats */
139 for (fmt
= 0; DstFormats
[fmt
].format
; fmt
++) {
140 ReadFormat
= DstFormats
[fmt
].format
;
141 ReadType
= DstFormats
[fmt
].type
;
143 /* loop over sizes */
144 for (sz
= 0; Sizes
[sz
]; sz
++) {
147 ReadWidth
= ReadHeight
= Sizes
[sz
];
148 imgSize
= ReadWidth
* ReadHeight
* DstFormats
[fmt
].pixel_size
;
149 ReadBuffer
= malloc(imgSize
);
151 if (ReadFormat
== GL_DEPTH_STENCIL_EXT
&& !HaveDepthStencil
) {
156 rate
= PerfMeasureRate(ReadPixels
);
157 mbPerSec
= rate
* imgSize
/ (1024.0 * 1024.0);
160 perf_printf("glReadPixels(%d x %d, %s): %.1f images/sec, %.1f Mpixels/sec\n",
161 ReadWidth
, ReadHeight
,
162 DstFormats
[fmt
].name
, rate
, mbPerSec
);