CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
TrVisDefs.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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-2024 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// GLES2 device definitions
24
25#ifndef ODTRVISDEVICEDEFINITIONS
26#define ODTRVISDEVICEDEFINITIONS
27
28#include "TD_PackPush.h"
29
30#include "Ge/GePoint3d.h"
31#include "Gs/Gs.h"
32
33#ifndef OD_FORCEINLINE
34#if defined(_MSC_VER) && (_MSC_VER >= 1200)
35#define OD_FORCEINLINE __forceinline
36#elif defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
37#define OD_FORCEINLINE inline __attribute__((always_inline))
38#elif defined(__APPLE__) && !defined(__GNUC__)
39#define OD_FORCEINLINE inline __attribute__((always_inline))
40#else
41#define OD_FORCEINLINE inline
42#endif
43#endif // OD_FORCEINLINE
44
45#if (__cplusplus > 199711L) || (_MSC_VER > 1700)
46#define OD_CPP0X_SUPPORTED
47#if defined(_MSC_VER) && (_MSC_VER < 1900)
48#define OD_CPP0X_PARTIAL_SUPPORT
49#endif
50#endif
51
52#ifndef OD_CONSTEXPR
53#if defined(OD_CPP0X_SUPPORTED) && !defined(OD_CPP0X_PARTIAL_SUPPORT)
54#define OD_CONSTEXPR_FUNC constexpr
55#define OD_CONSTEXPR constexpr
56#else
57#define OD_CONSTEXPR_FUNC OD_FORCEINLINE
58#define OD_CONSTEXPR
59#endif
60#endif // OD_CONSTEXPR
61
62// Uncomment to disable all prefetchers, which influence onto stability of MT-issues reproduction.
63//#define OD_TRVIS_SLOW_DEBUG
64
65// Main type includes.
66#include "TrVisMatrix.h"
67#include "TrVisIval.h"
68
74{
78 bool isSyncFlagSet(OdUInt32 flag) const { return GETBIT(m_syncFlags, flag); }
81 void setSyncAll() { m_syncFlags = 0xFFFFFFFF; }
82 bool isSynchronized() const { return m_syncFlags == 0; }
83};
84
85// GsMarker
86
90namespace{
91static inline bool isValidMarker(OdTrVisGsMarker marker){
92 return marker != kTrVisNullGsMarker;
93}
94}
95
96// Database owning (it is depends from underlying database)
98
99// Internal ID's
100
102
104
107
111
113
115
117
119
121
123
125
127
129
131
132#define OdTrVisPtrToId(ptr) ((OdTrVisId)((OdIntPtr)ptr))
133#define OdTrVisIdToPtr(ptrType, id) ((ptrType*)(OdIntPtr)(id))
134
137{
138 return id != kTrVisNegativeId;
139}
140
143{
144 return id == kTrVisNullId;
145}
146
152
158
159// State branch types
160
169
170typedef const void *OdTrVisStateBranchPtr;
171
172// There are several enumerations where order of data this entries should be compatible, so define following enumeration globally.
184
190{
192 bool operator ==(const OdTrVisColorRGBA &sec) const
193 { return (r == sec.r) && (g == sec.g) && (b == sec.b) && (a == sec.a); }
194 bool operator !=(const OdTrVisColorRGBA &sec) const
195 { return (r != sec.r) || (g != sec.g) || (b != sec.b) || (a != sec.a); }
197 r = _r; g = _g; b = _b; a = _a; return *this; }
198 OdTrVisColorRGBA &set_r(OdUInt8 _r) { r = _r; return *this; }
199 OdTrVisColorRGBA &set_g(OdUInt8 _g) { g = _g; return *this; }
200 OdTrVisColorRGBA &set_b(OdUInt8 _b) { b = _b; return *this; }
201 OdTrVisColorRGBA &set_a(OdUInt8 _a) { a = _a; return *this; }
203 b = ODGETBLUE(color); a = ODGETALPHA(color); return *this; }
204 void setFlt(float _r, float _g, float _b, float _a) { r = (OdUInt8)(_r * 255); g = (OdUInt8)(_g * 255);
205 b = (OdUInt8)(_b * 255); a = (OdUInt8)(_a * 255); }
206 void asFlt(float &_r, float &_g, float &_b, float &_a) const { _r = float(r) / 255; _g = float(g) / 255; _b = float(b) / 255; _a = float(a) / 255; }
207 ODCOLORREF asCRef() const { return ODRGBA(r, g, b, a); }
208 const OdUInt8 *asArray() const { return &r; }
209 // Color representations
211 void setRep(const OdTrVisColorRGBA &clr, ColorRep rep, OdUInt8 alpha = 255)
212 { switch (rep) {
213 case kRGBA: *this = clr; break; case kBGRA: r = clr.b; g = clr.g; b = clr.r; a = clr.a; break;
214 case kARGB: r = clr.g; g = clr.b; b = clr.a; a = clr.r; break; case kABGR: r = clr.a; g = clr.b; b = clr.g; a = clr.r; break;
215 case kRGBX: r = clr.r; g = clr.g; b = clr.b; a = alpha; break; case kBGRX: r = clr.b; g = clr.g; b = clr.r; a = alpha; break;
216 case kXRGB: r = clr.g; g = clr.b; b = clr.a; a = alpha; break; case kXBGR: r = clr.a; g = clr.b; b = clr.g; a = alpha; break;
217 } }
218 void getRep(OdTrVisColorRGBA &clr, ColorRep rep, OdUInt8 alpha = 255) const
219 { switch (rep) {
220 case kRGBA: clr = *this; break; case kBGRA: clr.r = b; clr.g = g; clr.b = r; clr.a = a; break;
221 case kARGB: clr.r = a; clr.g = r; clr.b = g; clr.a = b; break; case kABGR: clr.r = a; clr.g = b; clr.b = g; clr.a = r; break;
222 case kRGBX: clr.r = r; clr.g = g; clr.b = b; clr.a = alpha; break; case kBGRX: clr.r = b; clr.g = g; clr.b = r; clr.a = alpha; break;
223 case kXRGB: clr.r = alpha; clr.g = r; clr.b = g; clr.a = b; break; case kXBGR: clr.r = alpha; clr.g = b; clr.b = g; clr.a = r; break;
224 } }
225 OdTrVisColorRGBA getRep(ColorRep rep, OdUInt8 alpha = 255) const { OdTrVisColorRGBA getter; getRep(getter, rep, alpha); return getter; }
226};
227
233{
235 {
236 entry[0][0] = entry[0][1] = entry[0][2] = 0.0f;
237 entry[1][0] = entry[1][1] = 0.0f; entry[1][2] = 1.0f;
238 entry[2][0] = entry[2][1] = entry[2][2] = 0.0f;
239 }
245 {
246 entry[0][0] = (EntryType)position.x; entry[0][1] = (EntryType)position.y; entry[0][2] = (EntryType)position.z;
247 entry[1][0] = (EntryType)normal.x; entry[1][1] = (EntryType)normal.y; entry[1][2] = (EntryType)normal.z;
248 }
249 OdGePoint3d position() const { return OdGePoint3d(entry[0][0], entry[0][1], entry[0][2]); }
250 OdGeVector3d normal() const { return OdGeVector3d(entry[1][0], entry[1][1], entry[1][2]); }
251 void transformBy(const OdGeMatrix3d &xfm) { set(xfm * position(), xfm * normal()); }
253 OdGePoint3d pos = xfm * position(); OdGeVector3d norm = xfm * normal();
254 double dist = norm.dotProduct(pos.asVector());
255 pos = OdGePoint3d::kOrigin + norm * dist;
256 set(pos, norm);
257 }
258
259 template<typename ValType> bool isPtOnPlane(ValType x, ValType y, ValType z, float tol = 1.e-8f) const
260 { return Od_abs((x - entry[0][0]) * entry[1][0] + (y - entry[0][1]) * entry[1][1] + (z - entry[0][2]) * entry[1][2]) < tol; }
261 template<typename VecType> bool isPtOnPlane(const VecType &pt, float tol = 1.e-8f) const
262 { return isPtOnPlane(pt.x, pt.y, pt.z, tol); }
263
264 bool operator ==(const OdTrVisSectionPlane &sp) const;
265 bool operator !=(const OdTrVisSectionPlane &sp) const;
266};
267
269
270#define OD_TRVIS_OPAQUE(color) ((color) | 0xFF000000)
271#define OD_TRVIS_TRANSPARENT(color) ((color) & 0x00FFFFFF)
272#define OD_TRVIS_SETALPHA(color, alpha) (OD_TRVIS_TRANSPARENT(color) | (ODCOLORREF(alpha) << 24))
273
274// FP comparison functions
275
276OD_FORCEINLINE bool OdTrVisFPEqual(float a, float b, float tol = 1.e-8f)
277{ const float diff = a - b;
278 return (diff < tol) && (diff > -tol);
279}
280OD_FORCEINLINE bool OdTrVisFPZero(float a, float tol = 1.e-8f)
281{ return !(a > tol) && !(a < -tol); }
282OD_FORCEINLINE bool OdTrVisFPLess(float a, float b, float tol = 1.e-8f)
283{ return a < b - tol; }
284OD_FORCEINLINE bool OdTrVisFPGreater(float a, float b, float tol = 1.e-8f)
285{ return a > b + tol; }
286
288{
289 return OdTrVisFPEqual(entry[1][0], sp.entry[1][0]) && OdTrVisFPEqual(entry[1][1], sp.entry[1][1]) &&
290 OdTrVisFPEqual(entry[1][2], sp.entry[1][2]) && isPtOnPlane(sp.entry[0][0], sp.entry[0][1], sp.entry[0][2]);
291}
293{
294 return !OdTrVisFPEqual(entry[1][0], sp.entry[1][0]) || !OdTrVisFPEqual(entry[1][1], sp.entry[1][1]) ||
295 !OdTrVisFPEqual(entry[1][2], sp.entry[1][2]) || !isPtOnPlane(sp.entry[0][0], sp.entry[0][1], sp.entry[0][2]);
296}
297
299
300// Clamping
301
302template <typename Type>
303OD_FORCEINLINE Type &OdTrVisClamp(Type &val, Type valMin, Type valMax)
304{ if (val < valMin) val = valMin; else if (val > valMax) val = valMax;
305 return val; }
306template <typename Type>
307OD_FORCEINLINE Type OdTrVisClamp(const Type &val, Type valMin, Type valMax)
308{ if (val < valMin) return valMin; else if (val > valMax) return valMax;
309 return val; }
310
311// Helper temporary increment/decrement operators
312template <typename Type>
316template <typename Type>
320
321// OdSaveState for multiple elements
322template <typename DataType, long numEntries>
324{
325 protected:
326 DataType *m_pValue;
327 const size_t m_stride;
328 DataType m_oldValues[numEntries];
329 protected:
330 inline DataType *flip(DataType *pValue, long n, size_t stride) const
331 { return (DataType*)(((OdUInt8*)pValue) + stride * n); }
332 inline DataType *flip(DataType *pValue, long n) const
333 { return flip(pValue, n, m_stride); }
334 public:
335 OdTrVisMultiStateSaver(DataType *pValue, size_t stride = sizeof(DataType))
336 : m_pValue(pValue), m_stride(stride)
337 { for (long nEntry = 0; nEntry < numEntries; nEntry++)
338 m_oldValues[nEntry] = *flip(pValue, nEntry);
339 }
340 // Initialize all values by similar value
341 OdTrVisMultiStateSaver(DataType *pValue, const DataType &initValue, size_t stride = sizeof(DataType))
342 : m_pValue(pValue), m_stride(stride)
343 { for (long nEntry = 0; nEntry < numEntries; nEntry++)
344 { DataType &pLVal = *flip(pValue, nEntry);
345 m_oldValues[nEntry] = pLVal;
346 pLVal = initValue;
347 }
348 }
349 // Initialize all values by multiple values
350 OdTrVisMultiStateSaver(DataType *pValue, const DataType *pInitValue, size_t stride = sizeof(DataType), size_t stride2 = sizeof(DataType))
351 : m_pValue(pValue), m_stride(stride)
352 { for (long nEntry = 0; nEntry < numEntries; nEntry++)
353 { DataType &pLVal = *flip(pValue, nEntry);
354 m_oldValues[nEntry] = pLVal;
355 pLVal = *flip(const_cast<DataType*>(pInitValue), nEntry, stride2);
356 }
357 }
359 { for (long nEntry = 0; nEntry < numEntries; nEntry++)
360 *flip(m_pValue, nEntry) = m_oldValues[nEntry];
361 }
362};
363
369{
370 OdRxOverruleIterator* getOverrule(OverrulingType t) const { return 0; }
371 void setOverrule(OdRxOverruleIterator* pIt, OverrulingType t) {}
372};
373
374#include "TD_PackPop.h"
375
376#endif // ODTRVISDEVICEDEFINITIONS
tol
const OdGsMarker kNullSubentIndex
Definition Gs.h:1655
OdArray< float, OdMemoryAllocator< float > > OdFloatArray
Definition GsFiler.h:58
#define ODGETBLUE(rgb)
#define Od_abs
#define ODCOLORREF
#define ODGETGREEN(rgb)
#define ODRGBA(r, g, b, a)
#define ODGETALPHA(rgba)
#define ODGETRED(rgb)
unsigned int OdUInt32
unsigned char OdUInt8
#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
OverrulingType
Definition RxObject.h:819
const OdTrVisId kTrVisMainOverlayId
Definition TrVisDefs.h:147
const OdTrVisId kTrVisNegativeId
Definition TrVisDefs.h:135
const OdTrVisArrayId kTrVisNegativeArrayId
Definition TrVisDefs.h:153
OdUInt64 OdTrVisGsMarker
Definition TrVisDefs.h:87
const OdTrVisId kTrVisNullId
Definition TrVisDefs.h:141
OdArray< OdTrVisSectionPlane, OdMemoryAllocator< OdTrVisSectionPlane > > OdTrVisSectionPlaneArray
Definition TrVisDefs.h:268
OdTrVisId OdTrVisVisualStyleId
Definition TrVisDefs.h:120
OdTrVisId OdTrVisGroupId
Definition TrVisDefs.h:126
const void * OdTrVisStateBranchPtr
Definition TrVisDefs.h:170
OD_FORCEINLINE bool OdTrVisFPZero(float a, float tol=1.e-8f)
Definition TrVisDefs.h:280
OD_FORCEINLINE Type & OdTrVisClamp(Type &val, Type valMin, Type valMax)
Definition TrVisDefs.h:303
OdTrVisId OdTrVisOverlayId
Definition TrVisDefs.h:124
OdTrVisId OdTrVisRefPlaneId
Definition TrVisDefs.h:110
OdTrVisTextureType
Definition TrVisDefs.h:180
OdTrVisId OdTrVisViewportId
Definition TrVisDefs.h:103
OD_FORCEINLINE bool OdTrVisFPEqual(float a, float b, float tol=1.e-8f)
Definition TrVisDefs.h:276
OD_FORCEINLINE bool OdTrVisFPLess(float a, float b, float tol=1.e-8f)
Definition TrVisDefs.h:282
OD_FORCEINLINE bool isNullTrVisId(OdTrVisId id)
Definition TrVisDefs.h:142
OdTrVisId OdTrVisProgramId
Definition TrVisDefs.h:112
OdTrVisId OdTrVisMaterialId
Definition TrVisDefs.h:109
OdTrVisStateBranchType
Definition TrVisDefs.h:162
@ kTrVisNumStateBranchTypes
Definition TrVisDefs.h:167
@ kTrVisTransformBranch
Definition TrVisDefs.h:165
@ kTrVisVisibilityBranch
Definition TrVisDefs.h:164
@ kTrVisHighlightingBranch
Definition TrVisDefs.h:163
OdTrVisId OdTrVisExtensionId
Definition TrVisDefs.h:128
OdArray< OdTrVisGsMarker, OdMemoryAllocator< OdTrVisGsMarker > > OdTrVisGsMarkerArray
Definition TrVisDefs.h:88
OdUInt32 OdTrVisArrayId
Definition TrVisDefs.h:106
OdTrVisId OdTrVisLayerId
Definition TrVisDefs.h:122
const OdTrVisGsMarker kTrVisNullGsMarker
Definition TrVisDefs.h:89
OdTrVisId OdTrVisStateBranchId
Definition TrVisDefs.h:118
OD_FORCEINLINE bool isMainTrVisOverlayId(OdTrVisId id)
Definition TrVisDefs.h:148
OdTrVisNormalType
Definition TrVisDefs.h:174
OdTrVisId OdTrVisDisplayId
Definition TrVisDefs.h:114
OdTrVisId OdTrVisTextureId
Definition TrVisDefs.h:108
OdTrVisId OdTrVisBlockId
Definition TrVisDefs.h:130
OD_FORCEINLINE bool isValidTrVisId(OdTrVisId id)
Definition TrVisDefs.h:136
OD_FORCEINLINE bool OdTrVisFPGreater(float a, float b, float tol=1.e-8f)
Definition TrVisDefs.h:284
OdTrVisId OdTrVisLightId
Definition TrVisDefs.h:116
#define OD_FORCEINLINE
Definition TrVisDefs.h:41
OdTrVisId OdTrVisMetafileId
Definition TrVisDefs.h:105
OD_FORCEINLINE bool isValidTrVisArrayId(OdTrVisArrayId id)
Definition TrVisDefs.h:154
OdUInt64 OdTrVisOwning
Definition TrVisDefs.h:97
OdUInt64 OdTrVisId
Definition TrVisDefs.h:101
OdTrVisMatrix3x3f OdTrVisSubMat
const OdGeVector3d & asVector() const
Definition GePoint3d.h:570
static GE_STATIC_EXPORT const OdGePoint3d kOrigin
Definition GePoint3d.h:106
double dotProduct(const OdGeVector3d &vect) const
Definition GeVector3d.h:586
OdRxClass(OdRxClassImpl *)
const size_t m_stride
Definition TrVisDefs.h:327
OdTrVisMultiStateSaver(DataType *pValue, const DataType &initValue, size_t stride=sizeof(DataType))
Definition TrVisDefs.h:341
DataType * flip(DataType *pValue, long n, size_t stride) const
Definition TrVisDefs.h:330
OdTrVisMultiStateSaver(DataType *pValue, const DataType *pInitValue, size_t stride=sizeof(DataType), size_t stride2=sizeof(DataType))
Definition TrVisDefs.h:350
OdTrVisMultiStateSaver(DataType *pValue, size_t stride=sizeof(DataType))
Definition TrVisDefs.h:335
DataType m_oldValues[numEntries]
Definition TrVisDefs.h:328
DataType * flip(DataType *pValue, long n) const
Definition TrVisDefs.h:332
GLfloat GLfloat GLfloat alpha
Definition gles2_ext.h:147
GLfloat GLfloat GLfloat z
Definition gles2_ext.h:318
GLfloat x
Definition gles2_ext.h:314
GLint GLenum GLboolean GLsizei stride
Definition gles2_ext.h:322
GLfloat GLfloat y
Definition gles2_ext.h:316
void getRep(OdTrVisColorRGBA &clr, ColorRep rep, OdUInt8 alpha=255) const
Definition TrVisDefs.h:218
bool operator!=(const OdTrVisColorRGBA &sec) const
Definition TrVisDefs.h:194
OdTrVisColorRGBA & set(OdUInt8 _r, OdUInt8 _g, OdUInt8 _b, OdUInt8 _a)
Definition TrVisDefs.h:196
const OdUInt8 * asArray() const
Definition TrVisDefs.h:208
void setFlt(float _r, float _g, float _b, float _a)
Definition TrVisDefs.h:204
ODCOLORREF asCRef() const
Definition TrVisDefs.h:207
OdTrVisColorRGBA & set_r(OdUInt8 _r)
Definition TrVisDefs.h:198
OdTrVisColorRGBA & set_a(OdUInt8 _a)
Definition TrVisDefs.h:201
OdTrVisColorRGBA & setCRef(ODCOLORREF color)
Definition TrVisDefs.h:202
OdTrVisColorRGBA & set_b(OdUInt8 _b)
Definition TrVisDefs.h:200
bool operator==(const OdTrVisColorRGBA &sec) const
Definition TrVisDefs.h:192
OdTrVisColorRGBA getRep(ColorRep rep, OdUInt8 alpha=255) const
Definition TrVisDefs.h:225
OdTrVisColorRGBA & set_g(OdUInt8 _g)
Definition TrVisDefs.h:199
void setRep(const OdTrVisColorRGBA &clr, ColorRep rep, OdUInt8 alpha=255)
Definition TrVisDefs.h:211
void asFlt(float &_r, float &_g, float &_b, float &_a) const
Definition TrVisDefs.h:206
OdGeVector3d normal() const
Definition TrVisDefs.h:250
bool operator==(const OdTrVisSectionPlane &sp) const
Definition TrVisDefs.h:287
OdGePoint3d position() const
Definition TrVisDefs.h:249
bool isPtOnPlane(const VecType &pt, float tol=1.e-8f) const
Definition TrVisDefs.h:261
OdTrVisSectionPlane(const OdGePoint3d &position, const OdGeVector3d &normal)
Definition TrVisDefs.h:240
bool operator!=(const OdTrVisSectionPlane &sp) const
Definition TrVisDefs.h:292
void set(const OdGePoint3d &position, const OdGeVector3d &normal)
Definition TrVisDefs.h:244
void transformBy(const OdGeMatrix3d &xfm)
Definition TrVisDefs.h:251
bool isPtOnPlane(ValType x, ValType y, ValType z, float tol=1.e-8f) const
Definition TrVisDefs.h:259
void smartTransformBy(const OdGeMatrix3d &xfm)
Definition TrVisDefs.h:252
void resetSyncFlags()
Definition TrVisDefs.h:80
OdUInt32 m_syncFlags
Definition TrVisDefs.h:75
bool isSynchronized() const
Definition TrVisDefs.h:82
void setSyncAll()
Definition TrVisDefs.h:81
void resetSyncFlag(OdUInt32 flag)
Definition TrVisDefs.h:79
void setSyncFlag(OdUInt32 flag)
Definition TrVisDefs.h:77
bool isSyncFlagSet(OdUInt32 flag) const
Definition TrVisDefs.h:78
OdTrVisTemporalDescreasor(Type &val)
Definition TrVisDefs.h:318
OdTrVisTemporalIncreasor(Type &val)
Definition TrVisDefs.h:314