HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_WindowDrawable.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_WindowDrawable.h (RE Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __RE_WINDOWDRAWABLE_H_INCLUDED__
12 #define __RE_WINDOWDRAWABLE_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 "RE_Render.h"
21 #include <UT/UT_Rect.h>
22 
23 #if defined(USE_QT6)
24 #include <QtOpenGLWidgets/QOpenGLWidget>
25 #else
26 #include <QtWidgets/QOpenGLWidget>
27 #endif
28 #include <QtWidgets/QStylePainter>
29 
30 #undef emit
31 
32 
33 // Object names for QWidget and QWindow (drawable surface) objects used
34 // for OpenGL rendering. Note that the drawable surface name must be exactly
35 // equal to the drawable name plus "Window" as the suffix. This is a
36 // restriction of the QWidgetWindow class.
37 #define RE_WINDOW_DRAWABLE_OBJ_NAME "RE_WindowDrawable"
38 #define RE_WINDOW_DRAWABLE_SURFACE_OBJ_NAME \
39  RE_WINDOW_DRAWABLE_OBJ_NAME "Window"
40 #define RE_WINDOW_DRAWABLE_WRAPPER_OBJ_NAME \
41  RE_WINDOW_DRAWABLE_OBJ_NAME "Wrapper"
42 
43 
44 class QOpenGLContext;
45 class QSurfaceFormat;
46 class RE_Window;
47 class RE_WindowDrawable;
49 
50 /// Specialized style painter class for RE_WindowDrawable.
51 /// The class manages transitioning between native Houdini (OpenGL) painting
52 /// and Qt styled painting in the window drawable.
53 class RE_API RE_WindowDrawablePainter : public QStylePainter
54 {
55 public:
56  ///
57  /// Begin a new paint session.
58  /// This should only be called when not currently in a paint session.
59  ///
60  void beginPaintSession(RE_WindowDrawable *drawable, RE_Render *render);
61 
62  ///
63  /// End the current paint session.
64  /// This should only be called when currently in a paint session.
65  ///
66  void endPaintSession();
67 
68  ///
69  /// Switch to OpenGL painting mode.
70  /// This should only be called when currently in a paint session.
71  ///
72  void beginOpenGLPainting();
73 
74  ///
75  /// Switch to Qt styled painting mode.
76  /// This should only be called when currently in a paint session.
77  ///
78  void endOpenGLPainting();
79 
80  /// Return the paint state of the current paint session.
81  /// Return nullptr if there is currently no paint session.
82  static RE_WindowDrawablePaintState *currentPaintState();
83 
84 private:
85 
86  // The RE_WindwoDrawable that the current painting session applies to.
87  RE_WindowDrawable *myCurDrawable = nullptr;
88 
89  // The RE_Render used in the current painting session.
90  RE_Render *myCurRender = nullptr;
91 };
92 
93 /// Class to keep track of the painter and the current paint
94 /// area in a paint session. The paint area y-origin and height
95 /// are specified in Houdini's UI coordinate space
96 /// (i.e. bottom-left origin).
98 {
99 public:
101  RE_WindowDrawablePainter *painter,
102  int paint_area_x, int paint_area_y, int paint_area_w, int paint_area_h);
103  ~RE_WindowDrawablePaintState() = default;
104 
107  const RE_WindowDrawablePaintState &src);
108 
109  RE_WindowDrawablePainter *painter() const;
110 
111  /// Push onto the stack a new paint area.
112  /// This is needed by UI_Viewport, for example, which paints
113  /// into an FBO with a different viewport.
114  void pushPaintArea(
115  int paint_area_x, int paint_area_y,
116  int paint_area_w, int paint_area_h);
117 
118  /// Pop the current paint area from the stack.
119  void popPaintArea();
120 
121  /// Return the current paint area.
122  const UT_DimRect &paintArea() const;
123 
124  /// Convert the given x,y position from the Houdini UI coordinate space
125  /// to Qt's QPainter coordinate space. If x,y is for the (bottom-left)
126  /// corner of a rectangle, then specify the width and height of the
127  /// rectangle to convert the x,y position to the Qt (top-left)
128  /// rectangle.
129  void toPainterPosition(int &x, int &y, int w=0, int h=0) const;
130 
131  /// Convert the given x,y position from the Qt QPainter coordinate space
132  /// to the Houdini UI coordinate space. If x,y is for the (top-left)
133  /// corner of a rectangle, then specify the width and height of the
134  /// rectangle to convert the x,y position to the Houdini UI (bottom-left)
135  /// rectangle.
136  void toUIPosition(int &x, int &y, int w=0, int h=0) const;
137 
138 private:
139  RE_WindowDrawablePainter *myPainter;
140  UT_Array<UT_DimRect> myPaintAreaStack;
141 };
142 
143 /// Construct at the beginning of a painting code block to switch to
144 /// QPainter painting mode. If there is no active paint state, then
145 /// begin a new paint session to create an active paint state.
147 {
148 public:
151 
153  = delete;
154 
155  /// Return the underlying paint state.
157  { return myPaintState; }
158 
159  /// Convenience method to access the paint state's painter.
161  { return myPaintState->painter(); }
162 
163  /// Convenience method to access the paint state's paint area.
164  const UT_DimRect &paintArea() const
165  { return myPaintState->paintArea(); }
166 
167  /// Convenience method to call the paint state's toPainterPosition()
168  /// method.
169  void toPainterPosition(int &x, int &y, int w=0, int h=0) const
170  { myPaintState->toPainterPosition(x, y, w, h); }
171 
172  /// Convenience method to call the paint state's toUIPosition()
173  /// method.
174  void toUIPosition(int &x, int &y, int w=0, int h=0) const
175  { myPaintState->toUIPosition(x, y, w, h); }
176 
177 private:
178  RE_WindowDrawablePaintState *myPaintState = nullptr;
179  RE_WindowDrawable *myDrawable = nullptr;
180 };
181 
182 
183 /// Window drawable.
184 /// It currently uses an OpenGL backend via QOpenGLWidget.
185 class RE_API RE_WindowDrawable : public QOpenGLWidget
186 {
187 public:
188  RE_WindowDrawable(const QSurfaceFormat &format);
190  const QSurfaceFormat &format, QWidget *parent,
191  QOpenGLContext *sharedContext);
192  ~RE_WindowDrawable() override;
193 
194  /// Assign the drawable to the given window.
195  /// The given drawable will be used to render the contents of the window.
196  void setREWindow(RE_Window *window);
197 
198  static const char *widgetTag() { return RE_WINDOW_DRAWABLE_OBJ_NAME; }
199 
200  /// Return the string tag used to identify whether a QWindow
201  /// is used a drawable surface for Houdini.
202  static const char * drawableSurfaceTag()
204 
205  /// Return the string tag used to identify whether a QWidget
206  /// is the wrapper widget of a drawable in Houdini.
207  static const char *widgetWrapperTag()
209 
210  /// Return true if the new UI skin should be drawn.
211  static bool shouldDrawNewUI();
212 
213  /// Return the Painter used to paint the contents of the drawable.
214  RE_WindowDrawablePainter &painter();
215 
216 protected:
217  void initializeGL() override;
218  void paintGL() override;
219  void resizeGL(int w, int h) override;
220 
221 private:
222  void init_(
223  const QSurfaceFormat *format, QOpenGLContext *shared_context=nullptr);
224 
225  QOpenGLContext *myInitializedContext = nullptr;
226  RE_Window *myREWindow = nullptr;
227 
228  bool myIsPainting = false;
229 
230  RE_WindowDrawablePainter myPainter;
231 };
232 
233 
234 #endif // __RE_WINDOWDRAWABLE_H_INCLUDED__
void toUIPosition(int &x, int &y, int w=0, int h=0) const
#define RE_API
Definition: RE_API.h:10
==========================================================================
Definition: RE_Window.h:50
GLint y
Definition: glcorearb.h:103
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
static const char * widgetTag()
static const char * widgetWrapperTag()
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
const UT_DimRect & paintArea() const
Convenience method to access the paint state's paint area.
RE_WindowDrawablePainter * painter() const
Convenience method to access the paint state's painter.
GLint GLenum GLint x
Definition: glcorearb.h:409
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
#define RE_WINDOW_DRAWABLE_WRAPPER_OBJ_NAME
LeafData & operator=(const LeafData &)=delete
void toPainterPosition(int &x, int &y, int w=0, int h=0) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GLboolean r
Definition: glcorearb.h:1222
#define RE_WINDOW_DRAWABLE_OBJ_NAME
static const char * drawableSurfaceTag()
RE_WindowDrawablePaintState * paintState()
Return the underlying paint state.
GLenum src
Definition: glcorearb.h:1793
#define RE_WINDOW_DRAWABLE_SURFACE_OBJ_NAME