Back to Jetson Inference

Jetson Inference: jetson

docs/html/glBuffer_8h_source.html

latest7.8 KB
Original Source

| | Jetson Inference

DNN Vision Library |

glBuffer.h

Go to the documentation of this file.

1 /*

2 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.

3 *

4 * Permission is hereby granted, free of charge, to any person obtaining a

5 * copy of this software and associated documentation files (the "Software"),

6 * to deal in the Software without restriction, including without limitation

7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,

8 * and/or sell copies of the Software, and to permit persons to whom the

9 * Software is furnished to do so, subject to the following conditions:

10 *

11 * The above copyright notice and this permission notice shall be included in

12 * all copies or substantial portions of the Software.

13 *

14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER

20 * DEALINGS IN THE SOFTWARE.

21 */

22

23 #ifndef __GL_BUFFER_H__

24 #define __GL_BUFFER_H__

25

26

27 #include "cudaUtility.h"

28 #include "cuda_gl_interop.h"

29

30

35 #define GL_VERTEX_BUFFER GL_ARRAY_BUFFER

36

41 #define GL_INDEX_BUFFER GL_ELEMENT_ARRAY_BUFFER

42

47 #define GL_MAP_CPU 0x1

48

53 #define GL_MAP_CUDA 0x2

54

59 #define GL_FROM_CPU 0x3

60

65 #define GL_FROM_CUDA 0x4

66

71 #define GL_TO_CPU 0x5

72

77 #define GL_TO_CUDA 0x6

78

83 #define GL_WRITE_DISCARD (GL_READ_WRITE + 0xff)

84

89 #ifndef GL_WRITE_ONLY

90 #define GL_WRITE_ONLY GL_WRITE_ONLY_ARB

91 #endif

92

97 #ifndef GL_READ_ONLY

98 #define GL_READ_ONLY GL_READ_ONLY_ARB

99 #endif

100

105 #ifndef GL_READ_WRITE

106 #define GL_READ_WRITE GL_READ_WRITE_ARB

107 #endif

108

109

114 class glBuffer

115 {

116 public:

124static glBuffer* Create( uint32_t type, uint32_t size, void* data=NULL, uint32_t usage=GL_STATIC_DRAW );

125

134static glBuffer* Create( uint32_t type, uint32_t numElements, uint32_t elementSize, void* data=NULL, uint32_t usage=GL_STATIC_DRAW );

135

139~glBuffer();

140

144bool Bind();

145

149void Unbind();

150

154inline uint32_t GetID() const { return mID; }

155

159inline uint32_t GetType() const { return mType; }

160

164inline uint32_t GetSize() const { return mSize; }

165

172inline uint32_t GetNumElements() const { return mNumElements; }

173

180inline uint32_t GetElementSize() const { return mElementSize; }

181

197void* Map( uint32_t device, uint32_t flags );

198

203void Unmap();

204

222bool Copy( void* ptr, uint32_t flags );

223

240bool Copy( void* ptr, uint32_t size, uint32_t flags );

241

262bool Copy( void* ptr, uint32_t offset, uint32_t size, uint32_t flags );

263

264 private:

265glBuffer();

266

267bool init( uint32_t type, uint32_t size, void* data, uint32_t usage);

268

269 uint32_t mID;

270 uint32_t mSize;

271 uint32_t mType;

272 uint32_t mUsage;

273

274 uint32_t mNumElements;

275 uint32_t mElementSize;

276

277 uint32_t mMapDevice;

278 uint32_t mMapFlags;

279

280 cudaGraphicsResource* mInteropCUDA;

281 };

282

283

284 #endif

glBuffer::Create

static glBuffer * Create(uint32_t type, uint32_t size, void *data=NULL, uint32_t usage=GL_STATIC_DRAW)

Allocate an OpenGL buffer.

glBuffer::Copy

bool Copy(void *ptr, uint32_t flags)

Copy entire contents of the buffer to/from CPU or CUDA memory.

glBuffer::Map

void * Map(uint32_t device, uint32_t flags)

Map the buffer for accessing from the CPU or CUDA.

cudaUtility.h

glBuffer::GetSize

uint32_t GetSize() const

Retrieve the total size in bytes of the buffer.

Definition: glBuffer.h:164

glBuffer::~glBuffer

~glBuffer()

Free the buffer.

glBuffer::GetType

uint32_t GetType() const

Retrieve the buffer type (GL_VERTEX_BUFFER or GL_INDEX_BUFFER)

Definition: glBuffer.h:159

glBuffer::Bind

bool Bind()

Activate using the buffer.

glBuffer::GetElementSize

uint32_t GetElementSize() const

Retrieve the size in bytes of each element.

Definition: glBuffer.h:180

glBuffer::Unbind

void Unbind()

Deactivate using the buffer.

glBuffer::Unmap

void Unmap()

Unmap the buffer from CPU/CUDA access.

glBuffer

OpenGL buffer with CUDA interoperability.

Definition: glBuffer.h:114

glBuffer::GetID

uint32_t GetID() const

Retrieve the OpenGL resource handle of the buffer.

Definition: glBuffer.h:154

glBuffer::GetNumElements

uint32_t GetNumElements() const

Retrieve the number of elements (i.e.

Definition: glBuffer.h:172