CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GsBaseMaterialView.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 __OD_GS_BASE_MATERIAL_VIEW__
25#define __OD_GS_BASE_MATERIAL_VIEW__
26
27#include "Gs/GsBaseInclude.h"
28#include "Gs/GsExtAccum.h"
29#include "Gi/GiMapperItem.h"
30#include "Gi/GiMaterialItem.h"
32
33#include "TD_PackPush.h"
34
36
40{
48 virtual bool saveClientMaterialTextureData(const OdGiMaterialTextureData * /*pTextureData*/, OdGsFiler * /*pFiler*/)
49 {
50 return false;
51 }
52
58 {
60 }
61};
62
71{
77 bool has() const { return !m_accumulatedLightsData.isEmpty(); }
78 void append(bool bMtSync, OdGiLightTraitsData *pLightData);
79 void append(bool bMtSync, OdGsLightsAccumulationContainter &lightsAccum);
80 void clear();
81};
82
95{
96 public:
98 {
99 kProcessMappers = 1, // Process material mappers
100 kProcessMaterials = (1 << 1), // Process materials
101
102 kProcessMappersAndMaterials = 3, // Process both material mappers and materials
103
104 kMappersForRender = (1 << 2), // OdGiMapperRenderItem instead of OdGiMapperItem
105 kMaterialsForRender = (1 << 3), // OdGiMaterialRenderItem instead of OdGiMaterialItem
106
107 kMappersAndMaterialsForRender = 12, // kMappersForRender | kMaterialsForRender
108
109 kProcessForRender = 15, // kProcessMappersAndMaterials | kMappersAndMaterialsForRender
110
111 // #5127 fix. Delay cache implementation.
112 kEnableDelayCache = (1 << 4) // Enable cache, which drop extents data after drawable extents computation
113 };
114
115 // Cache structures
120 {
121 kInternal = 0, // Internal.
122 kUser // User-defined.
123 };
128 {
132 DelayCacheEntry() : m_pNext(NULL) { }
133
137 virtual ~DelayCacheEntry() { }
138
143
149 virtual DelayCacheEntryType internalType() const { return kUser; }
150
154 DelayCacheEntry *nextEntry() { return m_pNext; }
155
160 void setNextEntry(DelayCacheEntry *pNext) { m_pNext = pNext; }
161
162 virtual void play(OdGsBaseMaterialVectorizer &mView) const
163 {
164 mView.playDelayCacheEntry(this);
165 }
166 };
167 friend class OdDefDelayCacheEntryMap;
168 friend class OdManageMViewPerDrawableData;
169 private:
170 enum MaterialViewRuntimeFlags
171 {
172 kMaterialCommited = (1 << 0), // Material already emitted by GsModel
173 kAccumNonCacheLights = (1 << 1), // Accumulate lights which is not relate to GsModel
174 kAccumCacheLights = (1 << 2), // Accumulate GsModel-resident lights
175 kAccumLights = kAccumNonCacheLights | kAccumCacheLights
176 };
177 struct ExtentsContainer
178 {
179 const OdGiDrawable *m_pCurrentDrawable;
180 OdGeExtents3d m_Extents;
181 enum Flags
182 {
183 kExtentsValid = (1 << 0),
184 kExtentsAwaitingCalc = (1 << 1),
185 kLastFlag = kExtentsAwaitingCalc
186 };
187 ExtentsContainer() : m_pCurrentDrawable(NULL) {}
188 void clear() { m_pCurrentDrawable = NULL; }
189 };
190 struct DelayCache
191 {
192 const OdGiMapper *m_pCurMapper, *m_pCopyMapper;
193 const OdDbStub *m_pCurMaterial, *m_pCopyMaterial;
194 DelayCacheEntry m_Cache;
195 DelayCacheEntry *m_pTail;
196
197 DelayCache() : m_pCurMapper(NULL), m_pCopyMapper(NULL)
198 , m_pCurMaterial(NULL), m_pCopyMaterial(NULL)
199 , m_pTail(&m_Cache)
200 {
201 }
202
203 void clear();
204 };
205 struct MViewPerDrawableData : public ExtentsContainer
206 {
207 DelayCache m_DelayCache;
208 OdGeMatrix3d m_ModelTransform;
209 OdUInt32 m_flags;
210 enum Flags
211 {
212 kMapperNeedExtents = (ExtentsContainer::kLastFlag << 1), // Mapper awaiting current drawable extents
213 kBaseLevel = (ExtentsContainer::kLastFlag << 2),
214 kHasModelTransform = (ExtentsContainer::kLastFlag << 3),
215 kIsEntity = (ExtentsContainer::kLastFlag << 4)
216 };
217 MViewPerDrawableData()
218 : m_flags(0)
219 {
220 }
221 ~MViewPerDrawableData()
222 {
223 }
224 void clear()
225 {
226 ExtentsContainer::clear();
227 SETBIT_0(m_flags, ~kBaseLevel);
228 }
229 } *m_pCurMvDrawableData, m_mvBaseDrawableData, m_mvGlobalDrawableDataInitializer;
230 protected:
231 OdUInt32 m_uMaterialViewFlags; // Set of material view flags
238 public:
243 explicit OdGsBaseMaterialVectorizer(OdUInt32 uMaterialViewFlags = kProcessMappersAndMaterials);
244
249
250 // OdGsBaseVectorizerView overrides
251
255 virtual void onTraitsModified();
256
261 virtual void beginMetafile(OdRxObject* pMetafile);
262
267 virtual void endMetafile(OdRxObject* pMetafile);
268
273
277 virtual void endViewVectorization();
278
284 virtual void processMaterialNode(OdDbStub *materialId, OdGsMaterialNode *node);
285
293 virtual bool saveMaterialCache(const OdGsMaterialNode *pNode, OdGsFiler *pFiler);
294
302 virtual bool loadMaterialCache(OdGsMaterialNode *pNode, OdGsFiler *pFiler);
303
311 virtual bool doDraw(OdUInt32 drawableFlags, const OdGiDrawable *pDrawable);
312
313 // Lights-related functionality
314
315 void beginLightsAccumulation(bool bAccumNonCached = true, bool bAccumCached = false, bool bClear = false);
316 void playAccumulatedLights(OdGsLightsAccumulationContainter *pAccumLights = NULL, bool bClear = true);
317 const OdGsLightsAccumulationContainter &getAccumulatedLights() const { return m_lightsAccum; }
320 { return (GETBIT(m_uMaterialViewRtFlags, kAccumNonCacheLights) && !GETBIT(m_flags, kModelCache)) ||
321 (GETBIT(m_uMaterialViewRtFlags, kAccumCacheLights) && GETBIT(m_flags, kModelCache)); }
322
327
332
337
342
343 // OdGsBaseMaterialView methods
344
359 bool isMaterialEnabled() const;
374 OdGiMapperItemPtr currentMapper(bool bForCoords = true) const;
385 bool isMapperEnabled() const;
391 bool isMapperAvailable() const;
392
398 bool isMappingDelayed() const;
399
400 // Output callbacks
401
408 virtual bool getDeviceMapperMatrix(OdGeMatrix3d &dm) const;
416 virtual bool skipMaterialProcess(OdDbStub *materialId) const;
420 virtual void nullMaterialStub();
429 virtual OdGiMaterialItemPtr fillMaterialCache(OdGiMaterialItemPtr prevCache, OdDbStub *materialId, const OdGiMaterialTraitsData &materialData);
437 virtual void renderMaterialCache(OdGiMaterialItemPtr pCache, OdDbStub *materialId);
438
443 virtual void playDelayCacheEntry(const DelayCacheEntry *pEntry);
462 virtual void delayCacheProcessed(const OdGiDrawable *pDrawable);
463
471 bool saveMaterialItem(const OdGiMaterialItem *pMatItem, OdGsFiler *pFiler);
472
478
486 static bool saveMaterialTexture(const OdGiMaterialTexture *pTexture, OdGsFiler *pFiler);
487
493
503
513
521 virtual bool saveClientMaterialCache(const OdRxObject* pMtl, OdGsFiler *pFiler);
522
531 protected:
540 virtual bool computeDrawableExtents(const OdGiDrawable *pDrawable, OdGeExtents3d &extents);
549 virtual bool computeDelayedExtents(const OdGiDrawable *pDrawable, OdGeExtents3d &extents);
550 private:
551 void updateMViewModelTransform();
552 void computeDrawableExtents();
553 bool tryGsModelExtents(OdGeExtents3d &extents) const;
554 protected:
557};
558
567{
568 protected:
569 void resetConstructorFlags(OdUInt32 uMaterialViewFlags);
570 public:
575};
576
585{
586 public:
587 explicit OdGsBaseMaterialView(OdUInt32 uMaterialViewFlags = kProcessMappersAndMaterials)
588 {
589 resetConstructorFlags(uMaterialViewFlags);
590 }
591};
592
601{
602 public:
606 explicit OdGsBaseMaterialViewMT(OdUInt32 uMaterialViewFlags = kProcessMappersAndMaterials)
607 {
608 resetConstructorFlags(uMaterialViewFlags);
609 }
610
616 bool isMTView() const
617 {
618 return (&view() != this);
619 }
620};
621
622#include "TD_PackPop.h"
623
624#endif // __OD_GS_BASE_MATERIAL_VIEW__
OdSmartPtr< OdGiMaterialTextureData > OdGiMaterialTextureDataPtr
#define GS_TOOLKIT_EXPORT
Definition: GsExport.h:37
unsigned int OdUInt32
#define SETBIT_0(flags, bit)
Definition: OdaDefs.h:519
#define GETBIT(flags, bit)
Definition: OdaDefs.h:517
virtual void playDelayCacheEntry(const DelayCacheEntry *pEntry)
void resetCurrentMaterial(OdGiMaterialItemPtr pMaterial)
virtual void beginViewVectorization()
bool saveMaterialItem(const OdGiMaterialItem *pMatItem, OdGsFiler *pFiler)
virtual void onTraitsModified()
virtual bool getDeviceMapperMatrix(OdGeMatrix3d &dm) const
virtual void beginMetafile(OdRxObject *pMetafile)
virtual void delayCacheProcessed(const OdGiDrawable *pDrawable)
OdGiMaterialItemPtr m_pNullMaterialItem
OdGiMaterialTraitsData m_nullMaterialTraitsData
virtual void addDistantLight(const OdGiDistantLightTraitsData &)
OdGsBaseMaterialVectorizer(OdUInt32 uMaterialViewFlags=kProcessMappersAndMaterials)
OdGiMaterialItemPtr currentMaterial() const
static OdGiMaterialTexturePtr loadMaterialTexture(OdGsFiler *pFiler)
virtual bool saveClientMaterialCache(const OdRxObject *pMtl, OdGsFiler *pFiler)
OdGsLightsAccumulationContainter m_lightsAccum
void appendDelayCacheEntry(DelayCacheEntry *pEntry)
virtual bool computeDelayedExtents(const OdGiDrawable *pDrawable, OdGeExtents3d &extents)
virtual void addWebLight(const OdGiWebLightTraitsData &)
virtual void nullMaterialStub()
virtual bool loadMaterialCache(OdGsMaterialNode *pNode, OdGsFiler *pFiler)
virtual OdRxObjectPtr loadClientMaterialCache(OdGsFiler *pFiler, OdGiMaterialItem *pMatItem)
const OdGsLightsAccumulationContainter & getAccumulatedLights() const
virtual void addSpotLight(const OdGiSpotLightTraitsData &)
OdGsLightsAccumulationContainter & getAccumulatedLights()
virtual void endViewVectorization()
virtual bool saveMaterialCache(const OdGsMaterialNode *pNode, OdGsFiler *pFiler)
static bool saveMaterialTexture(const OdGiMaterialTexture *pTexture, OdGsFiler *pFiler)
bool isMapperAvailable() const
bool isMaterialEnabled() const
virtual void mapperChangedForDelayCache()
OdGiMaterialItemPtr m_pCurrentMaterialItem
OdGiMaterialItemPtr loadMaterialItem(OdGsFiler *pFiler)
void playAccumulatedLights(OdGsLightsAccumulationContainter *pAccumLights=NULL, bool bClear=true)
void resetCurrentMapper(OdGiMapperItemPtr pMapper)
bool isMaterialAvailable() const
void beginLightsAccumulation(bool bAccumNonCached=true, bool bAccumCached=false, bool bClear=false)
virtual void renderMaterialCache(OdGiMaterialItemPtr pCache, OdDbStub *materialId)
static bool saveMaterialTextureManager(const OdGiMaterialTextureManager *pManager, OdGsFiler *pFiler, OdGsMaterialTextureDataFiler *pSaver)
virtual void processMaterialNode(OdDbStub *materialId, OdGsMaterialNode *node)
virtual OdGiMaterialItemPtr fillMaterialCache(OdGiMaterialItemPtr prevCache, OdDbStub *materialId, const OdGiMaterialTraitsData &materialData)
virtual bool computeDrawableExtents(const OdGiDrawable *pDrawable, OdGeExtents3d &extents)
virtual bool doDraw(OdUInt32 drawableFlags, const OdGiDrawable *pDrawable)
OdGiMapperItemPtr m_pCurrentMapperItem
OdGiMapperItemPtr _itlCreateMapperItem() const
virtual void endMetafile(OdRxObject *pMetafile)
static bool loadMaterialTextureManager(OdGiMaterialTextureManager *pManager, OdGsFiler *pFiler, OdGsMaterialTextureDataFiler *pSaver)
OdGiMapperItemPtr currentMapper(bool bForCoords=true) const
virtual bool skipMaterialProcess(OdDbStub *materialId) const
virtual void addPointLight(const OdGiPointLightTraitsData &)
OdGiMaterialItemPtr _itlCreateMaterialItem() const
OdGsBaseMaterialView(OdUInt32 uMaterialViewFlags=kProcessMappersAndMaterials)
OdGsBaseMaterialViewMT(OdUInt32 uMaterialViewFlags=kProcessMappersAndMaterials)
void resetConstructorFlags(OdUInt32 uMaterialViewFlags)
bool isEmpty() const
Definition: OdVector.h:1326
DelayCacheEntry * nextEntry()
DelayCacheEntry()
virtual ~DelayCacheEntry()
virtual void play(OdGsBaseMaterialVectorizer &mView) const
virtual DelayCacheEntryType internalType() const
void setNextEntry(DelayCacheEntry *pNext)
DelayCacheEntry * m_pNext
void append(bool bMtSync, OdGiLightTraitsData *pLightData)
OdVector< OdGiLightTraitsData * > m_accumulatedLightsData
OdVector< OdGiLightTraitsData * > LightDataVector
void append(bool bMtSync, OdGsLightsAccumulationContainter &lightsAccum)
virtual OdGiMaterialTextureDataPtr loadClientMaterialTextureData(OdGsFiler *)
virtual bool saveClientMaterialTextureData(const OdGiMaterialTextureData *, OdGsFiler *)