Overte C++ Documentation
Sysmem.h
1 //
2 // Created by Sam Gateau on 10/8/2014.
3 // Split from Resource.h/Resource.cpp by Bradley Austin Davis on 2016/08/07
4 // Copyright 2014 High Fidelity, Inc.
5 //
6 // Distributed under the Apache License, Version 2.0.
7 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
8 //
9 #ifndef hifi_gpu_Sysmem_h
10 #define hifi_gpu_Sysmem_h
11 
12 
13 #include "Forward.h"
14 
15 namespace gpu {
16 
18 class Sysmem {
19 public:
20  static const Size NOT_ALLOCATED = INVALID_SIZE;
21 
22  Sysmem();
23 
28  Sysmem(Size size, const Byte* bytes);
29  Sysmem(const Sysmem& sysmem); // deep copy of the sysmem buffer
30  Sysmem& operator=(const Sysmem& sysmem); // deep copy of the sysmem buffer
31  ~Sysmem();
32 
36  Size getSize() const { return _size; }
37 
45  Size allocate(Size pSize);
46 
54  Size resize(Size pSize);
55 
62  Size setData(Size size, const Byte* bytes);
63 
74  Size setSubData(Size offset, Size size, const Byte* bytes);
75 
76  // Append new data at the end of the current buffer
77  // do a resize( size + getSIze) and copy the new data
78  // \return
87  Size append(Size size, const Byte* data);
88 
93  const Byte* readData() const { return _data; }
94 
99  Byte* editData() { return _data; }
100 
105  template< typename T > const T* read() const { return reinterpret_cast< T* > (_data); }
106 
111  template< typename T > T* edit() { return reinterpret_cast< T* > (_data); }
112 
118  Stamp getStamp() const { return _stamp; }
119 
120 private:
127  static Size allocateMemory(Byte** memAllocated, Size size);
128 
134  static void deallocateMemory(Byte* memDeallocated, Size size);
135 
139  bool isAvailable() const { return (_data != nullptr); }
140 
141 
142  Stamp _stamp{ 0 };
143  Size _size{ 0 };
144  Byte* _data{ nullptr };
145 }; // Sysmem
146 
147 }
148 
149 #endif
Sysmem is the underneath cache for the data of a resource in CPU RAM.
Definition: Sysmem.h:18
Byte * editData()
Access the byte array for reading and writing.
Definition: Sysmem.h:99
Size setSubData(Size offset, Size size, const Byte *bytes)
Update a subset of buffer data,.
Definition: Sysmem.cpp:126
Size getSize() const
Definition: Sysmem.h:36
Size setData(Size size, const Byte *bytes)
Assign data bytes and size (allocate for size, then copy bytes if exists).
Definition: Sysmem.cpp:117
const T * read() const
Definition: Sysmem.h:105
Size append(Size size, const Byte *data)
Append new data at the end of the current buffer.
Definition: Sysmem.cpp:134
Size allocate(Size pSize)
Allocate the byte array.
Definition: Sysmem.cpp:70
const Byte * readData() const
Access the byte array.
Definition: Sysmem.h:93
Stamp getStamp() const
Definition: Sysmem.h:118
Size resize(Size pSize)
Resize the byte array.
Definition: Sysmem.cpp:91
T * edit()
Definition: Sysmem.h:111