Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCL – adding `float4` to `float4` array does nothing

Tags:

opencl

I have an OpenGL VBO containing cl_float4 vertices and I'm trying to update the VBO via OpenCL (I'm rendering the VBO contents as GL_POINTS). I pass cl_mem object representing the VBO as a kernel argument (the buffer is set as CL_MEM_READ_WRITE).

Unfortunately I cannot update one vertex's float4 data at once.

Following snippet doesn't work (i.e. the rendered points doesn't move):

__kernel void update(__global float4* particle_positions)
{
    int gid = get_global_id(0);

    particle_positions[gid] += float4(0.1, 0.1, 0.1, 0.0);
}

Following snippet does work (i.e. the rendered points move):

__kernel void update(__global float4* particle_positions)
{ 
    int gid = get_global_id(0);

    particle_positions[gid].x += 0.1;
    particle_positions[gid].y += 0.1;
    particle_positions[gid].z += 0.1;
}
like image 757
sarasvati Avatar asked Dec 11 '25 06:12

sarasvati


1 Answers

It is needed to be in paranthesis like

(float4)(1,1,1,1)

to have a float4 type. Or you can use other types too

(float4)((float2)(1,1),(float2)(1,1))

or mixed type

(float4)((float2)(1,1),1,1)

acts like an overloaded function.

like image 147
huseyin tugrul buyukisik Avatar answered Dec 12 '25 18:12

huseyin tugrul buyukisik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!