chmod a-x **/glslnoise.c
[mesa-demos.git] / src / egl / demo1.c
blob9ef17e38b7daa4845283af90d31383681ba885aa
1 /*
2 * Exercise EGL API functions
3 */
5 #include <GLES/egl.h>
6 #include <assert.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
12 /**
13 * Test EGL_MESA_screen_surface functions
15 static void
16 TestScreens(EGLDisplay dpy)
18 #define MAX 8
19 EGLScreenMESA screens[MAX];
20 EGLint numScreens;
21 EGLint i;
23 eglGetScreensMESA(dpy, screens, MAX, &numScreens);
24 printf("Found %d screens\n", numScreens);
25 for (i = 0; i < numScreens; i++) {
26 printf(" Screen %d handle: %d\n", i, (int) screens[i]);
30 /**
31 * Print table of all available configurations.
33 static void
34 PrintConfigs(EGLDisplay d)
36 EGLConfig *configs;
37 EGLint numConfigs, i;
39 eglGetConfigs(d, NULL, 0, &numConfigs);
40 configs = malloc(sizeof(*configs) *numConfigs);
41 eglGetConfigs(d, configs, numConfigs, &numConfigs);
43 printf("Configurations:\n");
44 printf(" bf lv d st colorbuffer dp st supported \n");
45 printf(" id sz l b ro r g b a th cl surfaces \n");
46 printf("----------------------------------------------\n");
47 for (i = 0; i < numConfigs; i++) {
48 EGLint id, size, level;
49 EGLint red, green, blue, alpha;
50 EGLint depth, stencil;
51 EGLint surfaces;
52 EGLint doubleBuf = 1, stereo = 0;
53 char surfString[100] = "";
55 eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
56 eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
57 eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
59 eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
60 eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
61 eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
62 eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
63 eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
64 eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
65 eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
67 if (surfaces & EGL_WINDOW_BIT)
68 strcat(surfString, "win,");
69 if (surfaces & EGL_PBUFFER_BIT)
70 strcat(surfString, "pb,");
71 if (surfaces & EGL_PIXMAP_BIT)
72 strcat(surfString, "pix,");
73 if (strlen(surfString) > 0)
74 surfString[strlen(surfString) - 1] = 0;
76 printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %-12s\n",
77 id, size, level,
78 doubleBuf ? 'y' : '.',
79 stereo ? 'y' : '.',
80 red, green, blue, alpha,
81 depth, stencil, surfString);
83 free(configs);
88 int
89 main(int argc, char *argv[])
91 int maj, min;
92 EGLContext ctx;
93 EGLSurface pbuffer;
94 EGLConfig configs[10];
95 EGLBoolean b;
96 const EGLint pbufAttribs[] = {
97 EGL_WIDTH, 500,
98 EGL_HEIGHT, 500,
99 EGL_NONE
103 EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
105 EGLDisplay d = eglGetDisplay("!fb_dri");
106 assert(d);
108 if (!eglInitialize(d, &maj, &min)) {
109 printf("demo: eglInitialize failed\n");
110 exit(1);
113 printf("EGL version = %d.%d\n", maj, min);
114 printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
116 PrintConfigs(d);
118 ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
119 if (ctx == EGL_NO_CONTEXT) {
120 printf("failed to create context\n");
121 return 0;
124 pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs);
125 if (pbuffer == EGL_NO_SURFACE) {
126 printf("failed to create pbuffer\n");
127 return 0;
130 b = eglMakeCurrent(d, pbuffer, pbuffer, ctx);
131 if (!b) {
132 printf("make current failed\n");
133 return 0;
136 b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
138 TestScreens(d);
140 eglDestroySurface(d, pbuffer);
141 eglDestroyContext(d, ctx);
142 eglTerminate(d);
144 return 0;