20 TypeHandle eglGraphicsStateGuardian::_type_handle;
25 eglGraphicsStateGuardian::
29 GLES2GraphicsStateGuardian(engine, pipe)
31 GLESGraphicsStateGuardian(engine, pipe)
43 if (share_with !=
nullptr) {
44 _prepared_objects = share_with->get_prepared_objects();
45 _share_context = share_with->_context;
52 eglGraphicsStateGuardian::
53 ~eglGraphicsStateGuardian() {
54 if (_visuals !=
nullptr) {
57 if (_context != (EGLContext)
nullptr) {
58 if (!eglDestroyContext(_egl_display, _context)) {
59 egldisplay_cat.error() <<
"Failed to destroy EGL context: " 62 _context = (EGLContext)
nullptr;
71 bool &pbuffer_supported,
bool &pixmap_supported,
72 bool &slow, EGLConfig config) {
77 EGLint red_size, green_size, blue_size,
79 depth_size, stencil_size, samples, surface_type, caveat;
81 eglGetConfigAttrib(_egl_display, config, EGL_RED_SIZE, &red_size);
82 eglGetConfigAttrib(_egl_display, config, EGL_GREEN_SIZE, &green_size);
83 eglGetConfigAttrib(_egl_display, config, EGL_BLUE_SIZE, &blue_size);
84 eglGetConfigAttrib(_egl_display, config, EGL_ALPHA_SIZE, &alpha_size);
85 eglGetConfigAttrib(_egl_display, config, EGL_DEPTH_SIZE, &depth_size);
86 eglGetConfigAttrib(_egl_display, config, EGL_STENCIL_SIZE, &stencil_size);
87 eglGetConfigAttrib(_egl_display, config, EGL_SAMPLES, &samples);
88 eglGetConfigAttrib(_egl_display, config, EGL_SURFACE_TYPE, &surface_type);
89 eglGetConfigAttrib(_egl_display, config, EGL_CONFIG_CAVEAT, &caveat);
90 int err = eglGetError();
91 if (err != EGL_SUCCESS) {
92 egldisplay_cat.error() <<
"Failed to get EGL config attrib: " 96 pbuffer_supported =
false;
97 if ((surface_type & EGL_PBUFFER_BIT)!=0) {
98 pbuffer_supported =
true;
101 pixmap_supported =
false;
102 if ((surface_type & EGL_PIXMAP_BIT)!=0) {
103 pixmap_supported =
true;
107 if (caveat == EGL_SLOW_CONFIG) {
111 if ((surface_type & EGL_WINDOW_BIT)==0) {
116 properties.set_back_buffers(1);
117 properties.set_rgb_color(1);
118 properties.
set_rgba_bits(red_size, green_size, blue_size, alpha_size);
119 properties.set_stencil_bits(stencil_size);
120 properties.set_depth_bits(depth_size);
121 properties.set_multisamples(samples);
124 properties.set_force_software(1);
125 properties.set_force_hardware(1);
134 X11_Display *display,
135 int screen,
bool need_pbuffer,
bool need_pixmap) {
138 _egl_display = eglGetDisplay((NativeDisplayType) display);
146 int attrib_list[] = {
148 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
151 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
153 EGL_SURFACE_TYPE, EGL_DONT_CARE,
159 int num_configs = 0, returned_configs;
160 if (!eglChooseConfig(_egl_display, attrib_list,
nullptr, num_configs, &returned_configs) || returned_configs <= 0) {
161 egldisplay_cat.error() <<
"eglChooseConfig failed: " 166 num_configs = returned_configs;
167 EGLConfig *configs =
new EGLConfig[num_configs];
169 if (!eglChooseConfig(_egl_display, attrib_list, configs, num_configs, &returned_configs) || returned_configs <= 0) {
170 egldisplay_cat.error() <<
"eglChooseConfig failed: " 176 int best_quality = 0;
180 for (
int i = 0; i < num_configs; ++i) {
182 bool pbuffer_supported, pixmap_supported, slow;
188 const char *pbuffertext = pbuffer_supported ?
" (pbuffer)" :
"";
189 const char *pixmaptext = pixmap_supported ?
" (pixmap)" :
"";
190 const char *slowtext = slow ?
" (slow)" :
"";
191 egldisplay_cat.debug()
192 << i <<
": " << fbprops << pbuffertext << pixmaptext << slowtext <<
"\n";
194 if ((quality > 0)&&(slow)) quality -= 10000000;
196 if (need_pbuffer && !pbuffer_supported) {
199 if (need_pixmap && !pixmap_supported) {
203 if (quality > best_quality) {
204 best_quality = quality;
206 best_props = fbprops;
209 int depth = DefaultDepth(_display, _screen);
210 _visual =
new XVisualInfo;
211 XMatchVisualInfo(_display, _screen, depth, TrueColor, _visual);
213 if (best_quality > 0) {
214 egldisplay_cat.debug()
215 <<
"Chosen config " << best_result <<
": " << best_props <<
"\n";
216 _fbconfig = configs[best_result];
218 EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
219 _context = eglCreateContext(_egl_display, _fbconfig, _share_context, context_attribs);
221 _context = eglCreateContext(_egl_display, _fbconfig, _share_context,
nullptr);
223 int err = eglGetError();
224 if (_context && err == EGL_SUCCESS) {
226 _fbprops = best_props;
232 egldisplay_cat.error()
233 <<
"Could not create EGL context!\n" 241 egldisplay_cat.error() <<
242 "Could not find a usable pixel format.\n";
253 GLES2GraphicsStateGuardian::reset();
255 GLESGraphicsStateGuardian::reset();
260 if (_gl_renderer ==
"Software Rasterizer" ||
261 (_gl_renderer.find(
"Mesa") != std::string::npos &&
262 _gl_renderer.find(
"Mesa DRI") == std::string::npos)) {
264 _fbprops.set_force_software(1);
265 _fbprops.set_force_hardware(0);
267 _fbprops.set_force_hardware(1);
268 _fbprops.set_force_software(0);
278 if (_egl_version_major < major_version) {
281 if (_egl_version_minor < minor_version) {
290 void eglGraphicsStateGuardian::
295 GLES2GraphicsStateGuardian::gl_flush();
297 GLESGraphicsStateGuardian::gl_flush();
304 GLenum eglGraphicsStateGuardian::
305 gl_get_error()
const {
309 return GLES2GraphicsStateGuardian::gl_get_error();
311 return GLESGraphicsStateGuardian::gl_get_error();
318 void eglGraphicsStateGuardian::
321 GLES2GraphicsStateGuardian::query_gl_version();
323 GLESGraphicsStateGuardian::query_gl_version();
328 if (!eglInitialize(_egl_display, &_egl_version_major, &_egl_version_minor)) {
329 egldisplay_cat.error() <<
"Failed to get EGL version number: " 337 if (gles2gsg_cat.is_debug()) {
340 if (glesgsg_cat.is_debug()) {
343 <<
"EGL_VERSION = " << _egl_version_major <<
"." << _egl_version_minor
353 void eglGraphicsStateGuardian::
354 get_extra_extensions() {
355 save_extensions(eglQueryString(_egl_display, EGL_EXTENSIONS));
364 void *eglGraphicsStateGuardian::
365 do_get_extension_func(
const char *name) {
366 return (
void *)eglGetProcAddress(name);
void clear()
Unsets all properties that have been specified so far, and resets the FrameBufferProperties structure...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
const std::string get_egl_error_string(int error)
Returns the given EGL error as string.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.