Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

es1_info.c 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (C) 2008 Tunsgten Graphics,Inc. All Rights Reserved.
  3. */
  4. /*
  5. * List OpenGL ES extensions.
  6. * Print ES 1 or ES 2 extensions depending on which library we're
  7. * linked with: libGLESv1_CM.so vs libGLESv2.so
  8. */
  9. #define GL_GLEXT_PROTOTYPES
  10. #include <assert.h>
  11. #include <math.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <X11/Xlib.h>
  16. #include <X11/Xutil.h>
  17. #include <X11/keysym.h>
  18. #include <GLES/gl.h>
  19. #include <GLES/glext.h>
  20. #include <EGL/egl.h>
  21. /*
  22. * Print a list of extensions, with word-wrapping.
  23. */
  24. static void
  25. print_extension_list(const char *ext)
  26. {
  27. const char *indentString = " ";
  28. const int indent = 4;
  29. const int max = 79;
  30. int width, i, j;
  31. if (!ext || !ext[0])
  32. return;
  33. width = indent;
  34. printf(indentString);
  35. i = j = 0;
  36. while (1) {
  37. if (ext[j] == ' ' || ext[j] == 0) {
  38. /* found end of an extension name */
  39. const int len = j - i;
  40. if (width + len > max) {
  41. /* start a new line */
  42. printf("\n");
  43. width = indent;
  44. printf(indentString);
  45. }
  46. /* print the extension name between ext[i] and ext[j] */
  47. while (i < j) {
  48. printf("%c", ext[i]);
  49. i++;
  50. }
  51. /* either we're all done, or we'll continue with next extension */
  52. width += len + 1;
  53. if (ext[j] == 0) {
  54. break;
  55. }
  56. else {
  57. i++;
  58. j++;
  59. if (ext[j] == 0)
  60. break;
  61. printf(", ");
  62. width += 2;
  63. }
  64. }
  65. j++;
  66. }
  67. printf("\n");
  68. }
  69. static void
  70. info(EGLDisplay egl_dpy)
  71. {
  72. const char *s;
  73. s = eglQueryString(egl_dpy, EGL_VERSION);
  74. printf("EGL_VERSION = %s\n", s);
  75. s = eglQueryString(egl_dpy, EGL_VENDOR);
  76. printf("EGL_VENDOR = %s\n", s);
  77. s = eglQueryString(egl_dpy, EGL_EXTENSIONS);
  78. printf("EGL_EXTENSIONS = %s\n", s);
  79. s = eglQueryString(egl_dpy, EGL_CLIENT_APIS);
  80. printf("EGL_CLIENT_APIS = %s\n", s);
  81. printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION));
  82. printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER));
  83. printf("GL_EXTENSIONS:\n");
  84. print_extension_list((char *) glGetString(GL_EXTENSIONS));
  85. }
  86. /*
  87. * Create an RGB, double-buffered X window.
  88. * Return the window and context handles.
  89. */
  90. static void
  91. make_x_window(Display *x_dpy, EGLDisplay egl_dpy,
  92. const char *name,
  93. int x, int y, int width, int height, int es_ver,
  94. Window *winRet,
  95. EGLContext *ctxRet,
  96. EGLSurface *surfRet)
  97. {
  98. EGLint attribs[] = {
  99. EGL_RENDERABLE_TYPE, 0x0,
  100. EGL_RED_SIZE, 1,
  101. EGL_GREEN_SIZE, 1,
  102. EGL_BLUE_SIZE, 1,
  103. EGL_NONE
  104. };
  105. EGLint ctx_attribs[] = {
  106. EGL_CONTEXT_CLIENT_VERSION, 0,
  107. EGL_NONE
  108. };
  109. int scrnum;
  110. XSetWindowAttributes attr;
  111. unsigned long mask;
  112. Window root;
  113. Window win;
  114. XVisualInfo *visInfo, visTemplate;
  115. int num_visuals;
  116. EGLContext ctx;
  117. EGLConfig config;
  118. EGLint num_configs;
  119. EGLint vid;
  120. scrnum = DefaultScreen( x_dpy );
  121. root = RootWindow( x_dpy, scrnum );
  122. if (es_ver == 1)
  123. attribs[1] = EGL_OPENGL_ES_BIT;
  124. else
  125. attribs[1] = EGL_OPENGL_ES2_BIT;
  126. ctx_attribs[1] = es_ver;
  127. if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) {
  128. printf("Error: couldn't get an EGL visual config\n");
  129. exit(1);
  130. }
  131. assert(config);
  132. assert(num_configs > 0);
  133. if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
  134. printf("Error: eglGetConfigAttrib() failed\n");
  135. exit(1);
  136. }
  137. /* The X window visual must match the EGL config */
  138. visTemplate.visualid = vid;
  139. visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals);
  140. if (!visInfo) {
  141. printf("Error: couldn't get X visual\n");
  142. exit(1);
  143. }
  144. /* window attributes */
  145. attr.background_pixel = 0;
  146. attr.border_pixel = 0;
  147. attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone);
  148. attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
  149. mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  150. win = XCreateWindow( x_dpy, root, 0, 0, width, height,
  151. 0, visInfo->depth, InputOutput,
  152. visInfo->visual, mask, &attr );
  153. /* set hints and properties */
  154. {
  155. XSizeHints sizehints;
  156. sizehints.x = x;
  157. sizehints.y = y;
  158. sizehints.width = width;
  159. sizehints.height = height;
  160. sizehints.flags = USSize | USPosition;
  161. XSetNormalHints(x_dpy, win, &sizehints);
  162. XSetStandardProperties(x_dpy, win, name, name,
  163. None, (char **)NULL, 0, &sizehints);
  164. }
  165. eglBindAPI(EGL_OPENGL_ES_API);
  166. ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs );
  167. if (!ctx) {
  168. printf("Error: eglCreateContext failed\n");
  169. exit(1);
  170. }
  171. *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL);
  172. if (!*surfRet) {
  173. printf("Error: eglCreateWindowSurface failed\n");
  174. exit(1);
  175. }
  176. XFree(visInfo);
  177. *winRet = win;
  178. *ctxRet = ctx;
  179. }
  180. static void
  181. usage(void)
  182. {
  183. printf("Usage:\n");
  184. printf(" -display <displayname> set the display to run on\n");
  185. }
  186. int
  187. main(int argc, char *argv[])
  188. {
  189. const int winWidth = 400, winHeight = 300;
  190. Display *x_dpy;
  191. Window win;
  192. EGLSurface egl_surf;
  193. EGLContext egl_ctx;
  194. EGLDisplay egl_dpy;
  195. char *dpyName = NULL;
  196. EGLint egl_major, egl_minor, es_ver;
  197. int i;
  198. for (i = 1; i < argc; i++) {
  199. if (strcmp(argv[i], "-display") == 0) {
  200. dpyName = argv[i+1];
  201. i++;
  202. }
  203. else {
  204. usage();
  205. return -1;
  206. }
  207. }
  208. x_dpy = XOpenDisplay(dpyName);
  209. if (!x_dpy) {
  210. printf("Error: couldn't open display %s\n",
  211. dpyName ? dpyName : getenv("DISPLAY"));
  212. return -1;
  213. }
  214. egl_dpy = eglGetDisplay(x_dpy);
  215. if (!egl_dpy) {
  216. printf("Error: eglGetDisplay() failed\n");
  217. return -1;
  218. }
  219. if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) {
  220. printf("Error: eglInitialize() failed\n");
  221. return -1;
  222. }
  223. es_ver = 1;
  224. /* decide the version from the executable's name */
  225. if (argc > 0 && argv[0] && strstr(argv[0], "es2"))
  226. es_ver = 2;
  227. make_x_window(x_dpy, egl_dpy,
  228. "ES info", 0, 0, winWidth, winHeight, es_ver,
  229. &win, &egl_ctx, &egl_surf);
  230. /*XMapWindow(x_dpy, win);*/
  231. if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) {
  232. printf("Error: eglMakeCurrent() failed\n");
  233. return -1;
  234. }
  235. info(egl_dpy);
  236. eglDestroyContext(egl_dpy, egl_ctx);
  237. eglDestroySurface(egl_dpy, egl_surf);
  238. eglTerminate(egl_dpy);
  239. XDestroyWindow(x_dpy, win);
  240. XCloseDisplay(x_dpy);
  241. return 0;
  242. }