30 const std::string &name,
36 GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
39 DCAST_INTO_V(egl_pipe, _pipe);
41 _egl_display = egl_pipe->_egl_display;
44 _egl_surface = EGL_NO_SURFACE;
48 _screenshot_buffer_type = _draw_buffer_type;
55 ~eglGraphicsPixmap() {
56 nassertv(_x_pixmap == None && _egl_surface == EGL_NO_SURFACE);
67 PStatTimer timer(_make_current_pcollector, current_thread);
69 begin_frame_spam(mode);
70 if (_gsg ==
nullptr) {
75 DCAST_INTO_R(eglgsg, _gsg,
false);
76 if (!eglMakeCurrent(_egl_display, _egl_surface, _egl_surface, eglgsg->_context)) {
77 egldisplay_cat.error() <<
"Failed to call eglMakeCurrent: "
85 eglgsg->reset_if_new();
87 if (mode == FM_render) {
89 for (
size_t i = 0; i != cdata->_textures.size(); ++i) {
90 const RenderTexture &rt = cdata->_textures[i];
91 RenderTextureMode rtm_mode = rt._rtm_mode;
92 if (rtm_mode == RTM_bind_or_copy) {
93 CDWriter cdataw(_cycler, cdata,
false);
94 nassertr(cdata->_textures.size() == cdataw->_textures.size(),
false);
95 cdataw->_textures[i]._rtm_mode = RTM_copy_texture;
98 clear_cube_map_selection();
102 return _gsg->begin_frame(current_thread);
112 end_frame_spam(mode);
113 nassertv(_gsg !=
nullptr);
115 if (mode == FM_render) {
119 _gsg->end_frame(current_thread);
121 if (mode == FM_render) {
123 clear_cube_map_selection();
130 void eglGraphicsPixmap::
132 if (_gsg !=
nullptr) {
133 if (!eglMakeCurrent(_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
134 egldisplay_cat.error() <<
"Failed to call eglMakeCurrent: "
140 if (_egl_surface != EGL_NO_SURFACE) {
141 if (!eglDestroySurface(_egl_display, _egl_surface)) {
142 egldisplay_cat.error() <<
"Failed to destroy surface: "
145 _egl_surface = EGL_NO_SURFACE;
148 if (_x_pixmap != None) {
149 XFreePixmap(_display, _x_pixmap);
160 bool eglGraphicsPixmap::
163 DCAST_INTO_R(egl_pipe, _pipe,
false);
175 DCAST_INTO_R(eglgsg, _gsg,
false);
183 if (eglgsg->_fbconfig == None) {
189 XVisualInfo *visual_info = eglgsg->_visual;
190 if (visual_info ==
nullptr) {
192 egldisplay_cat.error()
193 <<
"No X visual: cannot create pixmap.\n";
198 if (_host !=
nullptr) {
199 if (_host->is_of_type(eglGraphicsWindow::get_class_type())) {
202 }
else if (_host->is_of_type(eglGraphicsPixmap::get_class_type())) {
204 _drawable = pix->_drawable;
208 _x_pixmap = XCreatePixmap(_display, _drawable,
209 _size.get_x(), _size.get_y(), visual_info->depth);
210 if (_x_pixmap == None) {
211 egldisplay_cat.error()
212 <<
"Failed to create X pixmap.\n";
217 nassertr(eglgsg->_fbconfig,
false);
218 _egl_surface = eglCreatePixmapSurface(_egl_display, eglgsg->_fbconfig, (NativePixmapType) _x_pixmap,
nullptr);
220 if (_egl_surface == EGL_NO_SURFACE) {
221 egldisplay_cat.error()
222 <<
"Failed to create EGL pixmap surface:"
228 eglMakeCurrent(_egl_display, _egl_surface, _egl_surface, eglgsg->_context);
229 eglgsg->reset_if_new();
230 if (!eglgsg->is_valid()) {
235 (_fb_properties, eglgsg->get_gl_renderer())) {