NW4F G3d
Loading...
Searching...
No Matches
g3d_Sizer.h
Go to the documentation of this file.
1#ifndef NW_G3D_SIZER_H_
2#define NW_G3D_SIZER_H_
3
4#include <nw/g3d/g3d_config.h>
5#include <nw/g3d/ut/g3d_Inlines.h>
6
7namespace nw { namespace g3d {
8
9class Sizer
10{
11public:
12 struct Chunk
13 {
16 };
17
19
20 size_t GetTotalSize() const { return totalSize; }
21
22 bool IsValid() const { return pChunk != NULL; }
23
24 void Invalidate() { pChunk = NULL; totalSize = 0; }
25
26 template <typename T>
27 NW_G3D_FORCE_INLINE T* GetPtr(void* ptr, int type) const
28 {
30 return pChunk[type].size ? AddOffset<T>(ptr, pChunk[type].offset) : NULL;
31 }
32
33 NW_G3D_FORCE_INLINE void* GetPtr(void* ptr, int type) const
34 {
36 return pChunk[type].size ? AddOffset(ptr, static_cast<size_t>(pChunk[type].offset)) : NULL;
37 }
38
39protected:
40 void CalcOffset(Chunk* chunk, int count)
41 {
42 int idx = 0;
43 chunk[idx].offset = 0;
44 for (; idx < count - 1; ++idx)
45 {
46 NW_G3D_ASSERT(IsAligned(chunk[idx].size));
47 chunk[idx + 1].offset = chunk[idx].offset + static_cast<ptrdiff_t>(chunk[idx].size);
48 }
49 totalSize = static_cast<size_t>(chunk[idx].offset) + chunk[idx].size;
50 pChunk = chunk;
51 }
52
53private:
56};
57
58} } // namespace nw::g3d
59
60#endif // NW_G3D_SIZER_H_
Definition g3d_Sizer.h:10
Sizer()
Definition g3d_Sizer.h:18
void CalcOffset(Chunk *chunk, int count)
Definition g3d_Sizer.h:40
bool IsValid() const
Definition g3d_Sizer.h:22
size_t GetTotalSize() const
Definition g3d_Sizer.h:20
void Invalidate()
Definition g3d_Sizer.h:24
NW_G3D_FORCE_INLINE T * GetPtr(void *ptr, int type) const
Definition g3d_Sizer.h:27
NW_G3D_FORCE_INLINE void * GetPtr(void *ptr, int type) const
Definition g3d_Sizer.h:33
Chunk * pChunk
Definition g3d_Sizer.h:54
size_t totalSize
Definition g3d_Sizer.h:55
#define NW_G3D_ASSERT_NOT_NULL(exp)
Definition g3d_assert.h:20
#define NW_G3D_ASSERT(exp)
Definition g3d_assert.h:17
#define NW_G3D_FORCE_INLINE
Definition g3d_defs.h:66
Definition g3d_GfxManage.cpp:10
Definition g3d_Sizer.h:13
ptrdiff_t offset
Definition g3d_Sizer.h:15
size_t size
Definition g3d_Sizer.h:14