Texture2D SetData with 3D array?

`
// u8 is a System.Byte
public u8[,] ScreenPixels { get; set; }
Screen = new u8[144, 160, 3];

// later the RGB value of each pixel is set
Screen[y, x, 0] = pixelColor.R;
Screen[y, x, 1] = pixelColor.G;
Screen[y, x, 2] = pixelColor.B;
`

The screen array represents a screen of 144 high, 160 wide and each pixel has an r, g, b associated with it.

I want to set the Screen 3D array data to the assigned texture. I’ve tried SetData<u8> and SetData<u8[,,]> the first case isn’t compatible, and the second case shows “cannot convert from u8[,] to u8[][,]” - as if it’s expecting a 1d array of 3d arrays.

Is what I’m trying to do possible? Guidance would be most appreciated. Thank you

I’d use something like:
Byte[] Screen = new Color[Width * Height * 3];
And loop Ly, x, and r,g,b with equivalent to the [,] like this:
Screen[yWidth + x3 + 0] = pixelColor.R;
Screen[yWidth + x3 + 1] = pixelColor.G;
Screen[yWidth + x3 + 2] = pixelColor.B;
destRect = new Rectangle(0, 0, Width, Height);
packTex.SetData< Byte>(0, destRect, Screen, 0, Width * Height * 3);

I don’t know how to do this or even if what he is trying to do is possible like im pretty sure texture2d can have mipmapping but this is a little bit of a different thing he is trying to do i think.

but to convert a 3d color index into a 1d index you do it like so.
setdata will take color arrays its just more confusing to add by bytes.

int index = (Width * Height * level) + y * Width + x;

to de-convert off the top of my head.

int level = (int)( index / (Width * Height) );
int y = (int)( (index - (Width * Height * level)) / Width );
int x = (int)( (index - (Width * Height * level)) - y * Width );

I just realized - you’re missing the alpha channel so it’s not going to be the right surface format data like Color is normally. Might wanna add a dummy value into the alpha. (I’m assuming you’re packing for data storage purposes)