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(EXPERIMENTAL_GL_DRAWABLE_FEEL)
21 #include <UT/UT_UniquePtr.h>
22 #endif
23 
24 #include <QtGui/QOpenGLContext>
25 #include <QtWidgets/QWidget>
26 #undef emit
27 
28 
29 // Object names for QWidget and QWindow (drawable surface) objects used
30 // for OpenGL rendering. Note that the drawable surface name must be exactly
31 // equal to the drawable name plus "Window" as the suffix. This is a
32 // restriction of the QWidgetWindow class.
33 #define RE_GL_DRAWABLE_OBJ_NAME "RE_GLDrawable"
34 #define RE_GL_DRAWABLE_SURFACE_OBJ_NAME RE_GL_DRAWABLE_OBJ_NAME "Window"
35 
36 #define RE_GL_DRAWABLE_WRAPPER_OBJ_NAME RE_GL_DRAWABLE_OBJ_NAME "Wrapper"
37 
38 
39 class QSurfaceFormat;
40 
41 class RE_GLDrawable;
42 #if defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
43 class RE_Render;
44 class RE_Visual;
45 #endif
46 
47 
48 class RE_GLContext : public QOpenGLContext
49 {
50 public:
51 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
53  myDrawable(nullptr)
54  {}
55 #else
57  const QSurfaceFormat &format, QOpenGLContext *shared_context=nullptr)
58  : myDrawable(nullptr)
59  {
60  setFormat(format);
61  if (shared_context)
62  setShareContext(shared_context);
63  }
64 #endif
65 
66  ~RE_GLContext() override {}
67 
68  RE_GLDrawable *drawable() const { return myDrawable; }
69  void setDrawable(RE_GLDrawable *drawable) { myDrawable = drawable; }
70 
71 private:
72  RE_GLDrawable *myDrawable;
73 };
74 
75 /// GL drawable for Qt5.
76 /// It's basically a plain Qt widget that manages a GL context.
77 class RE_API RE_GLDrawable : public QWidget
78 {
79 public:
80 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
81  RE_GLDrawable(const QSurfaceFormat &format);
83  const QSurfaceFormat &format, QWidget *parent,
84  QOpenGLContext *sharedContext);
85 #else
87  RE_Visual *visual, QWidget *parent=nullptr, bool is_main=false);
88 #endif
89  ~RE_GLDrawable() override;
90 
91 #if defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
92  RE_Visual *getVisual() { return myVisual; }
93  RE_Render *getRender() { return myRender.get(); }
94 #endif
95 
96 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
97  RE_GLContext *context() { return &myContext; }
98 #endif
99 
100 #if defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
101  bool isQuadBufferStereo() const;
102 #endif
103 
104  QPaintEngine *paintEngine() const override { return nullptr; };
105  static const char *widgetTag() { return RE_GL_DRAWABLE_OBJ_NAME; }
106 
107  /// Return the string tag used to identify whether a QWindow
108  /// is used a drawable surface for Houdini.
109  static const char * drawableSurfaceTag()
111 
112  /// Return the string tag used to identify whether a QWidget
113  /// is the wrapper widget of a GL drawable in Houdini.
114  static const char *widgetWrapperTag()
116 
117 protected:
118  void paintEvent(QPaintEvent *event) override;
119  void resizeEvent(QResizeEvent *event) override;
120  void mousePressEvent(QMouseEvent *event) override;
121 
122 private:
123  void init_();
124 
125 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
126  RE_GLContext myContext;
127 #else
128  UT_UniquePtr<RE_Render> myRender;
129  RE_Visual *myVisual;
130 #endif
131 };
132 
133 
134 #endif // __RE_GLDRAWABLE_H_INCLUDED__
void setDrawable(RE_GLDrawable *drawable)
Definition: RE_GLDrawable.h:69
static const char * drawableSurfaceTag()
#define RE_API
Definition: RE_API.h:10
static const char * widgetWrapperTag()
#define RE_GL_DRAWABLE_SURFACE_OBJ_NAME
Definition: RE_GLDrawable.h:34
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
struct _cl_event * event
Definition: glcorearb.h:2960
RE_GLContext * context()
Definition: RE_GLDrawable.h:97
static const char * widgetTag()
RE_GLDrawable * drawable() const
Definition: RE_GLDrawable.h:68
~RE_GLContext() override
Definition: RE_GLDrawable.h:66
#define RE_GL_DRAWABLE_OBJ_NAME
Definition: RE_GLDrawable.h:33
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
QPaintEngine * paintEngine() const override
#define RE_GL_DRAWABLE_WRAPPER_OBJ_NAME
Definition: RE_GLDrawable.h:36