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 #include <QtGui/QOpenGLContext>
21 #include <QtWidgets/QWidget>
22 
23 #if defined(EXPERIMENTAL_VOLT_STYLE)
24 #include <UI/UI_Look.h>
25 #include <UT/UT_Array.h>
26 #include <QtGui/QPainter>
27 #endif
28 
29 #undef emit
30 
31 
32 // Object names for QWidget and QWindow (drawable surface) objects used
33 // for OpenGL rendering. Note that the drawable surface name must be exactly
34 // equal to the drawable name plus "Window" as the suffix. This is a
35 // restriction of the QWidgetWindow class.
36 #define RE_GL_DRAWABLE_OBJ_NAME "RE_GLDrawable"
37 #define RE_GL_DRAWABLE_SURFACE_OBJ_NAME RE_GL_DRAWABLE_OBJ_NAME "Window"
38 
39 #define RE_GL_DRAWABLE_WRAPPER_OBJ_NAME RE_GL_DRAWABLE_OBJ_NAME "Wrapper"
40 
41 
42 class QSurfaceFormat;
43 class RE_GLDrawable;
44 
45 
46 class RE_GLContext : public QOpenGLContext
47 {
48 public:
50  myDrawable(nullptr)
51  {}
52 
53  ~RE_GLContext() override {}
54 
55  RE_GLDrawable *drawable() const { return myDrawable; }
56  void setDrawable(RE_GLDrawable *drawable) { myDrawable = drawable; }
57 
58 private:
59  RE_GLDrawable *myDrawable;
60 };
61 
62 /// GL drawable for Qt5.
63 /// It's basically a plain Qt widget that manages a GL context.
64 class RE_API RE_GLDrawable : public QWidget
65 {
66 public:
67  RE_GLDrawable(const QSurfaceFormat &format);
69  const QSurfaceFormat &format, QWidget *parent,
70  QOpenGLContext *sharedContext);
71  ~RE_GLDrawable() override;
72 
73  RE_GLContext *context() { return &myContext; }
74 
75  QPaintEngine *paintEngine() const override { return nullptr; };
76  static const char *widgetTag() { return RE_GL_DRAWABLE_OBJ_NAME; }
77 
78  /// Return the string tag used to identify whether a QWindow
79  /// is used a drawable surface for Houdini.
80  static const char * drawableSurfaceTag()
82 
83  /// Return the string tag used to identify whether a QWidget
84  /// is the wrapper widget of a GL drawable in Houdini.
85  static const char *widgetWrapperTag()
87 
88 #if defined(EXPERIMENTAL_VOLT_STYLE)
89  void updatePixmap(UI_Look *look, QPixmap pixmap)
90  {
91  for (int i = 0; i < myPixmapBuffer.size(); i++)
92  {
93  if (myPixmapBuffer[i].first == look)
94  {
95  myPixmapBuffer.removeIndex(i);
96  break;
97  }
98  }
99  myPixmapBuffer.append(std::make_pair(look, pixmap));
100  }
101 #endif
102 
103 protected:
104  void paintEvent(QPaintEvent *event) override;
105  void resizeEvent(QResizeEvent *event) override;
106  void mousePressEvent(QMouseEvent *event) override;
107 
108 private:
109  void init_();
110 
111  RE_GLContext myContext;
112 
113 #if defined(EXPERIMENTAL_VOLT_STYLE)
114  // Acts as a buffer for UI elements to store their pixmaps in when each of
115  // their render() functions is called. All pixmaps in this map get drawn to
116  // the screen during each paintEvent().
118 #endif
119 };
120 
121 
122 #endif // __RE_GLDRAWABLE_H_INCLUDED__
GLint first
Definition: glcorearb.h:405
void setDrawable(RE_GLDrawable *drawable)
Definition: RE_GLDrawable.h:56
static const char * drawableSurfaceTag()
Definition: RE_GLDrawable.h:80
#define RE_API
Definition: RE_API.h:10
static const char * widgetWrapperTag()
Definition: RE_GLDrawable.h:85
#define RE_GL_DRAWABLE_SURFACE_OBJ_NAME
Definition: RE_GLDrawable.h:37
struct _cl_event * event
Definition: glcorearb.h:2961
RE_GLContext * context()
Definition: RE_GLDrawable.h:73
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
static const char * widgetTag()
Definition: RE_GLDrawable.h:76
RE_GLDrawable * drawable() const
Definition: RE_GLDrawable.h:55
~RE_GLContext() override
Definition: RE_GLDrawable.h:53
#define RE_GL_DRAWABLE_OBJ_NAME
Definition: RE_GLDrawable.h:36
QPaintEngine * paintEngine() const override
Definition: RE_GLDrawable.h:75
#define RE_GL_DRAWABLE_WRAPPER_OBJ_NAME
Definition: RE_GLDrawable.h:39