Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

demo1.c 3.7KB

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