15 #include "eglGraphicsPixmap.h" 16 #include "eglGraphicsWindow.h" 17 #include "eglGraphicsStateGuardian.h" 18 #include "config_egldisplay.h" 19 #include "eglGraphicsPipe.h" 21 #include "graphicsPipe.h" 22 #include "pStatTimer.h" 39 GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
42 DCAST_INTO_V(egl_pipe, _pipe);
44 _egl_display = egl_pipe->_egl_display;
47 _egl_surface = EGL_NO_SURFACE;
51 _screenshot_buffer_type = _draw_buffer_type;
60 ~eglGraphicsPixmap() {
61 nassertv(_x_pixmap == None && _egl_surface == EGL_NO_SURFACE);
75 PStatTimer timer(_make_current_pcollector, current_thread);
77 begin_frame_spam(mode);
83 DCAST_INTO_R(eglgsg, _gsg,
false);
84 if (!eglMakeCurrent(_egl_display, _egl_surface, _egl_surface, eglgsg->_context)) {
85 egldisplay_cat.error() <<
"Failed to call eglMakeCurrent: " 86 << get_egl_error_string(eglGetError()) <<
"\n";
93 eglgsg->reset_if_new();
95 if (mode == FM_render) {
97 for (
size_t i = 0; i != cdata->_textures.size(); ++i) {
98 const RenderTexture &rt = cdata->_textures[i];
99 RenderTextureMode rtm_mode = rt._rtm_mode;
100 if (rtm_mode == RTM_bind_or_copy) {
101 CDWriter cdataw(_cycler, cdata,
false);
102 nassertr(cdata->_textures.size() == cdataw->_textures.size(),
false);
103 cdataw->_textures[i]._rtm_mode = RTM_copy_texture;
106 clear_cube_map_selection();
110 return _gsg->begin_frame(current_thread);
122 end_frame_spam(mode);
125 if (mode == FM_render) {
129 _gsg->end_frame(current_thread);
131 if (mode == FM_render) {
133 clear_cube_map_selection();
143 void eglGraphicsPixmap::
146 if (!eglMakeCurrent(_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
147 egldisplay_cat.error() <<
"Failed to call eglMakeCurrent: " 148 << get_egl_error_string(eglGetError()) <<
"\n";
153 if (_egl_surface != EGL_NO_SURFACE) {
154 if (!eglDestroySurface(_egl_display, _egl_surface)) {
155 egldisplay_cat.error() <<
"Failed to destroy surface: " 156 << get_egl_error_string(eglGetError()) <<
"\n";
158 _egl_surface = EGL_NO_SURFACE;
161 if (_x_pixmap != None) {
162 XFreePixmap(_display, _x_pixmap);
176 bool eglGraphicsPixmap::
179 DCAST_INTO_R(egl_pipe, _pipe,
false);
191 DCAST_INTO_R(eglgsg, _gsg,
false);
199 if (eglgsg->_fbconfig == None) {
205 XVisualInfo *visual_info = eglgsg->_visual;
206 if (visual_info == NULL) {
208 egldisplay_cat.error()
209 <<
"No X visual: cannot create pixmap.\n";
215 if (_host->is_of_type(eglGraphicsWindow::get_class_type())) {
218 }
else if (_host->is_of_type(eglGraphicsPixmap::get_class_type())) {
220 _drawable = pix->_drawable;
224 _x_pixmap = XCreatePixmap(_display, _drawable,
225 _size.get_x(), _size.get_y(), visual_info->depth);
226 if (_x_pixmap == None) {
227 egldisplay_cat.error()
228 <<
"Failed to create X pixmap.\n";
233 nassertr(eglgsg->_fbconfig,
false);
234 _egl_surface = eglCreatePixmapSurface(_egl_display, eglgsg->_fbconfig, (NativePixmapType) _x_pixmap, NULL);
236 if (_egl_surface == EGL_NO_SURFACE) {
237 egldisplay_cat.error()
238 <<
"Failed to create EGL pixmap surface:" 239 << get_egl_error_string(eglGetError()) <<
"\n";
244 eglMakeCurrent(_egl_display, _egl_surface, _egl_surface, eglgsg->_context);
245 eglgsg->reset_if_new();
246 if (!eglgsg->is_valid()) {
251 (_fb_properties, eglgsg->get_gl_renderer())) {
virtual void end_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread after rendering is completed for a given frame...
An interface to the egl system for managing GLES windows under X.
X11_Window get_root() const
Returns the handle to the root window on the pipe's display.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
This graphics pipe represents the interface for creating OpenGL ES graphics windows on an X-based (e...
int get_screen() const
Returns the X screen number associated with the pipe.
const FrameBufferProperties & get_fb_properties() const
Gets the FrameBufferProperties for all windows and buffers that use this GSG.
X11_Display * get_display() const
Returns a pointer to the X display associated with the pipe: the display on which to create the windo...
A container for the various kinds of properties we might ask to have on a graphics window before we o...
An offscreen buffer for rendering into.
virtual bool begin_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread before beginning rendering for a given frame...
An object to create GraphicsOutputs that share a particular 3-D API.
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
bool verify_hardware_software(const FrameBufferProperties &props, const string &renderer) const
Validates that the properties represent the desired kind of renderer (hardware or software)...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
Another offscreen buffer in the EGL environment.
This is a base class for the various different classes that represent the result of a frame of render...
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.
X11_Window get_xwindow() const
Returns the X11 Window handle.
A thread; that is, a lightweight process.
Encapsulates all the communication with a particular instance of a given rendering backend...
A tiny specialization on GLESGraphicsStateGuardian to add some egl-specific information.
bool subsumes(const FrameBufferProperties &other) const
Returns true if this set of properties makes strictly greater or equal demands of the framebuffer tha...
This class is the main interface to controlling the render process.
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...
const FrameBufferProperties & get_fb_properties() const
Returns the framebuffer properties of the window.