CFx SDK Documentation  2023 SP0
GsOverlayDefs.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef __GSOVERLAYDEFS_H_INCLUDED_
25 #define __GSOVERLAYDEFS_H_INCLUDED_
26 
27 #include "OdArray.h"
28 
29 #include "TD_PackPush.h"
30 
40 {
41  kGsMainOverlay = 0, // "Main" scene overlay
42  kGsDirectOverlay, // "Direct" overlay
43  kGsUserFg3Overlay, // "User Foreground 3" overlay
44  kGsUserBg1Overlay, // "User Background 1" overlay
45  kGsUserBg3Overlay, // "User Background 3" overlay
46  kGsUserFg1Overlay, // "User Foreground 1" overlay
47  kGsHighlightOverlay, // "Highlight" overlay
48  kGsHighlightSelectionOverlay, // "Highlight Selection" overlay
49  kGsDirectTopmostOverlay, // "Direct Topmost" overlay
50  kGsSpriteOverlay, // "Sprite" overlay
51  kGsContrastOverlay, // "Contrast" overlay
52  kGsUserFg2Overlay, // "User Foreground 2" overlay
53  kGsUserBg2Overlay, // "User Background 2" overlay
54  kNumGsOverlays, // Number of Gs overlays
55  kGsAllOverlays = 0x1FFF, // Mask for all overlays
56  kGsNoOverlays = 0, // Mask for no overlays
57  kGsUndefinedOverlay = -1 // Special code for undefined overlay
58 };
59 
66 {
67  protected:
69  {
74  };
75  public:
80  {
81  kMainDepth = 0, // Use main depth buffer
82  kNoDepth = 1, // Don't use depth buffer
83  kOwnDepth = 2, // Use own (alternative) depth buffer
84  kNoFrameBuf = 4, // Use direct rendering without frame buffer
85  kHltStyle = 8, // Draw with highlighting style
86  kContrastStyle = 16 // Draw with contast style
87  };
93  {
94  switch (id)
95  {
96  case kGsUserBg1Overlay: return kNoDepth;
97  case kGsUserBg2Overlay: return kOwnDepth;
98  case kGsUserBg3Overlay: return kMainDepth;
99  case kGsMainOverlay: return kMainDepth;
100  case kGsSpriteOverlay: return kOwnDepth;
101  case kGsDirectOverlay: return kNoDepth;
104  case kGsDirectTopmostOverlay: return kNoDepth;
106  case kGsUserFg1Overlay: return kMainDepth;
107  case kGsUserFg2Overlay: return kOwnDepth;
108  case kGsUserFg3Overlay: return kNoDepth;
109  default: ODA_FAIL();
110  }
111  return kNoDepth;
112  }
113  public:
119  {
120  switch (id)
121  {
122  case kGsMainOverlay: return kMain;
123  case kGsDirectOverlay: return kDirect;
124  case kGsUserFg3Overlay: return kUserFg3;
125  case kGsUserBg1Overlay: return kUserBg1;
126  case kGsUserBg3Overlay: return kUserBg3;
127  case kGsUserFg1Overlay: return kUserFg1;
128  case kGsHighlightOverlay: return kHighlight;
131  case kGsSpriteOverlay: return kSprite;
132  case kGsContrastOverlay: return kContrast;
133  case kGsUserFg2Overlay: return kUserFg2;
134  case kGsUserBg2Overlay: return kUserBg2;
135  default: ODA_FAIL();
136  }
137  return kMain;
138  }
144  {
145  switch (renderOrder)
146  {
147  case kUserBg1: return kGsUserBg1Overlay;
148  case kUserBg2: return kGsUserBg2Overlay;
149  case kUserBg3: return kGsUserBg3Overlay;
150  case kMain: return kGsMainOverlay;
151  case kSprite: return kGsSpriteOverlay;
152  case kDirect: return kGsDirectOverlay;
153  case kHighlight: return kGsHighlightOverlay;
156  case kContrast: return kGsContrastOverlay;
157  case kUserFg1: return kGsUserFg1Overlay;
158  case kUserFg2: return kGsUserFg2Overlay;
159  case kUserFg3: return kGsUserFg3Overlay;
160  default: ODA_FAIL();
161  }
162  return kGsMainOverlay;
163  }
169  inline static bool validateDefinitions(OdUInt32 gsModelDef)
170  {
171  return (gsModelDef == kNumOverlays) && (gsModelDef == kNumGsOverlays);
172  }
177  inline static bool validateOverlayIndex(OdGsOverlayId id)
178  {
179  return (id >= kGsMainOverlay) && (id < kNumGsOverlays);
180  }
185  inline static bool validateRenderingOrder(OdUInt32 renderOrder)
186  { // #CORE-12139 : expression is always true
187  return /* (renderOrder >= kUserBg1) && */ (renderOrder < kNumOverlays);
188  }
189 };
190 
192 {
193  public:
196 };
197 
198 template <typename OverlayDataType = OdGsOverlayDataPlaceholder>
200 {
201  public: // public allocator
202  struct Allocator
203  {
204  virtual OverlayDataType *createData() { return new OverlayDataType(); }
205  virtual void deleteData(OverlayDataType *pObj) { delete pObj; }
206  };
207  protected: // data structures and members
208  struct OverlayData
209  {
210  OverlayDataType* m_data;
213  };
220  protected: // implementations
221  void subAllocator(Allocator *pAllocator)
222  {
223  if ((pAllocator != m_pAllocator) && (pAllocator != NULL))
224  { // Apply recreation of OverlayData nodes
225  const OdUInt32 nOverlays = m_overlaysData.size();
226  OverlayData *pOverlays = m_overlaysData.asArrayPtr();
227  for (OdUInt32 nOverlay = 0; nOverlay < nOverlays; nOverlay++)
228  {
229  if (pOverlays[nOverlay].m_data)
230  {
231  OverlayDataType *pNewData = pAllocator->createData();
232  *pNewData = *pOverlays[nOverlay].m_data;
233  m_pAllocator->deleteData(pOverlays[nOverlay].m_data);
234  pOverlays[nOverlay].m_data = pNewData;
235  }
236  }
237  m_pAllocator = pAllocator;
238  }
239  }
240  void activate(OdGsOverlayId id) const
241  {
242  if (m_overlaysData.size() <= (unsigned)id)
243  m_overlaysData.resize(id + 1);
244  OverlayData &overlay = m_overlaysData.at(id);
245  if (!overlay.m_numOverlayRefs)
246  overlay.m_data = m_pAllocator->createData();
247  overlay.m_numOverlayRefs++;
248  SETBIT_1(m_uActiveOverlays, 1 << id);
249  }
251  {
252  if (m_overlaysData.size() > (unsigned)id)
253  {
254  OverlayData &overlay = m_overlaysData.at(id);
255  if (overlay.m_numOverlayRefs)
256  {
257  overlay.m_numOverlayRefs--;
258  if (!overlay.m_numOverlayRefs)
259  {
260  m_pAllocator->deleteData(overlay.m_data);
261  overlay.m_data = NULL;
262  SETBIT_0(m_uActiveOverlays, 1 << id);
263  SETBIT_0(m_uInvalidOverlays, 1 << id);
264  }
265  }
266  }
267  }
268  public:
270  : m_overlaysData(1, 1)
271  , m_uActiveOverlays(0)
272  , m_uInvalidOverlays(0)
273  { // Always keep main overlay activated
276  }
278  {
279  const OdUInt32 nOverlays = m_overlaysData.size();
280  OverlayData *pOverlays = m_overlaysData.asArrayPtr();
281  for (OdUInt32 nOverlay = 0; nOverlay < nOverlays; nOverlay++)
282  {
283  if (pOverlays[nOverlay].m_data)
284  m_pAllocator->deleteData(pOverlays[nOverlay].m_data);
285  }
286  }
287 
288  void substituteAllocator(Allocator *pAllocator)
289  {
290  subAllocator(pAllocator);
291  }
293  {
295  }
296 
298  {
299  const bool bActive = isOverlayActive(id);
300  activate(id);
301  return bActive != isOverlayActive(id);
302  }
304  {
305  const bool bActive = isOverlayActive(id);
306  deactivate(id);
307  return bActive != isOverlayActive(id);
308  }
309 
311  bool isOverlayActive(OdGsOverlayId id) const { return GETBIT(m_uActiveOverlays, 1 << id); }
312  bool isMultipleOverlays() const { return (m_uActiveOverlays & ~1) != 0; }
313 
314  OverlayDataType *getOverlayData(OdGsOverlayId id, bool bActivate = false)
315  {
316  if (!isOverlayActive(id))
317  {
318  if (bActivate)
319  activate(id);
320  else
321  return NULL;
322  }
323  return m_overlaysData[id].m_data;
324  }
325  const OverlayDataType *getOverlayData(OdGsOverlayId id, bool bActivate = false) const
326  {
327  if (!isOverlayActive(id))
328  {
329  if (bActivate)
330  activate(id);
331  else
332  return NULL;
333  }
334  return m_overlaysData[id].m_data;
335  }
336 
337  struct ForEach
338  {
339  virtual bool call(OdGsOverlayId overlayId, OverlayDataType *pData) = 0;
340  };
341  bool execForEach(ForEach &impl, OdUInt32 nMask = kGsAllOverlays) const
342  {
343  OdUInt32 bitSet = m_uActiveOverlays & nMask, nOlay = 0;
344  while (bitSet)
345  {
346  if (GETBIT(bitSet, 1 << nOlay))
347  {
348  if (!impl.call((OdGsOverlayId)nOlay, m_overlaysData[nOlay].m_data))
349  return false;
350  SETBIT_0(bitSet, 1 << nOlay);
351  }
352  nOlay++;
353  }
354  return true;
355  }
356 
357  class Iterator
358  {
359  protected:
362  friend class OdGsOverlayDataContainer<OverlayDataType>;
363  Iterator(OverlayDataArray &_overlaysData, OdUInt32 _bitSet)
364  : overlaysData(_overlaysData), bitSet(_bitSet), nOlay(0)
365  { init(); }
366  void init()
367  {
368  if (bitSet)
369  {
370  while (!GETBIT(bitSet, 1 << nOlay))
371  nOlay++;
372  }
373  }
374  public:
375  bool next()
376  {
377  SETBIT_0(bitSet, 1 << nOlay);
378  if (bitSet)
379  {
380  do { nOlay++; } while (!GETBIT(bitSet, 1 << nOlay));
381  return true;
382  }
383  return false;
384  }
385  bool done() const { return !bitSet; }
387  const OverlayDataType *overlayData() const { return overlaysData.getPtr()[nOlay].m_data; }
388  OverlayDataType *overlayData() { return overlaysData[nOlay].m_data; }
389  };
391  {
392  return Iterator(m_overlaysData, m_uActiveOverlays & nMask);
393  }
394 
396  bool isOverlayInvalid(OdGsOverlayId id) const { return GETBIT(m_uInvalidOverlays, 1 << id); }
397  void setOverlayInvalid(OdGsOverlayId id, bool bSet = true) { SETBIT(m_uInvalidOverlays, 1 << id, bSet); }
399  void setOverlaysInvalid(OdUInt32 nOverlays, bool bSet = true) { SETBIT(m_uInvalidOverlays, nOverlays & m_uActiveOverlays, bSet); }
400  bool isAnyOverlayInvalid() const { return (m_uInvalidOverlays & m_uActiveOverlays) != 0; }
402 };
403 
404 #include "TD_PackPop.h"
405 
406 #endif // __GSOVERLAYDEFS_H_INCLUDED_
#define ODA_FAIL()
Definition: DebugStuff.h:65
OdGsOverlayId
Definition: GsOverlayDefs.h:40
@ kGsUserFg1Overlay
Definition: GsOverlayDefs.h:46
@ kGsUserBg3Overlay
Definition: GsOverlayDefs.h:45
@ kGsMainOverlay
Definition: GsOverlayDefs.h:41
@ kGsUserBg1Overlay
Definition: GsOverlayDefs.h:44
@ kGsUserBg2Overlay
Definition: GsOverlayDefs.h:53
@ kGsDirectTopmostOverlay
Definition: GsOverlayDefs.h:49
@ kGsHighlightSelectionOverlay
Definition: GsOverlayDefs.h:48
@ kGsUndefinedOverlay
Definition: GsOverlayDefs.h:57
@ kGsUserFg3Overlay
Definition: GsOverlayDefs.h:43
@ kGsDirectOverlay
Definition: GsOverlayDefs.h:42
@ kGsNoOverlays
Definition: GsOverlayDefs.h:56
@ kGsContrastOverlay
Definition: GsOverlayDefs.h:51
@ kNumGsOverlays
Definition: GsOverlayDefs.h:54
@ kGsHighlightOverlay
Definition: GsOverlayDefs.h:47
@ kGsSpriteOverlay
Definition: GsOverlayDefs.h:50
@ kGsUserFg2Overlay
Definition: GsOverlayDefs.h:52
@ kGsAllOverlays
Definition: GsOverlayDefs.h:55
#define NULL
Definition: GsProperties.h:177
unsigned int OdUInt32
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:499
#define SETBIT_0(flags, bit)
Definition: OdaDefs.h:502
#define GETBIT(flags, bit)
Definition: OdaDefs.h:500
#define SETBIT_1(flags, bit)
Definition: OdaDefs.h:503
size_type size() const
Definition: OdArray.h:893
T & at(size_type arrayIndex)
Definition: OdArray.h:1140
const T * getPtr() const
Definition: OdArray.h:1102
const T * asArrayPtr() const
Definition: OdArray.h:1094
void resize(size_type logicalLength, const T &value)
Definition: OdArray.h:834
const OverlayDataType * overlayData() const
Iterator(OverlayDataArray &_overlaysData, OdUInt32 _bitSet)
OdGsOverlayId overlayId() const
bool deactivateOverlay(OdGsOverlayId id)
bool isMultipleOverlays() const
bool isOverlayActive(OdGsOverlayId id) const
bool isAnyOverlayInvalid() const
OverlayDataArray m_overlaysData
bool isAllOverlaysIvalid() const
void setOverlaysInvalid(OdUInt32 nOverlays, bool bSet=true)
void substituteAllocator(Allocator *pAllocator)
void setOverlaysInvalid(bool bSet=true)
bool activateOverlay(OdGsOverlayId id)
void subAllocator(Allocator *pAllocator)
void activate(OdGsOverlayId id) const
OdArray< OverlayData > OverlayDataArray
OdUInt32 activeOverlays() const
void setOverlayInvalid(OdGsOverlayId id, bool bSet=true)
const OverlayDataType * getOverlayData(OdGsOverlayId id, bool bActivate=false) const
OdUInt32 invalidOverlays() const
OverlayDataType * getOverlayData(OdGsOverlayId id, bool bActivate=false)
void deactivate(OdGsOverlayId id)
Iterator newIterator(OdUInt32 nMask=kGsAllOverlays) const
bool execForEach(ForEach &impl, OdUInt32 nMask=kGsAllOverlays) const
bool isOverlayInvalid(OdGsOverlayId id) const
virtual OverlayDataType * createData()
virtual void deleteData(OverlayDataType *pObj)
virtual bool call(OdGsOverlayId overlayId, OverlayDataType *pData)=0
static OdUInt32 overlayFlags(OdGsOverlayId id)
Definition: GsOverlayDefs.h:92
static bool validateOverlayIndex(OdGsOverlayId id)
static bool validateDefinitions(OdUInt32 gsModelDef)
static OdUInt32 overlayIndexToRenderingOrder(OdGsOverlayId id)
static bool validateRenderingOrder(OdUInt32 renderOrder)
static OdGsOverlayId overlayRenderingOrderToIndex(OdUInt32 renderOrder)