fork(1) download
  1. int chooseConfig(EGLDisplay display, EGLConfig *config)
  2. {
  3. EGLint numConfigs = 0;
  4.  
  5. if(!eglGetConfigs(display, nullptr, 0, &numConfigs) || numConfigs == 0)
  6. {
  7. trace("ERROR: There are no graphics configurations available for this device");
  8. return 0;
  9. }
  10.  
  11. EGLConfig *configs = new EGLConfig[numConfigs];
  12.  
  13. eglGetConfigs(display, configs, numConfigs, &numConfigs);
  14.  
  15. EGLConfig bestConfig = 0;
  16.  
  17. EGLint bestSurfaceType = 0;
  18. EGLint bestRenderableType = 0;
  19. EGLint bestRedSize = 0;
  20. EGLint bestGreenSize = 0;
  21. EGLint bestBlueSize = 0;
  22. EGLint bestAlphaSize = 0;
  23. EGLint bestBufferSize = 0;
  24. EGLint bestDepthSize = 0;
  25.  
  26. for(int i = 0; i < numConfigs; ++i)
  27. {
  28. EGLint surfaceType;
  29. EGLint renderableType;
  30. EGLint redSize;
  31. EGLint greenSize;
  32. EGLint blueSize;
  33. EGLint alphaSize;
  34. EGLint bufferSize;
  35. EGLint depthSize;
  36.  
  37. eglGetConfigAttrib(display, configs[i], EGL_SURFACE_TYPE, &surfaceType);
  38. eglGetConfigAttrib(display, configs[i], EGL_RENDERABLE_TYPE, &renderableType);
  39. eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &redSize);
  40. eglGetConfigAttrib(display, configs[i], EGL_GREEN_SIZE, &greenSize);
  41. eglGetConfigAttrib(display, configs[i], EGL_BLUE_SIZE, &blueSize);
  42. eglGetConfigAttrib(display, configs[i], EGL_ALPHA_SIZE, &alphaSize);
  43. eglGetConfigAttrib(display, configs[i], EGL_BUFFER_SIZE, &bufferSize);
  44. eglGetConfigAttrib(display, configs[i], EGL_DEPTH_SIZE, &depthSize);
  45.  
  46. // Must support both of these. Window bit for main window,
  47. // and pbuffer bit for the extra pbuffer in the aux ctx.
  48. int neededSurfType = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;
  49. if(surfaceType & neededSurfType != neededSurfType)
  50. continue;
  51.  
  52. // must support gles2
  53. if(renderableType & EGL_OPENGL_ES2_BIT == 0)
  54. continue;
  55.  
  56. // must have at least some bits in each channel
  57. // example: RGB with no alpha is no good (for me)
  58. if(redSize == 0 || greenSize == 0 || blueSize == 0 || alphaSize == 0)
  59. continue;
  60.  
  61. // must have both a color buffer and a depth buffer
  62. if(bufferSize == 0 || depthSize == 0)
  63. continue;
  64.  
  65. // make sure config with most the precision is used
  66. if(bestConfig == nullptr
  67. || renderableType > bestRenderableType
  68. || redSize > bestRedSize
  69. || greenSize > bestGreenSize
  70. || blueSize > bestBlueSize
  71. || alphaSize > bestAlphaSize
  72. || bufferSize > bestBufferSize
  73. || depthSize > bestDepthSize)
  74. {
  75. bestConfig = configs[i];
  76.  
  77. bestSurfaceType = surfaceType;
  78. bestRenderableType = renderableType;
  79. bestRedSize = redSize;
  80. bestGreenSize = greenSize;
  81. bestBlueSize = blueSize;
  82. bestAlphaSize = alphaSize;
  83. bestBufferSize = bufferSize;
  84. bestDepthSize = depthSize;
  85. }
  86. }
  87.  
  88. delete [] configs;
  89.  
  90. // a config was found that matches my minimum requirements
  91. if(bestConfig != 0)
  92. {
  93. *config = bestConfig;
  94.  
  95. trace("Using Display Configuration:");
  96. trace("EGL_SURFACE_TYPE - ", bestSurfaceType);
  97. trace("EGL_RENDERABLE_TYPE - ", bestRenderableType);
  98. trace("EGL_RED_SIZE - ", bestRedSize);
  99. trace("EGL_GREEN_SIZE - ", bestGreenSize);
  100. trace("EGL_BLUE_SIZE - ", bestBlueSize);
  101. trace("EGL_ALPHA_SIZE - ", bestAlphaSize);
  102. trace("EGL_BUFFER_SIZE - ", bestBufferSize);
  103. trace("EGL_DEPTH_SIZE - ", bestDepthSize);
  104. trace("-----------------------------");
  105.  
  106. return 1;
  107. }
  108.  
  109. // no config found.
  110. return 0;
  111. }
  112.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:18: error: 'EGLDisplay' was not declared in this scope
 int chooseConfig(EGLDisplay display, EGLConfig *config)
                  ^
prog.cpp:1:38: error: 'EGLConfig' was not declared in this scope
 int chooseConfig(EGLDisplay display, EGLConfig *config)
                                      ^
prog.cpp:1:49: error: 'config' was not declared in this scope
 int chooseConfig(EGLDisplay display, EGLConfig *config)
                                                 ^
prog.cpp:1:55: error: expression list treated as compound expression in initializer [-fpermissive]
 int chooseConfig(EGLDisplay display, EGLConfig *config)
                                                       ^
prog.cpp:2:1: error: expected ',' or ';' before '{' token
 {
 ^
stdout
Standard output is empty