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