Corporation of cuda and openGL Texture( Source Code sample)
来源:互联网 发布:2016淘宝上如何做代销 编辑:程序博客网 时间:2024/06/06 12:58
<Specification>
Notice that those important functions in corporation hava been distinguished with blue color.
The compute capability of the cuda file .cu should be changed to 2.0 or higher version, otherwise the compiler
cannot find the surface funtion.
Two important headers should be included:
#include<cuda_gl_interop.h> //Used for the basic corporation
#include "surface_functions.h" //Used for the surface write functions
struct cudaGraphicsResource * resource;
cudaChannelFormatDesc channelDesc =cudaCreateChannelDesc(8, 8, 8, 8,cudaChannelFormatKindUnsigned);
const surfaceReference * surfRefPtr; //surface reference ptr
static surface<void, cudaSurfaceType2D> surfRef; //2D surface reference, it has to be static
cudaArray * cuArray; // cuda Array,whcih store the texture mapping data
//notice that we don't have to malloc space to cuda Array, we will map
// the texture space into the array then.
cudaGLSetGLDevice(0);
///creat surface reference
cudaGetSurfaceReference(&surfRefPtr, "surfRef");
cudaGetChannelDesc(&channelDesc, cuArray);
///generate a texture
glGenTextures(1,&tex);
glBindTexture(GL_TEXTURE_2D, tex);
///set texture parameter
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 500, 500, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
if( cudaSuccess !=cudaGraphicsGLRegisterImage(&resource,tex,GL_TEXTURE_2D,
cudaGraphicsRegisterFlagsSurfaceLoadStore)) // Notice the last flag
printf(" cuda cannot register the image \m" );
glBindTexture(GL_TEXTURE_2D, 0);
glEnable(GL_TEXTURE_2D);
///modify the texture
if( cudaSuccess != cudaGraphicsMapResources(1,&resource,0) )
printf(" The resources cannot be mapped");
if( cudaSuccess != cudaGraphicsSubResourceGetMappedArray(&cuArray,resource,0,0))
printf(" Array cannot be mapped");
//bind the array to the surface
if( cudaSuccess != cudaBindSurfaceToArray(surfRefPtr, cuArray, &channelDesc))
printf("Array cannot bind to the surface");
dim3 grid( , );
dim3 block( , );
modifyPixel<<<grid,block>>>( );
if( cudaSuccess != cudaGraphicsUnmapResources(1,&resource,0) )
printf(" The resources cannot be Unmapped");
//code in device function
__global__
void modifyPixel()
{
int x = blockDim.x*blockIdx.x + threadIdx.x;
int y = blockDim.y*blockIdx.y + threadIdx.y;
// r g b a
uchar4 data = make_uchar4(0,255,255,255);
surf2Dwrite(data, surfRef, x*sizeof(uchar4), y);
__syncthreads();
}
- Corporation of cuda and openGL Texture( Source Code sample)
- sample code of webview
- nginx Remote Source Code Disclosure and Denial of Service Vulnerabilities
- Weka source code sample good website
- Source Code of exe2com.
- Source Code of exe2com
- Source code of CIH
- Study of Source code
- Source code of ZMRP_VSS_CLEANUP
- source code of CV
- UV Texture Coordinates and Texture Mapping - OpenGL / DirectX
- Understanding and Using OpenGL Texture Objects
- OpenGL ES 3.0 Programming Guide Sample Code
- Analysing the ASM code of a simple sample of C programming language at Linux Platform by GCC and GDB
- Dojo widgets introduction and sample code (1)
- Dojo widgets introduction and sample code (2)
- Dojo widgets introduction and sample code (3)
- Dojo widgets introduction and sample code (4)
- C#连接ACCESS数据库的详细步骤!
- 提升Java程序性能的经验原则和方法
- 给图片加上带版权的水印
- Linux启动和关闭时自动执行的所有脚本文件
- android系统编写helloworld模块,编译以及adb运行
- Corporation of cuda and openGL Texture( Source Code sample)
- 8大你不得不知的Android调试工具
- Image 转换为 byte[]数组 与 byte[]数组转换为 Image
- Flash发布iOS应用全攻略(一)——如何在Flash里发布iOS应用
- struts2 工作原理浅析
- Create an RSS feed in Rails Tian
- Flash发布iOS应用全攻略(二)——如何成为一个合法的iOS开发者
- C++实现所有文件格式复制
- android adb常用指令