saki4510t / UVC4UnityAndroid

UVC4UnityAndroid
Apache License 2.0
77 stars 19 forks source link

Trying to copy texture created with UVCManager ends in grey(empty) texture? #10

Closed eetteri closed 1 year ago

eetteri commented 1 year ago

First thanks for this great asset for UnityAndroid projects, really great.

I'm experiencing strange problem which I quite can't pin point. I have RawImage on my UI and my UVC device draws into it without problems. I am using the UVCDrawer prefab.

I need to also pass the video for some other processing and I'm trying to copy the texture data from RawImage into another one on update loop. Basicly like this

void Update() {
   targetTexture.SetPixels32((externalVideoRawImage.texture as Texture2D).GetPixels32());
   targetTexture.Apply();
}

For some reason I have not been able to copy the texture and I always end up light gray filled texture. If I swap eg. WebCamTexture as a source for RawImage, the texture copying above works fine.

So is this some quirk connected to Unity that I'm not grasping now or could this be related to UVC4UnityAndroid?

prakyath-07 commented 1 year ago

Hi, Did you find the solution for this?

eetteri commented 1 year ago

Actually yes. I was able to copy the texture onto another one on update loop by using

Graphics.CopyTexture(srcTexture, dstTexture)

where the dstTexture is initialized and set to RawImage at start. However I have another problem where I need to get raw bytes of the copied texture into a buffer with

NativeArray<byte> nativeByteArray = dstTexture.GetRawTextureData<byte>();

but that ends up with a buffer where all the values are 205. However this is a problem/bug/feature on Unity side and I'm exploring that still.

prakyath-07 commented 1 year ago

Thank you :) It worked