15 #include "glxGraphicsWindow.h"
16 #include "glxGraphicsStateGuardian.h"
17 #include "config_glxdisplay.h"
18 #include "glxGraphicsPipe.h"
20 #include "graphicsPipe.h"
21 #include "keyboardButton.h"
22 #include "mouseButton.h"
24 #include "clockObject.h"
25 #include "pStatTimer.h"
26 #include "textEncoder.h"
27 #include "throw_event.h"
28 #include "lightReMutexHolder.h"
63 PStatTimer timer(_make_current_pcollector, current_thread);
65 begin_frame_spam(mode);
69 if (_awaiting_configure) {
76 DCAST_INTO_R(glxgsg, _gsg,
false);
80 if (glXGetCurrentDisplay() == _display &&
81 glXGetCurrentDrawable() == _xwindow &&
82 glXGetCurrentContext() == glxgsg->_context) {
87 glXMakeCurrent(_display, _xwindow, glxgsg->_context);
95 glxgsg->reset_if_new();
97 if (mode == FM_render) {
99 clear_cube_map_selection();
103 return _gsg->begin_frame(current_thread);
127 glXSwapBuffers(_display, _xwindow);
138 void glxGraphicsWindow::
141 glXMakeCurrent(_display, None, NULL);
145 x11GraphicsWindow::close_window();
155 bool glxGraphicsWindow::
158 DCAST_INTO_R(glx_pipe, _pipe,
false);
170 DCAST_INTO_R(glxgsg, _gsg,
false);
178 if (glxgsg->_context == NULL) {
180 glxdisplay_cat.error()
181 <<
"No GLX context: cannot open window.\n";
185 _visual_info = glxgsg->_visual;
186 if (_visual_info == NULL) {
188 glxdisplay_cat.error()
189 <<
"No X visual: cannot open window.\n";
192 Visual *visual = _visual_info->visual;
194 if (glxgsg->_fbconfig != None) {
195 setup_colormap(glxgsg->_fbconfig);
197 setup_colormap(_visual_info);
200 if (!x11GraphicsWindow::open_window()) {
204 glXMakeCurrent(_display, _xwindow, glxgsg->_context);
205 glxgsg->reset_if_new();
206 if (!glxgsg->is_valid()) {
211 (_fb_properties, glxgsg->get_gl_renderer())) {
226 void glxGraphicsWindow::
227 setup_colormap(GLXFBConfig fbconfig) {
229 DCAST_INTO_V(glxgsg, _gsg);
230 nassertv(glxgsg->_supports_fbconfig);
232 XVisualInfo *visual_info = glxgsg->_glXGetVisualFromFBConfig(_display, fbconfig);
233 if (visual_info == NULL) {
237 int visual_class = visual_info->c_class;
238 Visual *visual = visual_info->visual;
242 DCAST_INTO_V(glx_pipe, _pipe);
243 X11_Window root_window = glx_pipe->
get_root();
247 switch (visual_class) {
249 rc = glxgsg->_glXGetFBConfigAttrib(_display, fbconfig, GLX_RGBA, &is_rgb);
250 if (rc == 0 && is_rgb) {
251 glxdisplay_cat.warning()
252 <<
"mesa pseudocolor not supported.\n";
254 _colormap = (Colormap)0;
257 _colormap = XCreateColormap(_display, root_window,
263 _colormap = XCreateColormap(_display, root_window,
269 _colormap = XCreateColormap(_display, root_window,
273 glxdisplay_cat.error()
274 <<
"Could not allocate a colormap for visual class "
275 << visual_class <<
".\n";
286 void glxGraphicsWindow::
287 setup_colormap(XVisualInfo *visual) {
289 DCAST_INTO_V(glx_pipe, _pipe);
290 X11_Window root_window = glx_pipe->
get_root();
292 int visual_class = visual->c_class;
295 switch (visual_class) {
297 rc = glXGetConfig(_display, visual, GLX_RGBA, &is_rgb);
298 if (rc == 0 && is_rgb) {
299 glxdisplay_cat.warning()
300 <<
"mesa pseudocolor not supported.\n";
302 _colormap = (Colormap)0;
305 _colormap = XCreateColormap(_display, root_window,
306 visual->visual, AllocAll);
311 _colormap = XCreateColormap(_display, root_window,
312 visual->visual, AllocNone);
317 _colormap = XCreateColormap(_display, root_window,
318 visual->visual, AllocNone);
321 glxdisplay_cat.error()
322 <<
"Could not allocate a colormap for visual class "
323 << visual_class <<
".\n";
This graphics pipe represents the interface for creating OpenGL graphics windows on an X-based (e...
A tiny specialization on GLGraphicsStateGuardian to add some glx-specific information.
const FrameBufferProperties & get_fb_properties() const
Gets the FrameBufferProperties for all windows and buffers that use this GSG.
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
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_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...
int get_screen() const
Returns the X screen number associated with the pipe.
bool subsumes(const FrameBufferProperties &other) const
Returns true if this set of properties makes strictly greater or equal demands of the framebuffer tha...
bool verify_hardware_software(const FrameBufferProperties &props, const string &renderer) const
Validates that the properties represent the desired kind of renderer (hardware or software)...
A container for the various kinds of properties we might ask to have on a graphics window before we o...
An object to create GraphicsOutputs that share a particular 3-D API.
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
X11_Display * get_display() const
Returns a pointer to the X display associated with the pipe: the display on which to create the windo...
This is a base class for the various different classes that represent the result of a frame of render...
Similar to MutexHolder, but for a light reentrant mutex.
A thread; that is, a lightweight process.
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
const FrameBufferProperties & get_fb_properties() const
Returns the framebuffer properties of the window.
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...
Interfaces to the X11 window system.
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...