/// <summary> /// /// </summary> public override void CreateDisplayResources() { base.CreateDisplayResources(); backbufferColor = new RenderTarget2D(device, swapChain.GetBackBuffer <D3D.Texture2D>(0)); oculusSwapChains = new OculusTextureSwapChain[2]; eyeTextures = new EyeTexture[2]; for (int i = 0; i < 2; i++) { OVR.Sizei idealSize = hmd.GetFovTextureSize((OVR.EyeType)i, hmd.DefaultEyeFov[i], 1.0f); oculusSwapChains[i] = hmd.CreateTextureSwapChain(d3dDevice.NativePointer, idealSize.Width, idealSize.Height); eyeTextures[i] = new EyeTexture(device, oculusSwapChains[i]) { DepthStencil2D = new DepthStencil2D(device, DepthFormat.D24S8, idealSize.Width, idealSize.Height), Viewport = new Viewport(0, 0, idealSize.Width, idealSize.Height), ViewportSize = new OVR.Recti(new OVR.Vector2i(0, 0), new OVR.Sizei { Width = idealSize.Width, Height = idealSize.Height }) }; //eyeTextures[i].DepthBufferDescription = new Texture2DDescription { // Width = idealSize.Width, // Height = idealSize.Height, // ArraySize = 1, // MipLevels = 1, // Format = Format.D32_Float, // CpuAccessFlags = CpuAccessFlags.None, // Usage = ResourceUsage.Default, // BindFlags = BindFlags.DepthStencil, // OptionFlags = ResourceOptionFlags.None, // SampleDescription = new SampleDescription(1, 0) //}; } hmd.CreateMirrorTexture(d3dDevice.NativePointer, new OVR.MirrorTextureDesc { Format = OVR.TextureFormat.OVR_FORMAT_R8G8B8A8_UNORM_SRGB, Width = backbufferColor.Width, Height = backbufferColor.Height, MiscFlags = OVR.TextureMiscFlags.None }, out mirrorTexture); layers = new Layers(); layerEyeFov = layers.AddLayerEyeFov(); hmd.SetTrackingOriginType(OVR.TrackingOrigin.EyeLevel); frameIndex = 0; Game.RenderSystem.Width = eyeTextures[0].Viewport.Width; Game.RenderSystem.Height = eyeTextures[0].Viewport.Height; }
public WindowsRtMediaPlayer(MediaPlayer.OptionsWindowsUWP options) : base() { _playerDescription = "WinRT"; _use10BitTextures = options.use10BitTextures; _useLowLiveLatency = options.useLowLiveLatency; for (int i = 0; i < _eyeTextures.Length; i++) { _eyeTextures[i] = new EyeTexture(); } }
public void SetTexture(EyeTexture tex) { if (tex == EyeTexture.Normal) { eye.gameObject.GetComponent <MeshRenderer>().material.mainTexture = normal; } else if (tex == EyeTexture.Cross) { eye.gameObject.GetComponent <MeshRenderer>().material.mainTexture = cross; } }
private void Update_Textures() { // See if there is a new frame ready { System.IntPtr texturePointerLeft = System.IntPtr.Zero; System.IntPtr texturePointerRight = System.IntPtr.Zero; ulong frameTimeStamp = 0; int width, height; if (Native.GetLatestFrame(_playerInstance, out texturePointerLeft, out texturePointerRight, out frameTimeStamp, out width, out height)) { bool isFrameUpdated = false; bool isNewFrameTime = (frameTimeStamp > _frameTimeStamp) || (_frameTimeStamp == 0 && frameTimeStamp == 0); for (int i = 0; i < _eyeTextures.Length; i++) { EyeTexture eyeTexture = _eyeTextures[i]; System.IntPtr texturePointer = texturePointerLeft; if (i == 1) { texturePointer = texturePointerRight; } bool isNewFrameSpecs = (eyeTexture.texture != null && (texturePointer == IntPtr.Zero || eyeTexture.texture.width != width || eyeTexture.texture.height != height)); //Debug.Log("tex? " + i + " " + width + " " + height + " " + (eyeTexture.texture != null) + " " + texturePointer.ToString() + " " + frameTimeStamp); // Check whether the latest frame is newer than the one we got last time if (isNewFrameTime || isNewFrameSpecs) { if (isNewFrameSpecs) { eyeTexture.Dispose(); // TODO: blit from the old texture to the new texture before destroying? } /// Switch to the latest texture pointer if (eyeTexture.texture != null) { // TODO: check whether UpdateExternalTexture resets the sampling filter to POINT - it seems to in Unity 5.6.6 if (eyeTexture.nativePointer != texturePointer) { eyeTexture.texture.UpdateExternalTexture(texturePointer); eyeTexture.nativePointer = texturePointer; } } else { if (texturePointer != IntPtr.Zero) { eyeTexture.texture = Texture2D.CreateExternalTexture(width, height, TextureFormat.RGBA32, false, false, texturePointer); if (eyeTexture.texture != null) { eyeTexture.texture.name = "AVProVideo"; eyeTexture.nativePointer = texturePointer; ApplyTextureProperties(eyeTexture.texture); } else { Debug.LogError("[AVProVideo] Failed to create texture"); } } } isFrameUpdated = true; } } if (isFrameUpdated) { _frameTimeStamp = frameTimeStamp; } } } }
/// <summary> /// /// </summary> public override void CreateDisplayResources() { base.CreateDisplayResources(); backbufferColor = new RenderTarget2D(device, swapChain.GetBackBuffer<D3D.Texture2D>(0)); oculusSwapChains = new OculusTextureSwapChain[2]; eyeTextures = new EyeTexture[2]; for (int i = 0; i < 2; i++) { OVR.Sizei idealSize = hmd.GetFovTextureSize((OVR.EyeType)i, hmd.DefaultEyeFov[i], 1.0f); oculusSwapChains[i] = hmd.CreateTextureSwapChain(d3dDevice.NativePointer, idealSize.Width, idealSize.Height); eyeTextures[i] = new EyeTexture(device, oculusSwapChains[i]) { DepthStencil2D = new DepthStencil2D(device, DepthFormat.D24S8, idealSize.Width, idealSize.Height), Viewport = new Viewport(0, 0, idealSize.Width, idealSize.Height), ViewportSize = new OVR.Recti(new OVR.Vector2i(0, 0), new OVR.Sizei {Width = idealSize.Width, Height = idealSize.Height}) }; //eyeTextures[i].DepthBufferDescription = new Texture2DDescription { // Width = idealSize.Width, // Height = idealSize.Height, // ArraySize = 1, // MipLevels = 1, // Format = Format.D32_Float, // CpuAccessFlags = CpuAccessFlags.None, // Usage = ResourceUsage.Default, // BindFlags = BindFlags.DepthStencil, // OptionFlags = ResourceOptionFlags.None, // SampleDescription = new SampleDescription(1, 0) //}; } hmd.CreateMirrorTexture(d3dDevice.NativePointer, new OVR.MirrorTextureDesc { Format = OVR.TextureFormat.OVR_FORMAT_R8G8B8A8_UNORM_SRGB, Width = backbufferColor.Width, Height = backbufferColor.Height, MiscFlags = OVR.TextureMiscFlags.None }, out mirrorTexture); layers = new Layers(); layerEyeFov = layers.AddLayerEyeFov(); hmd.SetTrackingOriginType(OVR.TrackingOrigin.EyeLevel); frameIndex = 0; Game.RenderSystem.Width = eyeTextures[0].Viewport.Width; Game.RenderSystem.Height = eyeTextures[0].Viewport.Height; }