2 * Measure glCopyPixels speed
13 #include "glut_wrap.h"
15 static GLint WinWidth
= 1000, WinHeight
= 800;
16 static GLint ImgWidth
, ImgHeight
;
18 static GLenum Buffer
= GL_FRONT
;
19 static GLenum AlphaTest
= GL_FALSE
;
20 static GLboolean UseBlit
= GL_FALSE
;
24 * draw teapot in lower-left corner of window
31 ImgWidth
= WinWidth
/ 3;
32 ImgHeight
= WinHeight
/ 3;
34 glViewport(0, 0, ImgWidth
, ImgHeight
);
35 glScissor(0, 0, ImgWidth
, ImgHeight
);
36 glEnable(GL_SCISSOR_TEST
);
38 glClearColor(0.5, 0.5, 0.5, 0.0);
39 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
41 ar
= (float) WinWidth
/ WinHeight
;
43 glMatrixMode(GL_PROJECTION
);
45 glFrustum(-ar
, ar
, -1.0, 1.0, 5.0, 25.0);
46 glMatrixMode(GL_MODELVIEW
);
48 glEnable(GL_LIGHTING
);
50 glEnable(GL_DEPTH_TEST
);
53 glRotatef(45, 1, 0, 0);
57 glDisable(GL_DEPTH_TEST
);
58 glDisable(GL_LIGHTING
);
60 glDisable(GL_SCISSOR_TEST
);
62 glViewport(0, 0, WinWidth
, WinHeight
);
70 return ((int) rand()) % max
;
82 } while (x
<= ImgWidth
&& y
<= ImgHeight
);
84 #ifdef GL_EXT_framebuffer_blit
87 glBlitFramebufferEXT(0, 0, ImgWidth
, ImgHeight
,
88 x
, y
, x
+ ImgWidth
, y
+ ImgHeight
,
89 GL_COLOR_BUFFER_BIT
, GL_LINEAR
);
94 glWindowPos2iARB(x
, y
);
95 glCopyPixels(0, 0, ImgWidth
, ImgHeight
, GL_COLOR
);
101 * Measure glCopyPixels rate
106 double t1
, t0
= glutGet(GLUT_ELAPSED_TIME
) / 1000.0;
108 float copyRate
, mbRate
;
112 glEnable(GL_ALPHA_TEST
);
113 glAlphaFunc(GL_GREATER
, 0.0);
116 glGetIntegerv(GL_RED_BITS
, &r
);
117 glGetIntegerv(GL_GREEN_BITS
, &g
);
118 glGetIntegerv(GL_BLUE_BITS
, &b
);
119 glGetIntegerv(GL_ALPHA_BITS
, &a
);
120 bpp
= (r
+ g
+ b
+ a
) / 8;
125 if (Buffer
== GL_FRONT
)
126 glFinish(); /* XXX to view progress */
130 t1
= glutGet(GLUT_ELAPSED_TIME
) / 1000.0;
131 } while (t1
- t0
< 5.0);
133 glDisable(GL_ALPHA_TEST
);
135 copyRate
= iters
/ (t1
- t0
);
136 mbRate
= ImgWidth
* ImgHeight
* bpp
* copyRate
/ (1024 * 1024);
138 printf("Image size: %d x %d, %d Bpp\n", ImgWidth
, ImgHeight
, bpp
);
139 printf("%d copies in %.2f = %.2f copies/sec, %.2f MB/s\n",
140 iters
, t1
-t0
, copyRate
, mbRate
);
147 glClearColor(0.0, 0.0, 0.0, 0.0);
148 glClearColor(0.2, 0.2, 0.8, 0);
149 glReadBuffer(Buffer
);
150 glDrawBuffer(Buffer
);
151 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
157 if (Buffer
== GL_FRONT
)
170 Reshape(int width
, int height
)
172 glViewport(0, 0, width
, height
);
173 glMatrixMode(GL_PROJECTION
);
175 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
176 glMatrixMode(GL_MODELVIEW
);
178 glTranslatef(0.0, 0.0, -15.0);
183 Key(unsigned char key
, int x
, int y
)
200 SpecialKey(int key
, int x
, int y
)
219 ParseArgs(int argc
, char *argv
[])
222 for (i
= 1; i
< argc
; i
++) {
223 if (strcmp(argv
[i
], "-back") == 0)
225 else if (strcmp(argv
[i
], "-alpha") == 0)
227 else if (strcmp(argv
[i
], "-blit") == 0)
236 if (glutExtensionSupported("GL_EXT_framebuffer_blit")) {
239 printf("Warning: GL_EXT_framebuffer_blit not supported.\n");
246 main(int argc
, char *argv
[])
248 GLint mode
= GLUT_RGB
| GLUT_ALPHA
| GLUT_DOUBLE
| GLUT_DEPTH
;
249 glutInit(&argc
, argv
);
251 ParseArgs(argc
, argv
);
255 glutInitWindowPosition(0, 0);
256 glutInitWindowSize(WinWidth
, WinHeight
);
257 glutInitDisplayMode(mode
);
258 glutCreateWindow(argv
[0]);
260 glutReshapeFunc(Reshape
);
261 glutKeyboardFunc(Key
);
262 glutSpecialFunc(SpecialKey
);
263 glutDisplayFunc(Draw
);
265 printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER
));
266 printf("Draw Buffer: %s\n", (Buffer
== GL_BACK
) ? "Back" : "Front");
269 printf("Mode: %s\n", (UseBlit
? "glBlitFramebuffer" : "glCopyPixels"));
270 printf("Alpha Test: %s\n", (AlphaTest
? "yes" : "no"));