Panda3D
wglGraphicsStateGuardian.h
1 // Filename: wglGraphicsStateGuardian.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 WGLGRAPHICSSTATEGUARDIAN_H
16 #define WGLGRAPHICSSTATEGUARDIAN_H
17 
18 #include "pandabase.h"
19 
20 #include "glgsg.h"
21 
22 // This must be included after we have included glgsg.h (which
23 // includes gl.h).
24 #include "wglext.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : wglGraphicsStateGuardian
28 // Description : A tiny specialization on GLGraphicsStateGuardian to
29 // add some wgl-specific information.
30 ////////////////////////////////////////////////////////////////////
31 class wglGraphicsStateGuardian : public GLGraphicsStateGuardian {
32 public:
34  wglGraphicsStateGuardian *share_with);
35  virtual ~wglGraphicsStateGuardian();
36 
37  INLINE int get_pfnum() const;
38  INLINE bool pfnum_supports_pbuffer() const;
39  INLINE const FrameBufferProperties &get_fb_properties() const;
40  bool fail_pfnum();
41 
42  INLINE bool made_context() const;
43  INLINE HGLRC get_context(HDC hdc);
44  void get_properties(FrameBufferProperties &properties, HDC hdc, int pfnum);
45  bool get_properties_advanced(FrameBufferProperties &properties, HDC hdc, int pfnum);
46  void choose_pixel_format(const FrameBufferProperties &properties, bool need_pbuffer);
47  virtual void reset();
48 
49  INLINE HDC get_twindow_dc();
50  INLINE bool get_supports_wgl_render_texture() const;
51 
52  static bool get_gamma_table(void);
53  static bool static_set_gamma(bool restore, PN_stdfloat gamma);
54  bool set_gamma(PN_stdfloat gamma);
55  void restore_gamma();
56  static void atexit_function(void);
57 
58 
59 protected:
60  virtual void get_extra_extensions();
61  virtual void *do_get_extension_func(const char *name);
62 
63 private:
64  void make_context(HDC hdc);
65  HGLRC get_share_context() const;
66  void redirect_share_pool(wglGraphicsStateGuardian *share_with);
67 
68 
69  bool make_twindow();
70  void release_twindow();
71 
72  static void register_twindow_class();
73 
74  // We have to save a pointer to the GSG we intend to share texture
75  // context with, since we don't create our own context in the
76  // constructor.
77  PT(wglGraphicsStateGuardian) _share_with;
78 
79  // These properties are for all wglGraphicsWindow that use this gsg.
80  FrameBufferProperties _pfnum_properties;
81  bool _pfnum_supports_pbuffer;
82  int _pfnum;
83 
84  // This pfnum is the pfnum chosen via DescribePixelFormat. It is
85  // used in case the one returned by wglChoosePixelFormatARB() fails.
86  FrameBufferProperties _pre_pfnum_properties;
87  int _pre_pfnum;
88 
89  bool _made_context;
90  HGLRC _context;
91 
92  HWND _twindow;
93  HDC _twindow_dc;
94 
95  static const char * const _twindow_class_name;
96  static bool _twindow_class_registered;
97 
98 public:
99  bool _supports_swap_control;
100  PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT;
101 
102  bool _supports_pbuffer;
103  PFNWGLCREATEPBUFFERARBPROC _wglCreatePbufferARB;
104  PFNWGLGETPBUFFERDCARBPROC _wglGetPbufferDCARB;
105  PFNWGLRELEASEPBUFFERDCARBPROC _wglReleasePbufferDCARB;
106  PFNWGLDESTROYPBUFFERARBPROC _wglDestroyPbufferARB;
107  PFNWGLQUERYPBUFFERARBPROC _wglQueryPbufferARB;
108 
109  bool _supports_pixel_format;
110  PFNWGLGETPIXELFORMATATTRIBIVARBPROC _wglGetPixelFormatAttribivARB;
111  PFNWGLGETPIXELFORMATATTRIBFVARBPROC _wglGetPixelFormatAttribfvARB;
112  PFNWGLCHOOSEPIXELFORMATARBPROC _wglChoosePixelFormatARB;
113 
114  bool _supports_wgl_multisample;
115 
116  bool _supports_wgl_render_texture;
117  PFNWGLBINDTEXIMAGEARBPROC _wglBindTexImageARB;
118  PFNWGLRELEASETEXIMAGEARBPROC _wglReleaseTexImageARB;
119  PFNWGLSETPBUFFERATTRIBARBPROC _wglSetPbufferAttribARB;
120 
121 public:
122  static TypeHandle get_class_type() {
123  return _type_handle;
124  }
125  static void init_type() {
126  GLGraphicsStateGuardian::init_type();
127  register_type(_type_handle, "wglGraphicsStateGuardian",
128  GLGraphicsStateGuardian::get_class_type());
129  }
130  virtual TypeHandle get_type() const {
131  return get_class_type();
132  }
133  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
134 
135 private:
136  static TypeHandle _type_handle;
137 
138  friend class wglGraphicsBuffer;
139 };
140 
141 #include "wglGraphicsStateGuardian.I"
142 
143 #endif
HDC get_twindow_dc()
Returns the DC associated with the temporary, invisible window that was created with the gsg to query...
int get_pfnum() const
Returns the pixel format number chosen for windows that use this context.
bool set_gamma(PN_stdfloat gamma)
Non static version of setting gamma.
static bool get_gamma_table(void)
Static function for getting the original gamma.
bool made_context() const
Returns true if the GSG has had a context made for it already, false otherwise.
void restore_gamma()
Restore original gamma.
static bool static_set_gamma(bool restore, PN_stdfloat gamma)
Static function for setting gamma which is needed for atexit.
bool get_properties_advanced(FrameBufferProperties &properties, HDC hdc, int pfnum)
Gets the FrameBufferProperties to match the indicated pixel format descriptor, using the WGL extensio...
bool fail_pfnum()
This is called by wglGraphicsWindow when it finds it cannot use the pfnum determined by the GSG...
A tiny specialization on GLGraphicsStateGuardian to add some wgl-specific information.
virtual void reset()
Resets all internal state as if the gsg were newly created.
bool get_supports_wgl_render_texture() const
Returns true if this particular GSG can render from a wglGraphicsBuffer directly into a texture...
HGLRC get_context(HDC hdc)
Returns the GL context associated with the GSG.
static void atexit_function(void)
This function is passed to the atexit function.
void choose_pixel_format(const FrameBufferProperties &properties, bool need_pbuffer)
Selects a pixel format for all the windows and buffers that use this gsg.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
void get_properties(FrameBufferProperties &properties, HDC hdc, int pfnum)
Gets the FrameBufferProperties to match the indicated pixel format descriptor.
const FrameBufferProperties & get_fb_properties() const
Returns the properties of the pixel format that was chosen for this gsg.
An offscreen render buffer.
bool pfnum_supports_pbuffer() const
Returns true if the gsg's pixel format is capable of supporting a pbuffer.
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...