VR-Forces 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) 2022 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 unsigned int releaseHandle(void);
55 
59  virtual bool updateBuffer(const int sizeToTransferInBytes, const void* data);
60 
65  virtual bool updateBuffer(const int offsetInBytes, const int sizeToTransferInBytes, const void* data);
66 
70  virtual void clearBuffer(unsigned int clearValue);
71 
73  virtual void bind() const;
77  virtual void unbind() const;
79 
80 
82  virtual unsigned char* stagingBuffer(void) const;
88 
91  virtual unsigned char* stagingBufferWithSize(unsigned int requestedSizeInBytes);
92 
95  virtual void syncStagingBufferToGpu(unsigned int offset, unsigned int sizeInBytes);
96 
99  virtual void syncStagingBufferToGpu();
101 
106  virtual bool bufferSubData(unsigned int offset, unsigned int sizeInBytes, const void* data);
107 
108 
110  virtual void resetStagingBuffer();
111 
113  virtual int sizeInBytes(void) const;
114 
116  virtual int sizeInBytesFromGl(void) const;
117 
119  virtual const unsigned int handle(void) const;
120 
122  virtual void setResizeMultiplier(float rmul);
123 
128  virtual void setUseIncrementalUpdate(bool incrementalUpdate);
129 
131  virtual bool useIncrementalUpdate();
132 
134  virtual float resizeMultiplier();
135 
137  unsigned int type(void) const;
138 
141  virtual uint64_t gpuResidentAddress();
142 
146  virtual const void* mapForReading(void) const;
147 
151  virtual void unMap(void) const;
152 
157  template <class T>
158  void printContents(std::ostream& outputStream, const std::string& strNumPrefix, const std::string& strValPrefix) const
159  {
160  if (myHandle == 0)
161  {
162  return;
163  }
164  const T* pRepType = (const T*)(mapForReading());
165  if (pRepType)
166  {
167  const size_t numOfRepTypes = sizeInBytes() / sizeof(T);
168  outputStream << strNumPrefix << numOfRepTypes << std::endl;
169  for (int i = 0; i < numOfRepTypes; ++i)
170  {
171  outputStream << strValPrefix << "[" << i << "]: " << pRepType[i] << std::endl;
172  }
173  }
174  unMap();
175  }
176 
183  virtual const DtGlBufferListener* listener(void) const;
184 
186  virtual DtGlBufferListener* listener(void);
187 
189  virtual void setListener(DtGlBufferListener* listener);
190 
194  virtual const std::string& name() const;
195 
197  virtual bool gpuResidentAddressWasCalledAtleastOnce(void) const;
198 
199  protected:
200 
203  virtual bool createAndBindBuffer();
204 
207  virtual int calculateNewSize(int requestedNewSizeInBytes);
208 
209  protected:
210 
211  std::string myName;
212  unsigned int myHandle;
213  unsigned int myType;
216  unsigned char* myStagingBuffer;
220 
225 
226  mutable bool myMutableIsMapped;
227 
229  };
230 }
int myLastBufferTransferOffset
Definition: DtGlBuffer.h:222
Dll export defines.
DtUsage myUsage
Definition: DtGlBuffer.h:218
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:214
bool myMutableIsMapped
Definition: DtGlBuffer.h:226
DtCpuAccess myAccessType
Definition: DtGlBuffer.h:219
std::string myName
Definition: DtGlBuffer.h:211
Buffer Usage enums.
DtUsage
Definition: DtUsage.h:13
Enumerations for cpu access required by textures/buffers.
unsigned int myHandle
Definition: DtGlBuffer.h:212
unsigned int myType
Definition: DtGlBuffer.h:213
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
bool myUseIncrementalUpdate
Definition: DtGlBuffer.h:221
unsigned char * myStagingBuffer
Definition: DtGlBuffer.h:216
DtGlBufferListener * myListener
Definition: DtGlBuffer.h:228
bool myIsResident
Definition: DtGlBuffer.h:224
bool myHasStagingBuffer
Definition: DtGlBuffer.h:217
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:223
#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:158
float myResizeMultiplier
Definition: DtGlBuffer.h:215

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)