39 const std::string &name,
57 PStatTimer timer(_make_current_pcollector, current_thread);
59 begin_frame_spam(mode);
60 if (_gsg ==
nullptr) {
63 if (_awaiting_configure) {
70 DCAST_INTO_R(glxgsg, _gsg,
false);
74 if (glXGetCurrentDisplay() == _display &&
75 glXGetCurrentDrawable() == _xwindow &&
76 glXGetCurrentContext() == glxgsg->_context) {
81 glXMakeCurrent(_display, _xwindow, glxgsg->_context);
89 glxgsg->reset_if_new();
91 if (mode == FM_render) {
92 glxgsg->push_group_marker(std::string(
"glxGraphicsWindow ") +
get_name());
94 clear_cube_map_selection();
98 return _gsg->begin_frame(current_thread);
109 end_frame_spam(mode);
110 nassertv(_gsg !=
nullptr);
112 if (mode == FM_render) {
117 _gsg->end_frame(current_thread);
119 if (mode == FM_render) {
121 clear_cube_map_selection();
124 DCAST_INTO_V(glxgsg, _gsg);
125 glxgsg->pop_group_marker();
138 if (_gsg !=
nullptr && _flip_ready) {
147 glXSwapBuffers(_display, _xwindow);
155 void glxGraphicsWindow::
159 if (_gsg !=
nullptr) {
160 glXMakeCurrent(_display, None,
nullptr);
164 x11GraphicsWindow::close_window();
171 bool glxGraphicsWindow::
174 DCAST_INTO_R(glx_pipe, _pipe,
false);
178 if (_gsg ==
nullptr) {
186 DCAST_INTO_R(glxgsg, _gsg,
false);
194 if (glxgsg->_context ==
nullptr) {
196 glxdisplay_cat.error()
197 <<
"No GLX context: cannot open window.\n";
201 _visual_info = glxgsg->_visual;
202 if (_visual_info ==
nullptr) {
204 glxdisplay_cat.error()
205 <<
"No X visual: cannot open window.\n";
211 if (glxgsg->_fbconfig != None) {
212 setup_colormap(glxgsg->_fbconfig);
214 setup_colormap(_visual_info);
217 if (!x11GraphicsWindow::open_window()) {
221 glXMakeCurrent(_display, _xwindow, glxgsg->_context);
222 glxgsg->reset_if_new();
223 if (!glxgsg->is_valid()) {
228 (_fb_properties, glxgsg->get_gl_renderer())) {
241 void glxGraphicsWindow::
242 setup_colormap(GLXFBConfig fbconfig) {
244 DCAST_INTO_V(glxgsg, _gsg);
245 nassertv(glxgsg->_supports_fbconfig);
247 XVisualInfo *visual_info = glxgsg->_glXGetVisualFromFBConfig(_display, fbconfig);
248 if (visual_info ==
nullptr) {
252 int visual_class = visual_info->c_class;
253 Visual *visual = visual_info->visual;
257 DCAST_INTO_V(glx_pipe, _pipe);
258 X11_Window root_window = glx_pipe->
get_root();
262 switch (visual_class) {
264 rc = glxgsg->_glXGetFBConfigAttrib(_display, fbconfig, GLX_RGBA, &is_rgb);
265 if (rc == 0 && is_rgb) {
266 glxdisplay_cat.warning()
267 <<
"mesa pseudocolor not supported.\n";
269 _colormap = (Colormap)0;
272 _colormap = XCreateColormap(_display, root_window,
278 _colormap = XCreateColormap(_display, root_window,
284 _colormap = XCreateColormap(_display, root_window,
288 glxdisplay_cat.error()
289 <<
"Could not allocate a colormap for visual class "
290 << visual_class <<
".\n";
299 void glxGraphicsWindow::
300 setup_colormap(XVisualInfo *visual) {
302 DCAST_INTO_V(glx_pipe, _pipe);
303 X11_Window root_window = glx_pipe->
get_root();
305 int visual_class = visual->c_class;
308 switch (visual_class) {
310 rc = glXGetConfig(_display, visual, GLX_RGBA, &is_rgb);
311 if (rc == 0 && is_rgb) {
312 glxdisplay_cat.warning()
313 <<
"mesa pseudocolor not supported.\n";
315 _colormap = (Colormap)0;
318 _colormap = XCreateColormap(_display, root_window,
319 visual->visual, AllocAll);
324 _colormap = XCreateColormap(_display, root_window,
325 visual->visual, AllocNone);
330 _colormap = XCreateColormap(_display, root_window,
331 visual->visual, AllocNone);
334 glxdisplay_cat.error()
335 <<
"Could not allocate a colormap for visual class "
336 << visual_class <<
".\n";