CFx SDK Documentation
2020SP3
SDK
CFx
dd_inc
Gi
GiTraitsCache.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 _ODGITRAITSCACHE_INCLUDED_
25
#define _ODGITRAITSCACHE_INCLUDED_
26
27
#include "
GiCommonDraw.h
"
28
29
#define STL_USING_MAP
30
#include "
OdaSTL.h
"
31
32
class
OdDbStub;
33
34
#include "
TD_PackPush.h
"
35
43
template
<
class
traitsContainer,
class
traitsTaker, OdUInt32 byMask = 0>
44
class
OdGiTraitsCache
:
public
traitsTaker
45
{
46
public
:
47
enum
CacheType
48
{
49
kCacheNone
= 0,
50
kCacheByMask
= 1,
51
kCacheAll
= 2
52
};
53
protected
:
54
struct
CacheEntry
55
{
56
traitsContainer
m_data
;
57
OdUInt32
m_flags
;
58
void
set
(
const
traitsContainer&
data
,
OdUInt32
flags) {
m_data
=
data
;
m_flags
= flags; }
59
};
60
61
protected
:
62
CacheType
m_cacheType
;
63
typedef
std::map<OdDbStub*, CacheEntry>
_mmap
;
64
_mmap
m_cacheData
;
65
OdUInt32
m_traitsAttrib
;
66
public
:
67
OdGiTraitsCache
()
68
: traitsTaker()
69
,
m_cacheType
(
kCacheNone
)
70
,
m_traitsAttrib
(0)
71
{
72
}
73
explicit
OdGiTraitsCache
(
CacheType
cacheType
)
74
: traitsTaker()
75
,
m_cacheType
(
cacheType
)
76
,
m_traitsAttrib
(0)
77
{
78
}
79
~OdGiTraitsCache
()
80
{
81
}
82
83
void
setCacheType
(
CacheType
cacheType
)
84
{
85
m_cacheType
=
cacheType
;
86
}
87
CacheType
cacheType
()
const
88
{
89
return
m_cacheType
;
90
}
91
92
void
setAttributes
(OdDbStub* objId,
OdGiContext
&giCtx,
bool
forceCaching =
false
)
93
{
94
if
(
m_cacheType
!=
kCacheNone
&&
m_cacheData
.size() > 0)
95
{
96
// Note: iterator won't compile in this context on all platforms.
97
typename
_mmap::iterator it =
m_cacheData
.find(objId);
98
if
(it !=
m_cacheData
.end())
99
{
100
m_traitsAttrib
= it->second.m_flags;
101
if
(!(
m_traitsAttrib
& byMask))
102
traitsTaker::setData(it->second.m_data);
103
return
;
104
}
105
}
106
OdGiDrawablePtr
drawable = giCtx.
openDrawable
(objId);
107
if
(!drawable.isNull())
108
{
109
m_traitsAttrib
= drawable->
setAttributes
(
this
);
110
if
(
m_cacheType
!=
kCacheNone
)
111
{
112
if
(
m_cacheType
==
kCacheAll
|| forceCaching || ((
m_traitsAttrib
& byMask) != 0))
113
{
114
m_cacheData
[objId].set(this->getData(),
m_traitsAttrib
);
115
}
116
}
117
}
118
}
119
120
void
setFlags
(
OdUInt32
uAttrib)
121
{
122
m_traitsAttrib
= uAttrib;
123
}
124
OdUInt32
getFlags
()
const
125
{
126
return
m_traitsAttrib
;
127
}
128
129
void
clear
()
130
{
131
m_cacheData
.clear();
132
}
133
};
134
135
// traitsContainer - must have operator =.
136
// traitsTaker - must have setData(traitsContainer), getData() methods.
137
138
#include "
TD_PackPop.h
"
139
140
#endif // #ifndef _ODGITRAITSCACHE_INCLUDED_
OdGiTraitsCache< OdGiMaterialTraitsData, OdGiMaterialTraitsTaker, OdGiMaterialTraits::kByBlock|OdGiMaterialTraits::kByLayer >::CacheType
CacheType
Definition:
GiTraitsCache.h:48
OdGiContext
Definition:
GiCommonDraw.h:108
OdGiTraitsCache::m_cacheData
_mmap m_cacheData
Definition:
GiTraitsCache.h:64
OdGiTraitsCache::kCacheNone
@ kCacheNone
Definition:
GiTraitsCache.h:49
OdGiTraitsCache::OdGiTraitsCache
OdGiTraitsCache()
Definition:
GiTraitsCache.h:67
OdGiTraitsCache::_mmap
std::map< OdDbStub *, CacheEntry > _mmap
Definition:
GiTraitsCache.h:63
OdGiTraitsCache::OdGiTraitsCache
OdGiTraitsCache(CacheType cacheType)
Definition:
GiTraitsCache.h:73
OdaSTL.h
TD_PackPop.h
OdGiTraitsCache::setAttributes
void setAttributes(OdDbStub *objId, OdGiContext &giCtx, bool forceCaching=false)
Definition:
GiTraitsCache.h:92
OdUInt32
unsigned int OdUInt32
Definition:
OdPlatformSettings.h:783
data
GLint GLenum GLsizei GLsizei GLint GLsizei const void * data
Definition:
gles2_ext.h:110
OdGiTraitsCache::kCacheAll
@ kCacheAll
Definition:
GiTraitsCache.h:51
OdGiContext::openDrawable
virtual OdGiDrawablePtr openDrawable(OdDbStub *drawableId)=0
OdGiTraitsCache::cacheType
CacheType cacheType() const
Definition:
GiTraitsCache.h:87
OdSmartPtr< OdGiDrawable >
OdGiTraitsCache::setFlags
void setFlags(OdUInt32 uAttrib)
Definition:
GiTraitsCache.h:120
OdGiTraitsCache::m_traitsAttrib
OdUInt32 m_traitsAttrib
Definition:
GiTraitsCache.h:65
OdGiTraitsCache::CacheEntry
Definition:
GiTraitsCache.h:55
OdGiTraitsCache::CacheEntry::m_flags
OdUInt32 m_flags
Definition:
GiTraitsCache.h:57
GiCommonDraw.h
TD_PackPush.h
OdGiTraitsCache::clear
void clear()
Definition:
GiTraitsCache.h:129
OdGiDrawable::setAttributes
ODRX_SEALED_VIRTUAL OdUInt32 setAttributes(OdGiDrawableTraits *pTraits) const ODRX_SEALED
OdGiTraitsCache::setCacheType
void setCacheType(CacheType cacheType)
Definition:
GiTraitsCache.h:83
OdGiTraitsCache::CacheEntry::set
void set(const traitsContainer &data, OdUInt32 flags)
Definition:
GiTraitsCache.h:58
OdGiTraitsCache::CacheEntry::m_data
traitsContainer m_data
Definition:
GiTraitsCache.h:56
OdGiTraitsCache::~OdGiTraitsCache
~OdGiTraitsCache()
Definition:
GiTraitsCache.h:79
OdGiTraitsCache::getFlags
OdUInt32 getFlags() const
Definition:
GiTraitsCache.h:124
OdGiTraitsCache::m_cacheType
CacheType m_cacheType
Definition:
GiTraitsCache.h:62
OdGiTraitsCache::kCacheByMask
@ kCacheByMask
Definition:
GiTraitsCache.h:50
OdGiTraitsCache
Definition:
GiTraitsCache.h:45
Generated on Mon Oct 12 2020 11:49:34