VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtGlBuffer.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2021 VT-MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
11 #include <string>
12 
17 
18 #include <iostream>
19 
20 namespace makVrv
21 {
22  class DtGlBufferListener;
23 
30  {
31  public:
38  DtGlBuffer(const char * name, DtBufferType type, DtUsage usage, DtCpuAccess accessType, bool hasStagingBuffer);
39 
41  virtual ~DtGlBuffer();
42 
43  private:
45  DtGlBuffer() = delete;
47  DtGlBuffer(const DtGlBuffer& other) = delete;
49  DtGlBuffer& operator=(const DtGlBuffer& other) = delete;
50 
51  public:
52 
54  virtual void tearDown(void);
55 
57  virtual unsigned int releaseHandle(void);
58 
62  virtual bool updateBuffer(const int sizeToTransferInBytes, const void* data);
63 
68  virtual bool updateBuffer(const int offsetInBytes, const int sizeToTransferInBytes, const void* data);
69 
73  virtual void clearBuffer(unsigned int clearValue);
74 
76  virtual void bind() const;
80  virtual void unbind() const;
82 
83 
85  virtual unsigned char* stagingBuffer(void) const;
91 
94  virtual unsigned char* stagingBufferWithSize(unsigned int requestedSizeInBytes);
95 
98  virtual void syncStagingBufferToGpu(unsigned int offset, unsigned int sizeInBytes);
99 
102  virtual void syncStagingBufferToGpu();
104 
109  virtual bool bufferSubData(unsigned int offset, unsigned int sizeInBytes, const void* data);
110 
111 
113  virtual void resetStagingBuffer();
114 
116  virtual int sizeInBytes(void) const;
117 
119  virtual int sizeInBytesFromGl(void) const;
120 
122  virtual const unsigned int handle(void) const;
123 
125  virtual void setResizeMultiplier(float rmul);
126 
131  virtual void setUseIncrementalUpdate(bool incrementalUpdate);
132 
134  virtual bool useIncrementalUpdate();
135 
137  virtual float resizeMultiplier();
138 
140  unsigned int type(void) const;
141 
144  virtual uint64_t gpuResidentAddress();
145 
149  virtual const void* mapForReading(void) const;
150 
154  virtual void unMap(void) const;
155 
160  template <class T>
161  void printContents(std::ostream& outputStream, const std::string& strNumPrefix, const std::string& strValPrefix) const
162  {
163  if (myHandle == 0)
164  {
165  return;
166  }
167  const T* pRepType = (const T*)(mapForReading());
168  if (pRepType)
169  {
170  const size_t numOfRepTypes = sizeInBytes() / sizeof(T);
171  outputStream << strNumPrefix << numOfRepTypes << std::endl;
172  for (int i = 0; i < numOfRepTypes; ++i)
173  {
174  outputStream << strValPrefix << "[" << i << "]: " << pRepType[i] << std::endl;
175  }
176  }
177  unMap();
178  }
179 
186  virtual const DtGlBufferListener* listener(void) const;
187 
189  virtual DtGlBufferListener* listener(void);
190 
192  virtual void setListener(DtGlBufferListener* listener);
193 
197  virtual const std::string& name() const;
198 
200  virtual bool gpuResidentAddressWasCalledAtleastOnce(void) const;
201 
202  protected:
203 
206  virtual bool createAndBindBuffer();
207 
210  virtual int calculateNewSize(int requestedNewSizeInBytes);
211 
212  protected:
213 
214  std::string myName;
215  unsigned int myHandle;
216  unsigned int myType;
219  unsigned char* myStagingBuffer;
223 
228 
229  mutable bool myMutableIsMapped;
230 
232  };
233 }
int myLastBufferTransferOffset
Definition: DtGlBuffer.h:225
Dll export defines.
DtUsage myUsage
Definition: DtGlBuffer.h:221
DtBufferType
An abstract buffer type (vertex buffer, index buffer, etc) Used, for example, to create DtGlBuffers o...
Definition: DtBufferType.h:15
int mySizeInBytes
Definition: DtGlBuffer.h:217
bool myMutableIsMapped
Definition: DtGlBuffer.h:229
DtCpuAccess myAccessType
Definition: DtGlBuffer.h:222
std::string myName
Definition: DtGlBuffer.h:214
Buffer Usage enums.
DtUsage
Definition: DtUsage.h:13
Enumerations for cpu access required by textures/buffers.
unsigned int myHandle
Definition: DtGlBuffer.h:215
unsigned int myType
Definition: DtGlBuffer.h:216
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
bool myUseIncrementalUpdate
Definition: DtGlBuffer.h:224
unsigned char * myStagingBuffer
Definition: DtGlBuffer.h:219
DtGlBufferListener * myListener
Definition: DtGlBuffer.h:231
bool myIsResident
Definition: DtGlBuffer.h:227
bool myHasStagingBuffer
Definition: DtGlBuffer.h:220
An abstract class to track a DtGlBuffer and its properties (size, residency, etc) Each DtGlBuffer can...
Definition: DtGlBufferListener.h:31
A generic OpenGL buffer. This can be: -&gt; a vertex buffer -&gt; an index buffer -&gt; a shader storage buffe...
Definition: DtGlBuffer.h:29
Buffer Type enums.
uint64_t myResidentAddress
Definition: DtGlBuffer.h:226
#define DT_DLL_VRVGRAPHICSUTILS
Definition: vrvGraphicsUtils.h:18
voidpf uLong offset
Definition: ioapi.h:42
DtCpuAccess
Definition: DtCpuAccess.h:13
void printContents(std::ostream &outputStream, const std::string &strNumPrefix, const std::string &strValPrefix) const
Template function to print the contents of the buffer. The contents are interpreted as items of type ...
Definition: DtGlBuffer.h:161
float myResizeMultiplier
Definition: DtGlBuffer.h:218

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)