Choose a config that most closely matches a given descriptor. If there are no matches, this method returns nullptr
.
72 {
73 if (!display_) {
74 return nullptr;
75 }
76
77 std::vector<EGLint> attributes;
78
79 {
80 attributes.push_back(EGL_RENDERABLE_TYPE);
81 switch (config.api) {
83 attributes.push_back(EGL_OPENGL_BIT);
84 break;
86 attributes.push_back(EGL_OPENGL_ES2_BIT);
87 break;
89 attributes.push_back(EGL_OPENGL_ES3_BIT);
90 break;
91 }
92 }
93
94 {
95 attributes.push_back(EGL_SURFACE_TYPE);
96 switch (config.surface_type) {
98 attributes.push_back(EGL_WINDOW_BIT);
99 break;
101 attributes.push_back(EGL_PBUFFER_BIT);
102 break;
103 }
104 }
105
106 {
107 switch (config.color_format) {
109 attributes.push_back(EGL_RED_SIZE);
110 attributes.push_back(8);
111 attributes.push_back(EGL_GREEN_SIZE);
112 attributes.push_back(8);
113 attributes.push_back(EGL_BLUE_SIZE);
114 attributes.push_back(8);
115 attributes.push_back(EGL_ALPHA_SIZE);
116 attributes.push_back(8);
117 break;
119 attributes.push_back(EGL_RED_SIZE);
120 attributes.push_back(5);
121 attributes.push_back(EGL_GREEN_SIZE);
122 attributes.push_back(6);
123 attributes.push_back(EGL_BLUE_SIZE);
124 attributes.push_back(5);
125 break;
126 }
127 }
128
129 {
130 attributes.push_back(EGL_DEPTH_SIZE);
131 attributes.push_back(static_cast<EGLint>(config.depth_bits));
132 }
133
134 {
135 attributes.push_back(EGL_STENCIL_SIZE);
136 attributes.push_back(static_cast<EGLint>(config.stencil_bits));
137 }
138
139 {
140 const auto sample_count = static_cast<EGLint>(config.samples);
141 if (sample_count > 1) {
142 attributes.push_back(EGL_SAMPLE_BUFFERS);
143 attributes.push_back(1);
144 attributes.push_back(EGL_SAMPLES);
145 attributes.push_back(sample_count);
146 }
147 }
148
149
150 attributes.push_back(EGL_NONE);
151
152 EGLConfig config_out = nullptr;
153 EGLint config_count_out = 0;
154 if (::eglChooseConfig(display_,
155 attributes.data(),
156 &config_out,
157 1,
158 &config_count_out
159 ) != EGL_TRUE) {
161 return nullptr;
162 }
163
164 if (config_count_out != 1u) {
166 return nullptr;
167 }
168
169 return std::make_unique<Config>(config, config_out);
170}