CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
TrRndExternalArraysManager.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// External renderer arrays manager.
24
25#ifndef ODTRRNDEXTERNALARRAYSMANAGER
26#define ODTRRNDEXTERNALARRAYSMANAGER
27
28#include "TD_PackPush.h"
29
30#include "../TrVisMetafileStream.h"
31
36{
37 public:
39 {
40 const void *m_pData;
42 };
43 public:
44 // Check does arrays manager supports extending without recreation.
45 virtual bool examSupportExtending() const { return true; }
46 // Initialize (create) array.
47 virtual void examInitializeArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems, OdTrVisArrayWrapper::DataSize dataTypeSize) const = 0;
48 // Extend exist array.
49 virtual void examExtendArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems) const = 0;
50 // Truncate exist array.
51 virtual void examTruncateArray(OdTrVisArrayWrapper &wrapArray, OdUInt32 uSizeElems) const = 0;
52 // Recreate array (will be called instead of Extend/Truncate in case if SupportExtending false).
53 virtual void examRecreateArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems) const = 0;
54 // Delete (free) exist array.
55 virtual void examFreeArray(OdTrVisArrayWrapper &wrapArray) const = 0;
56 // Returns true in case if array data can be accessed.
57 virtual bool examSupportAccess() const { return true; }
58 // Returns pointer to array data if this is supported.
59 virtual const void *examAccessArray(const OdTrVisArrayWrapper &wrapArray, bool bLock = true) const = 0;
60};
61
66{
67 protected:
68 static OdUInt32 examTotalSize(const ExamArrayEntry *pElem, OdUInt32 nElems)
69 { OdUInt32 counter = 0;
70 for (OdUInt32 nElem = 0; nElem < nElems; nElem++)
71 counter += pElem->m_uSizeElems;
72 return counter;
73 }
74 public:
75 // Initialize (create) array.
76 virtual void examInitializeArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems, OdTrVisArrayWrapper::DataSize dataTypeSize) const
77 { if (nElems == 1)
78 wrapArray.setArray(wrapArray.type(), pElem->m_pData, pElem->m_uSizeElems, dataTypeSize);
79 else
80 { // Optimized concatenation of multiple input arrays.
81 wrapArray.clearArray();
82 const size_t dataSize = size_t(examTotalSize(pElem, nElems)) << dataTypeSize;
83 wrapArray.m_pData = ::odrxAlloc(dataSize);
84 if (wrapArray.m_pData == NULL)
85 throw OdError(eOutOfMemory);
86 size_t curPtr = 0;
87 for (OdUInt32 nArray = 0; nArray < nElems; nArray++)
88 ::memcpy((OdUInt8*)wrapArray.m_pData + curPtr, pElem[nArray].m_pData, size_t(pElem[nArray].m_uSizeElems) << dataTypeSize),
89 curPtr += size_t(pElem[nArray].m_uSizeElems) << dataTypeSize;
90 wrapArray.m_uSize = OdUInt32(dataSize >> dataTypeSize); wrapArray.m_uData = dataTypeSize;
91 }
92 }
93 // Extend exist array.
94 virtual void examExtendArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems) const
95 {
96 if (nElems == 1)
97 wrapArray.concatArray(pElem->m_pData, pElem->m_uSizeElems, wrapArray.dataSize());
98 else
99 { // Optimized concatenation of multiple input arrays.
100 const size_t dataSize = size_t(examTotalSize(pElem, nElems)) << wrapArray.dataSize();
101 wrapArray.m_pData = ::odrxRealloc(wrapArray.m_pData, dataSize + wrapArray.arraySize(), wrapArray.arraySize());
102 if (wrapArray.m_pData == NULL)
103 throw OdError(eOutOfMemory);
104 size_t curPtr = wrapArray.dataSize();
105 for (OdUInt32 nArray = 0; nArray < nElems; nArray++)
106 ::memcpy((OdUInt8 *)wrapArray.m_pData + curPtr, pElem[nArray].m_pData, size_t(pElem[nArray].m_uSizeElems) << wrapArray.dataSize()),
107 curPtr += size_t(pElem[nArray].m_uSizeElems) << wrapArray.dataSize();
108 wrapArray.m_uSize += OdUInt32(dataSize >> wrapArray.dataSize());
109 }
110 }
111 // Truncate exist array.
112 virtual void examTruncateArray(OdTrVisArrayWrapper &wrapArray, OdUInt32 uSizeElems) const
113 {
114 wrapArray.truncateArray(uSizeElems, wrapArray.dataSize());
115 }
116 // Recreate array (will be called instead of Extend/Truncate in case if SupportExtending false).
117 virtual void examRecreateArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems) const
118 { const OdTrVisArrayWrapper::DataSize ds = wrapArray.dataSize();
119 examFreeArray(wrapArray);
120 examInitializeArray(wrapArray, pElem, nElems, ds);
121 }
122 // Delete (free) exist array.
123 virtual void examFreeArray(OdTrVisArrayWrapper &wrapArray) const
124 {
125 wrapArray.clearArray();
126 }
127 // Returns pointer to array data if this is supported.
128 virtual const void *examAccessArray(const OdTrVisArrayWrapper &wrapArray, bool bLock = true) const
129 {
130 return (bLock) ? wrapArray.m_pData : NULL;
131 }
132};
133
134#include "TD_PackPop.h"
135
136#endif // ODTRRNDEXTERNALARRAYSMANAGER
ALLOCDLL_EXPORT void * odrxRealloc(void *pMemBlock, size_t newSize, size_t oldSize)
ALLOCDLL_EXPORT void * odrxAlloc(size_t nBytes)
unsigned int OdUInt32
unsigned char OdUInt8
virtual void examRecreateArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems) const =0
virtual void examExtendArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems) const =0
virtual const void * examAccessArray(const OdTrVisArrayWrapper &wrapArray, bool bLock=true) const =0
virtual void examInitializeArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems, OdTrVisArrayWrapper::DataSize dataTypeSize) const =0
virtual void examTruncateArray(OdTrVisArrayWrapper &wrapArray, OdUInt32 uSizeElems) const =0
virtual void examFreeArray(OdTrVisArrayWrapper &wrapArray) const =0
virtual void examFreeArray(OdTrVisArrayWrapper &wrapArray) const
virtual void examTruncateArray(OdTrVisArrayWrapper &wrapArray, OdUInt32 uSizeElems) const
static OdUInt32 examTotalSize(const ExamArrayEntry *pElem, OdUInt32 nElems)
virtual void examExtendArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems) const
virtual void examInitializeArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems, OdTrVisArrayWrapper::DataSize dataTypeSize) const
virtual void examRecreateArray(OdTrVisArrayWrapper &wrapArray, const ExamArrayEntry *pElem, OdUInt32 nElems) const
virtual const void * examAccessArray(const OdTrVisArrayWrapper &wrapArray, bool bLock=true) const
OdUInt32 m_uSizeElems
const void * m_pData
OdUInt32 arraySize() const
DataSize dataSize() const
void setArray(Type type, const void *pPtr, OdUInt32 size, DataSize ds)
void concatArray(const void *pPtr, OdUInt32 size, DataSize ds, const ReallocLogic &racLg=g_defaultReallocLogic)
void truncateArray(OdUInt32 size, DataSize ds)