2 * Exercise EGL API functions
12 /*#define FRONTBUFFER*/
14 static void _subset_Rectf(GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
25 static void redraw(EGLDisplay dpy
, EGLSurface surf
, int rot
)
27 printf("Redraw event\n");
30 glDrawBuffer( GL_FRONT
);
32 glDrawBuffer( GL_BACK
);
35 glClearColor( rand()/(float)RAND_MAX
,
36 rand()/(float)RAND_MAX
,
37 rand()/(float)RAND_MAX
,
40 glClear( GL_COLOR_BUFFER_BIT
);
42 glColor3f( rand()/(float)RAND_MAX
,
43 rand()/(float)RAND_MAX
,
44 rand()/(float)RAND_MAX
);
46 glRotatef(rot
, 0, 0, 1);
48 _subset_Rectf( -1, -1, 1, 1 );
54 eglSwapBuffers( dpy
, surf
);
61 * Test EGL_MESA_screen_surface functions
64 TestScreens(EGLDisplay dpy
)
67 EGLScreenMESA screens
[MAX
];
71 eglGetScreensMESA(dpy
, screens
, MAX
, &numScreens
);
72 printf("Found %d screens\n", numScreens
);
73 for (i
= 0; i
< numScreens
; i
++) {
74 printf(" Screen %d handle: %d\n", i
, (int) screens
[i
]);
80 main(int argc
, char *argv
[])
84 EGLSurface pbuffer
, screen_surf
;
85 EGLConfig configs
[10];
88 const EGLint pbufAttribs
[] = {
93 const EGLint screenAttribs
[] = {
103 EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
105 EGLDisplay d
= eglGetDisplay("!EGL_i915");
108 if (!eglInitialize(d
, &maj
, &min
)) {
109 printf("demo: eglInitialize failed\n");
113 printf("EGL version = %d.%d\n", maj
, min
);
114 printf("EGL_VENDOR = %s\n", eglQueryString(d
, EGL_VENDOR
));
116 eglGetConfigs(d
, configs
, 10, &numConfigs
);
117 printf("Got %d EGL configs:\n", numConfigs
);
118 for (i
= 0; i
< numConfigs
; i
++) {
119 EGLint id
, red
, depth
;
120 eglGetConfigAttrib(d
, configs
[i
], EGL_CONFIG_ID
, &id
);
121 eglGetConfigAttrib(d
, configs
[i
], EGL_RED_SIZE
, &red
);
122 eglGetConfigAttrib(d
, configs
[i
], EGL_DEPTH_SIZE
, &depth
);
123 printf("%2d: Red Size = %d Depth Size = %d\n", id
, red
, depth
);
126 eglGetScreensMESA(d
, &screen
, 1, &count
);
127 eglGetModesMESA(d
, screen
, &mode
, 1, &count
);
129 ctx
= eglCreateContext(d
, configs
[0], EGL_NO_CONTEXT
, NULL
);
130 if (ctx
== EGL_NO_CONTEXT
) {
131 printf("failed to create context\n");
135 pbuffer
= eglCreatePbufferSurface(d
, configs
[0], pbufAttribs
);
136 if (pbuffer
== EGL_NO_SURFACE
) {
137 printf("failed to create pbuffer\n");
141 b
= eglMakeCurrent(d
, pbuffer
, pbuffer
, ctx
);
143 printf("make current failed\n");
147 b
= eglMakeCurrent(d
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
149 screen_surf
= eglCreateScreenSurfaceMESA(d
, configs
[0], screenAttribs
);
150 if (screen_surf
== EGL_NO_SURFACE
) {
151 printf("failed to create screen surface\n");
155 eglShowScreenSurfaceMESA(d
, screen
, screen_surf
, mode
);
157 b
= eglMakeCurrent(d
, screen_surf
, screen_surf
, ctx
);
159 printf("make current failed\n");
163 glViewport(0, 0, 1024, 768);
164 glDrawBuffer( GL_FRONT
);
171 glClear( GL_COLOR_BUFFER_BIT
);
176 glShadeModel( GL_FLAT
);
178 for (i
= 0; i
< 6; i
++) {
179 redraw(d
, screen_surf
, i
*10 );
181 printf("sleep(1)\n");
185 eglDestroySurface(d
, pbuffer
);
186 eglDestroyContext(d
, ctx
);