15 #include "eglGraphicsStateGuardian.h" 16 #include "config_egldisplay.h" 17 #include "lightReMutexHolder.h" 21 TypeHandle eglGraphicsStateGuardian::_type_handle;
28 eglGraphicsStateGuardian::
32 GLES2GraphicsStateGuardian(engine, pipe)
34 GLESGraphicsStateGuardian(engine, pipe)
47 _prepared_objects = share_with->get_prepared_objects();
48 _share_context = share_with->_context;
57 eglGraphicsStateGuardian::
58 ~eglGraphicsStateGuardian() {
59 if (_visuals != (XVisualInfo *)NULL) {
62 if (_context != (EGLContext)NULL) {
63 if (!eglDestroyContext(_egl_display, _context)) {
64 egldisplay_cat.error() <<
"Failed to destroy EGL context: " 65 << get_egl_error_string(eglGetError()) <<
"\n";
67 _context = (EGLContext)NULL;
79 bool &pbuffer_supported,
bool &pixmap_supported,
80 bool &slow, EGLConfig config) {
85 EGLint red_size, green_size, blue_size,
87 depth_size, stencil_size, samples, surface_type, caveat;
89 eglGetConfigAttrib(_egl_display, config, EGL_RED_SIZE, &red_size);
90 eglGetConfigAttrib(_egl_display, config, EGL_GREEN_SIZE, &green_size);
91 eglGetConfigAttrib(_egl_display, config, EGL_BLUE_SIZE, &blue_size);
92 eglGetConfigAttrib(_egl_display, config, EGL_ALPHA_SIZE, &alpha_size);
93 eglGetConfigAttrib(_egl_display, config, EGL_DEPTH_SIZE, &depth_size);
94 eglGetConfigAttrib(_egl_display, config, EGL_STENCIL_SIZE, &stencil_size);
95 eglGetConfigAttrib(_egl_display, config, EGL_SAMPLES, &samples);
96 eglGetConfigAttrib(_egl_display, config, EGL_SURFACE_TYPE, &surface_type);
97 eglGetConfigAttrib(_egl_display, config, EGL_CONFIG_CAVEAT, &caveat);
98 int err = eglGetError();
99 if (err != EGL_SUCCESS) {
100 egldisplay_cat.error() <<
"Failed to get EGL config attrib: " 101 << get_egl_error_string(err) <<
"\n";
104 pbuffer_supported =
false;
105 if ((surface_type & EGL_PBUFFER_BIT)!=0) {
106 pbuffer_supported =
true;
109 pixmap_supported =
false;
110 if ((surface_type & EGL_PIXMAP_BIT)!=0) {
111 pixmap_supported =
true;
115 if (caveat == EGL_SLOW_CONFIG) {
119 if ((surface_type & EGL_WINDOW_BIT)==0) {
124 properties.set_back_buffers(1);
125 properties.set_rgb_color(1);
126 properties.
set_rgba_bits(red_size, green_size, blue_size, alpha_size);
127 properties.set_stencil_bits(stencil_size);
128 properties.set_depth_bits(depth_size);
129 properties.set_multisamples(samples);
132 properties.set_force_software(1);
133 properties.set_force_hardware(1);
145 X11_Display *display,
146 int screen,
bool need_pbuffer,
bool need_pixmap) {
149 _egl_display = eglGetDisplay((NativeDisplayType) display);
157 int attrib_list[] = {
159 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
162 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
164 EGL_SURFACE_TYPE, EGL_DONT_CARE,
169 int num_configs = 0, returned_configs;
170 if (!eglChooseConfig(_egl_display, attrib_list, NULL, num_configs, &returned_configs) || returned_configs <= 0) {
171 egldisplay_cat.error() <<
"eglChooseConfig failed: " 172 << get_egl_error_string(eglGetError()) <<
"\n";
176 num_configs = returned_configs;
177 EGLConfig *configs =
new EGLConfig[num_configs];
179 if (!eglChooseConfig(_egl_display, attrib_list, configs, num_configs, &returned_configs) || returned_configs <= 0) {
180 egldisplay_cat.error() <<
"eglChooseConfig failed: " 181 << get_egl_error_string(eglGetError()) <<
"\n";
186 int best_quality = 0;
190 for (
int i = 0; i < num_configs; ++i) {
192 bool pbuffer_supported, pixmap_supported, slow;
197 const char *pbuffertext = pbuffer_supported ?
" (pbuffer)" :
"";
198 const char *pixmaptext = pixmap_supported ?
" (pixmap)" :
"";
199 const char *slowtext = slow ?
" (slow)" :
"";
200 egldisplay_cat.debug()
201 << i <<
": " << fbprops << pbuffertext << pixmaptext << slowtext <<
"\n";
203 if ((quality > 0)&&(slow)) quality -= 10000000;
205 if (need_pbuffer && !pbuffer_supported) {
208 if (need_pixmap && !pixmap_supported) {
212 if (quality > best_quality) {
213 best_quality = quality;
215 best_props = fbprops;
218 int depth = DefaultDepth(_display, _screen);
219 _visual =
new XVisualInfo;
220 XMatchVisualInfo(_display, _screen, depth, TrueColor, _visual);
222 if (best_quality > 0) {
223 egldisplay_cat.debug()
224 <<
"Chosen config " << best_result <<
": " << best_props <<
"\n";
225 _fbconfig = configs[best_result];
227 EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
228 _context = eglCreateContext(_egl_display, _fbconfig, _share_context, context_attribs);
230 _context = eglCreateContext(_egl_display, _fbconfig, _share_context, NULL);
232 int err = eglGetError();
233 if (_context && err == EGL_SUCCESS) {
235 _fbprops = best_props;
241 egldisplay_cat.error()
242 <<
"Could not create EGL context!\n" 243 << get_egl_error_string(err) <<
"\n";
250 egldisplay_cat.error() <<
251 "Could not find a usable pixel format.\n";
265 GLES2GraphicsStateGuardian::reset();
267 GLESGraphicsStateGuardian::reset();
273 if (_gl_renderer.find(
"Mesa") != string::npos &&
274 _gl_renderer.find(
"Mesa DRI") == string::npos) {
276 _fbprops.set_force_software(1);
277 _fbprops.set_force_hardware(0);
279 _fbprops.set_force_hardware(1);
280 _fbprops.set_force_software(0);
292 if (_egl_version_major < major_version) {
295 if (_egl_version_minor < minor_version) {
306 void eglGraphicsStateGuardian::
311 GLES2GraphicsStateGuardian::gl_flush();
313 GLESGraphicsStateGuardian::gl_flush();
322 GLenum eglGraphicsStateGuardian::
323 gl_get_error()
const {
327 return GLES2GraphicsStateGuardian::gl_get_error();
329 return GLESGraphicsStateGuardian::gl_get_error();
338 void eglGraphicsStateGuardian::
341 GLES2GraphicsStateGuardian::query_gl_version();
343 GLESGraphicsStateGuardian::query_gl_version();
348 if (!eglInitialize(_egl_display, &_egl_version_major, &_egl_version_minor)) {
349 egldisplay_cat.error() <<
"Failed to get EGL version number: " 350 << get_egl_error_string(eglGetError()) <<
"\n";
357 if (gles2gsg_cat.is_debug()) {
360 if (glesgsg_cat.is_debug()) {
363 <<
"EGL_VERSION = " << _egl_version_major <<
"." << _egl_version_minor
376 void eglGraphicsStateGuardian::
377 get_extra_extensions() {
378 save_extensions(eglQueryString(_egl_display, EGL_EXTENSIONS));
391 void *eglGraphicsStateGuardian::
392 do_get_extension_func(
const char *name) {
393 return (
void *)eglGetProcAddress(name);
void clear()
Unsets all properties that have been specified so far, and resets the FrameBufferProperties structure...
bool egl_is_at_least_version(int major_version, int minor_version) const
Returns true if the runtime GLX version number is at least the indicated value, false otherwise...
An object to create GraphicsOutputs that share a particular 3-D API.
Similar to MutexHolder, but for a light reentrant mutex.
void choose_pixel_format(const FrameBufferProperties &properties, X11_Display *_display, int _screen, bool need_pbuffer, bool need_pixmap)
Selects a visual or fbconfig for all the windows and buffers that use this gsg.
virtual void reset()
Resets all internal state as if the gsg were newly created.
void set_rgba_bits(int r, int g, int b, int a)
Convenience method for setting the red, green, blue and alpha bits in one go.
A tiny specialization on GLESGraphicsStateGuardian to add some egl-specific information.
This class is the main interface to controlling the render process.
void get_properties(FrameBufferProperties &properties, bool &pbuffer_supported, bool &pixmap_supported, bool &slow, EGLConfig config)
Gets the FrameBufferProperties to match the indicated config.
TypeHandle is the identifier used to differentiate C++ class types.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
int get_quality(const FrameBufferProperties &reqs) const
Assumes that these properties are a description of a window.