Jetson Inference
DNN Vision Library
glTexture.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 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_TEXTURE_H__
24 #define __GL_TEXTURE_H__
25 
26 
27 #include "glBuffer.h"
28 
29 
34 #ifndef GL_RGB32F
35 #define GL_RGB32F GL_RGB32F_ARB
36 #endif
37 
42 #ifndef GL_RGBA32F
43 #define GL_RGBA32F GL_RGBA32F_ARB
44 #endif
45 
46 
51 class glTexture
52 {
53 public:
61  static glTexture* Create( uint32_t width, uint32_t height, uint32_t format, void* data=NULL );
62 
66  ~glTexture();
67 
71  bool Bind();
72 
76  void Unbind();
77 
81  void Render( float x, float y );
82 
86  void Render( float x, float y, float width, float height );
87 
91  void Render( const float4& rect );
92 
96  inline uint32_t GetID() const { return mID; }
97 
101  inline uint32_t GetWidth() const { return mWidth; }
102 
106  inline uint32_t GetHeight() const { return mHeight; }
107 
111  inline uint32_t GetFormat() const { return mFormat; }
112 
116  inline uint32_t GetSize() const { return mSize; }
117 
133  void* Map( uint32_t device, uint32_t flags );
134 
139  void Unmap();
140 
158  bool Copy( void* ptr, uint32_t flags );
159 
176  bool Copy( void* ptr, uint32_t size, uint32_t flags );
177 
198  bool Copy( void* ptr, uint32_t offset, uint32_t size, uint32_t flags );
199 
200 
201 private:
202  glTexture();
203 
204  bool init( uint32_t width, uint32_t height, uint32_t format, void* data );
205 
206  uint32_t allocDMA( uint32_t type );
207  cudaGraphicsResource* allocInterop( uint32_t type, uint32_t flags );
208 
209  uint32_t mID;
210  uint32_t mPackDMA;
211  uint32_t mUnpackDMA;
212 
213  uint32_t mWidth;
214  uint32_t mHeight;
215  uint32_t mFormat;
216  uint32_t mSize;
217 
218  uint32_t mMapDevice;
219  uint32_t mMapFlags;
220 
221  cudaGraphicsResource* mInteropPack;
222  cudaGraphicsResource* mInteropUnpack;
223 };
224 
225 
226 #endif
glBuffer.h
glTexture::Create
static glTexture * Create(uint32_t width, uint32_t height, uint32_t format, void *data=NULL)
Allocate an OpenGL texture.
glTexture::GetFormat
uint32_t GetFormat() const
Retrieve the texture's format (e.g.
Definition: glTexture.h:111
glTexture::Copy
bool Copy(void *ptr, uint32_t flags)
Copy entire contents of the texture to/from CPU or CUDA memory.
glTexture::GetID
uint32_t GetID() const
Retrieve the OpenGL resource handle of the texture.
Definition: glTexture.h:96
glTexture::Unmap
void Unmap()
Unmap the texture from CPU/CUDA access.
glTexture::~glTexture
~glTexture()
Free the texture.
glTexture::Map
void * Map(uint32_t device, uint32_t flags)
Map the texture for accessing from the CPU or CUDA.
glTexture::GetWidth
uint32_t GetWidth() const
Retrieve the width in pixels of the texture.
Definition: glTexture.h:101
glTexture::Bind
bool Bind()
Activate using the texture.
glTexture
OpenGL texture with CUDA interoperability.
Definition: glTexture.h:51
glTexture::Render
void Render(float x, float y)
Render the texture at the specified window coordinates.
glTexture::Unbind
void Unbind()
Deactivate using the texture.
glTexture::GetSize
uint32_t GetSize() const
Retrieve the size in bytes of the texture.
Definition: glTexture.h:116
glTexture::GetHeight
uint32_t GetHeight() const
Retrieve the height in pixels of the texture.
Definition: glTexture.h:106