HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_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: RE_RenderUI.h ( RE Library, C++)
7  */
8 
9 #ifndef __RE_RenderUI__
10 #define __RE_RenderUI__
11 
12 #include "RE_API.h"
13 #include "RE_Types.h"
14 #include "RE_Font.h"
15 #include <UT/UT_BoundingRect.h>
16 #include <UT/UT_ValArray.h>
17 #include <UT/UT_Vector2Array.h>
18 #include <UT/UT_Vector3Array.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_SharedPtr.h>
21 #include <UT/UT_UniquePtr.h>
22 
23 class re_PolyConvex;
24 class RE_VertexArray;
25 class RE_ShaderHandle;
26 class RE_Render;
27 class RE_Shader;
28 
30 {
31 public:
32  RE_RenderUI();
33  virtual ~RE_RenderUI();
34 
35  void prepare(fpreal xperpixel, fpreal yperpixel,
36  fpreal xorigin, fpreal yorigin);
37  virtual void draw(RE_Render *r);
38  virtual void clearAllData();
39 
40  /// Get some standard fonts.
41  static RE_ShaderHandle *getUIShaderHandle(RE_Render *r);
42  static void initUIShaderUniforms(RE_Render *r,
44  static void initUIShaderUniforms(RE_Render *r,
45  RE_Shader *shader);
46  static fpreal32 getBufferedRenderZBump();
47 
48  /// Change the rendering "layer". This just modifies the depth
49  /// coordinate of the primitives.
50  void bumpLayer(int delta);
51 
52  /// Set the base depth for rendering this object. Provide a function
53  /// the get the final Z to use as the base for another object.
54  virtual void setZStart(fpreal32 zStart);
55  fpreal32 getZStart() const;
56  fpreal32 getZEnd() const;
57  void incrementZEnd();
58 
59  /// Get x or y distance in current units that corresponds to 1 pixel.
61  { return myXPerPixel; }
63  { return myYPerPixel; }
65  { return myXOrigin; }
67  { return myYOrigin; }
68 
69  /// These are options that can change per-vertex.
70  void pushColor();
71  void pushColor(const UT_Color &c,
72  fpreal32 a = 1.0f);
73  void pushColor(fpreal32 r, fpreal32 g, fpreal32 b,
74  fpreal32 a = 1.0f);
75  void setColor(const UT_Color &c,
76  fpreal32 a = 1.0f);
77  void setColor(fpreal32 r, fpreal32 g, fpreal32 b,
78  fpreal32 a = 1.0f);
79  void setAlpha(fpreal32 a);
80  void popColor();
81  void getColor(UT_Color &c) const;
82  fpreal32 getAlpha() const;
83 
84  /// Point options that can change per-point.
85  void pushPointSize(fpreal32 size);
86  void setPointSize(fpreal32 size);
87  void popPointSize();
88 
89  /// Line options that can change per-line.
90  void pushLineSmoothing(bool smooth_lines);
91  void pushLineSmoothing();
92  void setLineSmoothing(bool smooth_lines);
93  void popLineSmoothing();
94  void pushLineStyle(RE_LineStyle style);
95  void pushLineStyle();
96  void setLineStyle(RE_LineStyle style);
97  void popLineStyle();
98  void pushLineWidth(fpreal32 width);
99  void pushLineWidth();
100  void setLineWidth(fpreal32 width);
101  void popLineWidth();
102 
103  /// These functions mark the start or end of primitives.
104  void beginTriangles();
105  void endTriangles();
106  void beginTriangleFan();
107  void endTriangleFan();
108  void beginTriMesh();
109  void endTriMesh();
110 
111  void beginQuads();
112  void endQuads();
113  void beginQuadStrip();
114  void endQuadStrip();
115 
116  void beginPolygon(int concave);
117  void endPolygon();
118 
119  void beginLine();
120  void beginClosedLine();
121  void endLine();
122  void beginLines();
123  void endLines();
124 
125  void beginPoint();
126  void endPoint();
127 
128  /// Set vertex attributes.
129  void t2DW(const fpreal32 tx[2]);
130  void c3DW(const fpreal32 clr[3]);
131  void c4DW(const fpreal32 clr[4]);
132 
133  /// Create vertices for primitives.
134  void v2DW(const fpreal32 vtx[2]);
135  void v2DI(const int vtx[2]);
136  void vertex2DW(fpreal32 x, fpreal32 y);
137  void vertex2DI(int x, int y);
138  void vertex2DS(int x, int y);
139 
140  /// Text rendering functions.
141  void setFont(RE_Font &font);
142  void textMoveW(fpreal32 x, fpreal32 y);
143  void textMoveS(int x, int y);
144  void putMultiLineString(const utf8 *str);
145  void putString(RE_Font &font,
146  const utf8 *start, const utf8 *end,
147  UT_Unicode::transform *xform
148  = nullptr);
149  void putString(RE_Font &font,
150  const UT_StringView &sv,
151  UT_Unicode::transform *xform
152  = nullptr)
153  { putString(font,sv.begin(),sv.end(),xform); }
154  void putString(const utf8 *start, const utf8 *end);
155  void putString(const utf8 *str);
156  void putChar(utf32 c);
157 
158  /// Unfilled rectangles.
159  void rect2DW(fpreal32 x1, fpreal32 y1,
161  void rect2DS(int x1, int y1,
162  int x2, int y2);
163  void box2DS(int x1, int y1,
164  int x2, int y2);
165  /// Filled rectangles.
166  void rectf2DW(fpreal32 x1, fpreal32 y1,
168  void rectf2DS(int x1, int y1,
169  int x2, int y2);
170  void boxf2DS(int x1, int y1,
171  int x2, int y2);
172 
173  /// Unfilled arcs.
174  void circleW(float x, float y, float r);
175  void circleS(int x, int y, int r);
176  void arcW(float x, float y, float r,
177  int angle_start, int angle_end);
178  void arcS(int x, int y, int r,
179  int angle_start, int angle_end);
180 
181  /// Filled arcs.
182  void circlefW(float x, float y, float r);
183  void circlefS(int x, int y, int r);
184  void arcfW(float x, float y, float r,
185  int angle_start, int angle_end);
186  void arcfS(int x, int y, int r,
187  int angle_start, int angle_end);
188 
189  /// Partially filled circles (filled between inner and outer radii).
190  void ringfW(float x, float y,
191  float inner_r, float outer_r);
192  void ringfS(int x, int y, int inner_r, int outer_r);
193 
194  /// Partially filled arcs (filled between inner and outer radii).
195  void sectorW(float x, float y,
196  float inner_r, float outer_r,
197  float angle_start, float angle_end);
198  void sectorfW(float x, float y,
199  float inner_r, float outer_r,
200  float angle_start, float angle_end);
201 
202  /// A few limited functions for handling drawing to a 3D viewport.
203  void v3DW(const float vtx[3]);
204  void vertex3DW(float x, float y, float z);
205  void textMove3W(float x, float y, float z);
206 
207 protected:
208  /// The underlying function for adding a new vertex to our data arrays.
209  virtual void addVertex(fpreal32 x, fpreal32 y, fpreal32 z,
210  fpreal32 u = -1.0f,
211  fpreal32 v = -1.0f);
212  virtual void createVertexArrays(RE_Render *r, int nelems);
213  virtual void fillVertexArrays(RE_Render *r, int nelems);
214  virtual void bindVertexArrays(RE_Render *r);
215  virtual void unbindVertexArrays(RE_Render *r);
216  virtual bool applyDepthTestingToText() const;
217 
218  RE_Texture *createPatternTexture(RE_Render *r);
219  void pushDepthStateBeforeDraw(RE_Render *r);
220  void popDepthStateAfterDraw(RE_Render *r);
221  bool prepareText(RE_Render *r,
222  bool use_shared_buffers);
223  void renderText(RE_Render *r);
224 
225  void resetCurrentZ();
226  bool hasAnyData();
227  void clearSourceData();
228 
229  /// Basic vertex properties.
238 
239  /// Triangle primitives.
242 
243  /// Line primitives.
250 
251  /// Point primitives.
256 
257 private:
258  bool getPrimitiveIsActive() const;
259  inline void incrementLinePatternPos(
260  const UT_Vector3 &src_pos,
261  const fpreal32 dst_pos[2]);
262 
263  /// Data for tracking primitives while building the data arrays.
264  int myTriangleVertexCount;
265  bool myTriangleBuildFan;
266  bool myTriangleBuildStrip;
267  int myPolygonMaxVertexCount;
268  int myLineVertexCount;
269  fpreal32 myLinePatternPos;
270  bool myLineClosed;
271  bool myLineSegments;
272  int myPointVertexCount;
273 
274  /// Additional attributes.
275  UT_Array<UT_FRGBA> myColorStack;
276  UT_Array<bool> myLineSmoothStack;
277  UT_Array<RE_LineStyle> myLineStyleStack;
278  UT_Array<fpreal32> myLineWidthStack;
279  UT_Array<fpreal32> myPointSizeStack;
280 
281  /// Global state.
282  UT_Vector2F myImageUV;
283  fpreal32 myZ;
284  fpreal32 myZStart;
285  fpreal32 myXPerPixel;
286  fpreal32 myYPerPixel;
287  fpreal32 myXOrigin;
288  fpreal32 myYOrigin;
289 
290  /// Text rendering data.
291  RE_Font *myTextFont;
292  UT_Vector3 myTextPosition;
293  UT_StringArray myTextStrings;
295  UT_Array<RE_Font *> myTextFonts;
296  UT_Vector3Array myTextPositions;
297  UT_Array<UT_FRGBA> myTextColors;
298  UT_Array<RE_FontDeferData> myTextDeferData;
299 
300  /// Polygon convexing.
301  UT_UniquePtr<re_PolyConvex> myConvexer;
302 };
303 
306 
307 inline void
309 {
310  myImageUV.assign(tx[0], tx[1]);
311 }
312 
313 inline void
315 {
316  setColor(clr[0], clr[1], clr[2], 1.0f);
317 }
318 
319 inline void
321 {
322  setColor(clr[0], clr[1], clr[2], clr[3]);
323 }
324 
325 inline void
327 {
328  fpreal32 vtxf[2] = { x, y };
329  v2DW(vtxf);
330 }
331 
332 inline void
334 {
335  fpreal32 vtxf[2] = { fpreal32(x+0.375f), fpreal32(y+0.375f) };
336  v2DW(vtxf);
337 }
338 
339 inline void
341 {
342  fpreal32 vtxf[2] = { fpreal32(x+0.375f), fpreal32(y+0.375f) };
343  v2DW(vtxf);
344 }
345 
346 inline void
347 RE_RenderUI::v2DI(const int vtx[2])
348 {
349  fpreal32 vtxf[2] = { fpreal32(vtx[0]+0.375f),
350  fpreal32(vtx[1]+0.375f) };
351  v2DW(vtxf);
352 }
353 
354 #endif // __RE_RenderUI__
355 
void v2DI(const int vtx[2])
Definition: RE_RenderUI.h:347
UT_UniquePtr< RE_VertexArray > myLineElementArray
Definition: RE_RenderUI.h:245
UT_Vector2Array myImageUVData
Definition: RE_RenderUI.h:236
#define RE_API
Definition: RE_API.h:10
const GLdouble * v
Definition: glcorearb.h:837
UT_Vector2Array myPatternUVData
Definition: RE_RenderUI.h:234
GLuint start
Definition: glcorearb.h:475
UT_IntArray myLineWideElementData
Definition: RE_RenderUI.h:248
UT_Array< UT_FRGBA > myColorData
Definition: RE_RenderUI.h:232
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
GLboolean GLboolean g
Definition: glcorearb.h:1222
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator end() const
Returns a constant iterator pointing to the end of the string.
UT_SharedPtr< RE_RenderUI > RE_RenderUIHandle
Definition: RE_RenderUI.h:304
void putString(RE_Font &font, const UT_StringView &sv, UT_Unicode::transform *xform=nullptr)
Definition: RE_RenderUI.h:149
RE_LineStyle
Definition: RE_Types.h:452
GLint y
Definition: glcorearb.h:103
UT_UniquePtr< RE_VertexArray > myLineSmoothElementArray
Definition: RE_RenderUI.h:247
UT_UniquePtr< RE_VertexArray > myTriangleElementArray
Definition: RE_RenderUI.h:241
float fpreal32
Definition: SYS_Types.h:200
void vertex2DW(fpreal32 x, fpreal32 y)
Definition: RE_RenderUI.h:326
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
fpreal32 getYPerPixel() const
Definition: RE_RenderUI.h:62
UT_IntArray myTriangleElementData
Triangle primitives.
Definition: RE_RenderUI.h:240
A utility class to do read-only operations on a subset of an existing string.
Definition: UT_StringView.h:39
GLfloat f
Definition: glcorearb.h:1926
UT_Vector3Array myPositionData
Basic vertex properties.
Definition: RE_RenderUI.h:230
void setColor(const UT_Color &c, fpreal32 a=1.0f)
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
unsigned int utf32
Definition: SYS_Types.h:58
UT_UniquePtr< RE_VertexArray > myImageUVArray
Definition: RE_RenderUI.h:237
void c4DW(const fpreal32 clr[4])
Definition: RE_RenderUI.h:320
GLuint GLuint end
Definition: glcorearb.h:475
GLdouble y1
Definition: glad.h:2349
UT_UniquePtr< RE_VertexArray > myColorArray
Definition: RE_RenderUI.h:233
UT_UniquePtr< RE_VertexArray > myPointElementArray
Definition: RE_RenderUI.h:253
void t2DW(const fpreal32 tx[2])
Set vertex attributes.
Definition: RE_RenderUI.h:308
UT_UniquePtr< RE_VertexArray > myPointSizeArray
Definition: RE_RenderUI.h:255
UT_UniquePtr< RE_VertexArray > myPositionArray
Definition: RE_RenderUI.h:231
UT_Fpreal32Array myPointSizeData
Definition: RE_RenderUI.h:254
UT_IntArray myPointElementData
Point primitives.
Definition: RE_RenderUI.h:252
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
UT_Array< RE_RenderUIHandle > RE_RenderUIArray
Definition: RE_RenderUI.h:305
UT_UniquePtr< RE_VertexArray > myLineWideElementArray
Definition: RE_RenderUI.h:249
void vertex2DS(int x, int y)
Definition: RE_RenderUI.h:340
fpreal32 getYOrigin() const
Definition: RE_RenderUI.h:66
GLsizeiptr size
Definition: glcorearb.h:664
GLuint shader
Definition: glcorearb.h:785
fpreal64 fpreal
Definition: SYS_Types.h:277
void vertex2DI(int x, int y)
Definition: RE_RenderUI.h:333
UT_UniquePtr< RE_VertexArray > myPatternUVArray
Definition: RE_RenderUI.h:235
UT_IntArray myLineSmoothElementData
Definition: RE_RenderUI.h:246
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator begin() const
Returns a constant iterator pointing to the beginning of the string.
GLint GLsizei width
Definition: glcorearb.h:103
void assign(T xx=0.0f, T yy=0.0f)
Set the values of the vector components.
Definition: UT_Vector2.h:446
char utf8
Definition: SYS_Types.h:52
GLboolean r
Definition: glcorearb.h:1222
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
void v2DW(const fpreal32 vtx[2])
Create vertices for primitives.
fpreal32 getXOrigin() const
Definition: RE_RenderUI.h:64
UT_IntArray myLineElementData
Line primitives.
Definition: RE_RenderUI.h:244
fpreal32 getXPerPixel() const
Get x or y distance in current units that corresponds to 1 pixel.
Definition: RE_RenderUI.h:60
Simple interface to building a shader from a .prog file.
void c3DW(const fpreal32 clr[3])
Definition: RE_RenderUI.h:314