blob: d892734ee55f49de55995e8dcdebbd79265e6b3b [file] [log] [blame]
Brian Paulfc06f9f2005-04-22 21:17:14 +00001/*
2 * Exercise EGL API functions
3 */
4
Brian Paul096b79b2008-05-27 13:47:07 -06005#define EGL_EGLEXT_PROTOTYPES
6
Brian Paulaf540ef2008-06-04 10:11:25 -06007#include <EGL/egl.h>
8#include <EGL/eglext.h>
Brian Paulfc06f9f2005-04-22 21:17:14 +00009#include <assert.h>
10#include <stdio.h>
11#include <stdlib.h>
Jon Smirld06da502005-05-17 00:59:13 +000012#include <string.h>
Brian Paulfc06f9f2005-04-22 21:17:14 +000013
14
Brian Paul3aeae202005-05-04 03:32:39 +000015/**
16 * Test EGL_MESA_screen_surface functions
17 */
18static void
19TestScreens(EGLDisplay dpy)
20{
21#define MAX 8
22 EGLScreenMESA screens[MAX];
23 EGLint numScreens;
24 EGLint i;
25
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]);
30 }
31}
32
Jon Smirld06da502005-05-17 00:59:13 +000033/**
34 * Print table of all available configurations.
35 */
36static void
Chia-I Wue0b28482009-09-30 12:28:01 +080037PrintConfigs(EGLDisplay d, EGLConfig *configs, EGLint numConfigs)
Jon Smirld06da502005-05-17 00:59:13 +000038{
Chia-I Wue0b28482009-09-30 12:28:01 +080039 EGLint i;
Jon Smirld06da502005-05-17 00:59:13 +000040
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;
49 EGLint surfaces;
50 EGLint doubleBuf = 1, stereo = 0;
51 char surfString[100] = "";
52
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);
56
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);
64
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;
73
74 printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %-12s\n",
75 id, size, level,
76 doubleBuf ? 'y' : '.',
77 stereo ? 'y' : '.',
78 red, green, blue, alpha,
79 depth, stencil, surfString);
80 }
Jon Smirld06da502005-05-17 00:59:13 +000081}
82
Brian Paul3aeae202005-05-04 03:32:39 +000083
Brian Paulfc06f9f2005-04-22 21:17:14 +000084
85int
86main(int argc, char *argv[])
87{
88 int maj, min;
89 EGLContext ctx;
90 EGLSurface pbuffer;
Chia-I Wue0b28482009-09-30 12:28:01 +080091 EGLConfig *configs;
92 EGLint numConfigs;
Brian Paulfc06f9f2005-04-22 21:17:14 +000093 EGLBoolean b;
94 const EGLint pbufAttribs[] = {
95 EGL_WIDTH, 500,
96 EGL_HEIGHT, 500,
97 EGL_NONE
98 };
99
Brian Paulfc06f9f2005-04-22 21:17:14 +0000100 EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Brian Paulfc06f9f2005-04-22 21:17:14 +0000101 assert(d);
102
103 if (!eglInitialize(d, &maj, &min)) {
104 printf("demo: eglInitialize failed\n");
105 exit(1);
106 }
107
108 printf("EGL version = %d.%d\n", maj, min);
109 printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
110
Chia-I Wue0b28482009-09-30 12:28:01 +0800111 eglGetConfigs(d, NULL, 0, &numConfigs);
112 configs = malloc(sizeof(*configs) *numConfigs);
113 eglGetConfigs(d, configs, numConfigs, &numConfigs);
114
115 PrintConfigs(d, configs, numConfigs);
Brian Paulfc06f9f2005-04-22 21:17:14 +0000116
Chia-I Wu472a6012010-01-04 13:32:50 +0800117 eglBindAPI(EGL_OPENGL_API);
Brian Paulfc06f9f2005-04-22 21:17:14 +0000118 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;
122 }
123
124 pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs);
125 if (pbuffer == EGL_NO_SURFACE) {
126 printf("failed to create pbuffer\n");
127 return 0;
128 }
129
Chia-I Wue0b28482009-09-30 12:28:01 +0800130 free(configs);
131
Brian Paulfc06f9f2005-04-22 21:17:14 +0000132 b = eglMakeCurrent(d, pbuffer, pbuffer, ctx);
133 if (!b) {
134 printf("make current failed\n");
135 return 0;
136 }
137
138 b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
139
Brian Paul3aeae202005-05-04 03:32:39 +0000140 TestScreens(d);
141
Brian Paulfc06f9f2005-04-22 21:17:14 +0000142 eglDestroySurface(d, pbuffer);
143 eglDestroyContext(d, ctx);
144 eglTerminate(d);
145
146 return 0;
147}