2 * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
6 * List OpenGL ES extensions.
7 * Print ES 1 or ES 2 extensions depending on which library we're
8 * linked with: libGLESv1_CM.so vs libGLESv2.so
11 #define GL_GLEXT_PROTOTYPES
19 #include <X11/Xutil.h>
20 #include <X11/keysym.h>
22 #include <GLES/glext.h>
27 * Print a list of extensions, with word-wrapping.
30 print_extension_list(const char *ext
)
32 const char *indentString
= " ";
44 if (ext
[j
] == ' ' || ext
[j
] == 0) {
45 /* found end of an extension name */
46 const int len
= j
- i
;
47 if (width
+ len
> max
) {
48 /* start a new line */
53 /* print the extension name between ext[i] and ext[j] */
58 /* either we're all done, or we'll continue with next extension */
79 info(EGLDisplay egl_dpy
)
83 s
= eglQueryString(egl_dpy
, EGL_VERSION
);
84 printf("EGL_VERSION = %s\n", s
);
86 s
= eglQueryString(egl_dpy
, EGL_VENDOR
);
87 printf("EGL_VENDOR = %s\n", s
);
89 s
= eglQueryString(egl_dpy
, EGL_EXTENSIONS
);
90 printf("EGL_EXTENSIONS = %s\n", s
);
92 s
= eglQueryString(egl_dpy
, EGL_CLIENT_APIS
);
93 printf("EGL_CLIENT_APIS = %s\n", s
);
95 printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION
));
96 printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER
));
97 printf("GL_EXTENSIONS:\n");
98 print_extension_list((char *) glGetString(GL_EXTENSIONS
));
103 * Create an RGB, double-buffered X window.
104 * Return the window and context handles.
107 make_x_window(Display
*x_dpy
, EGLDisplay egl_dpy
,
109 int x
, int y
, int width
, int height
, int es_ver
,
115 EGL_RENDERABLE_TYPE
, 0x0,
121 EGLint ctx_attribs
[] = {
122 EGL_CONTEXT_CLIENT_VERSION
, 0,
127 XSetWindowAttributes attr
;
131 XVisualInfo
*visInfo
, visTemplate
;
138 scrnum
= DefaultScreen( x_dpy
);
139 root
= RootWindow( x_dpy
, scrnum
);
142 attribs
[1] = EGL_OPENGL_ES_BIT
;
144 attribs
[1] = EGL_OPENGL_ES2_BIT
;
145 ctx_attribs
[1] = es_ver
;
147 if (!eglChooseConfig( egl_dpy
, attribs
, &config
, 1, &num_configs
)) {
148 printf("Error: couldn't get an EGL visual config\n");
153 assert(num_configs
> 0);
155 if (!eglGetConfigAttrib(egl_dpy
, config
, EGL_NATIVE_VISUAL_ID
, &vid
)) {
156 printf("Error: eglGetConfigAttrib() failed\n");
160 /* The X window visual must match the EGL config */
161 visTemplate
.visualid
= vid
;
162 visInfo
= XGetVisualInfo(x_dpy
, VisualIDMask
, &visTemplate
, &num_visuals
);
164 printf("Error: couldn't get X visual\n");
168 /* window attributes */
169 attr
.background_pixel
= 0;
170 attr
.border_pixel
= 0;
171 attr
.colormap
= XCreateColormap( x_dpy
, root
, visInfo
->visual
, AllocNone
);
172 attr
.event_mask
= StructureNotifyMask
| ExposureMask
| KeyPressMask
;
173 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
175 win
= XCreateWindow( x_dpy
, root
, 0, 0, width
, height
,
176 0, visInfo
->depth
, InputOutput
,
177 visInfo
->visual
, mask
, &attr
);
179 /* set hints and properties */
181 XSizeHints sizehints
;
184 sizehints
.width
= width
;
185 sizehints
.height
= height
;
186 sizehints
.flags
= USSize
| USPosition
;
187 XSetNormalHints(x_dpy
, win
, &sizehints
);
188 XSetStandardProperties(x_dpy
, win
, name
, name
,
189 None
, (char **)NULL
, 0, &sizehints
);
192 eglBindAPI(EGL_OPENGL_ES_API
);
194 ctx
= eglCreateContext(egl_dpy
, config
, EGL_NO_CONTEXT
, ctx_attribs
);
196 printf("Error: eglCreateContext failed\n");
200 *surfRet
= eglCreateWindowSurface(egl_dpy
, config
, win
, NULL
);
203 printf("Error: eglCreateWindowSurface failed\n");
218 printf(" -display <displayname> set the display to run on\n");
223 main(int argc
, char *argv
[])
225 const int winWidth
= 400, winHeight
= 300;
231 char *dpyName
= NULL
;
232 EGLint egl_major
, egl_minor
, es_ver
;
235 for (i
= 1; i
< argc
; i
++) {
236 if (strcmp(argv
[i
], "-display") == 0) {
246 x_dpy
= XOpenDisplay(dpyName
);
248 printf("Error: couldn't open display %s\n",
249 dpyName
? dpyName
: getenv("DISPLAY"));
253 egl_dpy
= eglGetDisplay(x_dpy
);
255 printf("Error: eglGetDisplay() failed\n");
259 if (!eglInitialize(egl_dpy
, &egl_major
, &egl_minor
)) {
260 printf("Error: eglInitialize() failed\n");
265 /* decide the version from the executable's name */
266 if (argc
> 0 && argv
[0] && strstr(argv
[0], "es2"))
268 make_x_window(x_dpy
, egl_dpy
,
269 "ES info", 0, 0, winWidth
, winHeight
, es_ver
,
270 &win
, &egl_ctx
, &egl_surf
);
272 /*XMapWindow(x_dpy, win);*/
273 if (!eglMakeCurrent(egl_dpy
, egl_surf
, egl_surf
, egl_ctx
)) {
274 printf("Error: eglMakeCurrent() failed\n");
280 eglDestroyContext(egl_dpy
, egl_ctx
);
281 eglDestroySurface(egl_dpy
, egl_surf
);
282 eglTerminate(egl_dpy
);
285 XDestroyWindow(x_dpy
, win
);
286 XCloseDisplay(x_dpy
);