HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_GLDrawable.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RE_GLDrawable.h (RE Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __RE_GLDRAWABLE_H_INCLUDED__
12 #define __RE_GLDRAWABLE_H_INCLUDED__
13 
14 #include "RE_API.h"
15 
16 // We must include this before the Qt OpenGL headers in order to ensure the
17 // correct linkage on Windows.
18 #include "RE_OGL.h"
19 
20 #if defined(USE_QT6)
21 #include <UT/UT_UniquePtr.h>
22 #endif
23 
24 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
25 #include <QtWidgets/QOpenGLWidget>
26 #else
27 #include <QtGui/QOpenGLContext>
28 #include <QtWidgets/QWidget>
29 #endif
30 
31 #if defined(EXPERIMENTAL_VOLT_STYLE)
32 #include <UI/UI_Look.h>
33 #include <UT/UT_Array.h>
34 #include <QtGui/QPainter>
35 #endif
36 
37 #undef emit
38 
39 
40 // Object names for QWidget and QWindow (drawable surface) objects used
41 // for OpenGL rendering. Note that the drawable surface name must be exactly
42 // equal to the drawable name plus "Window" as the suffix. This is a
43 // restriction of the QWidgetWindow class.
44 #define RE_GL_DRAWABLE_OBJ_NAME "RE_GLDrawable"
45 #define RE_GL_DRAWABLE_SURFACE_OBJ_NAME RE_GL_DRAWABLE_OBJ_NAME "Window"
46 
47 #define RE_GL_DRAWABLE_WRAPPER_OBJ_NAME RE_GL_DRAWABLE_OBJ_NAME "Wrapper"
48 
49 
50 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
51 class QOpenGLContext;
52 #endif
53 class QSurfaceFormat;
54 class RE_GLDrawable;
55 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
56 class RE_Window;
57 #endif
58 
59 #if !defined(USE_QT6) && !defined(EXPERIMENTAL_QOPENGLWIDGET)
60 class RE_GLContext : public QOpenGLContext
61 {
62 public:
64  myDrawable(nullptr)
65  {}
66 
67  ~RE_GLContext() override {}
68 
69  RE_GLDrawable *drawable() const { return myDrawable; }
70  void setDrawable(RE_GLDrawable *drawable) { myDrawable = drawable; }
71 
72 private:
73  RE_GLDrawable *myDrawable;
74 };
75 #endif
76 
77 
78 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
79 /// GL drawable for Qt5.
80 class RE_API RE_GLDrawable : public QOpenGLWidget
81 #else
82 /// GL drawable for Qt5.
83 /// It's basically a plain Qt widget that manages a GL context.
84 class RE_API RE_GLDrawable : public QWidget
85 #endif
86 {
87 public:
88  RE_GLDrawable(const QSurfaceFormat &format);
90  const QSurfaceFormat &format, QWidget *parent,
91  QOpenGLContext *sharedContext);
92  ~RE_GLDrawable() override;
93 
94 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
95  /// Assign the GL drawable to the given window.
96  /// The given GL drawable will be used to render the contents of the window.
97  void setREWindow(RE_Window *window);
98 #else
99 #if defined(USE_QT6)
100  QOpenGLContext *context() { return myContext.get(); }
101 #else
102  RE_GLContext *context() { return &myContext; }
103 #endif
104 
105  QPaintEngine *paintEngine() const override { return nullptr; };
106 #endif
107 
108  static const char *widgetTag() { return RE_GL_DRAWABLE_OBJ_NAME; }
109 
110  /// Return the string tag used to identify whether a QWindow
111  /// is used a drawable surface for Houdini.
112  static const char * drawableSurfaceTag()
114 
115  /// Return the string tag used to identify whether a QWidget
116  /// is the wrapper widget of a GL drawable in Houdini.
117  static const char *widgetWrapperTag()
119 
120 #if defined(EXPERIMENTAL_VOLT_STYLE)
121  void updatePixmap(UI_Look *look, QPixmap pixmap)
122  {
123  for (int i = 0; i < myPixmapBuffer.size(); i++)
124  {
125  if (myPixmapBuffer[i].first == look)
126  {
127  myPixmapBuffer.removeIndex(i);
128  break;
129  }
130  }
131  myPixmapBuffer.append(std::make_pair(look, pixmap));
132  }
133 #endif
134 
135 protected:
136 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
137  void initializeGL() override;
138  void paintGL() override;
139  void resizeGL(int w, int h) override;
140 
141 #else
142  void paintEvent(QPaintEvent *event) override;
143  void resizeEvent(QResizeEvent *event) override;
144 #endif
145  void mousePressEvent(QMouseEvent *event) override;
146 
147 private:
148 #if defined(USE_QT6)
149  void init_(
150  const QSurfaceFormat *format, QOpenGLContext *shared_context=nullptr);
151 #else
152  void init_();
153 #endif
154 
155 #if defined(EXPERIMENTAL_QOPENGLWIDGET)
156  QOpenGLContext *myInitializedContext = nullptr;
157  RE_Window *myREWindow = nullptr;
158 
159  bool myIsPainting = false;
160 #else
161 #if defined(USE_QT6)
163 #else
164  RE_GLContext myContext;
165 #endif
166 #endif
167 
168 #if defined(EXPERIMENTAL_VOLT_STYLE)
169  // Acts as a buffer for UI elements to store their pixmaps in when each of
170  // their render() functions is called. All pixmaps in this map get drawn to
171  // the screen during each paintEvent().
173 #endif
174 };
175 
176 
177 #endif // __RE_GLDRAWABLE_H_INCLUDED__
GLint first
Definition: glcorearb.h:405
RE_GLDrawable(const QSurfaceFormat &format)
void setDrawable(RE_GLDrawable *drawable)
Definition: RE_GLDrawable.h:70
static const char * drawableSurfaceTag()
#define RE_API
Definition: RE_API.h:10
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:623
static const char * widgetWrapperTag()
~RE_GLDrawable() override
#define RE_GL_DRAWABLE_SURFACE_OBJ_NAME
Definition: RE_GLDrawable.h:45
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
struct _cl_event * event
Definition: glcorearb.h:2961
RE_GLContext * context()
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
static const char * widgetTag()
RE_GLDrawable * drawable() const
Definition: RE_GLDrawable.h:69
~RE_GLContext() override
Definition: RE_GLDrawable.h:67
#define RE_GL_DRAWABLE_OBJ_NAME
Definition: RE_GLDrawable.h:44
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
void paintEvent(QPaintEvent *event) override
void resizeEvent(QResizeEvent *event) override
QPaintEngine * paintEngine() const override
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
#define RE_GL_DRAWABLE_WRAPPER_OBJ_NAME
Definition: RE_GLDrawable.h:47
void mousePressEvent(QMouseEvent *event) override