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 #include <QtGui/QOpenGLContext>
25 #include <QtWidgets/QWidget>
26 
27 #undef emit
28 
29 
30 // Object names for QWidget and QWindow (drawable surface) objects used
31 // for OpenGL rendering. Note that the drawable surface name must be exactly
32 // equal to the drawable name plus "Window" as the suffix. This is a
33 // restriction of the QWidgetWindow class.
34 #define RE_GL_DRAWABLE_OBJ_NAME "RE_GLDrawable"
35 #define RE_GL_DRAWABLE_SURFACE_OBJ_NAME RE_GL_DRAWABLE_OBJ_NAME "Window"
36 #define RE_GL_DRAWABLE_WRAPPER_OBJ_NAME RE_GL_DRAWABLE_OBJ_NAME "Wrapper"
37 
38 class QSurfaceFormat;
39 class RE_GLDrawable;
40 
41 #if !defined(USE_QT6)
42 class RE_GLContext : public QOpenGLContext
43 {
44 public:
46  myDrawable(nullptr)
47  {}
48 
49  ~RE_GLContext() override {}
50 
51  RE_GLDrawable *drawable() const { return myDrawable; }
52  void setDrawable(RE_GLDrawable *drawable) { myDrawable = drawable; }
53 
54 private:
55  RE_GLDrawable *myDrawable;
56 };
57 #endif
58 
59 
60 /// GL drawable.
61 /// It's basically a plain Qt widget that manages a GL context.
62 class RE_API RE_GLDrawable : public QWidget
63 {
64 public:
65  RE_GLDrawable(const QSurfaceFormat &format);
67  const QSurfaceFormat &format, QWidget *parent,
68  QOpenGLContext *sharedContext);
69  ~RE_GLDrawable() override;
70 
71 #if defined(USE_QT6)
72  QOpenGLContext *context() { return myContext.get(); }
73 #else
74  RE_GLContext *context() { return &myContext; }
75 #endif
76 
77  QPaintEngine *paintEngine() const override { return nullptr; };
78 
79  static const char *widgetTag() { return RE_GL_DRAWABLE_OBJ_NAME; }
80 
81  /// Return the string tag used to identify whether a QWindow
82  /// is used a drawable surface for Houdini.
83  static const char * drawableSurfaceTag()
85 
86  /// Return the string tag used to identify whether a QWidget
87  /// is the wrapper widget of a GL drawable in Houdini.
88  static const char *widgetWrapperTag()
90 
91 protected:
92  void paintEvent(QPaintEvent *event) override;
93  void resizeEvent(QResizeEvent *event) override;
94  void mousePressEvent(QMouseEvent *event) override;
95 
96 private:
97 #if defined(USE_QT6)
98  void init_(
99  const QSurfaceFormat *format, QOpenGLContext *shared_context=nullptr);
100 #else
101  void init_();
102 #endif
103 
104 #if defined(USE_QT6)
106 #else
107  RE_GLContext myContext;
108 #endif
109 };
110 
111 
112 #endif // __RE_GLDRAWABLE_H_INCLUDED__
void setDrawable(RE_GLDrawable *drawable)
Definition: RE_GLDrawable.h:52
static const char * drawableSurfaceTag()
Definition: RE_GLDrawable.h:83
#define RE_API
Definition: RE_API.h:10
static const char * widgetWrapperTag()
Definition: RE_GLDrawable.h:88
#define RE_GL_DRAWABLE_SURFACE_OBJ_NAME
Definition: RE_GLDrawable.h:35
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()
Definition: RE_GLDrawable.h:74
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
static const char * widgetTag()
Definition: RE_GLDrawable.h:79
RE_GLDrawable * drawable() const
Definition: RE_GLDrawable.h:51
~RE_GLContext() override
Definition: RE_GLDrawable.h:49
#define RE_GL_DRAWABLE_OBJ_NAME
Definition: RE_GLDrawable.h:34
QPaintEngine * paintEngine() const override
Definition: RE_GLDrawable.h:77
#define RE_GL_DRAWABLE_WRAPPER_OBJ_NAME
Definition: RE_GLDrawable.h:36