PDA

View Full Version : problem in mapping values from cuda kernel to VBO



Janani
03-24-2010, 03:14 AM
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
1. VBO creation
2. mapping vbo with cuda
3. calling cuda kernel
4. 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 )
5. display (to show point , not displaying properly)


/////////VBO creation//////////
glBindBuffer(GL_ARRAY_BUFFER,vbo[1]);
glBufferDataGL_ARRAY_BUFFER,videovbosize,0,GL_DYNA MIC_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.x*blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y*blockDim.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