2 * Exercise EGL API functions
5 #define EGL_EGLEXT_PROTOTYPES
8 #include <EGL/eglext.h>
16 * Test EGL_MESA_screen_surface functions
19 TestScreens(EGLDisplay dpy
)
22 EGLScreenMESA screens
[MAX
];
26 eglGetScreensMESA(dpy
, screens
, MAX
, &numScreens
);
27 printf("Found %d screens\n", numScreens
);
28 for (i
= 0; i
< numScreens
; i
++) {
29 printf(" Screen %d handle: %d\n", i
, (int) screens
[i
]);
34 * Print table of all available configurations.
37 PrintConfigs(EGLDisplay d
, EGLConfig
*configs
, EGLint numConfigs
)
41 printf("Configurations:\n");
42 printf(" bf lv d st colorbuffer dp st supported \n");
43 printf(" id sz l b ro r g b a th cl surfaces \n");
44 printf("----------------------------------------------\n");
45 for (i
= 0; i
< numConfigs
; i
++) {
46 EGLint id
, size
, level
;
47 EGLint red
, green
, blue
, alpha
;
48 EGLint depth
, stencil
;
50 EGLint doubleBuf
= 1, stereo
= 0;
51 char surfString
[100] = "";
53 eglGetConfigAttrib(d
, configs
[i
], EGL_CONFIG_ID
, &id
);
54 eglGetConfigAttrib(d
, configs
[i
], EGL_BUFFER_SIZE
, &size
);
55 eglGetConfigAttrib(d
, configs
[i
], EGL_LEVEL
, &level
);
57 eglGetConfigAttrib(d
, configs
[i
], EGL_RED_SIZE
, &red
);
58 eglGetConfigAttrib(d
, configs
[i
], EGL_GREEN_SIZE
, &green
);
59 eglGetConfigAttrib(d
, configs
[i
], EGL_BLUE_SIZE
, &blue
);
60 eglGetConfigAttrib(d
, configs
[i
], EGL_ALPHA_SIZE
, &alpha
);
61 eglGetConfigAttrib(d
, configs
[i
], EGL_DEPTH_SIZE
, &depth
);
62 eglGetConfigAttrib(d
, configs
[i
], EGL_STENCIL_SIZE
, &stencil
);
63 eglGetConfigAttrib(d
, configs
[i
], EGL_SURFACE_TYPE
, &surfaces
);
65 if (surfaces
& EGL_WINDOW_BIT
)
66 strcat(surfString
, "win,");
67 if (surfaces
& EGL_PBUFFER_BIT
)
68 strcat(surfString
, "pb,");
69 if (surfaces
& EGL_PIXMAP_BIT
)
70 strcat(surfString
, "pix,");
71 if (strlen(surfString
) > 0)
72 surfString
[strlen(surfString
) - 1] = 0;
74 printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %-12s\n",
76 doubleBuf
? 'y' : '.',
78 red
, green
, blue
, alpha
,
79 depth
, stencil
, surfString
);
86 main(int argc
, char *argv
[])
94 const EGLint pbufAttribs
[] = {
100 EGLDisplay d
= eglGetDisplay(EGL_DEFAULT_DISPLAY
);
103 if (!eglInitialize(d
, &maj
, &min
)) {
104 printf("demo: eglInitialize failed\n");
108 printf("EGL version = %d.%d\n", maj
, min
);
109 printf("EGL_VENDOR = %s\n", eglQueryString(d
, EGL_VENDOR
));
111 eglGetConfigs(d
, NULL
, 0, &numConfigs
);
112 configs
= malloc(sizeof(*configs
) *numConfigs
);
113 eglGetConfigs(d
, configs
, numConfigs
, &numConfigs
);
115 PrintConfigs(d
, configs
, numConfigs
);
117 eglBindAPI(EGL_OPENGL_API
);
118 ctx
= eglCreateContext(d
, configs
[0], EGL_NO_CONTEXT
, NULL
);
119 if (ctx
== EGL_NO_CONTEXT
) {
120 printf("failed to create context\n");
124 pbuffer
= eglCreatePbufferSurface(d
, configs
[0], pbufAttribs
);
125 if (pbuffer
== EGL_NO_SURFACE
) {
126 printf("failed to create pbuffer\n");
132 b
= eglMakeCurrent(d
, pbuffer
, pbuffer
, ctx
);
134 printf("make current failed\n");
138 b
= eglMakeCurrent(d
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, EGL_NO_CONTEXT
);
142 eglDestroySurface(d
, pbuffer
);
143 eglDestroyContext(d
, ctx
);