20TypeHandle AndroidGraphicsStateGuardian::_type_handle;
25AndroidGraphicsStateGuardian::
29 GLES2GraphicsStateGuardian(engine, pipe)
31 GLESGraphicsStateGuardian(engine, pipe)
40 if (share_with !=
nullptr) {
41 _prepared_objects = share_with->get_prepared_objects();
42 _share_context = share_with->_context;
49AndroidGraphicsStateGuardian::
50~AndroidGraphicsStateGuardian() {
51 if (_context != (EGLContext)
nullptr) {
52 if (!eglDestroyContext(_egl_display, _context)) {
53 androiddisplay_cat.error() <<
"Failed to destroy EGL context: "
56 _context = (EGLContext)
nullptr;
65 bool &pbuffer_supported,
bool &pixmap_supported,
66 bool &slow, EGLConfig config) {
71 EGLint red_size, green_size, blue_size,
73 depth_size, stencil_size, samples, surface_type, caveat;
75 eglGetConfigAttrib(_egl_display, config, EGL_RED_SIZE, &red_size);
76 eglGetConfigAttrib(_egl_display, config, EGL_GREEN_SIZE, &green_size);
77 eglGetConfigAttrib(_egl_display, config, EGL_BLUE_SIZE, &blue_size);
78 eglGetConfigAttrib(_egl_display, config, EGL_ALPHA_SIZE, &alpha_size);
79 eglGetConfigAttrib(_egl_display, config, EGL_DEPTH_SIZE, &depth_size);
80 eglGetConfigAttrib(_egl_display, config, EGL_STENCIL_SIZE, &stencil_size);
81 eglGetConfigAttrib(_egl_display, config, EGL_SAMPLES, &samples);
82 eglGetConfigAttrib(_egl_display, config, EGL_SURFACE_TYPE, &surface_type);
83 eglGetConfigAttrib(_egl_display, config, EGL_CONFIG_CAVEAT, &caveat);
84 int err = eglGetError();
85 if (err != EGL_SUCCESS) {
86 androiddisplay_cat.error() <<
"Failed to get EGL config attrib: "
90 pbuffer_supported =
false;
91 if ((surface_type & EGL_PBUFFER_BIT)!=0) {
92 pbuffer_supported =
true;
95 pixmap_supported =
false;
96 if ((surface_type & EGL_PIXMAP_BIT)!=0) {
97 pixmap_supported =
true;
101 if (caveat == EGL_SLOW_CONFIG) {
105 if ((surface_type & EGL_WINDOW_BIT)==0) {
110 properties.set_back_buffers(1);
111 properties.set_rgb_color(1);
112 properties.
set_rgba_bits(red_size, green_size, blue_size, alpha_size);
113 properties.set_stencil_bits(stencil_size);
114 properties.set_depth_bits(depth_size);
115 properties.set_multisamples(samples);
118 properties.set_force_software(1);
119 properties.set_force_hardware(1);
128 bool need_pbuffer,
bool need_pixmap) {
130 _egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
134 int attrib_list[] = {
135 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
137 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
140 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
147 int num_configs = 0, returned_configs;
148 if (!eglChooseConfig(_egl_display, attrib_list,
nullptr, num_configs, &returned_configs) || returned_configs <= 0) {
149 androiddisplay_cat.error() <<
"eglChooseConfig failed: "
154 num_configs = returned_configs;
155 EGLConfig *configs =
new EGLConfig[num_configs];
157 if (!eglChooseConfig(_egl_display, attrib_list, configs, num_configs, &returned_configs) || returned_configs <= 0) {
158 androiddisplay_cat.error() <<
"eglChooseConfig failed: "
164 int best_quality = 0;
168 for (
int i = 0; i < num_configs; ++i) {
170 bool pbuffer_supported, pixmap_supported, slow;
176 const char *pbuffertext = pbuffer_supported ?
" (pbuffer)" :
"";
177 const char *pixmaptext = pixmap_supported ?
" (pixmap)" :
"";
178 const char *slowtext = slow ?
" (slow)" :
"";
179 androiddisplay_cat.debug()
180 << i <<
": " << fbprops << pbuffertext << pixmaptext << slowtext <<
"\n";
182 if ((quality > 0)&&(slow)) quality -= 10000000;
184 if (need_pbuffer && !pbuffer_supported) {
187 if (need_pixmap && !pixmap_supported) {
191 if (quality > best_quality) {
192 best_quality = quality;
194 best_props = fbprops;
198 if (best_quality > 0) {
199 androiddisplay_cat.debug()
200 <<
"Chosen config " << best_result <<
": " << best_props <<
"\n";
201 _fbconfig = configs[best_result];
202 eglGetConfigAttrib(_egl_display, _fbconfig, EGL_NATIVE_VISUAL_ID, &_format);
204 androiddisplay_cat.debug()
205 <<
"Window format: " << _format <<
"\n";
207 _fbprops = best_props;
211 androiddisplay_cat.error() <<
212 "Could not find a usable pixel format.\n";
223 if (_context != EGL_NO_CONTEXT) {
228 EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
229 _context = eglCreateContext(_egl_display, _fbconfig, _share_context, context_attribs);
231 _context = eglCreateContext(_egl_display, _fbconfig, _share_context,
nullptr);
234 int err = eglGetError();
235 if (_context != EGL_NO_CONTEXT && err == EGL_SUCCESS) {
240 androiddisplay_cat.error()
241 <<
"Could not create EGL context!\n"
251 if (_context == EGL_NO_CONTEXT) {
255 if (!eglMakeCurrent(_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
256 androiddisplay_cat.error() <<
"Failed to call eglMakeCurrent: "
262 eglDestroyContext(_egl_display, _context);
263 _context = EGL_NO_CONTEXT;
272 GLES2GraphicsStateGuardian::reset();
274 GLESGraphicsStateGuardian::reset();
278 if (_gl_renderer.find(
"PixelFlinger") != std::string::npos) {
279 _fbprops.set_force_software(1);
280 _fbprops.set_force_hardware(0);
282 _fbprops.set_force_hardware(1);
283 _fbprops.set_force_software(0);
293 if (_egl_version_major < major_version) {
296 if (_egl_version_minor < minor_version) {
305void AndroidGraphicsStateGuardian::
308 GLES2GraphicsStateGuardian::gl_flush();
310 GLESGraphicsStateGuardian::gl_flush();
317GLenum AndroidGraphicsStateGuardian::
318gl_get_error()
const {
320 return GLES2GraphicsStateGuardian::gl_get_error();
322 return GLESGraphicsStateGuardian::gl_get_error();
329void AndroidGraphicsStateGuardian::
332 GLES2GraphicsStateGuardian::query_gl_version();
334 GLESGraphicsStateGuardian::query_gl_version();
339 if (!eglInitialize(_egl_display, &_egl_version_major, &_egl_version_minor)) {
340 androiddisplay_cat.error() <<
"Failed to get EGL version number: "
348 if (gles2gsg_cat.is_debug()) {
351 if (glesgsg_cat.is_debug()) {
354 <<
"EGL_VERSION = " << _egl_version_major <<
"." << _egl_version_minor
364void AndroidGraphicsStateGuardian::
365get_extra_extensions() {
366 save_extensions(eglQueryString(_egl_display, EGL_EXTENSIONS));
375void *AndroidGraphicsStateGuardian::
376do_get_extension_func(
const char *name) {
377 return (
void *)eglGetProcAddress(name);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A tiny specialization on GLESGraphicsStateGuardian to add some egl-specific information.
bool create_context()
Creates the context based on the config previously obtained in choose_pixel_format.
void get_properties(FrameBufferProperties &properties, bool &pbuffer_supported, bool &pixmap_supported, bool &slow, EGLConfig config)
Gets the FrameBufferProperties to match the indicated config.
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.
virtual void reset()
Resets all internal state as if the gsg were newly created.
void destroy_context()
Destroys the context previously created by create_context.
void choose_pixel_format(const FrameBufferProperties &properties, bool need_pbuffer, bool need_pixmap)
Selects a visual or fbconfig for all the windows and buffers that use this gsg.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
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.
void clear()
Unsets all properties that have been specified so far, and resets the FrameBufferProperties structure...
int get_quality(const FrameBufferProperties &reqs) const
Assumes that these properties are a description of a window.
This class is the main interface to controlling the render process.
An object to create GraphicsOutputs that share a particular 3-D API.
TypeHandle is the identifier used to differentiate C++ class types.
const std::string get_egl_error_string(int error)
Returns the given EGL error as string.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.