| 1 |
//////////////////////////////////////////////////////////////////////////// |
| 2 |
// File: CuTexImage.h |
| 3 |
// Author: Changchang Wu |
| 4 |
// Description : interface for the CuTexImage class. |
| 5 |
// class for storing data in CUDA. |
| 6 |
// |
| 7 |
// Copyright (c) 2007 University of North Carolina at Chapel Hill |
| 8 |
// All Rights Reserved |
| 9 |
// |
| 10 |
// Permission to use, copy, modify and distribute this software and its |
| 11 |
// documentation for educational, research and non-profit purposes, without |
| 12 |
// fee, and without a written agreement is hereby granted, provided that the |
| 13 |
// above copyright notice and the following paragraph appear in all copies. |
| 14 |
// |
| 15 |
// The University of North Carolina at Chapel Hill make no representations |
| 16 |
// about the suitability of this software for any purpose. It is provided |
| 17 |
// 'as is' without express or implied warranty. |
| 18 |
// |
| 19 |
// Please send BUG REPORTS to [email protected] |
| 20 |
// |
| 21 |
//////////////////////////////////////////////////////////////////////////// |
| 22 |
|
| 23 |
|
| 24 |
#ifndef CU_TEX_IMAGE_H |
| 25 |
#define CU_TEX_IMAGE_H |
| 26 |
|
| 27 |
#include <cuda_runtime.h> |
| 28 |
|
| 29 |
class GLTexImage; |
| 30 |
|
| 31 |
class CuTexImage |
| 32 |
{ |
| 33 |
protected: |
| 34 |
void* _cuData; |
| 35 |
cudaArray* _cuData2D; |
| 36 |
int _numChannel; |
| 37 |
size_t _numBytes; |
| 38 |
int _imgWidth; |
| 39 |
int _imgHeight; |
| 40 |
int _texWidth; |
| 41 |
int _texHeight; |
| 42 |
GLuint _fromPBO; |
| 43 |
public: |
| 44 |
struct CuTexObj |
| 45 |
{ |
| 46 |
cudaTextureObject_t handle; |
| 47 |
~CuTexObj(); |
| 48 |
}; |
| 49 |
|
| 50 |
virtual void SetImageSize(int width, int height); |
| 51 |
virtual bool InitTexture(int width, int height, int nchannel = 1); |
| 52 |
void InitTexture2D(); |
| 53 |
CuTexObj BindTexture(const cudaTextureDesc& textureDesc, |
| 54 |
const cudaChannelFormatDesc& channelFmtDesc); |
| 55 |
CuTexObj BindTexture2D(const cudaTextureDesc& textureDesc, |
| 56 |
const cudaChannelFormatDesc& channelFmtDesc); |
| 57 |
void CopyToHost(void* buf); |
| 58 |
void CopyToHost(void* buf, int stream); |
| 59 |
void CopyFromHost(const void* buf); |
| 60 |
void CopyToTexture2D(); |
| 61 |
int CopyToPBO(GLuint pbo); |
| 62 |
void CopyFromPBO(int width, int height, GLuint pbo); |
| 63 |
public: |
| 64 |
inline int GetImgWidth(){return _imgWidth;} |
| 65 |
inline int GetImgHeight(){return _imgHeight;} |
| 66 |
inline int GetDataSize(){return _numBytes;} |
| 67 |
public: |
| 68 |
CuTexImage(); |
| 69 |
CuTexImage(int width, int height, int nchannel, GLuint pbo); |
| 70 |
virtual ~CuTexImage(); |
| 71 |
friend class ProgramCU; |
| 72 |
friend class PyramidCU; |
| 73 |
}; |
| 74 |
|
| 75 |
////////////////////////////////////////////////// |
| 76 |
//transfer OpenGL Texture to PBO, then to CUDA vector |
| 77 |
//#endif |
| 78 |
#endif // !defined(CU_TEX_IMAGE_H) |