Panda3D
|
00001 // Filename: glxGraphicsStateGuardian.h 00002 // Created by: drose (27Jan03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef GLXGRAPHICSSTATEGUARDIAN_H 00016 #define GLXGRAPHICSSTATEGUARDIAN_H 00017 00018 #include "pandabase.h" 00019 00020 #include "glgsg.h" 00021 #include "glxGraphicsPipe.h" 00022 00023 // Don't pick up the system glxext.h; use our own, which is better. 00024 #define __glxext_h_ 00025 00026 #include <GL/glx.h> 00027 00028 #if defined(GLX_VERSION_1_4) 00029 // If the system header files give us version 1.4, we can assume it's 00030 // safe to compile in a reference to glxGetProcAddress(). 00031 #define HAVE_GLXGETPROCADDRESS 1 00032 00033 #elif defined(GLX_ARB_get_proc_address) 00034 // Maybe the system header files give us the corresponding ARB call. 00035 #define HAVE_GLXGETPROCADDRESSARB 1 00036 00037 // Sometimes the system header files don't define this prototype for 00038 // some reason. 00039 extern "C" void (*glXGetProcAddressARB(const GLubyte *procName))( void ); 00040 00041 #endif 00042 00043 // This must be included after we have included glgsg.h (which 00044 // includes gl.h). 00045 #include "panda_glxext.h" 00046 00047 // drose: the version of GL/glx.h that ships with Fedora Core 2 seems 00048 // to define GLX_VERSION_1_4, but for some reason does not define 00049 // GLX_SAMPLE_BUFFERS or GLX_SAMPLES. We work around that here. 00050 00051 #ifndef GLX_SAMPLE_BUFFERS 00052 #define GLX_SAMPLE_BUFFERS 100000 00053 #endif 00054 #ifndef GLX_SAMPLES 00055 #define GLX_SAMPLES 100001 00056 #endif 00057 00058 // These typedefs are declared in glxext.h, but we must repeat them 00059 // here, mainly because they will not be included from glxext.h if the 00060 // system GLX version matches or exceeds the GLX version in which 00061 // these functions are defined, and the system glx.h sometimes doesn't 00062 // declare these typedefs. 00063 #ifndef __EDG__ // Protect the following from the Tau instrumentor. 00064 typedef __GLXextFuncPtr (* PFNGLXGETPROCADDRESSPROC) (const GLubyte *procName); 00065 typedef int (* PFNGLXSWAPINTERVALSGIPROC) (int interval); 00066 00067 typedef GLXFBConfig * (* PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements); 00068 typedef GLXContext (* PFNGLXCREATENEWCONTEXTPROC) (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct); 00069 typedef XVisualInfo * (* PFNGLXGETVISUALFROMFBCONFIGPROC) (Display *dpy, GLXFBConfig config); 00070 typedef int (* PFNGLXGETFBCONFIGATTRIBPROC) (Display *dpy, GLXFBConfig config, int attribute, int *value); 00071 typedef GLXPixmap (* PFNGLXCREATEPIXMAPPROC) (Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attrib_list); 00072 typedef GLXPbuffer (* PFNGLXCREATEPBUFFERPROC) (Display *dpy, GLXFBConfig config, const int *attrib_list); 00073 typedef void (* PFNGLXDESTROYPBUFFERPROC) (Display *dpy, GLXPbuffer pbuf); 00074 00075 #endif // __EDG__ 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Class : glxGraphicsStateGuardian 00079 // Description : A tiny specialization on GLGraphicsStateGuardian to 00080 // add some glx-specific information. 00081 //////////////////////////////////////////////////////////////////// 00082 class glxGraphicsStateGuardian : public GLGraphicsStateGuardian { 00083 public: 00084 INLINE const FrameBufferProperties &get_fb_properties() const; 00085 void get_properties(FrameBufferProperties &properties, XVisualInfo *visual); 00086 void get_properties_advanced(FrameBufferProperties &properties, 00087 bool &context_has_pbuffer, bool &pixmap_supported, 00088 bool &slow, GLXFBConfig config); 00089 void choose_pixel_format(const FrameBufferProperties &properties, 00090 Display *_display, 00091 int _screen, 00092 bool need_pbuffer, bool need_pixmap); 00093 00094 glxGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe, 00095 glxGraphicsStateGuardian *share_with); 00096 00097 virtual ~glxGraphicsStateGuardian(); 00098 00099 virtual void reset(); 00100 00101 bool glx_is_at_least_version(int major_version, int minor_version) const; 00102 00103 GLXContext _share_context; 00104 GLXContext _context; 00105 Display *_display; 00106 int _screen; 00107 XVisualInfo *_visual; 00108 XVisualInfo *_visuals; 00109 00110 GLXFBConfig _fbconfig; 00111 FrameBufferProperties _fbprops; 00112 bool _context_has_pbuffer; // true if the particular fbconfig supports pbuffers 00113 bool _context_has_pixmap; 00114 bool _slow; 00115 00116 public: 00117 bool _supports_swap_control; 00118 PFNGLXSWAPINTERVALSGIPROC _glXSwapIntervalSGI; 00119 00120 bool _supports_fbconfig; 00121 PFNGLXCHOOSEFBCONFIGPROC _glXChooseFBConfig; 00122 PFNGLXCREATENEWCONTEXTPROC _glXCreateNewContext; 00123 PFNGLXGETVISUALFROMFBCONFIGPROC _glXGetVisualFromFBConfig; 00124 PFNGLXGETFBCONFIGATTRIBPROC _glXGetFBConfigAttrib; 00125 PFNGLXCREATEPIXMAPPROC _glXCreatePixmap; 00126 00127 bool _supports_pbuffer; // true if the interface is available. 00128 bool _uses_sgix_pbuffer; 00129 PFNGLXCREATEPBUFFERPROC _glXCreatePbuffer; 00130 PFNGLXCREATEGLXPBUFFERSGIXPROC _glXCreateGLXPbufferSGIX; 00131 PFNGLXDESTROYPBUFFERPROC _glXDestroyPbuffer; 00132 00133 protected: 00134 virtual void gl_flush() const; 00135 virtual GLenum gl_get_error() const; 00136 00137 virtual void query_gl_version(); 00138 virtual void get_extra_extensions(); 00139 virtual void *do_get_extension_func(const char *prefix, const char *name); 00140 00141 private: 00142 void *get_system_func(const char *name); 00143 void show_glx_client_string(const string &name, int id); 00144 void show_glx_server_string(const string &name, int id); 00145 void choose_temp_visual(const FrameBufferProperties &properties); 00146 void init_temp_context(); 00147 void destroy_temp_xwindow(); 00148 00149 int _glx_version_major, _glx_version_minor; 00150 00151 void *_libgl_handle; 00152 bool _checked_get_proc_address; 00153 PFNGLXGETPROCADDRESSPROC _glXGetProcAddress; 00154 00155 GLXContext _temp_context; 00156 Window _temp_xwindow; 00157 Colormap _temp_colormap; 00158 00159 public: 00160 static TypeHandle get_class_type() { 00161 return _type_handle; 00162 } 00163 static void init_type() { 00164 GLGraphicsStateGuardian::init_type(); 00165 register_type(_type_handle, "glxGraphicsStateGuardian", 00166 GLGraphicsStateGuardian::get_class_type()); 00167 } 00168 virtual TypeHandle get_type() const { 00169 return get_class_type(); 00170 } 00171 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00172 00173 private: 00174 static TypeHandle _type_handle; 00175 }; 00176 00177 #include "glxGraphicsStateGuardian.I" 00178 00179 #endif