Panda3D
glxGraphicsStateGuardian.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file glxGraphicsStateGuardian.h
10  * @author drose
11  * @date 2003-01-27
12  */
13 
14 #ifndef GLXGRAPHICSSTATEGUARDIAN_H
15 #define GLXGRAPHICSSTATEGUARDIAN_H
16 
17 #include "pandabase.h"
18 
19 #include "glgsg.h"
20 #include "glxGraphicsPipe.h"
22 
23 #if defined(GLX_VERSION_1_4)
24 // If the system header files give us version 1.4, we can assume it's safe to
25 // compile in a reference to glxGetProcAddress().
26 #define HAVE_GLXGETPROCADDRESS 1
27 
28 #elif defined(GLX_ARB_get_proc_address)
29 // Maybe the system header files give us the corresponding ARB call.
30 #define HAVE_GLXGETPROCADDRESSARB 1
31 
32 // Sometimes the system header files don't define this prototype for some
33 // reason.
34 extern "C" void (*glXGetProcAddressARB(const GLubyte *procName))( void );
35 
36 #endif
37 
38 // This must be included after we have included glgsg.h (which includes gl.h).
39 #include "panda_glxext.h"
40 
41 // drose: the version of GLglx.h that ships with Fedora Core 2 seems to define
42 // GLX_VERSION_1_4, but for some reason does not define GLX_SAMPLE_BUFFERS or
43 // GLX_SAMPLES. We work around that here.
44 
45 #ifndef GLX_SAMPLE_BUFFERS
46 #define GLX_SAMPLE_BUFFERS 100000
47 #endif
48 #ifndef GLX_SAMPLES
49 #define GLX_SAMPLES 100001
50 #endif
51 
52 // These typedefs are declared in glxext.h, but we must repeat them here,
53 // mainly because they will not be included from glxext.h if the system GLX
54 // version matches or exceeds the GLX version in which these functions are
55 // defined, and the system glx.h sometimes doesn't declare these typedefs.
56 #ifndef __EDG__ // Protect the following from the Tau instrumentor.
57 typedef __GLXextFuncPtr (* PFNGLXGETPROCADDRESSPROC) (const GLubyte *procName);
58 typedef int (* PFNGLXSWAPINTERVALSGIPROC) (int interval);
59 
60 typedef GLXFBConfig * (* PFNGLXCHOOSEFBCONFIGPROC) (X11_Display *dpy, int screen, const int *attrib_list, int *nelements);
61 typedef GLXContext (* PFNGLXCREATENEWCONTEXTPROC) (X11_Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
62 typedef XVisualInfo * (* PFNGLXGETVISUALFROMFBCONFIGPROC) (X11_Display *dpy, GLXFBConfig config);
63 typedef int (* PFNGLXGETFBCONFIGATTRIBPROC) (X11_Display *dpy, GLXFBConfig config, int attribute, int *value);
64 typedef GLXPixmap (* PFNGLXCREATEPIXMAPPROC) (X11_Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list);
65 typedef GLXPbuffer (* PFNGLXCREATEPBUFFERPROC) (X11_Display *dpy, GLXFBConfig config, const int *attrib_list);
66 typedef void (* PFNGLXDESTROYPBUFFERPROC) (X11_Display *dpy, GLXPbuffer pbuf);
67 typedef GLXContext ( *PFNGLXCREATECONTEXTATTRIBSARBPROC) (X11_Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list);
68 #endif // __EDG__
69 
70 /**
71  * A tiny specialization on GLGraphicsStateGuardian to add some glx-specific
72  * information.
73  */
75 public:
76  INLINE const FrameBufferProperties &get_fb_properties() const;
77  void get_properties(FrameBufferProperties &properties, XVisualInfo *visual);
79  bool &context_has_pbuffer, bool &pixmap_supported,
80  bool &slow, GLXFBConfig config);
81  void choose_pixel_format(const FrameBufferProperties &properties,
82  X11_Display *_display,
83  int _screen,
84  bool need_pbuffer, bool need_pixmap);
85 
87  glxGraphicsStateGuardian *share_with);
88 
89  virtual ~glxGraphicsStateGuardian();
90 
91  bool glx_is_at_least_version(int major_version, int minor_version) const;
92 
93  GLXContext _share_context;
94  GLXContext _context;
95  X11_Display *_display;
96  int _screen;
97  XVisualInfo *_visual;
98  XVisualInfo *_visuals;
99 
100  GLXFBConfig _fbconfig;
101  FrameBufferProperties _fbprops;
102  bool _context_has_pbuffer; // true if the particular fbconfig supports pbuffers
103  bool _context_has_pixmap;
104  bool _slow;
105 
106 public:
107  bool _supports_swap_control;
108  PFNGLXSWAPINTERVALSGIPROC _glXSwapIntervalSGI;
109 
110  bool _supports_fbconfig;
111  PFNGLXCHOOSEFBCONFIGPROC _glXChooseFBConfig;
112  PFNGLXCREATENEWCONTEXTPROC _glXCreateNewContext;
113  PFNGLXGETVISUALFROMFBCONFIGPROC _glXGetVisualFromFBConfig;
114  PFNGLXGETFBCONFIGATTRIBPROC _glXGetFBConfigAttrib;
115  PFNGLXCREATEPIXMAPPROC _glXCreatePixmap;
116  PFNGLXCREATECONTEXTATTRIBSARBPROC _glXCreateContextAttribs;
117 
118  bool _supports_pbuffer; // true if the interface is available.
119  bool _uses_sgix_pbuffer;
120  PFNGLXCREATEPBUFFERPROC _glXCreatePbuffer;
121  PFNGLXCREATEGLXPBUFFERSGIXPROC _glXCreateGLXPbufferSGIX;
122  PFNGLXDESTROYPBUFFERPROC _glXDestroyPbuffer;
123 
124 protected:
125  virtual void gl_flush() const;
126  virtual GLenum gl_get_error() const;
127 
128  virtual void query_gl_version();
129  virtual void get_extra_extensions();
130  virtual void *do_get_extension_func(const char *name);
131 
132 private:
133  void query_glx_extensions();
134  void show_glx_client_string(const std::string &name, int id);
135  void show_glx_server_string(const std::string &name, int id);
136  void choose_temp_visual(const FrameBufferProperties &properties);
137  void init_temp_context();
138  void destroy_temp_xwindow();
139 
140  int _glx_version_major, _glx_version_minor;
141 
142  bool _checked_get_proc_address;
143  PFNGLXGETPROCADDRESSPROC _glXGetProcAddress;
144 
145  GLXContext _temp_context;
146  X11_Window _temp_xwindow;
147  Colormap _temp_colormap;
148 
149 public:
150  static TypeHandle get_class_type() {
151  return _type_handle;
152  }
153  static void init_type() {
154  PosixGraphicsStateGuardian::init_type();
155  register_type(_type_handle, "glxGraphicsStateGuardian",
156  PosixGraphicsStateGuardian::get_class_type());
157  }
158  virtual TypeHandle get_type() const {
159  return get_class_type();
160  }
161  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
162 
163 private:
164  static TypeHandle _type_handle;
165 };
166 
168 
169 #endif
A tiny specialization on GLGraphicsStateGuardian to add some glx-specific information.
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.
const FrameBufferProperties & get_fb_properties() const
Gets the FrameBufferProperties for all windows and buffers that use this GSG.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This GSG is used only for CallbackGraphicsWindow (which might not be using the glx interfaces),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool glx_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.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:52
void get_properties(FrameBufferProperties &properties, XVisualInfo *visual)
Gets the FrameBufferProperties to match the indicated visual.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void get_properties_advanced(FrameBufferProperties &properties, bool &context_has_pbuffer, bool &pixmap_supported, bool &slow, GLXFBConfig config)
Gets the FrameBufferProperties to match the indicated GLXFBConfig.
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.