|
|
|
|
|
|
|
|
|
|
static void UpdateRawImage(RawImage rawImage, XRCpuImage cpuImage) |
|
|
|
{ |
|
|
|
// Get the texture associated with the UI.RawImage that we wish to display on screen.
|
|
|
|
|
|
|
|
// If the texture hasn't yet been created, or if its dimensions have changed, (re)create the texture.
|
|
|
|
// Note: Although texture dimensions do not normally change frame-to-frame, they can change in response to
|
|
|
|
// a change in the camera resolution (for camera images) or changes to the quality of the human depth
|
|
|
|
// and human stencil buffers.
|
|
|
|
if (texture == null || texture.width != cpuImage.width || texture.height != cpuImage.height) |
|
|
|
{ |
|
|
|
texture = new Texture2D(cpuImage.width, cpuImage.height, cpuImage.format.AsTextureFormat(), false); |
|
|
|
|
|
|
// For display, we need to mirror about the vertical access.
|
|
|
|
|
|
|
|
// Get the Texture2D's underlying pixel buffer.
|
|
|
|
unsafe |
|
|
|
{ |
|
|
|
cpuImage.Convert(conversionParams, new IntPtr(rawTextureData.GetUnsafePtr()), rawTextureData.Length); |
|
|
|
} |
|
|
|
// Make sure the destination buffer is large enough to hold the converted data (they should be the same size)
|
|
|
|
Debug.Assert(rawTextureData.Length == cpuImage.GetConvertedDataSize(conversionParams.outputDimensions, conversionParams.outputFormat), |
|
|
|
"The Texture2D is not the same size as the converted data."); |
|
|
|
// Perform the conversion.
|
|
|
|
cpuImage.Convert(conversionParams, rawTextureData); |
|
|
|
|
|
|
|
// "Apply" the new pixel data to the Texture2D.
|
|
|
|
texture.Apply(); |
|
|
|
} |
|
|
|
|
|
|
|