private void _UpdateTextureIfNeeded() { // If running in editor, updates background texture from Instant Preview only. Texture2D previewBackgroundTexture = BackgroundTexture; if (InstantPreviewManager.UpdateBackgroundTextureIfNeeded(ref previewBackgroundTexture)) { BackgroundTexture = previewBackgroundTexture; return; } IntPtr frameHandle = IntPtr.Zero; ExternApi.ArPresto_getFrame(ref frameHandle); if (frameHandle == IntPtr.Zero) { // This prevents using a texture that has not been filled out by ARCore. return; } int backgroundTextureId = NativeSession.FrameApi.GetCameraTextureName(); Texture2D texture2d = null; if (m_TextureIdToTexture2D.TryGetValue(backgroundTextureId, out texture2d)) { BackgroundTexture = texture2d; } }
private void _UpdateTextureIfNeeded() { // If running in editor, updates background texture from Instant Preview only. Texture2D previewBackgroundTexture = BackgroundTexture; if (InstantPreviewManager.UpdateBackgroundTextureIfNeeded(ref previewBackgroundTexture)) { BackgroundTexture = previewBackgroundTexture; return; } IntPtr frameHandle = IntPtr.Zero; ExternApi.ArPresto_getFrame(ref frameHandle); if (frameHandle == IntPtr.Zero) { // This prevents using a texture that has not been filled out by ARCore. return; } if (m_CameraTextureId == -1) { return; } BackgroundTexture = m_CameraTexture2D; }
private void _UpdateTextureIfNeeded() { // If running in editor, updates background texture from Instant Preview only. Texture2D previewBackgroundTexture = BackgroundTexture; if (InstantPreviewManager.UpdateBackgroundTextureIfNeeded(ref previewBackgroundTexture)) { BackgroundTexture = previewBackgroundTexture; return; } IntPtr frameHandle = IntPtr.Zero; ExternApi.ArPresto_getFrame(ref frameHandle); int backgroundTextureId = ExternApi.ArCoreUnity_getBackgroundTextureId(); if (frameHandle == IntPtr.Zero) { // This prevents using a texture that has not been filled out by ARCore. return; } else if (backgroundTextureId == -1) { return; } else if (BackgroundTexture != null && BackgroundTexture.GetNativeTexturePtr().ToInt32() == backgroundTextureId) { return; } else if (BackgroundTexture == null) { // The Unity-cached size and format of the texture (0x0, ARGB) is not the // actual format of the texture. This is okay because the texture is not // accessed by pixels, it is accessed with UV coordinates. BackgroundTexture = Texture2D.CreateExternalTexture(0, 0, TextureFormat.ARGB32, false, false, new IntPtr(backgroundTextureId)); return; } BackgroundTexture.UpdateExternalTexture(new IntPtr(backgroundTextureId)); }