Panda3D

wglGraphicsStateGuardian.h

00001 // Filename: wglGraphicsStateGuardian.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 WGLGRAPHICSSTATEGUARDIAN_H
00016 #define WGLGRAPHICSSTATEGUARDIAN_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "glgsg.h"
00021 
00022 // This must be included after we have included glgsg.h (which
00023 // includes gl.h).
00024 #include "wglext.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : wglGraphicsStateGuardian
00028 // Description : A tiny specialization on GLGraphicsStateGuardian to
00029 //               add some wgl-specific information.
00030 ////////////////////////////////////////////////////////////////////
00031 class wglGraphicsStateGuardian : public GLGraphicsStateGuardian {
00032 public:
00033   wglGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe,
00034                            wglGraphicsStateGuardian *share_with);
00035   virtual ~wglGraphicsStateGuardian();
00036 
00037   INLINE int get_pfnum() const;
00038   INLINE bool pfnum_supports_pbuffer() const;
00039   INLINE const FrameBufferProperties &get_fb_properties() const;
00040   bool fail_pfnum();
00041 
00042   INLINE bool made_context() const;
00043   INLINE HGLRC get_context(HDC hdc);
00044   void get_properties(FrameBufferProperties &properties, HDC hdc, int pfnum);
00045   bool get_properties_advanced(FrameBufferProperties &properties, HDC hdc, int pfnum);
00046   void choose_pixel_format(const FrameBufferProperties &properties, bool need_pbuffer);
00047   virtual void reset();
00048 
00049   INLINE HDC get_twindow_dc();
00050 
00051   static bool get_gamma_table(void);
00052   static bool static_set_gamma(bool restore, float gamma);
00053   bool set_gamma(float gamma);
00054   void restore_gamma();
00055   static void atexit_function(void);
00056 
00057 protected:
00058   virtual void get_extra_extensions();
00059   virtual void *do_get_extension_func(const char *prefix, const char *name);
00060 
00061 private:
00062   void make_context(HDC hdc);
00063   HGLRC get_share_context() const;
00064   void redirect_share_pool(wglGraphicsStateGuardian *share_with);
00065   
00066 
00067   bool make_twindow();
00068   void release_twindow();
00069 
00070   static void register_twindow_class();
00071 
00072   // We have to save a pointer to the GSG we intend to share texture
00073   // context with, since we don't create our own context in the
00074   // constructor.
00075   PT(wglGraphicsStateGuardian) _share_with;
00076 
00077   // These properties are for all wglGraphicsWindow that use this gsg.
00078   FrameBufferProperties _pfnum_properties;
00079   bool _pfnum_supports_pbuffer;
00080   int _pfnum;
00081 
00082   // This pfnum is the pfnum chosen via DescribePixelFormat.  It is
00083   // used in case the one returned by wglChoosePixelFormatARB() fails.
00084   FrameBufferProperties _pre_pfnum_properties;
00085   int _pre_pfnum;
00086 
00087   
00088   bool _made_context;
00089   HGLRC _context;
00090 
00091   HWND _twindow;
00092   HDC _twindow_dc;
00093 
00094   static const char * const _twindow_class_name;
00095   static bool _twindow_class_registered;
00096 
00097 public:
00098   bool _supports_swap_control;
00099   PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT;
00100 
00101   bool _supports_pbuffer;
00102   PFNWGLCREATEPBUFFERARBPROC _wglCreatePbufferARB;
00103   PFNWGLGETPBUFFERDCARBPROC _wglGetPbufferDCARB;
00104   PFNWGLRELEASEPBUFFERDCARBPROC _wglReleasePbufferDCARB;
00105   PFNWGLDESTROYPBUFFERARBPROC _wglDestroyPbufferARB;
00106   PFNWGLQUERYPBUFFERARBPROC _wglQueryPbufferARB;
00107 
00108   bool _supports_pixel_format;
00109   PFNWGLGETPIXELFORMATATTRIBIVARBPROC _wglGetPixelFormatAttribivARB;
00110   PFNWGLGETPIXELFORMATATTRIBFVARBPROC _wglGetPixelFormatAttribfvARB;
00111   PFNWGLCHOOSEPIXELFORMATARBPROC _wglChoosePixelFormatARB;
00112 
00113   bool _supports_wgl_multisample;
00114 
00115   PFNWGLBINDTEXIMAGEARBPROC _wglBindTexImageARB;
00116   PFNWGLRELEASETEXIMAGEARBPROC _wglReleaseTexImageARB;
00117   PFNWGLSETPBUFFERATTRIBARBPROC _wglSetPbufferAttribARB;
00118 
00119 public:
00120   static TypeHandle get_class_type() {
00121     return _type_handle;
00122   }
00123   static void init_type() {
00124     GLGraphicsStateGuardian::init_type();
00125     register_type(_type_handle, "wglGraphicsStateGuardian",
00126                   GLGraphicsStateGuardian::get_class_type());
00127   }
00128   virtual TypeHandle get_type() const {
00129     return get_class_type();
00130   }
00131   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00132 
00133 private:
00134   static TypeHandle _type_handle;
00135 
00136   friend class wglGraphicsBuffer;
00137 };
00138 
00139 #include "wglGraphicsStateGuardian.I"
00140 
00141 #endif
 All Classes Functions Variables Enumerations