CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GsOverlayDefs.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 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
42{
43 kGsMainOverlay = 0, // "Main" scene overlay
44 kGsDirectOverlay, // "Direct" overlay
45 kGsUserFg3Overlay, // "User Foreground 3" overlay
46 kGsUserBg1Overlay, // "User Background 1" overlay
47 kGsUserBg3Overlay, // "User Background 3" overlay
48 kGsUserFg1Overlay, // "User Foreground 1" overlay
49 kGsHighlightOverlay, // "Highlight" overlay
50 kGsHighlightSelectionOverlay, // "Highlight Selection" overlay
51 kGsDirectTopmostOverlay, // "Direct Topmost" overlay
52 kGsSpriteOverlay, // "Sprite" overlay
53 kGsContrastOverlay, // "Contrast" overlay
54 kGsUserFg2Overlay, // "User Foreground 2" overlay
55 kGsUserBg2Overlay, // "User Background 2" overlay
56 kNumGsOverlays, // Number of Gs overlays
57 kGsAllOverlays = 0x1FFF, // Mask for all overlays
58 kGsNoOverlays = 0, // Mask for no overlays
59 kGsUndefinedOverlay = -1 // Special code for undefined overlay
60};
61
68{
69 protected:
71 {
76 };
77 public:
82 {
83 kMainDepth = 0, // Use main depth buffer
84 kNoDepth = 1, // Don't use depth buffer
85 kOwnDepth = 2, // Use own (alternative) depth buffer
86 kNoFrameBuf = 4, // Use direct rendering without frame buffer
87 kHltStyle = 8, // Draw with highlighting style
88 kContrastStyle = 16 // Draw with contast style
89 };
95 {
96 switch (id)
97 {
98 case kGsUserBg1Overlay: return kNoDepth;
99 case kGsUserBg2Overlay: return kOwnDepth;
100 case kGsUserBg3Overlay: return kMainDepth;
101 case kGsMainOverlay: return kMainDepth;
102 case kGsSpriteOverlay: return kOwnDepth;
103 case kGsDirectOverlay: return kNoDepth;
108 case kGsUserFg1Overlay: return kMainDepth;
109 case kGsUserFg2Overlay: return kOwnDepth;
110 case kGsUserFg3Overlay: return kNoDepth;
111 default: ODA_FAIL();
112 }
113 return kNoDepth;
114 }
115 public:
121 {
122 switch (id)
123 {
124 case kGsMainOverlay: return kMain;
125 case kGsDirectOverlay: return kDirect;
126 case kGsUserFg3Overlay: return kUserFg3;
127 case kGsUserBg1Overlay: return kUserBg1;
128 case kGsUserBg3Overlay: return kUserBg3;
129 case kGsUserFg1Overlay: return kUserFg1;
130 case kGsHighlightOverlay: return kHighlight;
133 case kGsSpriteOverlay: return kSprite;
134 case kGsContrastOverlay: return kContrast;
135 case kGsUserFg2Overlay: return kUserFg2;
136 case kGsUserBg2Overlay: return kUserBg2;
137 default: ODA_FAIL();
138 }
139 return kMain;
140 }
146 {
147 switch (renderOrder)
148 {
149 case kUserBg1: return kGsUserBg1Overlay;
150 case kUserBg2: return kGsUserBg2Overlay;
151 case kUserBg3: return kGsUserBg3Overlay;
152 case kMain: return kGsMainOverlay;
153 case kSprite: return kGsSpriteOverlay;
154 case kDirect: return kGsDirectOverlay;
155 case kHighlight: return kGsHighlightOverlay;
158 case kContrast: return kGsContrastOverlay;
159 case kUserFg1: return kGsUserFg1Overlay;
160 case kUserFg2: return kGsUserFg2Overlay;
161 case kUserFg3: return kGsUserFg3Overlay;
162 default: ODA_FAIL();
163 }
164 return kGsMainOverlay;
165 }
171 inline static bool validateDefinitions(OdUInt32 gsModelDef)
172 {
173 static const bool bSameEnums = (OdInt32(kNumOverlays) == OdInt32(kNumGsOverlays));
174 return (gsModelDef == kNumOverlays) && bSameEnums;
175 }
180 inline static bool validateOverlayIndex(OdGsOverlayId id)
181 {
182 return (id >= kGsMainOverlay) && (id < kNumGsOverlays);
183 }
188 inline static bool validateRenderingOrder(OdUInt32 renderOrder)
189 { // #CORE-12139 : expression is always true
190 return /* (renderOrder >= kUserBg1) && */ (renderOrder < kNumOverlays);
191 }
192};
193
195{
196 public:
201
206};
207
208template <typename OverlayDataType = OdGsOverlayDataPlaceholder>
210{
211 public: // public allocator
216 {
220 virtual OverlayDataType *createData() { return new OverlayDataType(); }
221
225 virtual void deleteData(OverlayDataType *pObj) { delete pObj; }
226 };
227 protected: // data structures and members
229 {
230 OverlayDataType* m_data;
233 };
240 protected: // implementations
241 void subAllocator(Allocator *pAllocator)
242 {
243 if ((pAllocator != m_pAllocator) && (pAllocator != NULL))
244 { // Apply recreation of OverlayData nodes
245 const OdUInt32 nOverlays = m_overlaysData.size();
247 for (OdUInt32 nOverlay = 0; nOverlay < nOverlays; nOverlay++)
248 {
249 if (pOverlays[nOverlay].m_data)
250 {
251 OverlayDataType *pNewData = pAllocator->createData();
252 *pNewData = *pOverlays[nOverlay].m_data;
253 m_pAllocator->deleteData(pOverlays[nOverlay].m_data);
254 pOverlays[nOverlay].m_data = pNewData;
255 }
256 }
257 m_pAllocator = pAllocator;
258 }
259 }
260 void activate(OdGsOverlayId id) const
261 {
262 if (m_overlaysData.size() <= (unsigned)id)
263 m_overlaysData.resize(id + 1);
264 OverlayData &overlay = m_overlaysData.at(id);
265 if (!overlay.m_numOverlayRefs)
266 overlay.m_data = m_pAllocator->createData();
267 overlay.m_numOverlayRefs++;
268 SETBIT_1(m_uActiveOverlays, 1 << id);
269 }
271 {
272 if (m_overlaysData.size() > (unsigned)id)
273 {
274 OverlayData &overlay = m_overlaysData.at(id);
275 if (overlay.m_numOverlayRefs)
276 {
277 overlay.m_numOverlayRefs--;
278 if (!overlay.m_numOverlayRefs)
279 {
281 overlay.m_data = NULL;
282 SETBIT_0(m_uActiveOverlays, 1 << id);
284 }
285 }
286 }
287 }
288 public:
293 : m_overlaysData(1, 1)
296 { // Always keep main overlay activated
299 }
300
305 {
306 const OdUInt32 nOverlays = m_overlaysData.size();
308 for (OdUInt32 nOverlay = 0; nOverlay < nOverlays; nOverlay++)
309 {
310 if (pOverlays[nOverlay].m_data)
311 m_pAllocator->deleteData(pOverlays[nOverlay].m_data);
312 }
313 }
314
321 {
322 subAllocator(pAllocator);
323 }
324
329 {
331 }
332
341 {
342 const bool bActive = isOverlayActive(id);
343 activate(id);
344 return bActive != isOverlayActive(id);
345 }
346
355 {
356 const bool bActive = isOverlayActive(id);
357 deactivate(id);
358 return bActive != isOverlayActive(id);
359 }
360
369 {
370 if( m_overlaysData.size() > (unsigned)id )
371 {
372 OverlayData& overlay = m_overlaysData.at( id );
373 return overlay.m_numOverlayRefs;
374 }
375 return 0;
376 }
377
382
390 bool isOverlayActive(OdGsOverlayId id) const { return GETBIT(m_uActiveOverlays, 1 << id); }
391
397 bool isMultipleOverlays() const { return (m_uActiveOverlays & ~1) != 0; }
398
405 OverlayDataType *getOverlayData(OdGsOverlayId id, bool bActivate = false)
406 {
407 if (!isOverlayActive(id))
408 {
409 if (bActivate)
410 activate(id);
411 else
412 return NULL;
413 }
414 return m_overlaysData[id].m_data;
415 }
416
423 const OverlayDataType *getOverlayData(OdGsOverlayId id, bool bActivate = false) const
424 {
425 if (!isOverlayActive(id))
426 {
427 if (bActivate)
428 activate(id);
429 else
430 return NULL;
431 }
432 return m_overlaysData[id].m_data;
433 }
434
435 struct ForEach
436 {
437 virtual bool call(OdGsOverlayId overlayId, OverlayDataType *pData) = 0;
438 };
439 bool execForEach(ForEach &impl, OdUInt32 nMask = kGsAllOverlays) const
440 {
441 OdUInt32 bitSet = m_uActiveOverlays & nMask, nOlay = 0;
442 while (bitSet)
443 {
444 if (GETBIT(bitSet, 1 << nOlay))
445 {
446 if (!impl.call((OdGsOverlayId)nOlay, m_overlaysData[nOlay].m_data))
447 return false;
448 SETBIT_0(bitSet, 1 << nOlay);
449 }
450 nOlay++;
451 }
452 return true;
453 }
454
459 {
460 protected:
463 friend class OdGsOverlayDataContainer<OverlayDataType>;
464 Iterator(OverlayDataArray &_overlaysData, OdUInt32 _bitSet)
465 : overlaysData(_overlaysData), bitSet(_bitSet), nOlay(0)
466 { init(); }
467 void init()
468 {
469 if (bitSet)
470 {
471 while (!GETBIT(bitSet, 1 << nOlay))
472 nOlay++;
473 }
474 }
475 public:
481 bool next()
482 {
483 SETBIT_0(bitSet, 1 << nOlay);
484 if (bitSet)
485 {
486 do { nOlay++; } while (!GETBIT(bitSet, 1 << nOlay));
487 return true;
488 }
489 return false;
490 }
491
497 bool done() const { return !bitSet; }
498
505
509 const OverlayDataType *overlayData() const { return overlaysData.getPtr()[nOlay].m_data; }
510
514 OverlayDataType *overlayData() { return overlaysData[nOlay].m_data; }
515 };
522 {
524 }
525
530
536 bool isOverlayInvalid(OdGsOverlayId id) const { return GETBIT(m_uInvalidOverlays, 1 << id); }
537
544 void setOverlayInvalid(OdGsOverlayId id, bool bSet = true) { SETBIT(m_uInvalidOverlays, 1 << id, bSet); }
545
552
559 void setOverlaysInvalid(OdUInt32 nOverlays, bool bSet = true) { SETBIT(m_uInvalidOverlays, nOverlays & m_uActiveOverlays, bSet); }
560
568
576};
577
578#include "TD_PackPop.h"
579
580#endif // __GSOVERLAYDEFS_H_INCLUDED_
#define ODA_FAIL()
Definition: DebugStuff.h:88
OdGsOverlayId
Definition: GsOverlayDefs.h:42
@ kGsUserFg1Overlay
Definition: GsOverlayDefs.h:48
@ kGsUserBg3Overlay
Definition: GsOverlayDefs.h:47
@ kGsMainOverlay
Definition: GsOverlayDefs.h:43
@ kGsUserBg1Overlay
Definition: GsOverlayDefs.h:46
@ kGsUserBg2Overlay
Definition: GsOverlayDefs.h:55
@ kGsDirectTopmostOverlay
Definition: GsOverlayDefs.h:51
@ kGsHighlightSelectionOverlay
Definition: GsOverlayDefs.h:50
@ kGsUndefinedOverlay
Definition: GsOverlayDefs.h:59
@ kGsUserFg3Overlay
Definition: GsOverlayDefs.h:45
@ kGsDirectOverlay
Definition: GsOverlayDefs.h:44
@ kGsNoOverlays
Definition: GsOverlayDefs.h:58
@ kGsContrastOverlay
Definition: GsOverlayDefs.h:53
@ kNumGsOverlays
Definition: GsOverlayDefs.h:56
@ kGsHighlightOverlay
Definition: GsOverlayDefs.h:49
@ kGsSpriteOverlay
Definition: GsOverlayDefs.h:52
@ kGsUserFg2Overlay
Definition: GsOverlayDefs.h:54
@ kGsAllOverlays
Definition: GsOverlayDefs.h:57
unsigned int OdUInt32
int OdInt32
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:516
#define SETBIT_0(flags, bit)
Definition: OdaDefs.h:519
#define GETBIT(flags, bit)
Definition: OdaDefs.h:517
#define SETBIT_1(flags, bit)
Definition: OdaDefs.h:520
const T * asArrayPtr() const
Definition: OdArray.h:1590
size_type size() const
Definition: OdArray.h:1247
T & at(size_type arrayIndex)
Definition: OdArray.h:1642
const T * getPtr() const
Definition: OdArray.h:1600
void resize(size_type logicalLength, const T &value)
Definition: OdArray.h:1185
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)
OverlayDataType * getOverlayData(OdGsOverlayId id, bool bActivate=false)
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)
OdUInt32 invalidOverlays() const
void deactivate(OdGsOverlayId id)
Iterator newIterator(OdUInt32 nMask=kGsAllOverlays) const
bool execForEach(ForEach &impl, OdUInt32 nMask=kGsAllOverlays) const
const OverlayDataType * getOverlayData(OdGsOverlayId id, bool bActivate=false) const
bool isOverlayInvalid(OdGsOverlayId id) const
OdUInt32 overlayNumRefs(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:94
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)