HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 GU_Detail;
18 class GR_DisplayOption;
19 class GT_Primitive;
20 
21 #include <SYS/SYS_Types.h>
22 #include <UT/UT_Color.h>
23 #include <UT/UT_BitArray.h>
24 #include <RE/RE_Texture.h>
25 
26 #include <GA/GA_Types.h>
27 #include <GT/GT_Types.h>
28 
29 #include "GR_API.h"
30 #include "GR_Defines.h"
31 #include "GR_RenderInfo.h"
32 #include "GR_UpdateParms.h"
33 
34 #define GR_DECOR_OPT_VECTOR_SCALE "vector_scale"
35 #define GR_DECOR_OPT_VECTOR_ARROW_TIP "vector_arrow_tip"
36 #define GR_DECOR_OPT_POINT_SCALE "point_scale"
37 #define GR_DECOR_OPT_COLOR "color"
38 #define GR_DECOR_OPT_SELECT_COLOR "select_color"
39 #define GR_DECOR_OPT_FONT_SIZE "font_size"
40 #define GR_DECOR_OPT_COLOR_ATTRIB "color_attrib"
41 #define GR_DECOR_OPT_NORMALIZE "normalize"
42 #define GR_DECOR_OPT_COLOR_XFORM "color_xform"
43 #define GR_DECOR_OPT_COLOR_XFORM_REF_VEC "color_xform_ref_vec"
44 
45 class GR_VisualizerInfo;
46 
48 {
49 public:
51  bool over,
52  bool over_vis,
53  int inst_grp,
55  : opts(opt),
56  overlay(over),
57  override_vis(over_vis),
58  instance_group(inst_grp),
59  render_flags(flags),
60  visualizer(NULL){ }
61 
63  bool overlay;
68 };
69 
70 
71 
72 
74 {
75 public:
77  virtual ~GR_DecorationRender();
78 
79  // Initializes all the decorations from the given display options.
80  // 'select_dec' is a bitfield of display option overrides (point marker,
81  // breakpoint marker, vertex marker)
82  // 'parms.needed_attribs' is modified so that any attributes a supported
83  // decoration migght need is appended to the list.
84  // 'supported' is a NULL terminated list of decorations supported by
85  // the primitive. (NULL is 0 or GR_NO_DECORATION)
86  void setupFromDisplayOptions(const GR_DisplayOption &opts,
87  GR_DecorationOverride select_dec,
88  GR_UpdateParms &parms,
89  const GR_Decoration *supported,
91 
92  // Update the geometry required to produce the active decorations. This may
93  // add new buffers to geo (normals, UV, etc).
94  bool updateDecoration(RE_Render *r,
95  GR_Decoration dec,
96  const GT_Primitive &prim,
97  const GR_UpdateParms &p,
98  RE_Geometry &geo);
99 
100  // Returns true if this decoration renderer supports mouse-motion visibility
101  // modes, and one of these modes is active
103  { return myHasOverlayDecorations; }
104 
106  {
108  TARGET_OVERLAY
109  };
110 
112  {
118  PRIM_TYPE_COUNT
119  };
120 
121  // Called before any calls to drawSingle.
122  void setupDrawing(RE_Render *r);
123 
124  // Draw a single decoration. The visibility affects which framebuffer is
125  // currently being drawn (main or
126  void drawSingle(RE_Render *r,
127  RE_Geometry &geo,
128  GR_Decoration dec,
129  const GR_DisplayOption *opt,
131  GR_SelectMode select,
132  RenderTarget render_mode,
133  GR_DecorVisibility *vis_override,
134  PrimitiveType glprim_type,
135  int instance_group,
136  int select_inst,
137  RE_OverrideList *override_list);
138 
139  // custom decorations
140  void drawSingleVisualizer(RE_Render *r,
141  RE_Geometry &geo,
142  const GR_VisualizerInfo *dec_info,
143  const GR_DisplayOption *opt,
145  PrimitiveType prim_type);
146 
147  static RE_Texture *getViewportFontTexture(RE_Render *r,
150  bool outlined,
151  UT_Vector3 &font_parms);
152 
153  /// Returns a 512-entry 1D texture.
154  static RE_Texture *getRampLookupTexture(RE_Render *r,
155  UT_ColorRamp rtype);
156 
157 private:
158  // Description of user decorations.
159  class GR_UserDecorInfo
160  {
161  public:
162  GR_UserDecorInfo()
163  : myCustomShaderRegistry(NULL),
164  myUserOption(NULL),
165  myAttribSize(0),
166  myIsFP(false),
167  myIsString(false)
168  { }
169  GR_UserDecorInfo(const RE_ShaderRegistry *shader_registry,
170  const GR_UserOption *user_option,
171  int attrib_size,
172  bool is_fp,
173  bool is_string)
174  : myCustomShaderRegistry(shader_registry),
175  myUserOption(user_option),
176  myAttribSize(attrib_size),
177  myIsFP(is_fp),
178  myIsString(is_string)
179  { }
180 
181  const RE_ShaderRegistry *myCustomShaderRegistry;
182  const GR_UserOption *myUserOption;
183  int myAttribSize;
184  bool myIsFP;
185  bool myIsString;
186  };
187 
188  // update a single decoration
189  bool update(RE_Render *r,
190  GR_Decoration dec,
191  const GT_Primitive &prim,
192  const GR_UpdateParms &p,
193  RE_Geometry &geo);
194 
195  // draw a single decoration
196  void draw(RE_Render *r,
197  RE_Geometry &geo,
198  GR_Decoration dec,
199  GR_DecorVisibility visibility,
200  const GR_DisplayOption *opt,
202  GR_SelectMode select,
203  PrimitiveType prim_type,
204  int instance_group,
205  int select_inst,
206  RE_OverrideList *override_list);
207 
208  static RE_Texture *getViewportBoxTexture(RE_Render *r,
210  bool pointed);
211 
212  static RE_Texture *getViewportVertexTexture(RE_Render *r);
213 
214  bool showSelections() const
215  { return myRenderInfo->showSelections(); }
216  bool getDecorationEnabled(GR_Decoration dec)
217  { return myDecorEnabled[dec]; }
218 
219  const RE_ShaderRegistry *getUserDecorShaderRegistry(int decor) const;
220  const GR_UserOption *getUserOption(int decor) const;
221  int getUserDecorAttribSize(int decor) const;
222  bool isFPUserDecor(int decor) const;
223  bool isStringUserDecor(int decor) const;
224 
225  void getUserOptionColors(const GR_UserOption *user,
226  const GR_DisplayOption *opt,
227  UT_Color &col, UT_Color &select);
228 
229  RE_Shader *setupDecorationParms(RE_Render *r,
230  RE_Geometry &geo,
231  GR_Decoration dec,
232  GR_DecorVisibility vis,
234  const GR_DisplayOption *opt,
235  RE_PrimType &type,
236  fpreal32 color[4],
237  fpreal32 select_color[4],
238  fpreal32 &scale,
239  int &npasses,
240  RE_OverrideList &attrib_override,
241  PrimitiveType prim_type);
242  void cleanupDecorationParms(RE_Render *r,
243  GR_Decoration dec);
244 
245  void setupShaderDepthTest(RE_Render *r, RE_Shader *sh,
246  bool zwrites);
247  void setupFontParms(RE_Render *r,
248  RE_Shader *sh,
249  const GR_DisplayOption *opt,
251  bool pointed_box,
253  void setupVertexColors(RE_Render *r, RE_Shader *sh);
254  void cleanupFontParms(RE_Render *r);
255 
256  // visualizer-based decorations
257  void drawVisualizer(RE_Render *r,
258  RE_Geometry &geo,
259  const GR_VisualizerInfo *dec_info,
260  const GR_DisplayOption *opt,
262  PrimitiveType prim_type);
263 
264  RE_Shader * setupVisualizerDraw(RE_Render *r,
265  RE_Geometry &geo,
266  const GR_VisualizerInfo *dec_info,
267  const GR_DisplayOption *opt,
269  PrimitiveType prim_type,
270  RE_PrimType &re_prim,
271  int &npasses,
272  RE_OverrideList &overrides);
273 
274  void cleanupVisualizerDraw(RE_Render *r,
275  const GR_VisualizerInfo *dec_info);
276  // cached option data
277  bool myCanDrawDecor[GR_MAX_DECORATIONS];
278  UT_Color myPointColor;
279  UT_Color mySelectedPointColor;
280  UT_Color myPrimColor;
281  UT_Color mySelectedPrimColor;
282  fpreal myNormalScale;
283  fpreal myPointSize;
284  fpreal myVectorScale;
285 
286  // Keep user option counts separate for primitive, point and vertex attribs.
287  int myUserStringCount[3];
288  int myUserStringIndex[3];
289 
290  bool myDecorEnabled[GR_MAX_DECORATIONS];
291  bool myHasDecorations;
292  bool myHasOverlayDecorations;
293  const GR_RenderInfo *myRenderInfo;
294 
295  UT_Map<int, GR_UserDecorInfo> myUserDecorMap;
296  static UT_Map<int, GR_UserDecorInfo> theStandardDecorMap;
297 };
298 
299 
300 // Structure used for passing various specifications of a custom
301 // decoration rendering down the rendering chain
302 
304 {
310 };
311 
313 {
314 public:
316  myDecorAttribOwner(GA_ATTRIB_POINT),
317  myDecorAttribSize(1),
318  myDecorAttribStorage(GT_STORE_INT32),
319  myStyle(GR_VISUALIZER_DECOR_TEXT),
320  mySelectMode(GR_SELECT_NONE),
321  myVisibility(GR_DECOR_ALWAYS_VISIBLE),
322  myOptions(0),
323  myOwnerId(-1)
324  {}
325 
327  int dec_attrib_size,
328  const char *dec_attrib,
329  GT_Storage dec_attrib_store,
330  bool overlay = false,
332  GR_SelectMode select_mode = GR_SELECT_NONE,
334  int owner_id = -1) :
335  myDecorAttribOwner(dec_attrib_owner),
336  myDecorAttribSize(dec_attrib_size),
337  myDecorAttribStorage( dec_attrib_store),
338  myStyle(style),
339  mySelectMode(select_mode),
340  myVisibility(visibility),
341  myOptions(0),
342  myOwnerId(owner_id)
343  {
344  if (dec_attrib)
345  myDecorAttrib.harden(dec_attrib);
346  }
347 
350  {
351  myDecorAttribOwner = src.myDecorAttribOwner;
352  myDecorAttribSize = src.myDecorAttribSize;
353 
354  myDecorAttrib.harden(src.myDecorAttrib);
355  myMaskAttrib.harden(src.myMaskAttrib);
356 
357  myStyle = src.myStyle;
358  mySelectMode = src.mySelectMode;
359  myVisibility = src.myVisibility;
360  myDecorAttribStorage = src.myDecorAttribStorage;
361 
362  myOptions = src.myOptions;
363  return *this;
364  }
365 
367  { return myDecorAttribOwner; }
369  { myDecorAttribOwner = owner; }
370  const char *getDecorAttrib() const
371  { return myDecorAttrib.length() ? myDecorAttrib : 0; }
372  void setDecorAttrib(const char *attrib)
373  { myDecorAttrib.harden(attrib); }
374  int getDecorAttribSize() const
375  { return myDecorAttribSize; }
377  { myDecorAttribSize = size; }
379  { return myDecorAttribStorage; }
381  { myDecorAttribStorage = store; }
382  const char *getMaskAttrib() const
383  { return myMaskAttrib.length() ? myMaskAttrib : 0; }
384  void setMaskAttrib(const char *attrib)
385  { myMaskAttrib.harden(attrib); }
387  { return myStyle; }
389  { myStyle = style; }
391  { return mySelectMode; }
393  { return myVisibility; }
395  { myVisibility = vis; }
396 
397  void attachOptions(UT_Options *opts) { myOptions = opts; }
398  void destroyOptions() { if (myOptions) delete myOptions; }
400  const { return myOptions; }
401 
402 
403  /// If an owner id other than -1 is set, then passing this object to
404  /// GUI_DecorationRender::customDecorationRender() will only cause
405  /// decoration rendering on VIS_Primitives created by the visualizer
406  /// with the given unique id. This way, a visualizer can trigger rendering
407  /// of decorations only on primitives it itself has created.
408 
409  void setOwnerId(int owner_id) { myOwnerId = owner_id; }
410  int getOwnerId() const { return myOwnerId; }
411 
412 private:
413  GA_AttributeOwner myDecorAttribOwner; // attribute class
414  int myDecorAttribSize; // num attrib components
415 
416  UT_String myDecorAttrib; // name attribute itself
417  UT_String myMaskAttrib; // boolean (uint8) group mask
418 
419  GR_VisualizerDecorStyle myStyle;
420  GR_SelectMode mySelectMode;
421  GR_DecorVisibility myVisibility;
422  GT_Storage myDecorAttribStorage;
423 
424  UT_Options *myOptions;
425  int myOwnerId; // See above!
426 };
427 
428 #endif
GT_Storage
Definition: GT_Types.h:17
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:205
GR_DecorVisibility getVisibility() const
GR_DecorationOverride
Definition: GR_Defines.h:194
const GR_DisplayOption * opts
GR_DecorFontType
Definition: GR_Defines.h:185
GLuint color
Definition: glcorearb.h:1260
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
GR_AttribMask
Definition: GR_Defines.h:303
GLint GLuint mask
Definition: glcorearb.h:123
GLbitfield flags
Definition: glcorearb.h:1595
const char * getDecorAttrib() const
GR_Decoration
Definition: GR_Defines.h:137
3D Vector class.
GLsizeiptr size
Definition: glcorearb.h:663
void setDecorAttribOwner(GA_AttributeOwner owner)
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:167
GR_DecorRenderFlags render_flags
void setOwnerId(int owner_id)
void setDecorAttrib(const char *attrib)
UT_ColorRamp
Definition: UT_Color.h:32
GR_DecorFontSize
Definition: GR_Defines.h:175
#define GR_API
Definition: GR_API.h:10
void setDecorAttribStorage(GT_Storage store)
GT_Storage getDecorAttribStorage() const
GR_VisualizerInfo & operator=(const GR_VisualizerInfo &src)
GA_AttributeOwner getDecorAttribOwner() const
The base class for all GT primitive types.
Definition: GT_Primitive.h:41
const UT_Options * getOptions() const
GR_SelectMode getSelectMode() const
GA_AttributeOwner
Definition: GA_Types.h:33
double fpreal
Definition: SYS_Types.h:269
A map of string to various well defined value types.
Definition: UT_Options.h:42
GR_VisualizerDecorStyle
void attachOptions(UT_Options *opts)
void setVisibility(GR_DecorVisibility vis)
bool hasOverlayDecorations() const
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
GLboolean r
Definition: glcorearb.h:1221
void setDecorAttribSize(int size)
const GR_VisualizerInfo * visualizer
RE_PrimType
Definition: RE_Types.h:191
float fpreal32
Definition: SYS_Types.h:190
GR_SelectMode
Definition: GR_Defines.h:215
GLenum src
Definition: glcorearb.h:1792