HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_Visual.h
Go to the documentation of this file.
1 #ifndef __RE_Visual_h__
2 #define __RE_Visual_h__
3 
4 #include "RE_API.h"
5 #include "RE_Types.h"
6 
7 #include <UT/UT_Lock.h>
9 
10 // Include this before including any QOpenGL files.
11 // This ensures that our OpenGL core profile API is included
12 // instead of the one shipped with Qt.
13 // TODO: We should look into moving over to Qt's OpenGL API
14 // (i.e. include QtGui/qopengl.h or maybe QtGui/QOpenGLFunctions.h
15 // instead of glcorearb.h)
16 #include "RE_OGL.h"
17 
18 class RE_Server;
19 class RE_OpenGLDrawable;
21 class RE_Window;
22 class RE_WindowDrawable;
23 
24 class QOpenGLContext;
25 class QSurfaceFormat;
26 class QWidget;
27 
28 
30 {
31 public:
32  RE_Visual(RE_DisplayMode newmode);
33  ~RE_Visual();
34 
35  /// ======================================================================
36  /// For new 2D UI drawing.
37 
38  // These methods manage drawables that support OpenGL painting.
39  // {
40  RE_WindowDrawable *createDrawable(RE_Window *win) const;
41  void deleteDrawable(RE_WindowDrawable *drawable) const;
42 
43  RE_WindowDrawable *grabDrawable(RE_Window *win, bool attach = true);
44  void returnDrawable(
45  RE_Window *win, RE_WindowDrawable *drawable);
46 
47  RE_OpenGLDrawable *createOpenGLDrawable(RE_Window *win) const;
48  void deleteOpenGLDrawable(
49  RE_OpenGLDrawable *drawable) const;
50 
51  RE_OpenGLDrawable *grabOpenGLDrawable(RE_Window *win, bool attach = true);
52  void returnOpenGLDrawable(
53  RE_Window *win, RE_OpenGLDrawable *drawable);
54  // }
55 
56  // These methods manage drawables that only supports QPainter painting
57  // (no OpenGL painting).
58  // {
59  RE_QPainterDrawable *createQPainterDrawable(RE_Window *win) const;
60  void deleteQPainterDrawable(
61  RE_QPainterDrawable *drawable) const;
62 
63  RE_QPainterDrawable *grabQPainterDrawable(RE_Window *win, bool attach = true);
64  void returnQPainterDrawable(
65  RE_Window *win, RE_QPainterDrawable *drawable);
66  // }
67 
68 
69  /// ======================================================================
70  //
71 
72  /// ======================================================================
73  /// For OpenGL 2D UI drawing.
74  RE_OGLContext createContext(RE_Window *win) const;
75  void deleteContext(RE_OGLContext) const;
76 
77  RE_OGLContext grabContext(RE_Window *win, bool attach = true);
78  void returnContext(RE_Window *win, RE_OGLContext ctx);
79  /// ======================================================================
80 
81  // isMode() returns true on an exact match. isCompatibleWithMode() returns
82  // true if this visual is equal to or a superset of the features in 'match'
83  bool isMode(RE_DisplayMode match) const;
84  bool isCompatibleWithMode(RE_DisplayMode match) const;
85 
86  bool isRGB() const;
87 
88  /// Returns the display mode used for the request to create this visual.
89  RE_DisplayMode getMode() const { return myVisualMode; }
90 
91  const QSurfaceFormat * getPixelFormat() const;
92  static QOpenGLContext * getSharedGLContext();
93  static void initDefaultGLFormat();
94 
95  /// Return the tag we use to identify our GL widgets.
96  /// This is useful when handling events in the event loop.
97  static const char * glWidgetTag();
98 
99  /// Return the tag we use to identify our GL widget wrappers.
100  /// This is useful when handling events in the event loop.
101  static const char * glWidgetWrapperTag();
102 
103  /// Return the window widget that is bound to the specified GL widget.
104  static QWidget * ownerWindowWidget(QWidget *gl_widget);
105 
106  /// ======================================================================
107  /// For new 2D UI drawing.
108  bool canOpenGLDrawableSupportQuadBufferStereo(
109  RE_OpenGLDrawable *drawable);
110  bool canDrawableSupportQuadBufferStereo(
111  RE_WindowDrawable *drawable);
112  /// ======================================================================
113 
114  /// ======================================================================
115  /// For OpenGL 2D UI drawing.
116  bool canSupportQuadBufferStereo(OGLDrawable drawable);
117  /// ======================================================================
118 
119 private:
120  void initPixelFormat_(RE_DisplayMode mode);
121  void createSharedGLWidget_();
122  void testGLVersions_();
123  bool canCreateGLContext_(
124  int gl_major, int gl_minor,
125  bool use_core_profile);
126 
127  RE_DisplayMode myVisualMode;
128 
129  /// ======================================================================
130  /// For new 2D UI drawing.
131 
132  UT_Lock myDrawableLock;
133  UT_Array<RE_WindowDrawable *> myVisibleDrawables[7];
134 
135  UT_Lock myOpenGLDrawableLock;
136  UT_Array<RE_OpenGLDrawable *> myVisibleOpenGLDrawables[7];
137 
138  UT_Lock myQPainterDrawableLock;
139  UT_Array<RE_QPainterDrawable *> myVisibleQPainterDrawables;
140  /// ======================================================================
141 
142  /// ======================================================================
143  /// For OpenGL 2D UI drawing.
144  UT_Lock myContextLock;
145  UT_Array<RE_OGLContext> myVisibleContexts;
146  /// ======================================================================
147 
148  // This widget is for stashing away returned GL widgets by containing them
149  // as children. This causes the GL widgets to be parented at all times so
150  // that their window flags do not change.
151  QWidget *myStashWidget;
152 
153  QSurfaceFormat * myPixelFormat;
154 };
155 
156 #endif
#define RE_API
Definition: RE_API.h:10
==========================================================================
Definition: RE_Window.h:57
RE_DisplayMode
Definition: RE_Types.h:580
RE_DisplayMode getMode() const
Returns the display mode used for the request to create this visual.
Definition: RE_Visual.h:89
GLenum mode
Definition: glcorearb.h:99
Window drawable that uses only QPainter for the new UI path.
QOpenGLContext * RE_OGLContext
Definition: RE_Types.h:956