FNA-XNA / FNA

FNA - Accuracy-focused XNA4 reimplementation for open platforms
https://fna-xna.github.io/
2.65k stars 272 forks source link

Add Texture2D.GetDataPointerEXT #486

Open kg opened 7 months ago

kg commented 7 months ago

Without this, it's not possible to cleanly queue up texture readback operations to execute later, since GetData checks the size of T against the texture format, instead of checking the size of the buffer - so you can't read a Color texture into a byte[] even if it's big enough.

flibitijibibo commented 7 months ago

I might be misremembering but I thought this worked like SetData where byte[] was okay... are we just missing some math checks that exist in SetData?

kg commented 7 months ago

I might be misremembering but I thought this worked like SetData where byte[] was okay... are we just missing some math checks that exist in SetData?

The

    int elementSizeInBytes = MarshalHelper.SizeOf<T>();
    ValidateGetDataFormat(Format, elementSizeInBytes);

should reject an attempt to download a Color surface into a byte[], I think. IIRC the last time I tried it, it didn't work.

kg commented 2 months ago

Alternate proposal: Don't do this, instead we add GetDataPointerAsyncEXT/SetDataPointerAsyncEXT, which only work on the SDL_GPU backend. If we had those I'd use them instead