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_Geometry;
16 class RE_ShaderRegistry;
17 class RV_Geometry;
18 class RV_Instance;
19 class RV_ShaderBlock;
20 class RV_ShaderProgram;
22 class GU_Detail;
23 class GR_DisplayOption;
24 class GR_GeoRender;
25 class GT_Primitive;
26 
27 #include <SYS/SYS_Types.h>
28 #include <UT/UT_Color.h>
29 #include <UT/UT_StringArray.h>
30 #include <UT/UT_BitArray.h>
31 #include <RE/RE_Texture.h>
32 #include <RE/RE_RenderContext.h>
33 
34 #include <GA/GA_Types.h>
35 #include <GT/GT_Types.h>
36 
37 #include "GR_API.h"
38 #include "GR_Defines.h"
39 #include "GR_RenderInfo.h"
40 #include "GR_UpdateParms.h"
41 
42 #define GR_DECOR_OPT_VECTOR_SCALE "vector_scale"
43 #define GR_DECOR_OPT_VECTOR_ARROW_TIP "vector_arrow_tip"
44 #define GR_DECOR_OPT_POINT_SCALE "point_scale"
45 #define GR_DECOR_OPT_COLOR "color"
46 #define GR_DECOR_OPT_SELECT_COLOR "select_color"
47 #define GR_DECOR_OPT_FONT_SIZE "font_size"
48 #define GR_DECOR_OPT_COLOR_ATTRIB "color_attrib"
49 #define GR_DECOR_OPT_NORMALIZE "normalize"
50 #define GR_DECOR_OPT_COLOR_XFORM "color_xform"
51 #define GR_DECOR_OPT_COLOR_XFORM_REF_VEC "color_xform_ref_vec"
52 
55 
57 {
58 public:
60  bool over,
61  bool over_vis,
62  int inst_grp,
64  : opts(opt),
65  overlay(over),
66  override_vis(over_vis),
67  instance_group(inst_grp),
68  render_flags(flags),
69  visualizer(NULL){ }
70 
72  bool overlay;
77 };
78 
79 
80 
81 
83 {
84 public:
86  virtual ~GR_DecorationRender();
87 
88  // Initializes all the decorations from the given display options.
89  // 'select_dec' is a bitfield of display option overrides (point marker,
90  // breakpoint marker, vertex marker)
91  // 'parms.needed_attribs' is modified so that any attributes a supported
92  // decoration migght need is appended to the list.
93  // 'supported' is a NULL terminated list of decorations supported by
94  // the primitive. (NULL is 0 or GR_NO_DECORATION)
95  void setupFromDisplayOptions(const GR_DisplayOption &opts,
96  GR_DecorationOverride select_dec,
97  GR_UpdateParms &parms,
98  const GR_Decoration *supported,
100 
101  // Returns true if this decoration renderer supports mouse-motion visibility
102  // modes, and one of these modes is active
104  { return myHasOverlayDecorations; }
105 
107  {
109  TARGET_OVERLAY
110  };
111 
113  {
119  PRIM_TYPE_COUNT
120  };
121 
122  // Update the geometry required to produce the active decorations. This may
123  // add new buffers to geo (normals, UV, etc).
124  bool updateDecoration(RE_Render *r,
125  GR_Decoration dec,
126  const GT_Primitive &prim,
127  const GR_UpdateParms &p,
128  RE_Geometry &geo);
129 
130  // Update the geometry required to produce the active decorations. This may
131  // add new buffers to geo (normals, UV, etc).
132  bool updateDecoration(RE_RenderContext r,
133  GR_Decoration dec,
134  const GT_Primitive &prim,
135  const GR_UpdateParms &p,
136  RV_Geometry &geo);
137 
138  // Called before any calls to drawSingle.
139  void setupDrawing(RE_RenderContext r);
140 
141  // Draw a single decoration. The visibility affects which framebuffer is
142  // currently being drawn (main or
143  void drawSingle(RE_Render *r,
144  RE_Geometry &geo,
145  GR_Decoration dec,
146  const GR_DisplayOption *opt,
149  RenderTarget render_mode,
150  GR_DecorVisibility *vis_override,
151  PrimitiveType glprim_type,
152  int instance_group,
153  int select_inst,
154  RE_OverrideList *override_list);
155 
156  // Draw a single decoration. The visibility affects which framebuffer is
157  // currently being drawn (main or
158  void drawSingle(RE_RenderContext r,
159  RV_Geometry &geo,
160  GR_GeoRender *gr,
161  GR_Decoration dec,
162  const GR_DisplayOption *opt,
165  RenderTarget render_mode,
166  GR_DecorVisibility *vis_override,
167  PrimitiveType glprim_type,
168  int instance_group,
169  int select_inst,
170  RV_OverrideList *override_list);
171 
172  // custom decorations
173  void drawSingleVisualizer(RE_Render *r,
174  RE_Geometry &geo,
175  const GR_VisualizerInfo *dec_info,
176  const GR_DisplayOption *opt,
178  PrimitiveType prim_type);
179 
180  void drawSingleVisualizer(RE_RenderContext r,
181  RV_Geometry &geo,
182  GR_GeoRender *gr,
183  const GR_VisualizerInfo *dec_info,
184  const GR_DisplayOption *opt,
186  PrimitiveType prim_type);
187 
188  static RE_Texture *getViewportFontTexture(RE_Render *r,
191  bool outlined,
192  UT_Vector3 &font_parms);
193 
194  /// Returns a 512-entry 1D texture.
195  static RE_Texture *getRampLookupTexture(RE_Render *r,
196  UT_ColorRamp rtype);
197 
198 
199  static void setupFontParms(RE_RenderContext r,
201  const GR_DisplayOption *opt,
202  GR_DecorFontType charset,
203  bool pointed_box,
204  UT_Vector3 &out_parms,
206 
207  static void bindViewportFontTexture(RE_RenderContext r,
211  bool outlined,
212  UT_Vector3 &out_parms);
213 
214  static void bindViewportVertexTexture(
216  RV_ShaderVariableSet *set);
217 
218  static bool initShaders(RV_Instance *inst);
219  static void cleanupShaders();
220 
221 private:
222  // Description of user decorations.
223  class GR_UserDecorInfo
224  {
225  public:
226  GR_UserDecorInfo()
227  : myCustomShaderRegistry(NULL),
228  myUserOption(NULL),
229  myAttribSize(0),
230  myIsFP(false),
231  myIsString(false)
232  { }
233  GR_UserDecorInfo(const RE_ShaderRegistry *shader_registry,
234  const GR_UserOption *user_option,
235  int attrib_size,
236  bool is_fp,
237  bool is_string)
238  : myCustomShaderRegistry(shader_registry),
239  myUserOption(user_option),
240  myAttribSize(attrib_size),
241  myIsFP(is_fp),
242  myIsString(is_string)
243  { }
244 
245  const RE_ShaderRegistry *myCustomShaderRegistry;
246  const GR_UserOption *myUserOption;
247  int myAttribSize;
248  bool myIsFP;
249  bool myIsString;
250  };
251 
252  static RE_Texture *getViewportBoxTexture(RE_Render *r,
254  bool pointed);
255 
256  static RE_Texture *getViewportVertexTexture(RE_Render *r);
257 
258  void updateUserDecoration(GR_Decoration dec,
259  const GT_Primitive &prim,
260  const GR_UpdateParms &p);
261 
262  bool showSelections() const
263  { return myRenderInfo->showSelections(); }
264  bool getDecorationEnabled(GR_Decoration dec)
265  { return myDecorEnabled[dec]; }
266 
267  const RE_ShaderRegistry *getUserDecorShaderRegistry(int decor) const;
268  const GR_UserOption *getUserOption(int decor) const;
269  int getUserDecorAttribSize(int decor) const;
270  bool isFPUserDecor(int decor) const;
271  bool isStringUserDecor(int decor) const;
272 
273  void getUserOptionColors(const GR_UserOption *user,
274  const GR_DisplayOption *opt,
275  UT_Color &col, UT_Color &select);
276 
277  // update a single decoration
278  bool update(RE_Render *r,
279  GR_Decoration dec,
280  const GT_Primitive &prim,
281  const GR_UpdateParms &p,
282  RE_Geometry &geo);
283 
284  // draw a single decoration
285  void draw(RE_Render *r,
286  RE_Geometry &geo,
287  GR_Decoration dec,
288  GR_DecorVisibility visibility,
289  const GR_DisplayOption *opt,
292  PrimitiveType prim_type,
293  int instance_group,
294  int select_inst,
295  RE_OverrideList *override_list);
296 
297  RE_Shader *setupDecorationParms(RE_Render *r,
298  RE_Geometry &geo,
299  GR_Decoration dec,
300  GR_DecorVisibility vis,
302  const GR_DisplayOption *opt,
303  RE_PrimType &type,
304  fpreal32 color[4],
305  fpreal32 select_color[4],
306  fpreal32 &scale,
307  int &npasses,
308  RE_OverrideList &attrib_override,
309  PrimitiveType prim_type);
310 
311  void cleanupDecorationParms(RE_Render *r,
312  GR_Decoration dec);
313 
314  void setupShaderDepthTest(RE_Render *r, RE_Shader *sh,
315  bool zwrites);
316  void setupFontParms(RE_Render *r,
317  RE_Shader *sh,
318  const GR_DisplayOption *opt,
320  bool pointed_box,
322  void setupVertexColors(RE_Render *r, RE_Shader *sh);
323  void cleanupFontParms(RE_Render *r);
324 
325  // visualizer-based decorations
326  void drawVisualizer(RE_Render *r,
327  RE_Geometry &geo,
328  const GR_VisualizerInfo *dec_info,
329  const GR_DisplayOption *opt,
331  PrimitiveType prim_type);
332 
333  RE_Shader * setupVisualizerDraw(RE_Render *r,
334  RE_Geometry &geo,
335  const GR_VisualizerInfo *dec_info,
336  const GR_DisplayOption *opt,
338  PrimitiveType prim_type,
339  RE_PrimType &re_prim,
340  int &npasses,
341  RE_OverrideList &overrides);
342 
343  void cleanupVisualizerDraw(RE_Render *r,
344  const GR_VisualizerInfo *dec_info);
345 
346 
347  // update a single decoration
348  bool update(RE_RenderContext r,
349  GR_Decoration dec,
350  const GT_Primitive &prim,
351  const GR_UpdateParms &p,
352  RV_Geometry &geo);
353 
354  // draw a single decoration
355  void draw(RE_RenderContext r,
356  RV_Geometry &geo,
357  GR_GeoRender *gr,
358  GR_Decoration dec,
359  GR_DecorVisibility visibility,
360  const GR_DisplayOption *opt,
363  PrimitiveType prim_type,
364  int instance_group,
365  int select_inst,
366  RV_OverrideList *override_list);
367 
368  RV_ShaderProgram *setupDecorationParms(RE_RenderContext r,
369  RV_Geometry &geo,
370  GR_Decoration dec,
371  GR_DecorVisibility vis,
373  const GR_DisplayOption *opt,
374  RE_PrimType &type,
375  fpreal32 color[4],
376  fpreal32 select_color[4],
377  fpreal32 &scale,
378  int &npasses,
379  RV_OverrideList &attrib_override,
380  PrimitiveType prim_type);
381 
382  void drawVisualizer(RE_RenderContext rc,
383  RV_Geometry &geo,
384  GR_GeoRender *gr,
385  const GR_VisualizerInfo *dec_info,
386  const GR_DisplayOption *opt,
388  PrimitiveType prim_type);
389 
390  RV_ShaderProgram * setupVisualizerDraw(RE_RenderContext rc,
391  RV_Geometry &geo,
393  UT_UniquePtr<RV_ShaderBlock> &decor_block,
394  const GR_VisualizerInfo *dec_info,
395  const GR_DisplayOption *opt,
397  PrimitiveType prim_type,
398  RE_PrimType &re_prim,
399  int &npasses,
400  RV_OverrideList &overrides);
401 
402  void cleanupVisualizerDraw(RE_RenderContext rc,
403  const GR_VisualizerInfo *dec_info);
404 
405  void cleanupDecorationParms(RE_RenderContext r,
406  GR_Decoration dec);
407 
408  // cached option data
409  bool myCanDrawDecor[GR_MAX_DECORATIONS];
410  UT_Color myPointColor;
411  UT_Color mySelectedPointColor;
412  UT_Color myPrimColor;
413  UT_Color mySelectedPrimColor;
414  fpreal myNormalScale;
415  fpreal myPointSize;
416  fpreal myVectorScale;
417 
418  // Keep user option counts separate for primitive, point and vertex attribs.
419  int myUserStringCount[3];
420  int myUserStringIndex[3];
421 
422  bool myDecorEnabled[GR_MAX_DECORATIONS];
423  bool myHasDecorations;
424  bool myHasOverlayDecorations;
425  const GR_RenderInfo *myRenderInfo;
426 
427  UT_Map<int, GR_UserDecorInfo> myUserDecorMap;
428  static UT_Map<int, GR_UserDecorInfo> theStandardDecorMap;
429 };
430 
431 
432 // Structure used for passing various specifications of a custom
433 // decoration rendering down the rendering chain
434 
436 {
442 };
443 
445 {
446 public:
448  myDecorAttribOwner(GA_ATTRIB_POINT),
449  myDecorAttribSize(1),
450  myDecorAttribStorage(GT_STORE_INT32),
451  myStyle(GR_VISUALIZER_DECOR_TEXT),
452  mySelectMode(GR_SELECT_NONE),
453  myVisibility(GR_DECOR_ALWAYS_VISIBLE),
454  myOptions(0),
455  myOwnerId(-1)
456  {}
457 
459  int dec_attrib_size,
460  const char *dec_attrib,
461  GT_Storage dec_attrib_store,
462  bool overlay = false,
464  GR_SelectMode select_mode = GR_SELECT_NONE,
466  int owner_id = -1) :
467  myDecorAttribOwner(dec_attrib_owner),
468  myDecorAttribSize(dec_attrib_size),
469  myDecorAttribStorage( dec_attrib_store),
470  myStyle(style),
471  mySelectMode(select_mode),
472  myVisibility(visibility),
473  myOptions(0),
474  myOwnerId(owner_id)
475  {
476  if (dec_attrib)
477  myDecorAttrib.harden(dec_attrib);
478  }
479 
482  {
483  myDecorAttribOwner = src.myDecorAttribOwner;
484  myDecorAttribSize = src.myDecorAttribSize;
485 
486  myDecorAttrib.harden(src.myDecorAttrib);
487  myMaskAttrib.harden(src.myMaskAttrib);
488 
489  myStyle = src.myStyle;
490  mySelectMode = src.mySelectMode;
491  myVisibility = src.myVisibility;
492  myDecorAttribStorage = src.myDecorAttribStorage;
493 
494  myOptions = src.myOptions;
495  return *this;
496  }
497 
499  { return myDecorAttribOwner; }
501  { myDecorAttribOwner = owner; }
502  const char *getDecorAttrib() const
503  { return myDecorAttrib.length()
504  ? (const char *)myDecorAttrib : nullptr; }
505  void setDecorAttrib(const char *attrib)
506  { myDecorAttrib.harden(attrib); }
507  int getDecorAttribSize() const
508  { return myDecorAttribSize; }
510  { myDecorAttribSize = size; }
512  { return myDecorAttribStorage; }
514  { myDecorAttribStorage = store; }
515  const char *getMaskAttrib() const
516  { return myMaskAttrib.length()
517  ? (const char*) myMaskAttrib : 0; }
518  void setMaskAttrib(const char *attrib)
519  { myMaskAttrib.harden(attrib); }
521  { return myStyle; }
523  { myStyle = style; }
525  { return mySelectMode; }
527  { return myVisibility; }
529  { myVisibility = vis; }
530 
531  void attachOptions(UT_Options *opts) { myOptions = opts; }
532  void destroyOptions() { if (myOptions) delete myOptions; }
534  const { return myOptions; }
535 
536 
537  /// If an owner id other than -1 is set, then passing this object to
538  /// GUI_DecorationRender::customDecorationRender() will only cause
539  /// decoration rendering on VIS_Primitives created by the visualizer
540  /// with the given unique id. This way, a visualizer can trigger rendering
541  /// of decorations only on primitives it itself has created.
542 
543  void setOwnerId(int owner_id) { myOwnerId = owner_id; }
544  int getOwnerId() const { return myOwnerId; }
545 
546 private:
547  GA_AttributeOwner myDecorAttribOwner; // attribute class
548  int myDecorAttribSize; // num attrib components
549 
550  UT_String myDecorAttrib; // name attribute itself
551  UT_String myMaskAttrib; // boolean (uint8) group mask
552 
553  GR_VisualizerDecorStyle myStyle;
554  GR_SelectMode mySelectMode;
555  GR_DecorVisibility myVisibility;
556  GT_Storage myDecorAttribStorage;
557 
558  UT_Options *myOptions;
559  int myOwnerId; // See above!
560 };
561 
562 #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:230
GR_DecorVisibility getVisibility() const
GR_DecorationOverride
Definition: GR_Defines.h:219
const GR_DisplayOption * opts
GR_DecorFontType
Definition: GR_Defines.h:210
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:53
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
GR_AttribMask
Definition: GR_Defines.h:342
GLdouble s
Definition: glad.h:3009
const char * getDecorAttrib() const
GR_Decoration
Definition: GR_Defines.h:162
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_DecorationParms(const GR_DisplayOption *opt, bool over, bool over_vis, int inst_grp, GR_DecorRenderFlags flags)
GR_DecorVisibility
Definition: GR_Defines.h:192
GR_DecorRenderFlags render_flags
void setOwnerId(int owner_id)
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
Definition: simd.h:4816
void setDecorAttrib(const char *attrib)
UT_ColorRamp
Definition: UT_Color.h:32
GLint GLuint mask
Definition: glcorearb.h:124
GR_DecorFontSize
Definition: GR_Defines.h:200
#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:38
GLdouble t
Definition: glad.h:2397
const UT_Options * getOptions() const
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:84
GR_VisualizerDecorStyle
GLuint color
Definition: glcorearb.h:1261
void attachOptions(UT_Options *opts)
fpreal64 fpreal
Definition: SYS_Types.h:277
void setVisibility(GR_DecorVisibility vis)
bool hasOverlayDecorations() const
GLboolean r
Definition: glcorearb.h:1222
void setDecorAttribSize(int size)
const GR_VisualizerInfo * visualizer
type
Definition: core.h:1059
RE_PrimType
Definition: RE_Types.h:193
GR_SelectMode
Definition: GR_Defines.h:241
GLenum src
Definition: glcorearb.h:1793