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 overlay)
159  // connect_group specifies the default connect group to use. if `gr` is
160  // provided it will be queried for the connect group instead, with
161  // GR_GeoRender::getVkDecorConnectGroup()
162  void drawSingle(RE_RenderContext r,
163  RV_Geometry &geo,
164  int connect_group,
165  GR_GeoRender *gr,
167  const GR_DisplayOption *opt,
170  RenderTarget render_mode,
171  GR_DecorVisibility *vis_override,
172  PrimitiveType glprim_type,
173  int instance_group,
174  int select_inst,
175  RV_OverrideList *override_list);
176 
177  void drawSingle(RE_RenderContext r,
178  RV_Geometry &geo,
179  GR_GeoRender *gr,
181  const GR_DisplayOption *opt,
184  RenderTarget render_mode,
185  GR_DecorVisibility *vis_override,
186  PrimitiveType glprim_type,
187  int instance_group,
188  int select_inst,
189  RV_OverrideList *override_list);
190 
191  // custom decorations
192  void drawSingleVisualizer(RE_Render *r,
193  RE_Geometry &geo,
194  const GR_VisualizerInfo *dec_info,
195  const GR_DisplayOption *opt,
197  PrimitiveType prim_type);
198 
199  // connect_group specifies the default connect group to use. if `gr` is
200  // provided it will be queried for the connect group instead, with
201  // GR_GeoRender::getVkDecorConnectGroup()
202  void drawSingleVisualizer(RE_RenderContext r,
203  RV_Geometry &geo,
204  int connect_group,
205  GR_GeoRender *gr,
206  const GR_VisualizerInfo *dec_info,
207  const GR_DisplayOption *opt,
209  PrimitiveType prim_type);
210 
211  void drawSingleVisualizer(RE_RenderContext r,
212  RV_Geometry &geo,
213  GR_GeoRender *gr,
214  const GR_VisualizerInfo *dec_info,
215  const GR_DisplayOption *opt,
217  PrimitiveType prim_type);
218 
219  static RE_Texture *getViewportFontTexture(RE_Render *r,
222  bool outlined,
223  UT_Vector3 &font_parms);
224 
225  /// Returns a 512-entry 1D texture.
226  static RE_Texture *getRampLookupTexture(RE_Render *r,
227  UT_ColorRamp rtype);
228 
229 
230  static void setupFontParms(RE_RenderContext r,
232  const GR_DisplayOption *opt,
233  GR_DecorFontType charset,
234  bool pointed_box,
235  UT_Vector3 &out_parms,
237 
238  static void bindViewportFontTexture(RE_RenderContext r,
242  bool outlined,
243  UT_Vector3 &out_parms);
244 
245  static void bindViewportVertexTexture(
248 
249  static bool initShaders(RV_Instance *inst);
250  static void cleanupShaders();
251 
252 private:
253  // Description of user decorations.
254  class GR_UserDecorInfo
255  {
256  public:
257  GR_UserDecorInfo()
258  : myCustomShaderRegistry(NULL),
259  myUserOption(NULL),
260  myAttribSize(0),
261  myIsFP(false),
262  myIsString(false)
263  { }
264  GR_UserDecorInfo(const RE_ShaderRegistry *shader_registry,
265  const GR_UserOption *user_option,
266  int attrib_size,
267  bool is_fp,
268  bool is_string)
269  : myCustomShaderRegistry(shader_registry),
270  myUserOption(user_option),
271  myAttribSize(attrib_size),
272  myIsFP(is_fp),
273  myIsString(is_string)
274  { }
275 
276  const RE_ShaderRegistry *myCustomShaderRegistry;
277  const GR_UserOption *myUserOption;
278  int myAttribSize;
279  bool myIsFP;
280  bool myIsString;
281  };
282 
283  static RE_Texture *getViewportBoxTexture(RE_Render *r,
285  bool pointed);
286 
287  static RE_Texture *getViewportVertexTexture(RE_Render *r);
288 
289  void updateUserDecoration(GR_Decoration dec,
290  const GT_Primitive &prim,
291  const GR_UpdateParms &p);
292 
293  bool showSelections() const
294  { return myRenderInfo->showSelections(); }
295  bool getDecorationEnabled(GR_Decoration dec)
296  { return myDecorEnabled[dec]; }
297 
298  const RE_ShaderRegistry *getUserDecorShaderRegistry(int decor) const;
299  const GR_UserOption *getUserOption(int decor) const;
300  int getUserDecorAttribSize(int decor) const;
301  bool isFPUserDecor(int decor) const;
302  bool isStringUserDecor(int decor) const;
303 
304  void getUserOptionColors(const GR_UserOption *user,
305  const GR_DisplayOption *opt,
306  UT_Color &col, UT_Color &select);
307 
308  // update a single decoration
309  bool update(RE_Render *r,
311  const GT_Primitive &prim,
312  const GR_UpdateParms &p,
313  RE_Geometry &geo);
314 
315  // draw a single decoration
316  void draw(RE_Render *r,
317  RE_Geometry &geo,
319  GR_DecorVisibility visibility,
320  const GR_DisplayOption *opt,
323  PrimitiveType prim_type,
324  int instance_group,
325  int select_inst,
326  RE_OverrideList *override_list);
327 
328  RE_Shader *setupDecorationParms(RE_Render *r,
329  RE_Geometry &geo,
331  GR_DecorVisibility vis,
333  const GR_DisplayOption *opt,
334  RE_PrimType &type,
335  fpreal32 color[4],
336  fpreal32 select_color[4],
337  fpreal32 &scale,
338  int &npasses,
339  RE_OverrideList &attrib_override,
340  PrimitiveType prim_type);
341 
342  void cleanupDecorationParms(RE_Render *r,
344 
345  void setupShaderDepthTest(RE_Render *r, RE_Shader *sh,
346  bool zwrites);
347  void setupFontParms(RE_Render *r,
348  RE_Shader *sh,
349  const GR_DisplayOption *opt,
351  bool pointed_box,
353  void setupVertexColors(RE_Render *r, RE_Shader *sh);
354  void cleanupFontParms(RE_Render *r);
355 
356  // visualizer-based decorations
357  void drawVisualizer(RE_Render *r,
358  RE_Geometry &geo,
359  const GR_VisualizerInfo *dec_info,
360  const GR_DisplayOption *opt,
362  PrimitiveType prim_type);
363 
364  RE_Shader * setupVisualizerDraw(RE_Render *r,
365  RE_Geometry &geo,
366  const GR_VisualizerInfo *dec_info,
367  const GR_DisplayOption *opt,
369  PrimitiveType prim_type,
370  RE_PrimType &re_prim,
371  int &npasses,
372  RE_OverrideList &overrides);
373 
374  void cleanupVisualizerDraw(RE_Render *r,
375  const GR_VisualizerInfo *dec_info);
376 
377 
378  // update a single decoration
379  bool update(RE_RenderContext r,
381  const GT_Primitive &prim,
382  const GR_UpdateParms &p,
383  RV_Geometry &geo);
384 
385  // draw a single decoration
386  void draw(RE_RenderContext r,
387  RV_Geometry &geo,
388  int geo_connect_group,
389  GR_GeoRender *gr,
391  GR_DecorVisibility visibility,
392  const GR_DisplayOption *opt,
395  PrimitiveType prim_type,
396  int instance_group,
397  int select_inst,
398  RV_OverrideList *override_list);
399 
400  RV_ShaderProgram *setupDecorationParms(RE_RenderContext r,
401  RV_Geometry &geo,
403  GR_DecorVisibility vis,
405  const GR_DisplayOption *opt,
406  RE_PrimType &type,
407  fpreal32 color[4],
408  fpreal32 select_color[4],
409  fpreal32 &scale,
410  int &npasses,
411  RV_OverrideList &attrib_override,
412  PrimitiveType prim_type);
413 
414  void drawVisualizer(RE_RenderContext rc,
415  RV_Geometry &geo,
416  int geo_connect_group,
417  GR_GeoRender *gr,
418  const GR_VisualizerInfo *dec_info,
419  const GR_DisplayOption *opt,
421  PrimitiveType prim_type);
422 
423  RV_ShaderProgram * setupVisualizerDraw(RE_RenderContext rc,
424  RV_Geometry &geo,
426  UT_UniquePtr<RV_ShaderBlock> &decor_block,
427  const GR_VisualizerInfo *dec_info,
428  const GR_DisplayOption *opt,
430  PrimitiveType prim_type,
431  RE_PrimType &re_prim,
432  int &npasses,
433  RV_OverrideList &overrides);
434 
435  void cleanupVisualizerDraw(RE_RenderContext rc,
436  const GR_VisualizerInfo *dec_info);
437 
438  void cleanupDecorationParms(RE_RenderContext r,
440 
441  // cached option data
442  bool myCanDrawDecor[GR_MAX_DECORATIONS];
443  UT_Color myPointColor;
444  UT_Color mySelectedPointColor;
445  UT_Color myPrimColor;
446  UT_Color mySelectedPrimColor;
447  fpreal myNormalScale;
448  fpreal myPointSize;
449  fpreal myVectorScale;
450 
451  // Keep user option counts separate for primitive, point and vertex attribs.
452  int myUserStringCount[3];
453  int myUserStringIndex[3];
454 
455  bool myDecorEnabled[GR_MAX_DECORATIONS];
456  bool myHasDecorations;
457  bool myHasOverlayDecorations;
458  const GR_RenderInfo *myRenderInfo;
459 
460  UT_Map<int, GR_UserDecorInfo> myUserDecorMap;
461  static UT_Map<int, GR_UserDecorInfo> theStandardDecorMap;
462 };
463 
464 
465 // Structure used for passing various specifications of a custom
466 // decoration rendering down the rendering chain
467 
469 {
475 };
476 
478 {
479 public:
481  myDecorAttribOwner(GA_ATTRIB_POINT),
482  myDecorAttribSize(1),
483  myDecorAttribStorage(GT_STORE_INT32),
484  myStyle(GR_VISUALIZER_DECOR_TEXT),
485  mySelectMode(GR_SELECT_NONE),
486  myVisibility(GR_DECOR_ALWAYS_VISIBLE),
487  myOptions(0),
488  myOwnerId(-1)
489  {}
490 
492  int dec_attrib_size,
493  const char *dec_attrib,
494  GT_Storage dec_attrib_store,
495  bool overlay = false,
497  GR_SelectMode select_mode = GR_SELECT_NONE,
499  int owner_id = -1) :
500  myDecorAttribOwner(dec_attrib_owner),
501  myDecorAttribSize(dec_attrib_size),
502  myDecorAttribStorage( dec_attrib_store),
503  myStyle(style),
504  mySelectMode(select_mode),
505  myVisibility(visibility),
506  myOptions(0),
507  myOwnerId(owner_id)
508  {
509  if (dec_attrib)
510  myDecorAttrib.harden(dec_attrib);
511  }
512 
515  {
516  myDecorAttribOwner = src.myDecorAttribOwner;
517  myDecorAttribSize = src.myDecorAttribSize;
518 
519  myDecorAttrib.harden(src.myDecorAttrib);
520  myMaskAttrib.harden(src.myMaskAttrib);
521 
522  myStyle = src.myStyle;
523  mySelectMode = src.mySelectMode;
524  myVisibility = src.myVisibility;
525  myDecorAttribStorage = src.myDecorAttribStorage;
526 
527  myOptions = src.myOptions;
528  return *this;
529  }
530 
532  { return myDecorAttribOwner; }
534  { myDecorAttribOwner = owner; }
535  const char *getDecorAttrib() const
536  { return myDecorAttrib.length()
537  ? (const char *)myDecorAttrib : nullptr; }
538  void setDecorAttrib(const char *attrib)
539  { myDecorAttrib.harden(attrib); }
540  int getDecorAttribSize() const
541  { return myDecorAttribSize; }
543  { myDecorAttribSize = size; }
545  { return myDecorAttribStorage; }
547  { myDecorAttribStorage = store; }
548  const char *getMaskAttrib() const
549  { return myMaskAttrib.length()
550  ? (const char*) myMaskAttrib : 0; }
551  void setMaskAttrib(const char *attrib)
552  { myMaskAttrib.harden(attrib); }
554  { return myStyle; }
556  { myStyle = style; }
558  { return mySelectMode; }
560  { return myVisibility; }
562  { myVisibility = vis; }
563 
564  void attachOptions(UT_Options *opts) { myOptions = opts; }
565  void destroyOptions() { if (myOptions) delete myOptions; }
567  const { return myOptions; }
568 
569 
570  /// If an owner id other than -1 is set, then passing this object to
571  /// GUI_DecorationRender::customDecorationRender() will only cause
572  /// decoration rendering on VIS_Primitives created by the visualizer
573  /// with the given unique id. This way, a visualizer can trigger rendering
574  /// of decorations only on primitives it itself has created.
575 
576  void setOwnerId(int owner_id) { myOwnerId = owner_id; }
577  int getOwnerId() const { return myOwnerId; }
578 
579 private:
580  GA_AttributeOwner myDecorAttribOwner; // attribute class
581  int myDecorAttribSize; // num attrib components
582 
583  UT_String myDecorAttrib; // name attribute itself
584  UT_String myMaskAttrib; // boolean (uint8) group mask
585 
586  GR_VisualizerDecorStyle myStyle;
587  GR_SelectMode mySelectMode;
588  GR_DecorVisibility myVisibility;
589  GT_Storage myDecorAttribStorage;
590 
591  UT_Options *myOptions;
592  int myOwnerId; // See above!
593 };
594 
595 #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:50
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