Hi,
I am building an output buffer via CUDA and I am trying to get a Rhino image buffer data to “see” this data. As I understand the most straight-away but perhaps slow method is to copy pixel by pixel from the one buffer (CUDA device) to the Rhino buffer.
for (int i = 0; i < num_pixels; ++i) {
const uchar4 pixel = cuda_buffer_data[i];
const int x = i % width;
const int y = (num_pixels - i - 1) / width; // Reverse the vertical coordinate due to top-down pixel ordering
float fColor[4];
fColor[0] = pixel.x;
fColor[1] = pixel.y;
fColor[2] = pixel.z;
fColor[3] = pixel.w;
// Assuming pChannel is a color channel
pChannel->SetValue(x, y, ComponentOrder::RGBA, fColor); // Set the pixel value in the Rhino SDK image buffer
}
What is that data format for cuda_buffer_data? If it’s not 8 bits per channel, then there is no way to do this any differently than what you show here…because the conversion is going to obviously have to take place in order to pack things into a 32bit, 4 channel format.
If cuda_buffer_data is already in a packed 32bit, 4 channel format, then you could just move it all into a CRhinoDib, making sure size and alignments are all correct (based on Width and Height), and then use the display pipeline’s method CopyToBackBuffer(dib) …again assuming cuda_buffer_data size and format all matches the current back buffer’s size and format.
Just know that on Windows this will require that you store things into cuda_buffer_data in BGRA byte order.
If this isn’t what you’re requesting, then I’ll need more information and specifics.