CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GiTraitsCache.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 _ODGITRAITSCACHE_INCLUDED_
25#define _ODGITRAITSCACHE_INCLUDED_
26
27#include "GiCommonDraw.h"
28
29#define STL_USING_MAP
30#include "OdaSTL.h"
31
32class OdDbStub;
33
34#include "TD_PackPush.h"
35
43template <class traitsContainer, class traitsTaker, OdUInt32 byMask = 0>
44class OdGiTraitsCache : public traitsTaker
45{
46 public:
51 {
57 kCacheAll = 2
58 };
59 protected:
61 {
62 traitsContainer m_data;
64 void set(const traitsContainer& data, OdUInt32 flags) { m_data = data; m_flags = flags; }
65 };
66
67 protected:
69 typedef std::map<OdDbStub*, CacheEntry> _mmap;
72 public:
78 : traitsTaker()
81 {
82 }
88 : traitsTaker()
91 {
92 }
97 {
98 }
99
106 {
108 }
109
114 {
115 return m_cacheType;
116 }
117
124 void setAttributes(OdDbStub* objId, OdGiContext &giCtx, bool forceCaching = false)
125 {
126 if (m_cacheType != kCacheNone && m_cacheData.size() > 0)
127 {
128 // Note: iterator won't compile in this context on all platforms.
129 typename _mmap::iterator it = m_cacheData.find(objId);
130 if(it != m_cacheData.end())
131 {
132 m_traitsAttrib = it->second.m_flags;
133 if(!(m_traitsAttrib & byMask))
134 traitsTaker::setData(it->second.m_data);
135 return;
136 }
137 }
138 OdGiDrawablePtr drawable = giCtx.openDrawable(objId);
139 if (!drawable.isNull())
140 {
141 m_traitsAttrib = drawable->setAttributes(this);
142 if (m_cacheType != kCacheNone)
143 {
144 if (m_cacheType == kCacheAll || forceCaching || ((m_traitsAttrib & byMask) != 0))
145 {
146 m_cacheData[objId].set(this->getData(), m_traitsAttrib);
147 }
148 }
149 }
150 }
151
156 void setFlags(OdUInt32 uAttrib)
157 {
158 m_traitsAttrib = uAttrib;
159 }
160
165 {
166 return m_traitsAttrib;
167 }
168
172 void clear()
173 {
174 m_cacheData.clear();
175 }
176};
177
178// traitsContainer - must have operator =.
179// traitsTaker - must have setData(traitsContainer), getData() methods.
180
181#include "TD_PackPop.h"
182
183#endif // #ifndef _ODGITRAITSCACHE_INCLUDED_
unsigned int OdUInt32
bool isNull() const
Definition: BaseObjectPtr.h:86
virtual OdGiDrawablePtr openDrawable(OdDbStub *drawableId)=0
ODRX_SEALED_VIRTUAL OdUInt32 setAttributes(OdGiDrawableTraits *pTraits) const ODRX_SEALED
OdUInt32 m_traitsAttrib
Definition: GiTraitsCache.h:71
OdGiTraitsCache(CacheType cacheType)
Definition: GiTraitsCache.h:87
CacheType m_cacheType
Definition: GiTraitsCache.h:68
std::map< OdDbStub *, CacheEntry > _mmap
Definition: GiTraitsCache.h:69
void setFlags(OdUInt32 uAttrib)
CacheType cacheType() const
void setCacheType(CacheType cacheType)
void setAttributes(OdDbStub *objId, OdGiContext &giCtx, bool forceCaching=false)
OdUInt32 getFlags() const
GLint GLenum GLsizei GLsizei GLint GLsizei const void * data
Definition: gles2_ext.h:110
Definition: GiTraitsCache.h:61
OdUInt32 m_flags
Definition: GiTraitsCache.h:63
traitsContainer m_data
Definition: GiTraitsCache.h:62
void set(const traitsContainer &data, OdUInt32 flags)
Definition: GiTraitsCache.h:64