HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_DecorationRender.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: GR_DecorationRender.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * Base class for decoration rendering
10  */
11 #ifndef GR_DecorationRender_h
12 #define GR_DecorationRender_h
13 
14 class RE_Render;
15 class RE_Shader;
16 class RE_Geometry;
17 class RE_ShaderRegistry;
18 class RV_Geometry;
19 class RV_Instance;
20 class RV_ShaderBlock;
21 class RV_ShaderProgram;
23 class GU_Detail;
24 class GR_DisplayOption;
25 class GR_GeoRender;
26 class GT_Primitive;
27 
28 #include <SYS/SYS_Types.h>
29 #include <UT/UT_Color.h>
30 #include <UT/UT_StringArray.h>
31 #include <UT/UT_BitArray.h>
32 #include <RE/RE_Texture.h>
33 #include <RE/RE_RenderContext.h>
34 
35 #include <GA/GA_Types.h>
36 #include <GT/GT_Types.h>
37 
38 #include "GR_API.h"
39 #include "GR_Defines.h"
40 #include "GR_RenderInfo.h"
41 #include "GR_UpdateParms.h"
42 
43 #define GR_DECOR_OPT_VECTOR_SCALE "vector_scale"
44 #define GR_DECOR_OPT_VECTOR_ARROW_TIP "vector_arrow_tip"
45 #define GR_DECOR_OPT_POINT_SCALE "point_scale"
46 #define GR_DECOR_OPT_COLOR "color"
47 #define GR_DECOR_OPT_SELECT_COLOR "select_color"
48 #define GR_DECOR_OPT_FONT_SIZE "font_size"
49 #define GR_DECOR_OPT_COLOR_ATTRIB "color_attrib"
50 #define GR_DECOR_OPT_NORMALIZE "normalize"
51 #define GR_DECOR_OPT_COLOR_XFORM "color_xform"
52 #define GR_DECOR_OPT_COLOR_XFORM_REF_VEC "color_xform_ref_vec"
53 
56 
58 {
59 public:
61  bool over,
62  bool over_vis,
63  int inst_grp,
65  : opts(opt),
66  overlay(over),
67  override_vis(over_vis),
68  instance_group(inst_grp),
69  render_flags(flags),
70  visualizer(NULL){ }
71 
73  bool overlay;
78 };
79 
80 
81 
82 
84 {
85 public:
87  virtual ~GR_DecorationRender();
88 
89  // Initializes all the decorations from the given display options.
90  // 'select_dec' is a bitfield of display option overrides (point marker,
91  // breakpoint marker, vertex marker)
92  // 'parms.needed_attribs' is modified so that any attributes a supported
93  // decoration migght need is appended to the list.
94  // 'supported' is a NULL terminated list of decorations supported by
95  // the primitive. (NULL is 0 or GR_NO_DECORATION)
96  void setupFromDisplayOptions(const GR_DisplayOption &opts,
97  GR_DecorationOverride select_dec,
99  const GR_Decoration *supported,
101 
102  // Returns true if this decoration renderer supports mouse-motion visibility
103  // modes, and one of these modes is active
105  { return myHasOverlayDecorations; }
106 
108  {
110  TARGET_OVERLAY
111  };
112 
114  {
120  PRIM_TYPE_COUNT
121  };
122 
123  // Update the geometry required to produce the active decorations. This may
124  // add new buffers to geo (normals, UV, etc).
125  bool updateDecoration(RE_Render *r,
127  const GT_Primitive &prim,
128  const GR_UpdateParms &p,
129  RE_Geometry &geo);
130 
131  // Update the geometry required to produce the active decorations. This may
132  // add new buffers to geo (normals, UV, etc).
133  bool updateDecoration(RE_RenderContext r,
135  const GT_Primitive &prim,
136  const GR_UpdateParms &p,
137  RV_Geometry &geo);
138 
139  // Called before any calls to drawSingle.
140  void setupDrawing(RE_RenderContext r);
141 
142  // Draw a single decoration. The visibility affects which framebuffer is
143  // currently being drawn (main or
144  void drawSingle(RE_Render *r,
145  RE_Geometry &geo,
147  const GR_DisplayOption *opt,
150  RenderTarget render_mode,
151  GR_DecorVisibility *vis_override,
152  PrimitiveType glprim_type,
153  int instance_group,
154  int select_inst,
155  RE_OverrideList *override_list);
156 
157  // Draw a single decoration. The visibility affects which framebuffer is
158  // currently being drawn (main or
159  void drawSingle(RE_RenderContext r,
160  RV_Geometry &geo,
161  GR_GeoRender *gr,
163  const GR_DisplayOption *opt,
166  RenderTarget render_mode,
167  GR_DecorVisibility *vis_override,
168  PrimitiveType glprim_type,
169  int instance_group,
170  int select_inst,
171  RV_OverrideList *override_list);
172 
173  // custom decorations
174  void drawSingleVisualizer(RE_Render *r,
175  RE_Geometry &geo,
176  const GR_VisualizerInfo *dec_info,
177  const GR_DisplayOption *opt,
179  PrimitiveType prim_type);
180 
181  void drawSingleVisualizer(RE_RenderContext r,
182  RV_Geometry &geo,
183  GR_GeoRender *gr,
184  const GR_VisualizerInfo *dec_info,
185  const GR_DisplayOption *opt,
187  PrimitiveType prim_type);
188 
189  static RE_Texture *getViewportFontTexture(RE_Render *r,
192  bool outlined,
193  UT_Vector3 &font_parms);
194 
195  /// Returns a 512-entry 1D texture.
196  static RE_Texture *getRampLookupTexture(RE_Render *r,
197  UT_ColorRamp rtype);
198 
199 
200  static void setupFontParms(RE_RenderContext r,
202  const GR_DisplayOption *opt,
203  GR_DecorFontType charset,
204  bool pointed_box,
205  UT_Vector3 &out_parms,
207 
208  static void bindViewportFontTexture(RE_RenderContext r,
212  bool outlined,
213  UT_Vector3 &out_parms);
214 
215  static void bindViewportVertexTexture(
218 
219  static bool initShaders(RV_Instance *inst);
220  static void cleanupShaders();
221 
222 private:
223  // Description of user decorations.
224  class GR_UserDecorInfo
225  {
226  public:
227  GR_UserDecorInfo()
228  : myCustomShaderRegistry(NULL),
229  myUserOption(NULL),
230  myAttribSize(0),
231  myIsFP(false),
232  myIsString(false)
233  { }
234  GR_UserDecorInfo(const RE_ShaderRegistry *shader_registry,
235  const GR_UserOption *user_option,
236  int attrib_size,
237  bool is_fp,
238  bool is_string)
239  : myCustomShaderRegistry(shader_registry),
240  myUserOption(user_option),
241  myAttribSize(attrib_size),
242  myIsFP(is_fp),
243  myIsString(is_string)
244  { }
245 
246  const RE_ShaderRegistry *myCustomShaderRegistry;
247  const GR_UserOption *myUserOption;
248  int myAttribSize;
249  bool myIsFP;
250  bool myIsString;
251  };
252 
253  static RE_Texture *getViewportBoxTexture(RE_Render *r,
255  bool pointed);
256 
257  static RE_Texture *getViewportVertexTexture(RE_Render *r);
258 
259  void updateUserDecoration(GR_Decoration dec,
260  const GT_Primitive &prim,
261  const GR_UpdateParms &p);
262 
263  bool showSelections() const
264  { return myRenderInfo->showSelections(); }
265  bool getDecorationEnabled(GR_Decoration dec)
266  { return myDecorEnabled[dec]; }
267 
268  const RE_ShaderRegistry *getUserDecorShaderRegistry(int decor) const;
269  const GR_UserOption *getUserOption(int decor) const;
270  int getUserDecorAttribSize(int decor) const;
271  bool isFPUserDecor(int decor) const;
272  bool isStringUserDecor(int decor) const;
273 
274  void getUserOptionColors(const GR_UserOption *user,
275  const GR_DisplayOption *opt,
276  UT_Color &col, UT_Color &select);
277 
278  // update a single decoration
279  bool update(RE_Render *r,
281  const GT_Primitive &prim,
282  const GR_UpdateParms &p,
283  RE_Geometry &geo);
284 
285  // draw a single decoration
286  void draw(RE_Render *r,
287  RE_Geometry &geo,
289  GR_DecorVisibility visibility,
290  const GR_DisplayOption *opt,
293  PrimitiveType prim_type,
294  int instance_group,
295  int select_inst,
296  RE_OverrideList *override_list);
297 
298  RE_Shader *setupDecorationParms(RE_Render *r,
299  RE_Geometry &geo,
301  GR_DecorVisibility vis,
303  const GR_DisplayOption *opt,
304  RE_PrimType &type,
305  fpreal32 color[4],
306  fpreal32 select_color[4],
307  fpreal32 &scale,
308  int &npasses,
309  RE_OverrideList &attrib_override,
310  PrimitiveType prim_type);
311 
312  void cleanupDecorationParms(RE_Render *r,
314 
315  void setupShaderDepthTest(RE_Render *r, RE_Shader *sh,
316  bool zwrites);
317  void setupFontParms(RE_Render *r,
318  RE_Shader *sh,
319  const GR_DisplayOption *opt,
321  bool pointed_box,
323  void setupVertexColors(RE_Render *r, RE_Shader *sh);
324  void cleanupFontParms(RE_Render *r);
325 
326  // visualizer-based decorations
327  void drawVisualizer(RE_Render *r,
328  RE_Geometry &geo,
329  const GR_VisualizerInfo *dec_info,
330  const GR_DisplayOption *opt,
332  PrimitiveType prim_type);
333 
334  RE_Shader * setupVisualizerDraw(RE_Render *r,
335  RE_Geometry &geo,
336  const GR_VisualizerInfo *dec_info,
337  const GR_DisplayOption *opt,
339  PrimitiveType prim_type,
340  RE_PrimType &re_prim,
341  int &npasses,
342  RE_OverrideList &overrides);
343 
344  void cleanupVisualizerDraw(RE_Render *r,
345  const GR_VisualizerInfo *dec_info);
346 
347 
348  // update a single decoration
349  bool update(RE_RenderContext r,
351  const GT_Primitive &prim,
352  const GR_UpdateParms &p,
353  RV_Geometry &geo);
354 
355  // draw a single decoration
356  void draw(RE_RenderContext r,
357  RV_Geometry &geo,
358  GR_GeoRender *gr,
360  GR_DecorVisibility visibility,
361  const GR_DisplayOption *opt,
364  PrimitiveType prim_type,
365  int instance_group,
366  int select_inst,
367  RV_OverrideList *override_list);
368 
369  RV_ShaderProgram *setupDecorationParms(RE_RenderContext r,
370  RV_Geometry &geo,
372  GR_DecorVisibility vis,
374  const GR_DisplayOption *opt,
375  RE_PrimType &type,
376  fpreal32 color[4],
377  fpreal32 select_color[4],
378  fpreal32 &scale,
379  int &npasses,
380  RV_OverrideList &attrib_override,
381  PrimitiveType prim_type);
382 
383  void drawVisualizer(RE_RenderContext rc,
384  RV_Geometry &geo,
385  GR_GeoRender *gr,
386  const GR_VisualizerInfo *dec_info,
387  const GR_DisplayOption *opt,
389  PrimitiveType prim_type);
390 
391  RV_ShaderProgram * setupVisualizerDraw(RE_RenderContext rc,
392  RV_Geometry &geo,
394  UT_UniquePtr<RV_ShaderBlock> &decor_block,
395  const GR_VisualizerInfo *dec_info,
396  const GR_DisplayOption *opt,
398  PrimitiveType prim_type,
399  RE_PrimType &re_prim,
400  int &npasses,
401  RV_OverrideList &overrides);
402 
403  void cleanupVisualizerDraw(RE_RenderContext rc,
404  const GR_VisualizerInfo *dec_info);
405 
406  void cleanupDecorationParms(RE_RenderContext r,
408 
409  // cached option data
410  bool myCanDrawDecor[GR_MAX_DECORATIONS];
411  UT_Color myPointColor;
412  UT_Color mySelectedPointColor;
413  UT_Color myPrimColor;
414  UT_Color mySelectedPrimColor;
415  fpreal myNormalScale;
416  fpreal myPointSize;
417  fpreal myVectorScale;
418 
419  // Keep user option counts separate for primitive, point and vertex attribs.
420  int myUserStringCount[3];
421  int myUserStringIndex[3];
422 
423  bool myDecorEnabled[GR_MAX_DECORATIONS];
424  bool myHasDecorations;
425  bool myHasOverlayDecorations;
426  const GR_RenderInfo *myRenderInfo;
427 
428  UT_Map<int, GR_UserDecorInfo> myUserDecorMap;
429  static UT_Map<int, GR_UserDecorInfo> theStandardDecorMap;
430 };
431 
432 
433 // Structure used for passing various specifications of a custom
434 // decoration rendering down the rendering chain
435 
437 {
443 };
444 
446 {
447 public:
449  myDecorAttribOwner(GA_ATTRIB_POINT),
450  myDecorAttribSize(1),
451  myDecorAttribStorage(GT_STORE_INT32),
452  myStyle(GR_VISUALIZER_DECOR_TEXT),
453  mySelectMode(GR_SELECT_NONE),
454  myVisibility(GR_DECOR_ALWAYS_VISIBLE),
455  myOptions(0),
456  myOwnerId(-1)
457  {}
458 
460  int dec_attrib_size,
461  const char *dec_attrib,
462  GT_Storage dec_attrib_store,
463  bool overlay = false,
465  GR_SelectMode select_mode = GR_SELECT_NONE,
467  int owner_id = -1) :
468  myDecorAttribOwner(dec_attrib_owner),
469  myDecorAttribSize(dec_attrib_size),
470  myDecorAttribStorage( dec_attrib_store),
471  myStyle(style),
472  mySelectMode(select_mode),
473  myVisibility(visibility),
474  myOptions(0),
475  myOwnerId(owner_id)
476  {
477  if (dec_attrib)
478  myDecorAttrib.harden(dec_attrib);
479  }
480 
483  {
484  myDecorAttribOwner = src.myDecorAttribOwner;
485  myDecorAttribSize = src.myDecorAttribSize;
486 
487  myDecorAttrib.harden(src.myDecorAttrib);
488  myMaskAttrib.harden(src.myMaskAttrib);
489 
490  myStyle = src.myStyle;
491  mySelectMode = src.mySelectMode;
492  myVisibility = src.myVisibility;
493  myDecorAttribStorage = src.myDecorAttribStorage;
494 
495  myOptions = src.myOptions;
496  return *this;
497  }
498 
500  { return myDecorAttribOwner; }
502  { myDecorAttribOwner = owner; }
503  const char *getDecorAttrib() const
504  { return myDecorAttrib.length()
505  ? (const char *)myDecorAttrib : nullptr; }
506  void setDecorAttrib(const char *attrib)
507  { myDecorAttrib.harden(attrib); }
508  int getDecorAttribSize() const
509  { return myDecorAttribSize; }
511  { myDecorAttribSize = size; }
513  { return myDecorAttribStorage; }
515  { myDecorAttribStorage = store; }
516  const char *getMaskAttrib() const
517  { return myMaskAttrib.length()
518  ? (const char*) myMaskAttrib : 0; }
519  void setMaskAttrib(const char *attrib)
520  { myMaskAttrib.harden(attrib); }
522  { return myStyle; }
524  { myStyle = style; }
526  { return mySelectMode; }
528  { return myVisibility; }
530  { myVisibility = vis; }
531 
532  void attachOptions(UT_Options *opts) { myOptions = opts; }
533  void destroyOptions() { if (myOptions) delete myOptions; }
535  const { return myOptions; }
536 
537 
538  /// If an owner id other than -1 is set, then passing this object to
539  /// GUI_DecorationRender::customDecorationRender() will only cause
540  /// decoration rendering on VIS_Primitives created by the visualizer
541  /// with the given unique id. This way, a visualizer can trigger rendering
542  /// of decorations only on primitives it itself has created.
543 
544  void setOwnerId(int owner_id) { myOwnerId = owner_id; }
545  int getOwnerId() const { return myOwnerId; }
546 
547 private:
548  GA_AttributeOwner myDecorAttribOwner; // attribute class
549  int myDecorAttribSize; // num attrib components
550 
551  UT_String myDecorAttrib; // name attribute itself
552  UT_String myMaskAttrib; // boolean (uint8) group mask
553 
554  GR_VisualizerDecorStyle myStyle;
555  GR_SelectMode mySelectMode;
556  GR_DecorVisibility myVisibility;
557  GT_Storage myDecorAttribStorage;
558 
559  UT_Options *myOptions;
560  int myOwnerId; // See above!
561 };
562 
563 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
GT_Storage
Definition: GT_Types.h:19
GLbitfield flags
Definition: glcorearb.h:1596
GR_VisualizerInfo(GA_AttributeOwner dec_attrib_owner, int dec_attrib_size, const char *dec_attrib, GT_Storage dec_attrib_store, bool overlay=false, GR_VisualizerDecorStyle style=GR_VISUALIZER_DECOR_TEXT, GR_SelectMode select_mode=GR_SELECT_NONE, GR_DecorVisibility visibility=GR_DECOR_ALWAYS_VISIBLE, int owner_id=-1)
GR_DecorRenderFlags
Definition: GR_Defines.h:235
GR_DecorVisibility getVisibility() const
GR_DecorationOverride
Definition: GR_Defines.h:224
const GR_DisplayOption * opts
GR_DecorFontType
Definition: GR_Defines.h:215
const char * getMaskAttrib() const
void setMaskAttrib(const char *attrib)
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:52
GR_VisualizerDecorStyle getStyle() const
int getDecorAttribSize() const
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
GLdouble s
Definition: glad.h:3009
const char * getDecorAttrib() const
GR_Decoration
Definition: GR_Defines.h:167
float fpreal32
Definition: SYS_Types.h:200
Temporary container for either a RV_Render and an RE_Render.
void setDecorAttribOwner(GA_AttributeOwner owner)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
set of parameters sent to GR_Primitive::update()
void setStyle(GR_VisualizerDecorStyle style)
GA_API const UT_StringHolder scale
GR_AttribMask
Definition: GR_Defines.h:347
GR_DecorationParms(const GR_DisplayOption *opt, bool over, bool over_vis, int inst_grp, GR_DecorRenderFlags flags)
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
GR_DecorVisibility
Definition: GR_Defines.h:197
GR_DecorRenderFlags render_flags
void setOwnerId(int owner_id)
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
Definition: simd.h:4983
void setDecorAttrib(const char *attrib)
constexpr auto set(type rhs) -> int
Definition: core.h:610
UT_ColorRamp
Definition: UT_Color.h:33
GLint GLuint mask
Definition: glcorearb.h:124
RV_API void cleanupShaders()
GR_DecorFontSize
Definition: GR_Defines.h:205
#define GR_API
Definition: GR_API.h:10
void setDecorAttribStorage(GT_Storage store)
GT_Storage getDecorAttribStorage() const
GR_VisualizerInfo & operator=(const GR_VisualizerInfo &src)
ImageBuf OIIO_API over(const ImageBuf &A, const ImageBuf &B, ROI roi={}, int nthreads=0)
GA_AttributeOwner getDecorAttribOwner() const
UT_StringArray RV_OverrideList
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
GLdouble t
Definition: glad.h:2397
const UT_Options * getOptions() const
RV_API bool initShaders(RV_Instance *inst)
GR_SelectMode getSelectMode() const
GLsizeiptr size
Definition: glcorearb.h:664
GA_AttributeOwner
Definition: GA_Types.h:35
A map of string to various well defined value types.
Definition: UT_Options.h:87
GA_API const UT_StringHolder parms
GR_VisualizerDecorStyle
GLuint color
Definition: glcorearb.h:1261
void attachOptions(UT_Options *opts)
fpreal64 fpreal
Definition: SYS_Types.h:283
void setVisibility(GR_DecorVisibility vis)
bool hasOverlayDecorations() const
GLboolean r
Definition: glcorearb.h:1222
void setDecorAttribSize(int size)
const GR_VisualizerInfo * visualizer
RE_PrimType
Definition: RE_Types.h:199
GR_SelectMode
Definition: GR_Defines.h:246
GLenum src
Definition: glcorearb.h:1793