Hi,
As I’m waiting for RH-64925 to be resolved I’ve started testing the rhinocommon implementation of a RenderWindow viewer instead of the C++ SDK.
Now I’m trying to find the best way to set the frame buffer from an rgba float4 array in C++.
Looking at the API, the RenderWindow.Channel.SetValues and dotNET sample, this feels like a reasonable implementation:
Scene.RenderFrame(); // render image to temporary buffer in C++
var size = rw.Size();
IntPtr ptr = Marshal.AllocHGlobal(sizeof(float) * size.Width * size.Height * 4);
Scene.SetFrameBuffer(frameBuffer); // copy framebuffer to allocated ptr
using (var channel = rw.OpenChannel(RenderWindow.StandardChannels.RGBA))
{
channel.SetValues(System.Drawing.Rectangle.FromLTRB(0, 0, size.Width, size.Height), rw.Size(), new PixelBuffer(ptr));
}
But it renders black.
I’ve verified that my values are in the IntPtr through:
float[] frameBuffer = new float[rw.Size().Width * rw.Size().Height * 4];
Marshal.Copy(ptr, frameBuffer, 0, frameBuffer.Length);
I’ve also looped through the buffer like so:
for (var x = 0; x < size.Width; x++)
{
for (var y = 0; y < size.Height; y++)
{
int loc = (y * size.Width + x) * 4;
channel.SetValue(x, y, Color4f.FromArgb(frameBuffer[loc + 3], frameBuffer[loc], frameBuffer[loc + 1], frameBuffer[ loc + 2]));
}
if (_shutdown) break;
}
which does show the image but it’s obviously very slow.
Any recommendation on the ideal workflow for this?