HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 
90  // Utility methods to convert a GR_ShadingMode to/from a token. The parse
91  // method returns -1 on a failure.
92  static void saveShadingMode(std::ostream &os, GR_ShadingMode mode);
93  static int parseShadingMode(const char *token);
94 
95  // "Get" methods.
96  bool drawPointMarkers() const { return myFlags.drawPointMarkers; }
97  bool drawPointNums () const { return myFlags.drawPointNums; }
98  bool drawPointNmls () const { return myFlags.drawPointNmls; }
99  bool drawPointTxtNums() const { return myFlags.drawPointTxtNums; }
100  bool drawPointPos () const { return myFlags.drawPointPos; }
101  bool drawPointVelocity() const { return myFlags.drawPointVelocity; }
102  bool drawPointCoincident() const
103  { return myFlags.drawPointCoincident; }
104  bool drawVertexMarkers() const{ return myFlags.drawVertexMarkers; }
105  bool drawVertexNums () const { return myFlags.drawVertexNums; }
106  bool drawVertexTxtNums() const { return myFlags.drawVertexTxtNums; }
107  bool drawVertexNmls () const { return myFlags.drawVertexNmls; }
108  bool drawPrimNums () const { return myFlags.drawPrimNums; }
109  bool drawPrimNmls () const { return myFlags.drawPrimNmls; }
110  bool drawPrimHulls () const { return myFlags.drawPrimHulls; }
111  bool drawPrimBreakpoints() const{return myFlags.drawPrimBreakpoints;}
112  bool drawProfiles () const { return myFlags.drawProfiles; }
113  bool drawProfNums () const { return myFlags.drawProfNums; }
114  bool drawLit () const { return myFlags.drawLit; }
115  bool drawFaded () const { return myFlags.drawFaded; }
116  bool drawGhosted () const { return myFlags.drawGhosted; }
117  bool drawXRay () const { return myFlags.drawXRay; }
118  bool appliesToSelection() const { return myFlags.appliesToSelection;}
119  bool toggleAffectsSet() const { return myFlags.toggleAffectsSet; }
120  bool boundBox () const;
121  bool hlGhostFill () const;
122  bool hlXray () const;
123  int drawMode () const;
124  bool wireHiddenLine () const;
125  bool flatShaded () const;
126  bool wireOverShaded () const;
127 
128  bool lockShadingMode () const { return myFlags.lockShadingMode; }
129  bool uvFillBackFaces () const { return myFlags.uvFillBackFaces; }
130  bool uvFillOverlap () const { return myFlags.uvFillOverlap; }
131 
132  // "Set" methods.
133  void drawPointMarkers(bool onoff){ASSIGN_BUMP(drawPointMarkers);}
134  void drawPointNums(bool onoff) { ASSIGN_BUMP(drawPointNums);}
135  void drawPointNmls(bool onoff) { ASSIGN_BUMP(drawPointNmls);}
136  void drawPointTxtNums(bool onoff) { ASSIGN_BUMP(drawPointTxtNums);}
137  void drawPointPos(bool onoff) { ASSIGN_BUMP(drawPointPos);}
138  void drawPointVelocity(bool onoff){ ASSIGN_BUMP(drawPointVelocity);}
139  void drawPointCoincident(bool onoff)
140  { ASSIGN_BUMP(drawPointCoincident);}
141  void drawVertexMarkers(bool onoff)
142  { ASSIGN_BUMP(drawVertexMarkers);}
143  void drawVertexNums(bool onoff) { ASSIGN_BUMP(drawVertexNums);}
144  void drawVertexNmls(bool onoff) { ASSIGN_BUMP(drawVertexNmls);}
145  void drawVertexTxtNums(bool onoff){ ASSIGN_BUMP(drawVertexTxtNums);}
146  void drawPrimNums (bool onoff) { ASSIGN_BUMP(drawPrimNums);}
147  void drawPrimNmls (bool onoff) { ASSIGN_BUMP(drawPrimNmls);}
148  void drawPrimHulls (bool onoff) { ASSIGN_BUMP(drawPrimHulls);}
149  void drawPrimBreakpoints (bool onoff)
150  { ASSIGN_BUMP(drawPrimBreakpoints);}
151 
152  void drawProfiles (bool onoff) { myFlags.drawProfiles =onoff;}
153  void drawProfNums (bool onoff) { myFlags.drawProfNums =onoff;}
154  void drawLit (bool onoff) { myFlags.drawLit =onoff;}
155  void drawFaded (bool onoff) { myFlags.drawFaded =onoff;}
156  void drawGhosted (bool onoff) { myFlags.drawGhosted =onoff;}
157  void drawXRay (bool onoff) { myFlags.drawXRay =onoff;}
158  void appliesToSelection(bool onoff)
159  { myFlags.appliesToSelection = onoff; }
160  void toggleAffectsSet(bool onoff) { myFlags.toggleAffectsSet =onoff;}
161  void lockShadingMode (bool onoff) { myFlags.lockShadingMode =onoff;}
162  void uvFillBackFaces (bool onoff) { myFlags.uvFillBackFaces =onoff;}
163  void uvFillOverlap (bool onoff) { myFlags.uvFillOverlap =onoff;}
164 
165  // Decorations with enhanced visibility options.
166  void pointMarkersVisible(GR_DecorVisibility m);
167  void pointNumsVisible(GR_DecorVisibility m);
168  void pointNmlsVisible(GR_DecorVisibility m);
169  void pointTxtNumsVisible(GR_DecorVisibility m);
170  void pointPosVisible(GR_DecorVisibility m);
171  void pointVelocityVisible(GR_DecorVisibility m);
172  void vertexMarkersVisible(GR_DecorVisibility m);
173  void vertexNumsVisible(GR_DecorVisibility m);
174  void vertexNmlsVisible(GR_DecorVisibility m);
175  void vertexTxtNumsVisible(GR_DecorVisibility m);
176  void primNumsVisible(GR_DecorVisibility m);
177  void primNmlsVisible(GR_DecorVisibility m);
178  void primBreakpointsVisible(GR_DecorVisibility m);
179 
180  GR_DecorVisibility pointMarkersVisible() const;
181  GR_DecorVisibility pointNumsVisible() const;
182  GR_DecorVisibility pointNmlsVisible () const;
183  GR_DecorVisibility pointTxtNumsVisible() const;
184  GR_DecorVisibility pointPosVisible () const;
185  GR_DecorVisibility pointVelocityVisible () const;
186  GR_DecorVisibility vertexMarkersVisible() const;
187  GR_DecorVisibility vertexNumsVisible() const;
188  GR_DecorVisibility vertexNmlsVisible() const;
189  GR_DecorVisibility vertexTxtNumsVisible() const;
190  GR_DecorVisibility primNumsVisible() const;
191  GR_DecorVisibility primNmlsVisible() const;
192  GR_DecorVisibility primBreakpointsVisible() const;
193 
194  GR_DecorVisibility getVisibilityFor(GR_Decoration d) const;
195 
196  GR_BoundaryMode boundaryMode() const { return myBoundaryMode; }
198  {
199  if (mode != myBoundaryMode)
200  {
201  myBoundaryMode = mode;
202  mySerialNum++;
203  }
204  }
205 
206  GR_CommonDispOption&common() { return *myCommonOptions; }
207  const GR_CommonDispOption&common() const { return *myCommonOptions; }
208 
209  void enableUserOption(const char *name, bool onoff);
210  bool getUserOptionState(const char *name) const;
211  void disableAllUserOptions();
212 
214  { return myUserOptions.entries() > 0; }
215 
216  // This method is called when user options are being destroyed. We need
217  // to take the option_id since there is no way at that time for us to map
218  // an option name to the id.
219  void removeUserOption(int option_id);
220 
221  // Methods to query the enabled user options.
222  int getNumUserOptions() const { return myUserOptions.entries(); }
223  const GR_UserOption *getUserOption(int i) const;
224  const GR_UserOption *getOption(const char *name) const;
225  int getOptionId(int i) const;
226 
227  // Display list support
228  void clearNonCachedDrawFlag() const { myNonCachedDrawFlag = false; }
229  void setNonCachedDrawFlag() const { myNonCachedDrawFlag = true; }
230  bool hasNonCachedDraw() const { return myNonCachedDrawFlag ; }
231 
232  void setNonCachedPass(bool nc_pass) { myNonCachedPass = nc_pass; }
233  bool isNonCachedPass() const { return myNonCachedPass; }
234 
235  void setLightList(const RE_LightList *list) {myLights=list;}
236  const RE_LightList *getLightList() const { return myLights; }
237 
238  int getSerialNum() const { return (common().getSerialNum() +
239  mySerialNum + myRefineSerial); }
240  int getRefineSerial() const { return myRefineSerial; }
241  void bumpRefineSerial() { myRefineSerial++; }
242  int64 getUniqueID() const { return int64(mySerialNum)<<int64(32) |
243  int64(common().getUniqueID()); }
244 
245  void print(std::ostream &os) const;
246 
247  // return true if 'opt' uses the same shading mode and would request the
248  // same attributes as this display option set.
249  bool compatibleWith(const GR_DisplayOption &opt) const;
250 
251  int getVisContext() const { return common().getVisContext(); }
252 
253 private:
254  GR_CommonDispOption *myCommonOptions;
255  int myDisplaySet;
256  bool myOwnCommonOptionsFlag;
257 
258  //
259  // A simple class to store the unique id and version of a GR_UserOption.
260  // This needs to be here or else the UT_Array template won't be able
261  // to compile on Windows.
262  //
263  class gr_UserOptionRef
264  {
265  public:
266  gr_UserOptionRef(): myId(-1), myVersion(-1) {}
267  gr_UserOptionRef( int id, int version )
268  : myId(id), myVersion(version) {}
269 
270  int operator==(const gr_UserOptionRef &opt)
271  { return myId == opt.myId && myVersion == opt.myVersion; }
272  static int compareID(const gr_UserOptionRef *r1,
273  const gr_UserOptionRef *r2)
274  {
275  return r1->myId - r2->myId;
276  }
277 
278  int myId;
279  int myVersion;
280  };
281 
282  // This array consists only of references to the enabled user options, and
283  // is stored sorted by option id for performance reasons.
284  UT_Array<gr_UserOptionRef> myUserOptions;
285 
286  struct grDrawFlags
287  {
288  unsigned drawPointMarkers :1, // draw points
289  drawPointNums :1, // draw point numbers
290  drawPointNmls :1, // draw point normals
291  drawPointTxtNums :1, // draw point texture numbers
292  drawPointPos :1, // draw point positions
293  drawPointVelocity:1, // draw point velocity (v)
294  drawPointCoincident:1, // draw # of point coincidences
295 
296  drawVertexMarkers:1, // draw vertex markers
297  drawVertexNums :1, // draw vertex numbers
298  drawVertexNmls :1, // draw vertex normals
299  drawVertexTxtNums:1, // draw vertex texture numbers
300 
301  drawPrimNums :1, // draw primitive numbers
302  drawPrimNmls :1, // draw primitive normals
303  drawPrimHulls :1, // draw Spline prim hulls
304  drawPrimBreakpoints:1, // draw primitive break points
305 
306  drawProfiles :1, // draw profiles
307  drawProfNums :1, // draw profile numbers
308  drawFaded :1, // draw without point colors or textures
309  drawGhosted :1, // draw blended with BG color
310 
311  appliesToSelection:1, // use for selected or non-selected?
312  toggleAffectsSet:1, // RHS toolbar toggles affect this set
313 
314  drawLit :1,
315  drawXRay :1,
316  lockShadingMode :1,
317  uvFillBackFaces :1,
318  uvFillOverlap :1;
319  };
320  grDrawFlags myFlags;
321  GR_BoundaryMode myBoundaryMode;
322  GR_ShadingMode myShadingMode;
323  mutable bool myNonCachedDrawFlag;
324  bool myNonCachedPass;
325  const RE_LightList *myLights;
326  int mySerialNum;
327  int myUniqueID;
328  int myRefineSerial;
329 
331 };
332 
333 inline void
335 { myVisibility[GR_POINT_MARKER] = m;}
336 
337 inline void
339 { myVisibility[GR_POINT_NUMBER] = m; }
340 
341 inline void
343 { myVisibility[GR_POINT_NORMAL] = m; }
344 
345 inline void
347 { myVisibility[GR_POINT_UV] = m; }
348 
349 inline void
351 { myVisibility[GR_POINT_POSITION] = m; }
352 
353 inline void
355 { myVisibility[GR_POINT_VELOCITY] = m; }
356 
357 inline void
359 { myVisibility[GR_VERTEX_MARKER] = m; }
360 
361 inline void
363 { myVisibility[GR_VERTEX_NUMBER] = m; }
364 
365 inline void
367 { myVisibility[GR_VERTEX_NORMAL] = m; }
368 
369 inline void
371 { myVisibility[GR_VERTEX_UV] = m; }
372 
373 inline void
375 { myVisibility[GR_PRIM_NUMBER] = m; }
376 
377 inline void
379 { myVisibility[GR_PRIM_NORMAL] = m; }
380 
381 inline void
383 { myVisibility[GR_PRIM_BREAKPOINT] = m; }
384 
385 inline GR_DecorVisibility
387 { return myVisibility[GR_POINT_MARKER]; }
388 
389 inline GR_DecorVisibility
391 { return myVisibility[GR_POINT_NUMBER]; }
392 
393 inline GR_DecorVisibility
395 { return myVisibility[GR_POINT_NORMAL]; }
396 
397 inline GR_DecorVisibility
399 { return myVisibility[GR_POINT_UV]; }
400 
401 inline GR_DecorVisibility
403 { return myVisibility[GR_POINT_POSITION]; }
404 
405 inline GR_DecorVisibility
407 { return myVisibility[GR_POINT_VELOCITY]; }
408 
409 inline GR_DecorVisibility
411 { return myVisibility[GR_VERTEX_MARKER]; }
412 
413 inline GR_DecorVisibility
415 { return myVisibility[GR_VERTEX_NUMBER]; }
416 
417 inline GR_DecorVisibility
419 { return myVisibility[GR_VERTEX_NORMAL]; }
420 
421 inline GR_DecorVisibility
423 { return myVisibility[GR_VERTEX_UV]; }
424 
425 inline GR_DecorVisibility
427 { return myVisibility[GR_PRIM_NUMBER]; }
428 
429 inline GR_DecorVisibility
431 { return myVisibility[GR_PRIM_NORMAL]; }
432 
433 inline GR_DecorVisibility
435 { return myVisibility[GR_PRIM_BREAKPOINT]; }
436 
437 inline GR_DecorVisibility
439 {
440  if(d < GR_USER_DECORATION)
441  return myVisibility[d];
442 
444 }
445 
446 inline bool
448 {
449  return (myShadingMode == GR_BOUNDING_BOX_WIRE ||
450  myShadingMode == GR_BOUNDING_BOX_SHADED);
451 }
452 
453 inline bool
455 {
456  return myShadingMode == GR_HIDDEN_LINE_GHOST;
457 }
458 
459 inline bool
461 {
462  return myShadingMode == GR_WIRE_GHOST;
463 }
464 
465 inline int
467 {
468  if(myShadingMode >= GR_WIRE && myShadingMode <= GR_HIDDEN_LINE_GHOST)
469  return GR_DRAW_WIREFRAME;
470  else if(myShadingMode >= GR_FLAT_SHADED)
471  return GR_DRAW_SHADED;
472 
473  return 0; // no enum for bbox
474 }
475 
476 inline bool
478 {
479  return (myShadingMode == GR_WIRE_GHOST ||
480  myShadingMode == GR_HIDDEN_LINE_INVISIBLE ||
481  myShadingMode == GR_HIDDEN_LINE_GHOST);
482 }
483 
484 inline bool
486 {
487  return (myShadingMode == GR_FLAT_SHADED ||
488  myShadingMode == GR_FLAT_WIRE_SHADED);
489 }
490 
491 inline bool
493 {
494  return (myShadingMode == GR_SMOOTH_WIRE_SHADED ||
495  myShadingMode == GR_FLAT_WIRE_SHADED);
496 }
497 
498 
499 #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)
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:16
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:137
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:100
void boundaryMode(GR_BoundaryMode mode)
bool drawGhosted() const
void drawPointNmls(bool onoff)
bool drawProfiles() const
bool hlXray() const
bool drawPointMarkers() const
GR_DecorVisibility
Definition: GR_Defines.h:167
GR_CommonDispOption & common()
bool drawPrimBreakpoints() const
bool hasNonCachedDraw() const
GR_DecorVisibility pointMarkersVisible() const
void drawXRay(bool onoff)
void lockShadingMode(bool onoff)
bool drawVertexNmls() const
GR_ShadingMode
Definition: GR_Defines.h:27
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)
void drawPrimBreakpoints(bool onoff)
void drawPrimNmls(bool onoff)
int getVisContext() const
bool drawPointPos() 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:340
bool drawPointCoincident() const
bool isNonCachedPass() const
GR_DecorVisibility pointPosVisible() const
#define GR_DRAW_SHADED
Definition: GR_Defines.h:17
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)