HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_OpenGLDrawable.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_OpenGLDrawable.h (RE Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __RE_OPENGLDRAWABLE_H_INCLUDED__
12 #define __RE_OPENGLDRAWABLE_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 // Needed for RE_WindowDrawablePainter.
21 #include "RE_WindowDrawable.h"
22 #include <UT/UT_UniquePtr.h>
23 
24 #include <QtGui/QOpenGLContext>
25 #include <QtGui/QSurfaceFormat>
26 #include <QtOpenGL/QOpenGLPaintDevice>
27 #include <QtWidgets/QWidget>
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_OPENGL_DRAWABLE_OBJ_NAME "RE_OpenGLDrawable"
37 #define RE_OPENGL_DRAWABLE_SURFACE_OBJ_NAME \
38  RE_OPENGL_DRAWABLE_OBJ_NAME "Window"
39 #define RE_OPENGL_DRAWABLE_WRAPPER_OBJ_NAME \
40  RE_OPENGL_DRAWABLE_OBJ_NAME "Wrapper"
41 
42 class QPaintDevice;
43 class QPaintEngine;
44 class RE_Window;
45 
46 /// Window drawable that uses OpenGL and QPainter for the new UI path.
47 /// The drawable is a QWidget that manages its own OpenGL context and
48 /// is backed by a QWindow with a OpenGL surface type.
49 class RE_API RE_OpenGLDrawable : public QWidget
50 {
51 public:
52  RE_OpenGLDrawable(const QSurfaceFormat &format);
54  const QSurfaceFormat &format, QWidget *parent,
55  QOpenGLContext *sharedContext);
56  ~RE_OpenGLDrawable() override;
57 
58  /// Assign the drawable to the given window.
59  /// The given drawable will be used to render the contents of the window.
60  void setREWindow(RE_Window *window);
61 
62  /// Return the window that the drawable is currently assigned to.
63  const RE_Window *getREWindow() const { return myREWindow; }
64 
65  /// Return the OpenGL context tied to this drawable.
66  /// If the context has not yet been initialized, then return nullptr.
67  QOpenGLContext *context();
68 
69  /// Make this drawable's context the current OpenGL context.
70  void makeCurrent();
71 
72  /// Clear this drawable's context as the current context.
73  /// Do nothing if the drawable's context is not the current context.
74  void doneCurrent();
75 
76  /// Swap the front and back buffers in the drawable's OpenGL context.
77  void swapBuffers();
78 
79  /// Return the drawable's paint device that QPainter objects should paint
80  /// to.
81  QPaintDevice *stylePaintDevice();
82 
83  QPaintEngine *paintEngine() const override { return nullptr; };
84 
85  /// Multisample sample count this drawable was created with (-1 if none).
86  int samples() const { return mySamples; }
87 
88  static const char *widgetTag() { return RE_OPENGL_DRAWABLE_OBJ_NAME; }
89 
90  /// Return the string tag used to identify whether a QWindow
91  /// is used a drawable surface for Houdini.
92  static const char * drawableSurfaceTag()
94 
95  /// Return the string tag used to identify whether a QWidget
96  /// is the wrapper widget of a drawable in Houdini.
97  static const char *widgetWrapperTag()
99 
100  /// Return the Painter used to paint the contents of the drawable.
101  RE_WindowDrawablePainter &painter();
102 
103  void initializeGL();
104 
105 protected:
106  void paintEvent(QPaintEvent *event) override;
107  void resizeEvent(QResizeEvent *event) override;
108  void showEvent(QShowEvent *event) override;
109 
110 private:
111  void init_(const QSurfaceFormat *format);
112 
113  void createGLContext_();
114  void render_();
115  void paintGL_();
116 
117  QSurfaceFormat myFormat;
119  UT_UniquePtr<QOpenGLPaintDevice> myStylePaintDevice;
120  QOpenGLContext *mySharedContext = nullptr;
121  bool myIsContextInitialized = false;
122  RE_Window *myREWindow = nullptr;
123  bool myIsPainting = false;
124  bool myNeedsOwnerUpdate = false;
125  int mySamples = -1;
126 
127  RE_WindowDrawablePainter myPainter;
128 };
129 
130 
131 #endif // __RE_OPENGLDRAWABLE_H_INCLUDED__
#define RE_OPENGL_DRAWABLE_WRAPPER_OBJ_NAME
#define RE_API
Definition: RE_API.h:10
==========================================================================
Definition: RE_Window.h:57
#define RE_OPENGL_DRAWABLE_SURFACE_OBJ_NAME
#define RE_OPENGL_DRAWABLE_OBJ_NAME
int samples() const
Multisample sample count this drawable was created with (-1 if none).
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
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
static const char * widgetWrapperTag()
static const char * widgetTag()
const RE_Window * getREWindow() const
Return the window that the drawable is currently assigned to.
QPaintEngine * paintEngine() const override
static const char * drawableSurfaceTag()