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.

demo1.c 3.7KB

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