2 * Measure glCopyPixels speed
8 #define GL_GLEXT_PROTOTYPES
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) random()) % max
;
77 * Measure glCopyPixels rate
82 double t1
, t0
= glutGet(GLUT_ELAPSED_TIME
) / 1000.0;
84 float copyRate
, mbRate
;
88 glEnable(GL_ALPHA_TEST
);
89 glAlphaFunc(GL_GREATER
, 0.0);
92 glGetIntegerv(GL_RED_BITS
, &r
);
93 glGetIntegerv(GL_GREEN_BITS
, &g
);
94 glGetIntegerv(GL_BLUE_BITS
, &b
);
95 glGetIntegerv(GL_ALPHA_BITS
, &a
);
96 bpp
= (r
+ g
+ b
+ a
) / 8;
103 if (x
> ImgWidth
|| y
> ImgHeight
) {
104 #ifdef GL_EXT_framebuffer_blit
107 glBlitFramebufferEXT_func(0, 0, ImgWidth
, ImgHeight
,
108 x
, y
, x
+ ImgWidth
, y
+ ImgHeight
,
109 GL_COLOR_BUFFER_BIT
, GL_LINEAR
);
114 glWindowPos2iARB(x
, y
);
115 glCopyPixels(0, 0, ImgWidth
, ImgHeight
, GL_COLOR
);
117 glFinish(); /* XXX OK? */
121 t1
= glutGet(GLUT_ELAPSED_TIME
) / 1000.0;
123 } while (t1
- t0
< 5.0);
125 glDisable(GL_ALPHA_TEST
);
127 copyRate
= iters
/ (t1
- t0
);
128 mbRate
= ImgWidth
* ImgHeight
* bpp
* copyRate
/ (1024 * 1024);
130 printf("Image size: %d x %d, %d Bpp\n", ImgWidth
, ImgHeight
, bpp
);
131 printf("%d copies in %.2f = %.2f copies/sec, %.2f MB/s\n",
132 iters
, t1
-t0
, copyRate
, mbRate
);
139 glClearColor(0.0, 0.0, 0.0, 0.0);
140 glClearColor(0.2, 0.2, 0.8, 0);
141 glReadBuffer(Buffer
);
142 glDrawBuffer(Buffer
);
143 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
149 if (Buffer
== GL_FRONT
)
160 Reshape(int width
, int height
)
162 glViewport(0, 0, width
, height
);
163 glMatrixMode(GL_PROJECTION
);
165 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
166 glMatrixMode(GL_MODELVIEW
);
168 glTranslatef(0.0, 0.0, -15.0);
173 Key(unsigned char key
, int x
, int y
)
187 SpecialKey(int key
, int x
, int y
)
206 ParseArgs(int argc
, char *argv
[])
209 for (i
= 1; i
< argc
; i
++) {
210 if (strcmp(argv
[i
], "-back") == 0)
212 else if (strcmp(argv
[i
], "-alpha") == 0)
214 else if (strcmp(argv
[i
], "-blit") == 0)
223 if (glutExtensionSupported("GL_EXT_framebuffer_blit")) {
224 glBlitFramebufferEXT_func
= (PFNGLBLITFRAMEBUFFEREXTPROC
)
225 glutGetProcAddress("glBlitFramebufferEXT");
228 printf("Warning: GL_EXT_framebuffer_blit not supported.\n");
235 main(int argc
, char *argv
[])
237 GLint mode
= GLUT_RGB
| GLUT_ALPHA
| GLUT_DOUBLE
| GLUT_DEPTH
;
238 glutInit(&argc
, argv
);
240 ParseArgs(argc
, argv
);
244 glutInitWindowPosition(0, 0);
245 glutInitWindowSize(WinWidth
, WinHeight
);
246 glutInitDisplayMode(mode
);
247 glutCreateWindow(argv
[0]);
248 glutReshapeFunc(Reshape
);
249 glutKeyboardFunc(Key
);
250 glutSpecialFunc(SpecialKey
);
251 glutDisplayFunc(Draw
);
253 printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER
));
254 printf("Draw Buffer: %s\n", (Buffer
== GL_BACK
) ? "Back" : "Front");