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