Panda3D
 All Classes Functions Variables Enumerations
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   INLINE bool get_supports_wgl_render_texture() const;
00051 
00052   static bool get_gamma_table(void);
00053   static bool static_set_gamma(bool restore, PN_stdfloat gamma);
00054   bool set_gamma(PN_stdfloat gamma);
00055   void restore_gamma();
00056   static void atexit_function(void);
00057 
00058 
00059 protected:
00060   virtual void get_extra_extensions();
00061   virtual void *do_get_extension_func(const char *prefix, const char *name);
00062 
00063 private:
00064   void make_context(HDC hdc);
00065   HGLRC get_share_context() const;
00066   void redirect_share_pool(wglGraphicsStateGuardian *share_with);
00067   
00068 
00069   bool make_twindow();
00070   void release_twindow();
00071 
00072   static void register_twindow_class();
00073 
00074   // We have to save a pointer to the GSG we intend to share texture
00075   // context with, since we don't create our own context in the
00076   // constructor.
00077   PT(wglGraphicsStateGuardian) _share_with;
00078 
00079   // These properties are for all wglGraphicsWindow that use this gsg.
00080   FrameBufferProperties _pfnum_properties;
00081   bool _pfnum_supports_pbuffer;
00082   int _pfnum;
00083 
00084   // This pfnum is the pfnum chosen via DescribePixelFormat.  It is
00085   // used in case the one returned by wglChoosePixelFormatARB() fails.
00086   FrameBufferProperties _pre_pfnum_properties;
00087   int _pre_pfnum;
00088 
00089   bool _made_context;
00090   HGLRC _context;
00091 
00092   HWND _twindow;
00093   HDC _twindow_dc;
00094 
00095   static const char * const _twindow_class_name;
00096   static bool _twindow_class_registered;
00097 
00098 public:
00099   bool _supports_swap_control;
00100   PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT;
00101 
00102   bool _supports_pbuffer;
00103   PFNWGLCREATEPBUFFERARBPROC _wglCreatePbufferARB;
00104   PFNWGLGETPBUFFERDCARBPROC _wglGetPbufferDCARB;
00105   PFNWGLRELEASEPBUFFERDCARBPROC _wglReleasePbufferDCARB;
00106   PFNWGLDESTROYPBUFFERARBPROC _wglDestroyPbufferARB;
00107   PFNWGLQUERYPBUFFERARBPROC _wglQueryPbufferARB;
00108 
00109   bool _supports_pixel_format;
00110   PFNWGLGETPIXELFORMATATTRIBIVARBPROC _wglGetPixelFormatAttribivARB;
00111   PFNWGLGETPIXELFORMATATTRIBFVARBPROC _wglGetPixelFormatAttribfvARB;
00112   PFNWGLCHOOSEPIXELFORMATARBPROC _wglChoosePixelFormatARB;
00113 
00114   bool _supports_wgl_multisample;
00115 
00116   bool _supports_wgl_render_texture;
00117   PFNWGLBINDTEXIMAGEARBPROC _wglBindTexImageARB;
00118   PFNWGLRELEASETEXIMAGEARBPROC _wglReleaseTexImageARB;
00119   PFNWGLSETPBUFFERATTRIBARBPROC _wglSetPbufferAttribARB;
00120 
00121 public:
00122   static TypeHandle get_class_type() {
00123     return _type_handle;
00124   }
00125   static void init_type() {
00126     GLGraphicsStateGuardian::init_type();
00127     register_type(_type_handle, "wglGraphicsStateGuardian",
00128                   GLGraphicsStateGuardian::get_class_type());
00129   }
00130   virtual TypeHandle get_type() const {
00131     return get_class_type();
00132   }
00133   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00134 
00135 private:
00136   static TypeHandle _type_handle;
00137 
00138   friend class wglGraphicsBuffer;
00139 };
00140 
00141 #include "wglGraphicsStateGuardian.I"
00142 
00143 #endif
 All Classes Functions Variables Enumerations