2 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
3 * Copyright (C) 2008 Brian Paul All Rights Reserved.
4 * Copyright (C) 2008 Jakob Bornecrantz All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * This program is based on eglgears and xegl_tri.
26 * Remixed by Jakob Bornecrantz
28 * No command line options.
29 * Program runs for 5 seconds then exits, outputing framerate to console
32 #define EGL_EGLEXT_PROTOTYPES
41 #include <EGL/eglext.h>
43 #define MAX_CONFIGS 10
47 /* XXX this probably isn't very portable */
52 /* return current time (in seconds) */
58 (void) gettimeofday(&tv
, NULL
);
61 (void) gettimeofday(&tv
, &tz
);
63 return (double) tv
.tv_sec
+ tv
.tv_usec
/ 1000000.0;
67 static GLfloat view_rotx
= 0.0, view_roty
= 0.0, view_rotz
= 0.0;
71 static const GLfloat verts
[3][2] = {
76 static const GLfloat colors
[3][3] = {
82 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
85 glRotatef(view_rotx
, 1, 0, 0);
86 glRotatef(view_roty
, 0, 1, 0);
87 glRotatef(view_rotz
, 0, 0, 1);
90 glVertexPointer(2, GL_FLOAT
, 0, verts
);
91 glColorPointer(3, GL_FLOAT
, 0, colors
);
92 glEnableClientState(GL_VERTEX_ARRAY
);
93 glEnableClientState(GL_COLOR_ARRAY
);
95 glDrawArrays(GL_TRIANGLES
, 0, 3);
97 glDisableClientState(GL_VERTEX_ARRAY
);
98 glDisableClientState(GL_COLOR_ARRAY
);
106 glClearColor(0.4, 0.4, 0.4, 0.0);
109 /* new window size or exposure */
110 static void reshape(int width
, int height
)
112 GLfloat ar
= (GLfloat
) width
/ (GLfloat
) height
;
114 glViewport(0, 0, (GLint
) width
, (GLint
) height
);
116 glMatrixMode(GL_PROJECTION
);
118 glFrustum(-ar
, ar
, -1, 1, 5.0, 60.0);
120 glMatrixMode(GL_MODELVIEW
);
122 glTranslatef(0.0, 0.0, -10.0);
125 static void run(EGLDisplay dpy
, EGLSurface surf
, int ttr
)
127 double st
= current_time();
131 while (ct
- st
< ttr
)
133 double tt
= current_time();
139 eglSwapBuffers(dpy
, surf
);
144 GLfloat seconds
= ct
- st
;
145 GLfloat fps
= frames
/ seconds
;
146 printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames
, seconds
, fps
);
149 int main(int argc
, char *argv
[])
153 EGLSurface screen_surf
;
154 EGLConfig configs
[MAX_CONFIGS
];
155 EGLint numConfigs
, i
;
158 EGLint screenAttribs
[10];
159 EGLModeMESA mode
[MAX_MODES
];
160 EGLScreenMESA screen
;
161 EGLint count
, chosenMode
= 0;
162 GLboolean printInfo
= GL_FALSE
;
163 EGLint width
= 0, height
= 0;
165 /* parse cmd line args */
166 for (i
= 1; i
< argc
; i
++)
168 if (strcmp(argv
[i
], "-info") == 0)
173 printf("Warning: unknown parameter: %s\n", argv
[i
]);
176 /* DBR : Create EGL context/surface etc */
177 d
= eglGetDisplay((EGLNativeDisplayType
)"!EGL_i915");
180 if (!eglInitialize(d
, &maj
, &min
)) {
181 printf("egltri: eglInitialize failed\n");
185 printf("egltri: EGL version = %d.%d\n", maj
, min
);
186 printf("egltri: EGL_VENDOR = %s\n", eglQueryString(d
, EGL_VENDOR
));
188 /* XXX use ChooseConfig */
189 eglGetConfigs(d
, configs
, MAX_CONFIGS
, &numConfigs
);
190 eglGetScreensMESA(d
, &screen
, 1, &count
);
192 if (!eglGetModesMESA(d
, screen
, mode
, MAX_MODES
, &count
) || count
== 0) {
193 printf("egltri: eglGetModesMESA failed!\n");
197 /* Print list of modes, and find the one to use */
198 printf("egltri: Found %d modes:\n", count
);
199 for (i
= 0; i
< count
; i
++) {
201 eglGetModeAttribMESA(d
, mode
[i
], EGL_WIDTH
, &w
);
202 eglGetModeAttribMESA(d
, mode
[i
], EGL_HEIGHT
, &h
);
203 printf("%3d: %d x %d\n", i
, w
, h
);
204 if (w
> width
&& h
> height
) {
210 printf("egltri: Using screen mode/size %d: %d x %d\n", chosenMode
, width
, height
);
212 ctx
= eglCreateContext(d
, configs
[0], EGL_NO_CONTEXT
, NULL
);
213 if (ctx
== EGL_NO_CONTEXT
) {
214 printf("egltri: failed to create context\n");
218 /* build up screenAttribs array */
220 screenAttribs
[i
++] = EGL_WIDTH
;
221 screenAttribs
[i
++] = width
;
222 screenAttribs
[i
++] = EGL_HEIGHT
;
223 screenAttribs
[i
++] = height
;
224 screenAttribs
[i
++] = EGL_NONE
;
226 screen_surf
= eglCreateScreenSurfaceMESA(d
, configs
[0], screenAttribs
);
227 if (screen_surf
== EGL_NO_SURFACE
) {
228 printf("egltri: failed to create screen surface\n");
232 b
= eglShowScreenSurfaceMESA(d
, screen
, screen_surf
, mode
[chosenMode
]);
234 printf("egltri: show surface failed\n");
238 b
= eglMakeCurrent(d
, screen_surf
, screen_surf
, ctx
);
240 printf("egltri: make current failed\n");
246 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
247 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
248 printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
249 printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS
));
253 reshape(width
, height
);
255 glDrawBuffer( GL_BACK
);
257 run(d
, screen_surf
, 5.0);
259 eglDestroySurface(d
, screen_surf
);
260 eglDestroyContext(d
, ctx
);