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 
35 /// Vulkan text rendering class for viewport UI elements.
37 {
38 public:
39  RV_TextRender();
40  ~RV_TextRender();
41 
42  RV_TextRender(const RV_TextRender &) = delete;
43  RV_TextRender &operator=(const RV_TextRender &) = delete;
44 
45  /// Initialize text rendering with the given viewport. Clears any existing
46  /// text entries.
47  void beginText(RV_Render *r, const UT_DimRect &viewport);
48 
49  /// Add a text string to be rendered with the given font, position, and
50  /// color.
51  void addText(
52  const char *text,
53  RE_Font &font,
54  fpreal32 x,
55  fpreal32 y,
56  const UT_Color &color,
57  fpreal32 alpha = 1.0f);
58 
59  /// Add a text string to be rendered with the given font, position, depth,
60  /// and color.
61  void addText(
62  const char *text,
63  RE_Font &font,
64  fpreal32 x,
65  fpreal32 y,
66  fpreal32 z,
67  const UT_Color &color,
68  fpreal32 alpha = 1.0f);
69 
70  /// Build the geometry and texture data needed for rendering. Needs to be
71  /// called after beginText() and before render().
72  void endText();
73 
74  /// Render the text
75  void render(RV_Render *r);
76 
77  void render(RV_Render *r, const UT_DimRect &viewport);
78 
79  void render(RV_Render *r, const UT_Matrix4F &proj);
80 
81  /// Clear the text entries
82  void clear();
83 
84  void setEnableBlending(bool val) { myEnableBlending = val; }
85  void setPreserveDepthState(bool val) { myPreserveDepthState = val; }
86 
87  /// Check if there is any text to render.
88  bool hasText() const { return !myTextEntries.isEmpty(); }
89 
90  /// Get the number of text entries awaiting rendering
91  int numEntries() const { return myTextEntries.entries(); }
92 
93  /// Render text directly. This should be used for simple single-string
94  /// rendering as it does not batch render calls.
95 
96  static void renderText(
97  RV_Render *r,
98  RE_Font &font,
99  const char *text,
100  fpreal32 x,
101  fpreal32 y,
102  fpreal32 z,
103  const UT_Color &color,
104  fpreal32 alpha,
105  const UT_DimRect &viewport);
106 
107  static void renderText(
108  RV_Render *r,
109  RE_Font &font,
110  const char *text,
111  fpreal32 x,
112  fpreal32 y,
113  const UT_Color &color,
114  fpreal32 alpha,
115  const UT_DimRect &viewport)
116  {
117  renderText(r, font, text, x, y, 0.0f, color, alpha, viewport);
118  }
119 
120  /// Convienience function to render text with a soft shadow (1 px offset)
121  static void renderTextWithShadow(
122  RV_Render *r,
123  RE_Font &font,
124  const char *text,
125  fpreal32 x,
126  fpreal32 y,
127  fpreal32 z,
128  const UT_Color &text_color,
129  const UT_Color &shadow_color,
130  fpreal32 alpha_scale,
131  const UT_DimRect &viewport);
132 
133  static void renderTextWithShadow(
134  RV_Render *r,
135  RE_Font &font,
136  const char *text,
137  fpreal32 x,
138  fpreal32 y,
139  const UT_Color &text_color,
140  const UT_Color &shadow_color,
141  fpreal32 alpha_scale,
142  const UT_DimRect &viewport)
143  {
144  renderTextWithShadow(
145  r, font, text, x, y, 0.0f, text_color, shadow_color,
146  alpha_scale, viewport);
147  }
148 
149  static void cleanup();
150 
151 private:
152  // Get or create the text rendering shader program if not initialized.
153  static RV_ShaderProgram *getTextShader(RV_Instance *inst);
154 
155  // Build the geometry from accumulated text entries
156  void buildGeometry(RV_Render *r);
157 
158  // A single text entry to be rendered
159  struct TextEntry
160  {
161  TextEntry() = default;
162  TextEntry(
163  const UT_StringHolder &text,
164  RE_Font *font,
165  const UT_Vector3F &position,
166  const UT_Color &color,
167  fpreal32 alpha = 1.0f);
168 
169  UT_StringHolder myText;
170  RE_Font *myFont = nullptr;
171  UT_Vector3F myPosition;
172  UT_Color myColor;
173  fpreal32 myAlpha = 1.0f;
174  };
175  UT_Array<TextEntry> myTextEntries;
176 
177  // Text data for rendering
178  class TextDeferData
179  {
180  public:
181  TextDeferData();
182  ~TextDeferData();
183 
184  TextDeferData(TextDeferData &&other) noexcept;
185  TextDeferData &operator=(TextDeferData &&other) noexcept;
186 
187  TextDeferData(const TextDeferData &) = delete;
188  TextDeferData &operator=(const TextDeferData &) = delete;
189 
190  RV_VKImage *myAtlasTexture;
191 
192  UT_UniquePtr<RV_Geometry> myGeometry;
193 
194  int myNumVertices;
195  };
196  UT_Array<TextDeferData> myDeferData;
197 
198  UT_DimRect myViewport;
199  bool myIsBuilding;
200  bool myEnableBlending;
201  bool myPreserveDepthState;
202 };
203 
204 #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)
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
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
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
Vulkan text rendering class for viewport UI elements.
Definition: RV_TextRender.h:36
void setEnableBlending(bool val)
Definition: RV_TextRender.h:84
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:50
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)
int numEntries() const
Get the number of text entries awaiting rendering.
Definition: RV_TextRender.h:91
GLuint color
Definition: glcorearb.h:1261
LeafData & operator=(const LeafData &)=delete
void setPreserveDepthState(bool val)
Definition: RV_TextRender.h:85
SIM_API const UT_StringHolder position
GLuint GLfloat * val
Definition: glcorearb.h:1608
GLboolean r
Definition: glcorearb.h:1222
bool hasText() const
Check if there is any text to render.
Definition: RV_TextRender.h:88