HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_RenderUI.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: RV_RenderUI.h ( RV Library, C++)
7  *
8  */
9 
10 #ifndef RV_RenderUI_h
11 #define RV_RenderUI_h
12 
13 #include <UT/UT_Array.h>
14 #include <UT/UT_BoundingRect.h>
15 #include <UT/UT_Matrix4.h>
16 #include <UT/UT_NonCopyable.h>
17 #include <UT/UT_Rect.h>
18 #include <UT/UT_SharedPtr.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_UniquePtr.h>
21 #include <UT/UT_ValArray.h>
22 #include <UT/UT_Vector3.h>
23 #include <UT/UT_Vector3Array.h>
24 #include <UT/UT_Vector4.h>
25 #include <UT/UT_VectorTypes.h>
26 #include <RE/RE_Render.h>
27 #include <RE/RE_RenderContext.h>
28 
29 #include "RV_API.h"
30 #include "RV_TypePtrs.h"
31 
32 class RV_Geometry;
33 class RV_Instance;
34 class RV_Render;
35 class RV_ShaderBlock;
36 class RV_ShaderProgram;
38 
39 class UT_Color;
40 class rv_RenderUIPolyConvex;
41 
42 
44 {
45  public:
46 
47  RV_RenderUI();
48  virtual ~RV_RenderUI();
49 
50  void prepare(fpreal xperpixel, fpreal yperpixel, fpreal xorigin,
51  fpreal yorigin);
52 
53  /// Draw all buffered primitives
54  virtual void draw(
55  RV_Render* r,
56  bool pickpass = false,
57  int pick_depthpass = 0);
58 
59  /// Clear all buffered data. Also called at the end of draw.
60  virtual void clearAllData();
61 
62  /// Change the rendering "layer". This just modifies the depth
63  /// coordinate of the primitives.
64  void bumpLayer(int delta);
65 
66  /// Z value for use as the base for another object.
67  virtual void setZStart(fpreal32 zStart);
68  fpreal32 getZStart() const;
69  fpreal32 getZEnd() const;
70  void incrementZEnd();
71 
72  /// Set the view and projection matrices for 3D rendering.
73  /// These must be set before calling draw() for proper transformation.
74  void setViewProjection(const UT_Matrix4F& view, const UT_Matrix4F& proj);
75 
76  /// Helper to copy view matrices from the current OpenGL state, and use
77  /// provided projection matrix
78  void copyViewFromGL(RE_RenderContext r, const UT_Matrix4F &proj);
79 
80  /// Helper to copy view/projection matrices from the current OpenGL state.
81  void copyViewProjectionFromGL(RE_RenderContext r);
82 
83  /// Get x or y distance in current units that corresponds to 1 pixel.
84  fpreal32 getXPerPixel() const { return myXPerPixel; }
85  fpreal32 getYPerPixel() const { return myYPerPixel; }
86  fpreal32 getXOrigin() const { return myXOrigin; }
87  fpreal32 getYOrigin() const { return myYOrigin; }
88 
89  /// These are options that can change per-vertex.
90  void pushColor();
91  void pushColor(const UT_Color& c, fpreal32 a = 1.0f);
92  void pushColor(fpreal32 r, fpreal32 g, fpreal32 b, fpreal32 a = 1.0f);
93  void setColor(const UT_Color& c, fpreal32 a = 1.0f);
94  void setColor(fpreal32 r, fpreal32 g, fpreal32 b, fpreal32 a = 1.0f);
95  void setAlpha(fpreal32 a);
96  void popColor();
97  void getColor(UT_Color& c) const;
98  fpreal32 getAlpha() const;
99 
100  void pushPointSize(fpreal32 size);
101  void setPointSize(fpreal32 size);
102  void popPointSize();
103 
104  /// Pick state used by Vulkan UI pick pass rendering.
105  /// If high_priority is true, the pick will be treated as a high priority
106  /// target
107  void pushPick(UT_Vector3i pick_base_id, UT_Vector3i pick_component_id,
108  bool high_priority = false);
109  void setPickHighPriority(bool high_priority);
110  void popPick();
111  // High priority pick flag similar to DM_Handle
112  static constexpr int PICK_HIGH_PRIORITY_FLAG = 0x80000000;
113 
114  void pushLineSmoothing(bool smooth_lines);
115  void pushLineSmoothing();
116  void setLineSmoothing(bool smooth_lines);
117  void popLineSmoothing();
118 
119  void pushLineStyle(RE_LineStyle style);
120  void pushLineStyle();
121  void setLineStyle(RE_LineStyle style);
122  void popLineStyle();
123 
124  void pushLineWidth(fpreal32 width);
125  void pushLineWidth();
126  void setLineWidth(fpreal32 width);
127  void popLineWidth();
128 
129  // Deprecated. Should call addTriangles() instead. This only exists to support porting old OpenGL code.
130  void beginTriangles();
131  void endTriangles();
132 
133  void addTriangles(const UT_Vector2FArray &pts);
134  void addTriangles(const UT_Vector3FArray &pts);
135 
136  // Deprecated. Should call addTriangleFan() instead. These only exist to support porting old OpenGL code.
137  void beginTriangleFan();
138  void endTriangleFan();
139 
140  void addTriangleFan(const UT_Vector2FArray &pts);
141  void addTriangleFan(const UT_Vector3FArray &pts);
142 
143  // Deprecated. Should call addTriMesh() instead. These only exist to support porting old OpenGL code.
144  void beginTriMesh();
145  void endTriMesh();
146 
147  void addTriMesh(const UT_Vector2FArray &pts);
148  void addTriMesh(const UT_Vector3FArray &pts);
149 
150  // Deprecated. Should call addQuads() instead. These only exist to support porting old OpenGL code.
151  void beginQuads();
152  void endQuads();
153 
154  // Quads are just converted to triangles internally
155  void addQuads(const UT_Vector2FArray &pts);
156  void addQuads(const UT_Vector3FArray &pts);
157 
158  // Deprecated. Should call addQuadStrip() instead. These only exist to support porting old OpenGL code.
159  void beginQuadStrip();
160  void endQuadStrip();
161 
162  void addQuadStrip(const UT_Vector2FArray &pts);
163  void addQuadStrip(const UT_Vector3FArray &pts);
164 
165  // Deprecated. Should call addPolygon() instead. These only exist to support porting old OpenGL code.
166  void beginPolygon(int concave);
167  void endPolygon();
168 
169  void addPolygon(const UT_Vector2FArray &pts, int concave = 0);
170  void addPolygon(const UT_Vector3FArray &pts, int concave = 0);
171 
172  // Deprecated. Should call addLine() instead. These only exist to support porting old OpenGL code.
173  void beginLine();
174  void beginClosedLine();
175  void endLine();
176  void beginLines();
177  void endLines();
178 
179  /// Lines can be either a single strip or multiple segments.
180  /// If segments is true, each pair of vertices is a separate line segment.
181  /// If closed is true, the last vertex will be connected to the first.
182  void addLine(const UT_Vector2FArray &pts,
183  bool closed = false,
184  bool segments = false);
185  void addLine(const UT_Vector3FArray &pts,
186  bool closed = false,
187  bool segments = false);
188 
189  // Deprecated. Should call drawViewportPoint() instead.
190  void beginPoint();
191  void endPoint();
192 
193  void drawViewportPoint(const float vtx[3], fpreal32 size);
194  void drawViewportPoint(const UT_Vector3F &vtx, fpreal32 size);
195 
196  /// Set vertex attributes.
197  void c3DW(const fpreal32 clr[3]);
198  void c4DW(const fpreal32 clr[4]);
199 
200  /// Create vertices for primitives.
201  void v2DW(const fpreal32 vtx[2]);
202  void v2DI(const int vtx[2]);
203  void vertex2DW(fpreal32 x, fpreal32 y);
204  void vertex2DI(int x, int y);
205  void vertex2DS(int x, int y);
206 
207  // 3D Vertex creation
208  void v3DW(const float vtx[3]);
209  void vertex3DW(float x, float y, float z);
210 
211  /// Unfilled rectangles.
212  void rect2DW(fpreal32 x1, fpreal32 y1, fpreal32 x2, fpreal32 y2);
213  void rect2DS(int x1, int y1, int x2, int y2);
214  void box2DS(int x1, int y1, int x2, int y2);
215 
216  /// Filled rectangles.
217  void rectf2DW(fpreal32 x1, fpreal32 y1, fpreal32 x2, fpreal32 y2);
218  void rectf2DS(int x1, int y1, int x2, int y2);
219  void boxf2DS(int x1, int y1, int x2, int y2);
220 
221  /// Unfilled circles and arcs.
222  void circleW(float x, float y, float r);
223  void circleS(int x, int y, int r);
224  void arcW(float x, float y, float r, int angle_start, int angle_end);
225  void arcS(int x, int y, int r, int angle_start, int angle_end);
226 
227 
228  /// Filled circles and arcs.
229  void circlefW(float x, float y, float r);
230  void circlefS(int x, int y, int r);
231  void arcfW(float x, float y, float r, int angle_start, int angle_end);
232  void arcfS(int x, int y, int r, int angle_start, int angle_end);
233 
234  // Rings and Sectors
235  void ringfW(float x, float y, float inner_r, float outer_r);
236  void ringfS(int x, int y, int inner_r, int outer_r);
237  void sectorW(float x, float y, float inner_r, float outer_r,
238  float angle_start, float angle_end);
239  void sectorfW(float x, float y, float inner_r, float outer_r,
240  float angle_start, float angle_end);
241 
242 
243  static RV_ShaderProgram* getUIShader(RV_Instance* inst);
244  static RV_ShaderProgram* getUIPickShader(RV_Instance* inst);
245 
246  static void cleanup();
247 
248  static fpreal32 getBufferedRenderZBump();
249 
250  protected:
251  virtual void addVertex(fpreal32 x, fpreal32 y, fpreal32 z);
252 
253  void resetCurrentZ();
254  bool hasAnyData();
255  void clearSourceData();
256 
257  /// Basic vertex properties.
265 
267 
272 
274 
275  private:
276  bool getPrimitiveIsActive() const;
277 
278  void buildGeometry(RV_Render* r);
279  void createUISet(
280  RV_Render* r,
281  RV_Instance* inst,
282  RV_ShaderProgram* draw_shader,
283  bool pickpass,
284  int pick_depthpass,
287  void renderPrimitives(RV_Render* r, bool pickpass, int pick_depthpass);
288 
289  int myTriangleVertexCount;
290  bool myTriangleBuildFan;
291  bool myTriangleBuildStrip;
292  int myPolygonMaxVertexCount;
293  int myLineVertexCount;
294  bool myLineClosed;
295  bool myLineSegments;
296  int myPointVertexCount;
297 
298  UT_Array<UT_Vector4F> myColorStack;
299  UT_Array<bool> myLineSmoothStack;
300  UT_Array<RE_LineStyle> myLineStyleStack;
301  UT_Array<fpreal32> myLineWidthStack;
302  UT_Array<fpreal32> myPointSizeStack;
303 
304  fpreal32 myZ;
305  fpreal32 myZStart;
306  fpreal32 myXPerPixel;
307  fpreal32 myYPerPixel;
308  fpreal32 myXOrigin;
309  fpreal32 myYOrigin;
310 
311  UT_Matrix4F myViewMatrix;
312  UT_Matrix4F myProjMatrix;
313  bool myMatricesSet;
314  UT_Vector3i myPickBaseID;
315  UT_Vector3i myPickComponentID;
316 
317  /// Convexer for concave polygons.
319 
320  /// Cached geometry for rendering.
321  UT_UniquePtr<RV_Geometry> myTriangleGeometry;
322  UT_UniquePtr<RV_Geometry> myLineGeometry;
323  UT_UniquePtr<RV_Geometry> myLineDottedGeometry;
324  UT_UniquePtr<RV_Geometry> myLineSmoothGeometry;
325  UT_UniquePtr<RV_Geometry> myLineWideGeometry;
326  UT_UniquePtr<RV_Geometry> myPointGeometry;
327 };
328 
331 
332 // Inline implementations
333 inline void RV_RenderUI::c3DW(const fpreal32 clr[3]) {
334  setColor(clr[0], clr[1], clr[2], 1.0f);
335 }
336 
337 inline void RV_RenderUI::c4DW(const fpreal32 clr[4]) {
338  setColor(clr[0], clr[1], clr[2], clr[3]);
339 }
340 
342  fpreal32 vtxf[2] = {x, y};
343  v2DW(vtxf);
344 }
345 
346 inline void RV_RenderUI::vertex2DI(int x, int y) {
347  fpreal32 vtxf[2] = {fpreal32(x + 0.375f), fpreal32(y + 0.375f)};
348  v2DW(vtxf);
349 }
350 
351 inline void RV_RenderUI::vertex2DS(int x, int y) {
352  fpreal32 vtxf[2] = {fpreal32(x + 0.375f), fpreal32(y + 0.375f)};
353  v2DW(vtxf);
354 }
355 
356 inline void RV_RenderUI::v2DI(const int vtx[2]) {
357  fpreal32 vtxf[2] = {fpreal32(vtx[0] + 0.375f), fpreal32(vtx[1] + 0.375f)};
358  v2DW(vtxf);
359 }
360 
361 inline void RV_RenderUI::vertex3DW(float x, float y, float z) {
362  float vtx[3] = {x, y, z};
363  v3DW(vtx);
364 }
365 
366 #endif // RV_RenderUI_h
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
UT_Array< UT_Vector4F > myColorData
Definition: RV_RenderUI.h:259
UT_Fpreal32Array myWidthData
Definition: RV_RenderUI.h:261
UT_SharedPtr< RV_RenderUI > RV_RenderUIHandle
Definition: RV_RenderUI.h:329
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
GLboolean GLboolean g
Definition: glcorearb.h:1222
fpreal32 getYOrigin() const
Definition: RV_RenderUI.h:87
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
void c4DW(const fpreal32 clr[4])
Definition: RV_RenderUI.h:337
UT_Vector3Array myPositionData
Basic vertex properties.
Definition: RV_RenderUI.h:258
RE_LineStyle
Definition: RE_Types.h:459
void vertex2DW(fpreal32 x, fpreal32 y)
Definition: RV_RenderUI.h:341
GLint y
Definition: glcorearb.h:103
void v3DW(const float vtx[3])
float fpreal32
Definition: SYS_Types.h:200
Temporary container for either a RV_Render and an RE_Render.
GLdouble GLdouble x2
Definition: glad.h:2349
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UT_Array< UT_Vector3i > myPickComponentData
Definition: RV_RenderUI.h:264
UT_IntArray myPointElementData
Definition: RV_RenderUI.h:273
void v2DW(const fpreal32 vtx[2])
Create vertices for primitives.
GLfloat f
Definition: glcorearb.h:1926
UT_IntArray myLineElementData
Definition: RV_RenderUI.h:268
void v2DI(const int vtx[2])
Definition: RV_RenderUI.h:356
UT_Fpreal32Array myPointSizeData
Definition: RV_RenderUI.h:260
UT_IntArray myLineDottedElementData
Definition: RV_RenderUI.h:269
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
constexpr auto set(type rhs) -> int
Definition: core.h:610
fpreal32 getXPerPixel() const
Get x or y distance in current units that corresponds to 1 pixel.
Definition: RV_RenderUI.h:84
GLdouble y1
Definition: glad.h:2349
UT_Fpreal32Array myLineStyleData
Definition: RV_RenderUI.h:262
#define RV_API
Definition: RV_API.h:10
void vertex2DS(int x, int y)
Definition: RV_RenderUI.h:351
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
GLint GLenum GLint x
Definition: glcorearb.h:409
UT_IntArray myTriangleElementData
Definition: RV_RenderUI.h:266
UT_IntArray myLineSmoothElementData
Definition: RV_RenderUI.h:270
void setColor(const UT_Color &c, fpreal32 a=1.0f)
FS_API bool cleanup(UT_StringArray &removed, UT_StringArray &error_files, exint &memory_freed, bool dry_run, const char *override_path=nullptr)
UT_IntArray myLineWideElementData
Definition: RV_RenderUI.h:271
GLsizeiptr size
Definition: glcorearb.h:664
fpreal64 fpreal
Definition: SYS_Types.h:283
void vertex3DW(float x, float y, float z)
Definition: RV_RenderUI.h:361
GLint GLsizei width
Definition: glcorearb.h:103
fpreal32 getYPerPixel() const
Definition: RV_RenderUI.h:85
UT_Array< RV_RenderUIHandle > RV_RenderUIArray
Definition: RV_RenderUI.h:330
GLboolean r
Definition: glcorearb.h:1222
void vertex2DI(int x, int y)
Definition: RV_RenderUI.h:346
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
UT_Array< UT_Vector3i > myPickBaseData
Definition: RV_RenderUI.h:263
void c3DW(const fpreal32 clr[3])
Set vertex attributes.
Definition: RV_RenderUI.h:333
fpreal32 getXOrigin() const
Definition: RV_RenderUI.h:86