HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_TextRender.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_TextRender.h ( RV Library, C++)
7  *
8  */
9 
10 #ifndef RV_TextRender_h
11 #define RV_TextRender_h
12 
13 #include "RV_API.h"
14 #include "RV_TypePtrs.h"
15 
16 #include <UT/UT_Array.h>
17 #include <UT/UT_Color.h>
18 #include <UT/UT_Rect.h>
19 #include <UT/UT_SharedPtr.h>
20 #include <UT/UT_StringHolder.h>
21 #include <UT/UT_UniquePtr.h>
22 #include <UT/UT_Vector2.h>
23 #include <UT/UT_Vector3.h>
24 #include <UT/UT_Vector4.h>
25 
26 class RE_Font;
27 class RV_Geometry;
28 class RV_Instance;
29 class RV_Render;
30 class RV_ShaderProgram;
32 class RV_VKImage;
33 
34 /// Text data for rendering
36 {
37 public:
40 
41  RV_TextDeferData(RV_TextDeferData &&other) noexcept;
42  RV_TextDeferData &operator=(RV_TextDeferData &&other) noexcept;
43 
44  RV_TextDeferData(const RV_TextDeferData &) = delete;
45  RV_TextDeferData &operator=(const RV_TextDeferData &) = delete;
46 
48 
50 
52 };
53 
54 /// A single text entry to be rendered
56 {
57  RV_TextEntry() = default;
59  const UT_StringHolder &text,
60  RE_Font *font,
61  const UT_Vector3F &position,
62  const UT_Color &color,
63  fpreal32 alpha = 1.0f);
64 
66  RE_Font *myFont = nullptr;
69  fpreal32 myAlpha = 1.0f;
70 };
71 
72 /// Vulkan text rendering class for viewport UI elements.
74 {
75 public:
76  RV_TextRender();
77  ~RV_TextRender();
78 
79  RV_TextRender(const RV_TextRender &) = delete;
80  RV_TextRender &operator=(const RV_TextRender &) = delete;
81 
82  /// Initialize text rendering with the given viewport. Clears any existing
83  /// text entries.
84  void beginText(RV_Render *r, const UT_DimRect &viewport);
85 
86  /// Add a text string to be rendered with the given font, position, and
87  /// color.
88  void addText(
89  const char *text,
90  RE_Font &font,
91  fpreal32 x,
92  fpreal32 y,
93  const UT_Color &color,
94  fpreal32 alpha = 1.0f);
95 
96  /// Add a text string to be rendered with the given font, position, depth,
97  /// and color.
98  void addText(
99  const char *text,
100  RE_Font &font,
101  fpreal32 x,
102  fpreal32 y,
103  fpreal32 z,
104  const UT_Color &color,
105  fpreal32 alpha = 1.0f);
106 
107  /// Build the geometry and texture data needed for rendering. Needs to be
108  /// called after beginText() and before render().
109  void endText();
110 
111  /// Render the text
112  void render(RV_Render *r);
113 
114  void render(RV_Render *r, const UT_DimRect &viewport);
115 
116  void render(RV_Render *r, const UT_Matrix4F &proj);
117 
118  /// Clear the text entries
119  void clear();
120 
121  void setEnableBlending(bool val) { myEnableBlending = val; }
122  void setPreserveDepthState(bool val) { myPreserveDepthState = val; }
123 
124  /// Check if there is any text to render.
125  bool hasText() const { return !myTextEntries.isEmpty(); }
126 
127  /// Get the number of text entries awaiting rendering
128  int numEntries() const { return myTextEntries.entries(); }
129 
130  /// Render text directly. This should be used for simple single-string
131  /// rendering as it does not batch render calls.
132 
133  static void renderText(
134  RV_Render *r,
135  RE_Font &font,
136  const char *text,
137  fpreal32 x,
138  fpreal32 y,
139  fpreal32 z,
140  const UT_Color &color,
141  fpreal32 alpha,
142  const UT_DimRect &viewport);
143 
144  static void renderText(
145  RV_Render *r,
146  RE_Font &font,
147  const char *text,
148  fpreal32 x,
149  fpreal32 y,
150  const UT_Color &color,
151  fpreal32 alpha,
152  const UT_DimRect &viewport)
153  {
154  renderText(r, font, text, x, y, 0.0f, color, alpha, viewport);
155  }
156 
157  /// Convienience function to render text with a soft shadow (1 px offset)
158  static void renderTextWithShadow(
159  RV_Render *r,
160  RE_Font &font,
161  const char *text,
162  fpreal32 x,
163  fpreal32 y,
164  fpreal32 z,
165  const UT_Color &text_color,
166  const UT_Color &shadow_color,
167  fpreal32 alpha_scale,
168  const UT_DimRect &viewport);
169 
170  static void renderTextWithShadow(
171  RV_Render *r,
172  RE_Font &font,
173  const char *text,
174  fpreal32 x,
175  fpreal32 y,
176  const UT_Color &text_color,
177  const UT_Color &shadow_color,
178  fpreal32 alpha_scale,
179  const UT_DimRect &viewport)
180  {
181  renderTextWithShadow(
182  r, font, text, x, y, 0.0f, text_color, shadow_color,
183  alpha_scale, viewport);
184  }
185 
186  static void cleanup();
187 
188 private:
189  /// Get or create the text rendering shader program if not initialized.
190  static RV_ShaderProgram *getTextShader(RV_Instance *inst);
191 
192  /// Build the geometry from accumulated text entries
193  void buildGeometry(RV_Render *r);
194 
195  UT_Array<RV_TextEntry> myTextEntries;
196  UT_Array<RV_TextDeferData> myDeferData;
197  UT_DimRect myViewport;
198  bool myIsBuilding;
199  bool myEnableBlending;
200  bool myPreserveDepthState;
201 };
202 
203 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
static void renderText(RV_Render *r, RE_Font &font, const char *text, fpreal32 x, fpreal32 y, const UT_Color &color, fpreal32 alpha, const UT_DimRect &viewport)
RV_VKImage * myAtlasTexture
Definition: RV_TextRender.h:47
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
Text data for rendering.
Definition: RV_TextRender.h:35
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
GLint y
Definition: glcorearb.h:103
static void renderTextWithShadow(RV_Render *r, RE_Font &font, const char *text, fpreal32 x, fpreal32 y, const UT_Color &text_color, const UT_Color &shadow_color, fpreal32 alpha_scale, const UT_DimRect &viewport)
float fpreal32
Definition: SYS_Types.h:200
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
UT_UniquePtr< RV_Geometry > myGeometry
Definition: RV_TextRender.h:49
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UT_Vector3F myPosition
Definition: RV_TextRender.h:67
Vulkan text rendering class for viewport UI elements.
Definition: RV_TextRender.h:73
void setEnableBlending(bool val)
GLfloat f
Definition: glcorearb.h:1926
#define RV_API
Definition: RV_API.h:10
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
GLint GLenum GLint x
Definition: glcorearb.h:409
FS_API bool cleanup(UT_StringArray &removed, UT_StringArray &error_files, exint &memory_freed, bool dry_run, const char *override_path=nullptr)
UT_StringHolder myText
Definition: RV_TextRender.h:65
int numEntries() const
Get the number of text entries awaiting rendering.
UT_Color myColor
Definition: RV_TextRender.h:68
GLuint color
Definition: glcorearb.h:1261
LeafData & operator=(const LeafData &)=delete
void setPreserveDepthState(bool val)
SIM_API const UT_StringHolder position
GLuint GLfloat * val
Definition: glcorearb.h:1608
A single text entry to be rendered.
Definition: RV_TextRender.h:55
GLboolean r
Definition: glcorearb.h:1222
bool hasText() const
Check if there is any text to render.