2 * Measure glCopyPixels speed
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
;
22 static PFNGLBLITFRAMEBUFFEREXTPROC glBlitFramebufferEXT_func
= NULL
;
26 * draw teapot in lower-left corner of window
33 ImgWidth
= WinWidth
/ 3;
34 ImgHeight
= WinHeight
/ 3;
36 glViewport(0, 0, ImgWidth
, ImgHeight
);
37 glScissor(0, 0, ImgWidth
, ImgHeight
);
38 glEnable(GL_SCISSOR_TEST
);
40 glClearColor(0.5, 0.5, 0.5, 0.0);
41 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
43 ar
= (float) WinWidth
/ WinHeight
;
45 glMatrixMode(GL_PROJECTION
);
47 glFrustum(-ar
, ar
, -1.0, 1.0, 5.0, 25.0);
48 glMatrixMode(GL_MODELVIEW
);
50 glEnable(GL_LIGHTING
);
52 glEnable(GL_DEPTH_TEST
);
55 glRotatef(45, 1, 0, 0);
59 glDisable(GL_DEPTH_TEST
);
60 glDisable(GL_LIGHTING
);
62 glDisable(GL_SCISSOR_TEST
);
64 glViewport(0, 0, WinWidth
, WinHeight
);
72 return ((int) rand()) % max
;
84 } while (x
<= ImgWidth
&& y
<= ImgHeight
);
86 #ifdef GL_EXT_framebuffer_blit
89 glBlitFramebufferEXT_func(0, 0, ImgWidth
, ImgHeight
,
90 x
, y
, x
+ ImgWidth
, y
+ ImgHeight
,
91 GL_COLOR_BUFFER_BIT
, GL_LINEAR
);
96 glWindowPos2iARB(x
, y
);
97 glCopyPixels(0, 0, ImgWidth
, ImgHeight
, GL_COLOR
);
103 * Measure glCopyPixels rate
108 double t1
, t0
= glutGet(GLUT_ELAPSED_TIME
) / 1000.0;
110 float copyRate
, mbRate
;
114 glEnable(GL_ALPHA_TEST
);
115 glAlphaFunc(GL_GREATER
, 0.0);
118 glGetIntegerv(GL_RED_BITS
, &r
);
119 glGetIntegerv(GL_GREEN_BITS
, &g
);
120 glGetIntegerv(GL_BLUE_BITS
, &b
);
121 glGetIntegerv(GL_ALPHA_BITS
, &a
);
122 bpp
= (r
+ g
+ b
+ a
) / 8;
127 if (Buffer
== GL_FRONT
)
128 glFinish(); /* XXX to view progress */
132 t1
= glutGet(GLUT_ELAPSED_TIME
) / 1000.0;
133 } while (t1
- t0
< 5.0);
135 glDisable(GL_ALPHA_TEST
);
137 copyRate
= iters
/ (t1
- t0
);
138 mbRate
= ImgWidth
* ImgHeight
* bpp
* copyRate
/ (1024 * 1024);
140 printf("Image size: %d x %d, %d Bpp\n", ImgWidth
, ImgHeight
, bpp
);
141 printf("%d copies in %.2f = %.2f copies/sec, %.2f MB/s\n",
142 iters
, t1
-t0
, copyRate
, mbRate
);
149 glClearColor(0.0, 0.0, 0.0, 0.0);
150 glClearColor(0.2, 0.2, 0.8, 0);
151 glReadBuffer(Buffer
);
152 glDrawBuffer(Buffer
);
153 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
159 if (Buffer
== GL_FRONT
)
172 Reshape(int width
, int height
)
174 glViewport(0, 0, width
, height
);
175 glMatrixMode(GL_PROJECTION
);
177 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
178 glMatrixMode(GL_MODELVIEW
);
180 glTranslatef(0.0, 0.0, -15.0);
185 Key(unsigned char key
, int x
, int y
)
202 SpecialKey(int key
, int x
, int y
)
221 ParseArgs(int argc
, char *argv
[])
224 for (i
= 1; i
< argc
; i
++) {
225 if (strcmp(argv
[i
], "-back") == 0)
227 else if (strcmp(argv
[i
], "-alpha") == 0)
229 else if (strcmp(argv
[i
], "-blit") == 0)
238 if (glutExtensionSupported("GL_EXT_framebuffer_blit")) {
239 glBlitFramebufferEXT_func
= (PFNGLBLITFRAMEBUFFEREXTPROC
)
240 glutGetProcAddress("glBlitFramebufferEXT");
243 printf("Warning: GL_EXT_framebuffer_blit not supported.\n");
250 main(int argc
, char *argv
[])
252 GLint mode
= GLUT_RGB
| GLUT_ALPHA
| GLUT_DOUBLE
| GLUT_DEPTH
;
253 glutInit(&argc
, argv
);
255 ParseArgs(argc
, argv
);
259 glutInitWindowPosition(0, 0);
260 glutInitWindowSize(WinWidth
, WinHeight
);
261 glutInitDisplayMode(mode
);
262 glutCreateWindow(argv
[0]);
264 glutReshapeFunc(Reshape
);
265 glutKeyboardFunc(Key
);
266 glutSpecialFunc(SpecialKey
);
267 glutDisplayFunc(Draw
);
269 printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER
));
270 printf("Draw Buffer: %s\n", (Buffer
== GL_BACK
) ? "Back" : "Front");