HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_DisplayOption.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_DisplayOption.h
7  *
8  * COMMENTS: Drawing options for the render library. Authored by Mark.
9  *
10  */
11 
12 
13 #ifndef __GR_DisplayOption_h__
14 #define __GR_DisplayOption_h__
15 
16 #include "GR_API.h"
17 #include <string.h>
18 #include <UT/UT_Defines.h>
19 #include <UT/UT_VectorTypes.h>
20 #include <UT/UT_SymbolTable.h>
21 #include <UT/UT_Color.h>
22 #include <UT/UT_Array.h>
23 #include "GR_Defines.h"
24 #include "GR_CommonDispOption.h"
25 #include "GR_OptionTable.h"
26 #include "GR_UserOption.h"
27 
28 class RE_Render;
29 class RE_LightList;
30 
31 #define ASSIGN_BUMP(flag) if(myFlags.flag != onoff) mySerialNum++; \
32  myFlags.flag=onoff
33 
34 class GR_UserOption;
35 
37 {
38 public:
39  GR_DisplayOption(GR_CommonDispOption *common_options = 0, int t = 0);
42 
43  // Return the display set type this option set represents
44  int getDisplaySet() const { return myDisplaySet; }
45 
46  GR_DisplayOption &operator=(const GR_DisplayOption &opt);
47 
48  // Copy all but the common display options from the given GR_DisplayOption
49  // object.
50  void copyNonCommon(const GR_DisplayOption &opt);
51 
52  // Copy the user options (not done by copyNonCommon).
53  void copyUserOptions(const GR_DisplayOption &opt);
54 
55  // Refresh the version key for all of the enabled user options from the
56  // global option table.
57  void refreshUserOptionVersions();
58 
59  // Return whether or not the specified object has the same set of enabled
60  // user options. Version keys are ignored.
61  bool userOptionStatesEqual(
62  const GR_DisplayOption &opt) const;
63 
64  // Set the enabled user options to match the specified object. Note that
65  // version keys are also copied. However, this is irrelevant as version
66  // keys only matter while drawing and will have been refreshed in that
67  // case anyway.
68  void matchUserOptionStates(const GR_DisplayOption &opt);
69 
70  // Class I/O methods. Return true if successful, false if not.
71  bool save(std::ostream &, int indent=0) const;
72  bool load(UT_IStream &);
73 
74  const char *className() const;
75 
76  // Set the shading mode. The draw mode is either wireframe or shaded,
77  // but the shading mode can be hiddenwire, flag shaded, wire over gouraud,
78  // etc. Changing the shading mode will change the drawing mode as well as
79  // other flags in this class.
80  void shadingMode(GR_ShadingMode shading_mode);
81 
82  // Find which shading mode we're currently using.
83  GR_ShadingMode shadingMode() const;
84 
85  // Utility methods to convert a GR_BoundaryMode to/from a token. The parse
86  // method returns GR_BOUNDARY_NONE on a failure.
87  static void saveBoundaryMode(std::ostream &os, GR_BoundaryMode mode);
88  static GR_BoundaryMode parseBoundaryMode(const char *token,
89  bool for_uv_view = false);
90 
91  // Utility methods to convert a GR_ShadingMode to/from a token. The parse
92  // method returns -1 on a failure.
93  static void saveShadingMode(std::ostream &os, GR_ShadingMode mode);
94  static int parseShadingMode(const char *token);
95 
96  // "Get" methods.
97  bool drawPointMarkers() const { return myFlags.drawPointMarkers; }
98  bool drawPointNums () const { return myFlags.drawPointNums; }
99  bool drawPointNmls () const { return myFlags.drawPointNmls; }
100  bool drawPointTxtNums() const { return myFlags.drawPointTxtNums; }
101  bool drawPointPos () const { return myFlags.drawPointPos; }
102  bool drawPointVelocity() const { return myFlags.drawPointVelocity; }
103  bool drawPointCoincident() const
104  { return myFlags.drawPointCoincident; }
105  bool drawVertexMarkers() const{ return myFlags.drawVertexMarkers; }
106  bool drawVertexNums () const { return myFlags.drawVertexNums; }
107  bool drawVertexTxtNums() const { return myFlags.drawVertexTxtNums; }
108  bool drawVertexNmls () const { return myFlags.drawVertexNmls; }
109  bool drawPrimNums () const { return myFlags.drawPrimNums; }
110  bool drawPrimNmls () const { return myFlags.drawPrimNmls; }
111  bool drawPrimHulls () const { return myFlags.drawPrimHulls; }
112  bool drawPrimBreakpoints() const{return myFlags.drawPrimBreakpoints;}
113  bool drawProfiles () const { return myFlags.drawProfiles; }
114  bool drawProfNums () const { return myFlags.drawProfNums; }
115  bool drawLit () const { return myFlags.drawLit; }
116  bool drawFaded () const { return myFlags.drawFaded; }
117  bool drawGhosted () const { return myFlags.drawGhosted; }
118  bool drawXRay () const { return myFlags.drawXRay; }
119  bool appliesToSelection() const { return myFlags.appliesToSelection;}
120  bool toggleAffectsSet() const { return myFlags.toggleAffectsSet; }
121  bool boundBox () const;
122  bool hlGhostFill () const;
123  bool hlXray () const;
124  int drawMode () const;
125  bool wireHiddenLine () const;
126  bool flatShaded () const;
127  bool wireOverShaded () const;
128 
129  bool lockShadingMode () const { return myFlags.lockShadingMode; }
130  bool uvFillBackFaces () const { return myFlags.uvFillBackFaces; }
131  bool uvFillOverlap () const { return myFlags.uvFillOverlap; }
132  bool tintBackfaces () const { return myFlags.tintBackfaces; }
133 
134  // "Set" methods.
135  void drawPointMarkers(bool onoff){ASSIGN_BUMP(drawPointMarkers);}
136  void drawPointNums(bool onoff) { ASSIGN_BUMP(drawPointNums);}
137  void drawPointNmls(bool onoff) { ASSIGN_BUMP(drawPointNmls);}
138  void drawPointTxtNums(bool onoff) { ASSIGN_BUMP(drawPointTxtNums);}
139  void drawPointPos(bool onoff) { ASSIGN_BUMP(drawPointPos);}
140  void drawPointVelocity(bool onoff){ ASSIGN_BUMP(drawPointVelocity);}
141  void drawPointCoincident(bool onoff)
142  { ASSIGN_BUMP(drawPointCoincident);}
143  void drawVertexMarkers(bool onoff)
144  { ASSIGN_BUMP(drawVertexMarkers);}
145  void drawVertexNums(bool onoff) { ASSIGN_BUMP(drawVertexNums);}
146  void drawVertexNmls(bool onoff) { ASSIGN_BUMP(drawVertexNmls);}
147  void drawVertexTxtNums(bool onoff){ ASSIGN_BUMP(drawVertexTxtNums);}
148  void drawPrimNums (bool onoff) { ASSIGN_BUMP(drawPrimNums);}
149  void drawPrimNmls (bool onoff) { ASSIGN_BUMP(drawPrimNmls);}
150  void drawPrimHulls (bool onoff) { ASSIGN_BUMP(drawPrimHulls);}
151  void drawPrimBreakpoints (bool onoff)
152  { ASSIGN_BUMP(drawPrimBreakpoints);}
153 
154  void drawProfiles (bool onoff) { myFlags.drawProfiles =onoff;}
155  void drawProfNums (bool onoff) { myFlags.drawProfNums =onoff;}
156  void drawLit (bool onoff) { myFlags.drawLit =onoff;}
157  void drawFaded (bool onoff) { myFlags.drawFaded =onoff;}
158  void drawGhosted (bool onoff) { myFlags.drawGhosted =onoff;}
159  void drawXRay (bool onoff) { myFlags.drawXRay =onoff;}
160  void appliesToSelection(bool onoff)
161  { myFlags.appliesToSelection = onoff; }
162  void toggleAffectsSet(bool onoff) { myFlags.toggleAffectsSet =onoff;}
163  void lockShadingMode (bool onoff) { myFlags.lockShadingMode =onoff;}
164  void uvFillBackFaces (bool onoff) { myFlags.uvFillBackFaces =onoff;}
165  void uvFillOverlap (bool onoff) { myFlags.uvFillOverlap =onoff;}
166  void tintBackfaces (bool onoff) { myFlags.tintBackfaces =onoff;}
167 
168  // Decorations with enhanced visibility options.
169  void pointMarkersVisible(GR_DecorVisibility m);
170  void pointNumsVisible(GR_DecorVisibility m);
171  void pointNmlsVisible(GR_DecorVisibility m);
172  void pointTxtNumsVisible(GR_DecorVisibility m);
173  void pointPosVisible(GR_DecorVisibility m);
174  void pointVelocityVisible(GR_DecorVisibility m);
175  void vertexMarkersVisible(GR_DecorVisibility m);
176  void vertexNumsVisible(GR_DecorVisibility m);
177  void vertexNmlsVisible(GR_DecorVisibility m);
178  void vertexTxtNumsVisible(GR_DecorVisibility m);
179  void primNumsVisible(GR_DecorVisibility m);
180  void primNmlsVisible(GR_DecorVisibility m);
181  void primBreakpointsVisible(GR_DecorVisibility m);
182 
183  GR_DecorVisibility pointMarkersVisible() const;
184  GR_DecorVisibility pointNumsVisible() const;
185  GR_DecorVisibility pointNmlsVisible () const;
186  GR_DecorVisibility pointTxtNumsVisible() const;
187  GR_DecorVisibility pointPosVisible () const;
188  GR_DecorVisibility pointVelocityVisible () const;
189  GR_DecorVisibility vertexMarkersVisible() const;
190  GR_DecorVisibility vertexNumsVisible() const;
191  GR_DecorVisibility vertexNmlsVisible() const;
192  GR_DecorVisibility vertexTxtNumsVisible() const;
193  GR_DecorVisibility primNumsVisible() const;
194  GR_DecorVisibility primNmlsVisible() const;
195  GR_DecorVisibility primBreakpointsVisible() const;
196 
197  GR_DecorVisibility getVisibilityFor(GR_Decoration d) const;
198 
199  GR_BoundaryMode boundaryMode() const { return myBoundaryMode; }
201  {
202  if (mode != myBoundaryMode)
203  {
204  myBoundaryMode = mode;
205  mySerialNum++;
206  }
207  }
208  GR_BoundaryMode uvBoundaryMode() const { return myBoundaryUVMode; }
210  {
211  if (mode != myBoundaryUVMode)
212  {
213  myBoundaryUVMode = mode;
214  mySerialNum++;
215  }
216  }
217 
218  GR_CommonDispOption&common() { return *myCommonOptions; }
219  const GR_CommonDispOption&common() const { return *myCommonOptions; }
220 
221  void enableUserOption(const char *name, bool onoff);
222  bool getUserOptionState(const char *name) const;
223  void disableAllUserOptions();
224 
226  { return myUserOptions.entries() > 0; }
227 
228  // This method is called when user options are being destroyed. We need
229  // to take the option_id since there is no way at that time for us to map
230  // an option name to the id.
231  void removeUserOption(int option_id);
232 
233  // Methods to query the enabled user options.
234  int getNumUserOptions() const { return myUserOptions.entries(); }
235  const GR_UserOption *getUserOption(int i) const;
236  const GR_UserOption *getOption(const char *name) const;
237  int getOptionId(int i) const;
238 
239  // Display list support
240  void clearNonCachedDrawFlag() const { myNonCachedDrawFlag = false; }
241  void setNonCachedDrawFlag() const { myNonCachedDrawFlag = true; }
242  bool hasNonCachedDraw() const { return myNonCachedDrawFlag ; }
243 
244  void setNonCachedPass(bool nc_pass) { myNonCachedPass = nc_pass; }
245  bool isNonCachedPass() const { return myNonCachedPass; }
246 
247  void setLightList(const RE_LightList *list) {myLights=list;}
248  const RE_LightList *getLightList() const { return myLights; }
249 
250  int getSerialNum() const { return (common().getSerialNum() +
251  mySerialNum + myRefineSerial); }
252  int getRefineSerial() const { return myRefineSerial; }
253  void bumpRefineSerial() { myRefineSerial++; }
254  int64 getUniqueID() const { return int64(mySerialNum)<<int64(32) |
255  int64(common().getUniqueID()); }
256 
257  void print(std::ostream &os) const;
258 
259  // return true if 'opt' uses the same shading mode and would request the
260  // same attributes as this display option set.
261  bool compatibleWith(const GR_DisplayOption &opt) const;
262 
263  int getVisContext() const { return common().getVisContext(); }
264 
265 private:
266  GR_CommonDispOption *myCommonOptions;
267  int myDisplaySet;
268  bool myOwnCommonOptionsFlag;
269 
270  //
271  // A simple class to store the unique id and version of a GR_UserOption.
272  // This needs to be here or else the UT_Array template won't be able
273  // to compile on Windows.
274  //
275  class gr_UserOptionRef
276  {
277  public:
278  gr_UserOptionRef(): myId(-1), myVersion(-1) {}
279  gr_UserOptionRef( int id, int version )
280  : myId(id), myVersion(version) {}
281 
282  int operator==(const gr_UserOptionRef &opt)
283  { return myId == opt.myId && myVersion == opt.myVersion; }
284  static int compareID(const gr_UserOptionRef *r1,
285  const gr_UserOptionRef *r2)
286  {
287  return r1->myId - r2->myId;
288  }
289 
290  int myId;
291  int myVersion;
292  };
293 
294  // This array consists only of references to the enabled user options, and
295  // is stored sorted by option id for performance reasons.
296  UT_Array<gr_UserOptionRef> myUserOptions;
297 
298  struct grDrawFlags
299  {
300  unsigned drawPointMarkers :1, // draw points
301  drawPointNums :1, // draw point numbers
302  drawPointNmls :1, // draw point normals
303  drawPointTxtNums :1, // draw point texture numbers
304  drawPointPos :1, // draw point positions
305  drawPointVelocity:1, // draw point velocity (v)
306  drawPointCoincident:1, // draw # of point coincidences
307 
308  drawVertexMarkers:1, // draw vertex markers
309  drawVertexNums :1, // draw vertex numbers
310  drawVertexNmls :1, // draw vertex normals
311  drawVertexTxtNums:1, // draw vertex texture numbers
312 
313  drawPrimNums :1, // draw primitive numbers
314  drawPrimNmls :1, // draw primitive normals
315  drawPrimHulls :1, // draw Spline prim hulls
316  drawPrimBreakpoints:1, // draw primitive break points
317 
318  drawProfiles :1, // draw profiles
319  drawProfNums :1, // draw profile numbers
320  drawFaded :1, // draw without point colors or textures
321  drawGhosted :1, // draw blended with BG color
322 
323  appliesToSelection:1, // use for selected or non-selected?
324  toggleAffectsSet:1, // RHS toolbar toggles affect this set
325 
326  drawLit :1,
327  drawXRay :1,
328  lockShadingMode :1,
329  uvFillBackFaces :1,
330  uvFillOverlap :1,
331  tintBackfaces :1;
332  };
333  grDrawFlags myFlags;
334  GR_BoundaryMode myBoundaryMode;
335  GR_BoundaryMode myBoundaryUVMode;
336  GR_ShadingMode myShadingMode;
337  mutable bool myNonCachedDrawFlag;
338  bool myNonCachedPass;
339  const RE_LightList *myLights;
340  int mySerialNum;
341  int myUniqueID;
342  int myRefineSerial;
343 
345 };
346 
347 inline void
349 { myVisibility[GR_POINT_MARKER] = m;}
350 
351 inline void
353 { myVisibility[GR_POINT_NUMBER] = m; }
354 
355 inline void
357 { myVisibility[GR_POINT_NORMAL] = m; }
358 
359 inline void
361 { myVisibility[GR_POINT_UV] = m; }
362 
363 inline void
365 { myVisibility[GR_POINT_POSITION] = m; }
366 
367 inline void
369 { myVisibility[GR_POINT_VELOCITY] = m; }
370 
371 inline void
373 { myVisibility[GR_VERTEX_MARKER] = m; }
374 
375 inline void
377 { myVisibility[GR_VERTEX_NUMBER] = m; }
378 
379 inline void
381 { myVisibility[GR_VERTEX_NORMAL] = m; }
382 
383 inline void
385 { myVisibility[GR_VERTEX_UV] = m; }
386 
387 inline void
389 { myVisibility[GR_PRIM_NUMBER] = m; }
390 
391 inline void
393 { myVisibility[GR_PRIM_NORMAL] = m; }
394 
395 inline void
397 { myVisibility[GR_PRIM_BREAKPOINT] = m; }
398 
399 inline GR_DecorVisibility
401 { return myVisibility[GR_POINT_MARKER]; }
402 
403 inline GR_DecorVisibility
405 { return myVisibility[GR_POINT_NUMBER]; }
406 
407 inline GR_DecorVisibility
409 { return myVisibility[GR_POINT_NORMAL]; }
410 
411 inline GR_DecorVisibility
413 { return myVisibility[GR_POINT_UV]; }
414 
415 inline GR_DecorVisibility
417 { return myVisibility[GR_POINT_POSITION]; }
418 
419 inline GR_DecorVisibility
421 { return myVisibility[GR_POINT_VELOCITY]; }
422 
423 inline GR_DecorVisibility
425 { return myVisibility[GR_VERTEX_MARKER]; }
426 
427 inline GR_DecorVisibility
429 { return myVisibility[GR_VERTEX_NUMBER]; }
430 
431 inline GR_DecorVisibility
433 { return myVisibility[GR_VERTEX_NORMAL]; }
434 
435 inline GR_DecorVisibility
437 { return myVisibility[GR_VERTEX_UV]; }
438 
439 inline GR_DecorVisibility
441 { return myVisibility[GR_PRIM_NUMBER]; }
442 
443 inline GR_DecorVisibility
445 { return myVisibility[GR_PRIM_NORMAL]; }
446 
447 inline GR_DecorVisibility
449 { return myVisibility[GR_PRIM_BREAKPOINT]; }
450 
451 inline GR_DecorVisibility
453 {
454  if(d < GR_USER_DECORATION)
455  return myVisibility[d];
456 
458 }
459 
460 inline bool
462 {
463  return (myShadingMode == GR_BOUNDING_BOX_WIRE ||
464  myShadingMode == GR_BOUNDING_BOX_SHADED);
465 }
466 
467 inline bool
469 {
470  return myShadingMode == GR_HIDDEN_LINE_GHOST;
471 }
472 
473 inline bool
475 {
476  return myShadingMode == GR_WIRE_GHOST;
477 }
478 
479 inline int
481 {
482  if(myShadingMode >= GR_WIRE && myShadingMode <= GR_HIDDEN_LINE_GHOST)
483  return GR_DRAW_WIREFRAME;
484  else if(myShadingMode >= GR_FLAT_SHADED)
485  return GR_DRAW_SHADED;
486 
487  return 0; // no enum for bbox
488 }
489 
490 inline bool
492 {
493  return (myShadingMode == GR_WIRE_GHOST ||
494  myShadingMode == GR_HIDDEN_LINE_INVISIBLE ||
495  myShadingMode == GR_HIDDEN_LINE_GHOST);
496 }
497 
498 inline bool
500 {
501  return (myShadingMode == GR_FLAT_SHADED ||
502  myShadingMode == GR_FLAT_WIRE_SHADED);
503 }
504 
505 inline bool
507 {
508  return (myShadingMode == GR_SMOOTH_WIRE_SHADED ||
509  myShadingMode == GR_FLAT_WIRE_SHADED);
510 }
511 
512 
513 #endif
void appliesToSelection(bool onoff)
bool wireOverShaded() const
#define ASSIGN_BUMP(flag)
void drawVertexMarkers(bool onoff)
bool drawProfNums() const
void drawFaded(bool onoff)
void drawPointMarkers(bool onoff)
void tintBackfaces(bool onoff)
const RE_LightList * getLightList() const
bool flatShaded() const
void drawProfiles(bool onoff)
bool drawPointVelocity() const
void drawProfNums(bool onoff)
void toggleAffectsSet(bool onoff)
bool drawVertexNums() const
bool uvFillBackFaces() const
#define GR_DRAW_WIREFRAME
Definition: GR_Defines.h:18
int64 getUniqueID() const
void drawPointNums(bool onoff)
void drawVertexNmls(bool onoff)
GR_DecorVisibility pointVelocityVisible() const
void drawPrimHulls(bool onoff)
GR_DecorVisibility vertexNmlsVisible() const
void drawGhosted(bool onoff)
const GR_CommonDispOption & common() const
void drawVertexTxtNums(bool onoff)
bool hlGhostFill() const
void setNonCachedDrawFlag() const
int getNumUserOptions() const
bool drawFaded() const
GR_Decoration
Definition: GR_Defines.h:139
GR_DecorVisibility vertexNumsVisible() const
void uvFillBackFaces(bool onoff)
png_uint_32 i
Definition: png.h:2877
bool drawXRay() const
bool wireHiddenLine() const
GR_DecorVisibility pointTxtNumsVisible() const
bool uvFillOverlap() const
void setLightList(const RE_LightList *list)
bool drawVertexTxtNums() const
bool drawPointNums() const
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
long long int64
Definition: SYS_Types.h:107
void boundaryMode(GR_BoundaryMode mode)
bool drawGhosted() const
void uvBoundaryMode(GR_BoundaryMode mode)
void drawPointNmls(bool onoff)
bool drawProfiles() const
bool hlXray() const
bool drawPointMarkers() const
GR_DecorVisibility
Definition: GR_Defines.h:169
GR_CommonDispOption & common()
bool drawPrimBreakpoints() const
bool hasNonCachedDraw() const
GR_DecorVisibility pointMarkersVisible() const
void drawXRay(bool onoff)
bool tintBackfaces() const
void lockShadingMode(bool onoff)
bool drawVertexNmls() const
GR_ShadingMode
Definition: GR_Defines.h:29
int getDisplaySet() const
void drawVertexNums(bool onoff)
bool drawVertexMarkers() const
#define GR_API
Definition: GR_API.h:10
const GR_UserOption * getOption(int i) const
GR_DecorVisibility getVisibilityFor(GR_Decoration d) const
int getSerialNum() const
int getRefineSerial() const
GR_DecorVisibility primNumsVisible() const
bool drawPrimNums() const
GLuint const GLchar * name
Definition: glcorearb.h:785
void drawPointPos(bool onoff)
void drawPointVelocity(bool onoff)
GR_API GR_OptionTable * GRgetOptionTable()
bool drawPointNmls() const
GLenum mode
Definition: glcorearb.h:98
void drawLit(bool onoff)
GT_API const UT_StringHolder version
void drawPrimBreakpoints(bool onoff)
void drawPrimNmls(bool onoff)
int getVisContext() const
bool drawPointPos() const
GR_BoundaryMode uvBoundaryMode() const
GR_DecorVisibility pointNumsVisible() const
void drawPointTxtNums(bool onoff)
void drawPrimNums(bool onoff)
bool toggleAffectsSet() const
GR_DecorVisibility getVisibility() const
Definition: GR_UserOption.h:79
void clearNonCachedDrawFlag() const
bool drawLit() const
bool boundBox() const
GR_DecorVisibility vertexMarkersVisible() const
GR_DecorVisibility primBreakpointsVisible() const
GR_BoundaryMode boundaryMode() const
bool drawPrimNmls() const
int drawMode() const
GR_DecorVisibility primNmlsVisible() const
bool hasEnabledUserOptions() const
bool drawPrimHulls() const
GR_BoundaryMode
Definition: GR_Defines.h:348
bool drawPointCoincident() const
bool isNonCachedPass() const
GR_DecorVisibility pointPosVisible() const
#define GR_DRAW_SHADED
Definition: GR_Defines.h:19
void uvFillOverlap(bool onoff)
GR_DecorVisibility pointNmlsVisible() const
bool appliesToSelection() const
void drawPointCoincident(bool onoff)
bool drawPointTxtNums() const
bool lockShadingMode() const
GR_DecorVisibility vertexTxtNumsVisible() const
void setNonCachedPass(bool nc_pass)