Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Exercise EGL API functions |
| 3 | */ |
| 4 | |
Brian Paul | 096b79b | 2008-05-27 13:47:07 -0600 | [diff] [blame] | 5 | #define EGL_EGLEXT_PROTOTYPES |
| 6 | |
Brian Paul | af540ef | 2008-06-04 10:11:25 -0600 | [diff] [blame] | 7 | #include <EGL/egl.h> |
| 8 | #include <EGL/eglext.h> |
Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 9 | #include <assert.h> |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
Jon Smirl | d06da50 | 2005-05-17 00:59:13 +0000 | [diff] [blame] | 12 | #include <string.h> |
Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 13 | |
| 14 | |
Brian Paul | 3aeae20 | 2005-05-04 03:32:39 +0000 | [diff] [blame] | 15 | /** |
| 16 | * Test EGL_MESA_screen_surface functions |
| 17 | */ |
| 18 | static void |
| 19 | TestScreens(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 Smirl | d06da50 | 2005-05-17 00:59:13 +0000 | [diff] [blame] | 33 | /** |
| 34 | * Print table of all available configurations. |
| 35 | */ |
| 36 | static void |
Chia-I Wu | e0b2848 | 2009-09-30 12:28:01 +0800 | [diff] [blame] | 37 | PrintConfigs(EGLDisplay d, EGLConfig *configs, EGLint numConfigs) |
Jon Smirl | d06da50 | 2005-05-17 00:59:13 +0000 | [diff] [blame] | 38 | { |
Chia-I Wu | e0b2848 | 2009-09-30 12:28:01 +0800 | [diff] [blame] | 39 | EGLint i; |
Jon Smirl | d06da50 | 2005-05-17 00:59:13 +0000 | [diff] [blame] | 40 | |
| 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 Smirl | d06da50 | 2005-05-17 00:59:13 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Brian Paul | 3aeae20 | 2005-05-04 03:32:39 +0000 | [diff] [blame] | 83 | |
Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 84 | |
| 85 | int |
| 86 | main(int argc, char *argv[]) |
| 87 | { |
| 88 | int maj, min; |
| 89 | EGLContext ctx; |
| 90 | EGLSurface pbuffer; |
Chia-I Wu | e0b2848 | 2009-09-30 12:28:01 +0800 | [diff] [blame] | 91 | EGLConfig *configs; |
| 92 | EGLint numConfigs; |
Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 93 | EGLBoolean b; |
| 94 | const EGLint pbufAttribs[] = { |
| 95 | EGL_WIDTH, 500, |
| 96 | EGL_HEIGHT, 500, |
| 97 | EGL_NONE |
| 98 | }; |
| 99 | |
Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 100 | EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 101 | 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 Wu | e0b2848 | 2009-09-30 12:28:01 +0800 | [diff] [blame] | 111 | eglGetConfigs(d, NULL, 0, &numConfigs); |
| 112 | configs = malloc(sizeof(*configs) *numConfigs); |
| 113 | eglGetConfigs(d, configs, numConfigs, &numConfigs); |
| 114 | |
| 115 | PrintConfigs(d, configs, numConfigs); |
Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 116 | |
| 117 | ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL); |
| 118 | if (ctx == EGL_NO_CONTEXT) { |
| 119 | printf("failed to create context\n"); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs); |
| 124 | if (pbuffer == EGL_NO_SURFACE) { |
| 125 | printf("failed to create pbuffer\n"); |
| 126 | return 0; |
| 127 | } |
| 128 | |
Chia-I Wu | e0b2848 | 2009-09-30 12:28:01 +0800 | [diff] [blame] | 129 | free(configs); |
| 130 | |
Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 131 | b = eglMakeCurrent(d, pbuffer, pbuffer, ctx); |
| 132 | if (!b) { |
| 133 | printf("make current failed\n"); |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 138 | |
Brian Paul | 3aeae20 | 2005-05-04 03:32:39 +0000 | [diff] [blame] | 139 | TestScreens(d); |
| 140 | |
Brian Paul | fc06f9f | 2005-04-22 21:17:14 +0000 | [diff] [blame] | 141 | eglDestroySurface(d, pbuffer); |
| 142 | eglDestroyContext(d, ctx); |
| 143 | eglTerminate(d); |
| 144 | |
| 145 | return 0; |
| 146 | } |