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