I am trying to do some computation in cuda and map the result to VBO
, it is not happening properly
I have attached part of coding
- VBO creation
- mapping vbo with cuda
- calling cuda kernel
- assigning values to vertices in cuda ( i am not doing any computation here, just trying to map values from cuda kernel to screen through VBO )
- display (to show point , not displaying properly)
/////////VBO creation//////////
glBindBuffer(GL_ARRAY_BUFFER,vbo[1]);
glBufferDataGL_ARRAY_BUFFER,videovbosize,0,GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
cudaGLRegisterBufferObject(vbo[1]);
/////////////////cuda mapping
cudaGLMapBufferObject((void**)&dptr, vbo[1]);
float *dptr;
launch_kernel(dptr,d_A,d_W,d_O,prevwidth,cpivalue);
cudaGLUnmapBufferObject(vbo[1]);
//////////////cuda//////////////
extern āCā void launch_kernel(float* pos,int* d_A,int* d_W,int* d_O,int prevwidth,int cpivalue)
{
// execute the kernel
dim3 block(16,16,1);
dim3 grid(100,1,1);
mykernel<<<grid,block>>>(pos,d_A,d_W,d_O,prevwidth,cpivalue);
}
global void mykernel(float* pos,int* g_idata,int* g_width, int* g_odata, int prevwidth,int cpivalue)
{
unsigned int x = blockIdx.xblockDim.x + threadIdx.x;
unsigned int y = blockIdx.yblockDim.y + threadIdx.y;
int w=16;
float v1=0.0,v2=0.0;
int index=y*w+x;
v1=0.42*sin(0.0157)
v2=0.42*cos(0.0157);
pos[(index*2)+0]=v1;
pos[(index*2)+1]=v2;
// pos[index]=make_float4(v1,v2,0.0f,1.0f);
}
display
glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
glVertexPointer(2,GL_FLOAT,0,0);
glEnableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0,1.0, 0.0);
glDrawArrays(GL_POINTS, 0,100);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
In mykernel i have passed values but i am not showing any computation here.
can anyone tell me what mistake i am making in mapping the values to vbo.
Thank you