c++ - How to Access data on cuda by openGL? -


i have learned opengl interoperability cuda, problem this:

i have lot of arrays, vertex, norm , alpha value alone, , pointers these arrays on device memory (something dev_ver, dev_norm) used in kernel. have mapped resource , want use these data in shaders make effects. rendering code this:

gluseprogram                (programid);  glbindbuffer                (gl_array_buffer, vertexbuffer_0); glbufferdata(gl_array_buffer, size, _data_on_cpu_0, gl_dynamic_draw); glvertexattribpointer       (0, 3, gl_float, gl_false, 0, (void*)0);  glbindbuffer                (gl_array_buffer, vertexbuffer_1); glbufferdata(gl_array_buffer, size, _data_on_cpu_1, gl_dynamic_draw); glvertexattribpointer       (1, 3, gl_float, gl_false, 0, (void*)0);  glbindbuffer                (gl_array_buffer, vertexbuffer_2); glbufferdata(gl_array_buffer, size, _data_on_cpu_2, gl_dynamic_draw); glvertexattribpointer       (2, 3, gl_float, gl_false, 0, (void*)0);  glenablevertexattribarray   (0); glenablevertexattribarray   (1); glenablevertexattribarray   (2);  gldrawarrays                (gl_triangles, 0, _max_);  gldisablevertexattribarray  (0); gldisablevertexattribarray  (1); gldisablevertexattribarray  (2); 

however, have no _data_on_cpu_, still possible same thing ? sample in cuda 6.0 this:

glbindbuffer(gl_array_buffer, posvbo); glvertexpointer(4, gl_float, 0, 0); glenableclientstate(gl_vertex_array);  glbindbufferarb(gl_array_buffer_arb, normalvbo); glnormalpointer(gl_float, sizeof(float)*4, 0); glenableclientstate(gl_normal_array);  glcolor3f(1.0, 0.0, 0.0); gldrawarrays(gl_triangles, 0, totalverts); gldisableclientstate(gl_vertex_array); gldisableclientstate(gl_normal_array); 

i don't understand how work , in case.

by way, method have used cudamemcpy dev_ host , render usual, not efficient, because when rendering again send data gpu opengl (if i'm right).

it's not clear asking for, mention cuda yet none of code have posted cuda specific. i'm guessing vertexbuffer_2 contains additional per vertex information want access in shader?

opengl calls efficient it, aren't copying data device host. sending addresses device, telling data , how data use render.

you need fill vertex , normal information @ start of program, there isn't reason changing information during execution. can change data stored in texture buffers pass additional per entity data shaders change model position, rotation, colour etc.


when write shader must include in it; attribute in vec3 v_data; (or similar)

when init shader must then;

gluint vs_v_data = glgetattriblocation(p_shaderprogram, "v_data");  

then instead of your;

glbindbuffer                (gl_array_buffer, vertexbuffer_2); glbufferdata(gl_array_buffer, size, _data_on_cpu_2, gl_dynamic_draw); glvertexattribpointer       (2, 3, gl_float, gl_false, 0, (void*)0); 

you use;

glenablevertexattribarray   (vs_v_data); glbindbuffer                (gl_array_buffer, vertexbuffer_2); glbufferdata(gl_array_buffer, size, _data_on_cpu_2, gl_dynamic_draw); glvertexattribpointer       (vs_v_data, 3, gl_float, gl_false, 0, (void*)0); 

this should let access float3 inside vshaders called v_data has whatevers stored in vertexbuffer_2, presumably secondary vertex information lerp between animation.


a simple shader repositions vertices based on input tick

#version 120 attribute in float tick; attribute in vec3 v_data; void main() {     gl_vertex.xyz = mix(gl_vertex.xyz, v_data, tick); } 

if want per entity data instead of/in addition per vertex data, should doing via texture buffers.


if trying access vertex buffer obj data inside kernels need use bunch of functions;

cudagraphicsglregisterbuffer() give resource pointer buffer, execute once after setup vbo.

cudagraphicsmapresources() map buffer (you can use in cuda not gl)

cudagraphicsresourcegetmappedpointer() give device pointer buffer, pass the kernel.

cudagraphicsunmapresources() unmap buffer (you can use in gl, not cuda)


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -