Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Resolved Is there way to get Texture2DArray.GetPixelData() for all whole Array?

Discussion in 'General Graphics' started by nomadshiba, Sep 18, 2022.

  1. nomadshiba

    nomadshiba

    Joined:
    Jun 22, 2015
    Posts:
    27
    I'm trying to create a texture using Unity.Jobs, but when i try to use GetPixelData(), it requires me to enter an index for the element. So I can't pass the data to a IJobParallelFor in one array.

    Is there way to get a NativeArray<Color32> for the whole Texture2DArray, not just the element slice, so i can write to it in a Job?
     
  2. nomadshiba

    nomadshiba

    Joined:
    Jun 22, 2015
    Posts:
    27
    Did something like this but doesnt work.
    Code (CSharp):
    1. var data = texture2dArray.GetPixelData<Color32>(0, 0);
    2. NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<Color32>(NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(data), data.Length * texture2dArray.depth, Allocator.None)
    If i have to skip some bytes between elements, i can do that inside the job. I just need to know how to do it somehow.
     
    Last edited: Sep 18, 2022
  3. nomadshiba

    nomadshiba

    Joined:
    Jun 22, 2015
    Posts:
    27
    someone told me, they are not sequentially, well then i cant do this i guess
     
  4. nomadshiba

    nomadshiba

    Joined:
    Jun 22, 2015
    Posts:
    27
    ok managed to do it by making a NativeArray of NativeArray pointers.
    If someone else has the same problem i can give an example.