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