protected virtual void Dispose(bool disposing) { if (!disposing) { return; } for (int i = 0; i < this._textures.Length; ++i) { _textures[i].RTView.Dispose(); _textures[i].SRView.Dispose(); if (_textures[i].DepthBuffer != null) { _textures[i].DepthBuffer.Dispose(); } if (_textures[i].DepthStencilView != null) { _textures[i].DepthStencilView.Dispose(); } } _textures = null; _currentIndex = -1; _size = new Sizei(); _viewport = new ViewportF(); _ovr = null; _sessionPtr = IntPtr.Zero; _textureSwapChainPtr = IntPtr.Zero; }
private void ConfigureEyeDesc(OVREye eye) { #if !UNITY_ANDROID || UNITY_EDITOR HmdDesc desc = OVRManager.capiHmd.GetDesc(); FovPort fov = desc.DefaultEyeFov[(int)eye]; fov.LeftTan = fov.RightTan = Mathf.Max(fov.LeftTan, fov.RightTan); fov.UpTan = fov.DownTan = Mathf.Max(fov.UpTan, fov.DownTan); // Configure Stereo settings. Default pixel density is one texel per pixel. float desiredPixelDensity = 1f; Sizei texSize = OVRManager.capiHmd.GetFovTextureSize((Ovr.Eye)eye, fov, desiredPixelDensity); float fovH = 2f * Mathf.Rad2Deg * Mathf.Atan(fov.LeftTan); float fovV = 2f * Mathf.Rad2Deg * Mathf.Atan(fov.UpTan); eyeDescs[(int)eye] = new EyeRenderDesc() { resolution = texSize.ToVector2(), fov = new Vector2(fovH, fovV) }; #else eyeDescs[(int)eye] = new EyeRenderDesc() { resolution = new Vector2(1024, 1024), fov = new Vector2(90, 90) }; #endif }
private void OnCalibrate(Sizei resolution, Matrix3x3f intrinsic, Vector5f distorsion) { /* * var m = new Matrix4x4(); * for (int r = 0; r < 3; ++r) * { * for (int c = 0; c < 3; ++c) * { * m[r, c] = intrinsic.coeff(r, c); * } * } * Debug.Log(m); * Debug.Log(resolution.width); * Debug.Log(resolution.height); */ var fY = intrinsic.coeff(1, 1) * 2 / resolution.height; var fX = intrinsic.coeff(0, 0) * 2 / resolution.width; //var fovY = CameraUtility.Focal2Fov(fY, resolution.height); //var fovX = CameraUtility.Focal2Fov(fX, resolution.width); //camera.fieldOfView = fovY; //CameraUtility.ApplyProjectionMatrix() var projectionMatrix = Perspective(fX, fY, camera.nearClipPlane, camera.farClipPlane); camera.projectionMatrix = projectionMatrix; MoveVideoPlane(); }
public GameWindow(Sizei size, string title, bool fullscreen, Monitor monitor, GameWindow share) : this() { // Set default window hints GLFW.GLFW.DefaultWindowHints(); GLFW.GLFW.WindowHint(GLFW.GLFW.Hint.Resizable, false); GLFW.GLFW.WindowHint(GLFW.GLFW.Hint.AutoIconify, true); GLFW.GLFW.WindowHint(GLFW.GLFW.Hint.Doublebuffer, true); if (GameSettings.MultisampleEnabled) { GLFW.GLFW.WindowHint(GLFW.GLFW.Hint.Samples, GameSettings.MultisampleLevel); } else { GLFW.GLFW.WindowHint(GLFW.GLFW.Hint.Samples, 0); } Handle = GLFW.GLFW.CreateWindow(size.Width, size.Height, title, (GameSettings.GameWindowFullscreenMode) ? monitor.Handle : Monitor.None.Handle, (share != null) ? share.Handle : None.Handle); if (!Handle) { GLFW.GLFW.Shutdown(); Environment.Exit(-1); } // Enable V-Sync if (GameSettings.VSyncEnabled) { GLFW.GLFW.SwapInterval(GameSettings.VSyncInterval); } }
public void Session_GetFovTextureSize() { IntPtr sessionPtr = CreateSession(); Assert.AreNotEqual(IntPtr.Zero, sessionPtr); FovPort fieldOfView = new FovPort(); fieldOfView.DownTan = (float)Math.Tan(0.523598776); // 0.523598776 radians = 30 degrees. fieldOfView.UpTan = (float)Math.Tan(0.523598776); // 0.523598776 radians = 30 degrees. fieldOfView.LeftTan = (float)Math.Tan(0.785398163); // 0.785398163 radians = 45 degrees. fieldOfView.RightTan = (float)Math.Tan(0.785398163); // 0.785398163 radians = 45 degrees. Sizei size = OVR.GetFovTextureSize(sessionPtr, EyeType.Left, fieldOfView, 1.0f); //Assert.AreEqual(1099, size.Width); //Assert.AreEqual(635, size.Height); //Assert.AreEqual(1586, size.Width); //Assert.AreEqual(915, size.Height); // The following is reported on 1.17: Assert.AreEqual(1600, size.Width); Assert.AreEqual(928, size.Height); }
public virtual void setResolution(Sizei resolution) { solar_api_input_devicesPINVOKE.ICamera_setResolution(swigCPtr, Sizei.getCPtr(resolution)); if (solar_api_input_devicesPINVOKE.SWIGPendingException.Pending) { throw solar_api_input_devicesPINVOKE.SWIGPendingException.Retrieve(); } }
public virtual Sizei getResolution() { Sizei ret = new Sizei(solar_api_input_devicesPINVOKE.ICamera_getResolution(swigCPtr), true); if (solar_api_input_devicesPINVOKE.SWIGPendingException.Pending) { throw solar_api_input_devicesPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
private void OnCalibrate(Sizei resolution, Matrix3x3f intrinsic, Vector5f distorsion) { var fY = intrinsic.coeff(1, 1); var fovY = CameraUtility.Focal2Fov(fY, resolution.height); var fX = intrinsic.coeff(0, 0); var aspect = (fY / resolution.height) / (fX / resolution.width); var projectionMatrix = Matrix4x4.Perspective(fovY, aspect, camera.nearClipPlane, camera.farClipPlane); CameraUtility.ApplyProjectionMatrix(camera, projectionMatrix); }
private void RefreshSize() { var viewport = this.graphicsDevice.Viewport; var size = new Sizei((uint)viewport.Width, (uint)viewport.Height); if (this.lastSize == size) { return; } this.lastSize = size; this.view.SetSize((ushort)viewport.Width, (ushort)viewport.Height); }
/// <summary> /// Creates a simple Direct3D graphics engine, used in unit tests. /// </summary> /// <param name="session">Existing session used to retrieve the size of the test engine.</param> /// <returns>Created test engine.</returns> /// <remarks>Remember to dispose the created test engine, after use.</remarks> private TestEngine CreateTestEngine(IntPtr session) { // Define field of view (This is used for both left and right eye). FovPort fieldOfView = new FovPort(); fieldOfView.DownTan = (float)Math.Tan(0.523598776); // 0.523598776 radians = 30 degrees. fieldOfView.UpTan = (float)Math.Tan(0.523598776); // 0.523598776 radians = 30 degrees. fieldOfView.LeftTan = (float)Math.Tan(0.785398163); // 0.785398163 radians = 45 degrees. fieldOfView.RightTan = (float)Math.Tan(0.785398163); // 0.785398163 radians = 45 degrees. EyeRenderDesc renderDescLeft = OVR.GetRenderDesc(session, EyeType.Left, fieldOfView); EyeRenderDesc renderDescRight = OVR.GetRenderDesc(session, EyeType.Left, fieldOfView); // Determine texture size matching the field of view. Sizei sizeLeft = OVR.GetFovTextureSize(session, EyeType.Left, fieldOfView, 1.0f); Sizei sizeRight = OVR.GetFovTextureSize(session, EyeType.Right, fieldOfView, 1.0f); TestEngine testEngine = new TestEngine(sizeLeft.Width + sizeRight.Width, sizeLeft.Height); return(testEngine); }
// -------------------- /// <summary> /// Load game settings from the configuration file. /// </summary> static GameSettings() { int _int1, _int2; // Parse the config file IniParser config = new IniParser("game.ini"); // Get parsed values if (int.TryParse(config.RawResult["MultisampleEnabled"], out _int1)) { MultisampleEnabled = _int1 == 1; } else { MultisampleEnabled = false; } if (int.TryParse(config.RawResult["MultisampleLevel"], out _int1)) { MultisampleLevel = _int1; } else { MultisampleLevel = 0; } if (int.TryParse(config.RawResult["VSyncEnabled"], out _int1)) { VSyncEnabled = _int1 == 1; } else { VSyncEnabled = false; } if (int.TryParse(config.RawResult["VSyncInterval"], out _int1)) { VSyncInterval = _int1; } else { VSyncInterval = 0; } if (int.TryParse(config.RawResult["Width"], out _int1) && int.TryParse(config.RawResult["Height"], out _int2)) { GameWindowSize = new Sizei(_int1, _int2); } else { GameWindowSize = Sizei.Zero; } if (int.TryParse(config.RawResult["FullscreenMode"], out _int1)) { GameWindowFullscreenMode = _int1 == 1; } else { GameWindowFullscreenMode = false; } }
/// <summary> /// Creates a framebuffer object and its associated resources (depth and frame buffers). /// </summary> /// <param name="size">Specifies the size (in pixels) of the framebuffer and its associated buffers.</param> /// <param name="attachment">Specifies the attachment to use for the frame buffer.</param> /// <param name="format">Specifies the internal pixel format for the frame buffer.</param> /// <param name="mipmaps">Specifies whether to build mipmaps after the frame buffer is unbound.</param> public FBO(Sizei size, FramebufferAttachment attachment = FramebufferAttachment.ColorAttachment0, PixelInternalFormat format = PixelInternalFormat.Rgba8, bool mipmaps = true, bool renderbuffer = true, bool multisampled = false) : this(size, new FramebufferAttachment[] { attachment }, format, mipmaps) { }
/// <summary> /// Creates a framebuffer object and its associated resources (depth and frame buffers). /// </summary> /// <param name="size">Specifies the size (in pixels) of the framebuffer and its associated buffers.</param> /// <param name="attachments">Specifies the attachments to use for the frame buffer.</param> /// <param name="format">Specifies the internal pixel format for the frame buffer.</param> /// <param name="mipmaps">Specifies whether to build mipmaps after the frame buffer is unbound.</param> /// <param name="filterType">Specifies the type of filtering to apply to the frame buffer when bound as a texture.</param> /// <param name="pixelType">Specifies the pixel type to use for the underlying format of the frame buffer.</param> public FBO(Sizei size, FramebufferAttachment[] attachments, PixelInternalFormat format, bool mipmaps = false, TextureParameter filterType = TextureParameter.Linear, PixelType pixelType = PixelType.UnsignedByte, bool renderbuffer = true, bool multisampled = false) { Size = size; Attachments = attachments; Format = format; MipMaps = mipmaps; Multisampled = multisampled; // First create the framebuffer BufferID = GL.GenFramebuffer(); GL.BindFramebuffer(FramebufferTarget.Framebuffer, BufferID); _attachementMap = new Dictionary <FramebufferAttachment, uint>(); TextureTarget textureTarget = Multisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D; if (Attachments.Length == 1 && Attachments[0] == FramebufferAttachment.DepthAttachment) { // if this is a depth attachment only TextureID = new uint[] { GL.GenTexture() }; GL.BindTexture(textureTarget, TextureID[0]); if (Multisampled) { GL.TexImage2DMultisample(textureTarget, GameSettings.MultisampleLevel, Format, Size.Width, Size.Height, true); } else { GL.TexImage2D(textureTarget, 0, Format, Size.Width, Size.Height, 0, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero); GL.TexParameteri(textureTarget, TextureParameterName.TextureMagFilter, TextureParameter.Nearest); GL.TexParameteri(textureTarget, TextureParameterName.TextureMinFilter, TextureParameter.Nearest); GL.TexParameteri(textureTarget, TextureParameterName.TextureWrapS, TextureParameter.ClampToEdge); GL.TexParameteri(textureTarget, TextureParameterName.TextureWrapT, TextureParameter.ClampToEdge); } GL.BindTexture(textureTarget, 0); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, textureTarget, TextureID[0], 0); GL.DrawBuffer(DrawBufferMode.None); GL.ReadBuffer(ReadBufferMode.None); _attachementMap.Add(FramebufferAttachment.DepthAttachment, 0); } else { // Create n texture buffers (known by the number of attachments) TextureID = new uint[Attachments.Length]; GL.GenTextures(Attachments.Length, TextureID); // Bind the n texture buffers to the framebuffer for (int i = 0; i < Attachments.Length; i++) { GL.BindTexture(textureTarget, TextureID[i]); if (Multisampled) { GL.TexImage2DMultisample(textureTarget, GameSettings.MultisampleLevel, Format, Size.Width, Size.Height, true); } else { GL.TexImage2D(textureTarget, 0, Format, Size.Width, Size.Height, 0, PixelFormat.Rgba, pixelType, IntPtr.Zero); if (MipMaps) { GL.TexParameteri(textureTarget, TextureParameterName.TextureMagFilter, TextureParameter.Linear); GL.TexParameteri(textureTarget, TextureParameterName.TextureMinFilter, TextureParameter.LinearMipMapLinear); GL.GenerateMipmap(Multisampled ? GenerateMipmapTarget.Texture2DMultisample : GenerateMipmapTarget.Texture2D); } else { GL.TexParameteri(textureTarget, TextureParameterName.TextureMagFilter, filterType); GL.TexParameteri(textureTarget, TextureParameterName.TextureMinFilter, filterType); } } GL.BindTexture(textureTarget, 0); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, Attachments[i], textureTarget, TextureID[i], 0); _attachementMap.Add(Attachments[i], TextureID[i]); } if (renderbuffer) { // Create and attach a 24-bit depth buffer to the framebuffer DepthID = GL.GenRenderbuffer(); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, DepthID); if (Multisampled) { GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, GameSettings.MultisampleLevel, PixelInternalFormat.Depth32fStencil8, Size.Width, Size.Height); } else { GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, PixelInternalFormat.Depth24Stencil8, Size.Width, Size.Height); } GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, RenderbufferTarget.Renderbuffer, DepthID); //GL.TexParameteri(textureTarget, TextureParameterName.TextureMagFilter, TextureParameter.Nearest); //GL.TexParameteri(textureTarget, TextureParameterName.TextureMinFilter, TextureParameter.Nearest); //GL.TexParameteri(textureTarget, TextureParameterName.TextureWrapS, TextureParameter.ClampToEdge); //GL.TexParameteri(textureTarget, TextureParameterName.TextureWrapT, TextureParameter.ClampToEdge); //GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, textureTarget, DepthID, 0); //GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.StencilAttachment, textureTarget, DepthID, 0); _attachementMap.Add(FramebufferAttachment.DepthStencilAttachment, DepthID); //_attachementMap.Add(FramebufferAttachment.StencilAttachment, DepthID); } } // Build the framebuffer and check for errors FramebufferStatus status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); if (status != FramebufferStatus.FramebufferComplete) { Console.WriteLine("Frame buffer did not compile correctly. Returned {0}, glError: {1}", status.ToString(), GL.GetError().ToString()); } // Make sure this framebuffer is not modified from outside GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); // Register this framebuffer as a disposable object ResourcesManager.AddDisposableResource(this); }
/// <summary> /// Converts a plain C# Sizei to a Unity Vector2. /// </summary> /// <returns>The size as a Unity Vector2.</returns> /// <param name="size">The size as a C# Sizei.</param> public static Vector2 ToVector2(this Sizei size) { return(new Vector2(size.w, size.h)); }
public void Session_SubmitFrame() { IntPtr sessionPtr = CreateSession(); Assert.AreNotEqual(IntPtr.Zero, sessionPtr); // Define field of view (This is used for both left and right eye). FovPort fieldOfView = new FovPort(); fieldOfView.DownTan = (float)Math.Tan(0.523598776); // 0.523598776 radians = 30 degrees. fieldOfView.UpTan = (float)Math.Tan(0.523598776); // 0.523598776 radians = 30 degrees. fieldOfView.LeftTan = (float)Math.Tan(0.785398163); // 0.785398163 radians = 45 degrees. fieldOfView.RightTan = (float)Math.Tan(0.785398163); // 0.785398163 radians = 45 degrees. EyeRenderDesc renderDescLeft = OVR.GetRenderDesc(sessionPtr, EyeType.Left, fieldOfView); EyeRenderDesc renderDescRight = OVR.GetRenderDesc(sessionPtr, EyeType.Left, fieldOfView); var viewScaleDesc = new ViewScaleDesc(); viewScaleDesc.HmdToEyePose0 = renderDescLeft.HmdToEyePose; viewScaleDesc.HmdToEyePose1 = renderDescRight.HmdToEyePose; viewScaleDesc.HmdSpaceToWorldScaleInMeters = 1; // Determine texture size matching the field of view. Sizei sizeLeft = OVR.GetFovTextureSize(sessionPtr, EyeType.Left, fieldOfView, 1.0f); Sizei sizeRight = OVR.GetFovTextureSize(sessionPtr, EyeType.Right, fieldOfView, 1.0f); var hmdToEyeViewOffset = new Vector3f[2]; var poses = new Posef[2]; double sensorSampleTime; hmdToEyeViewOffset[0].X = -0.1f; hmdToEyeViewOffset[1].X = 0.1f; OVR.GetEyePoses(sessionPtr, 0, true, hmdToEyeViewOffset, ref poses, out sensorSampleTime); // Create a set of layers to submit. LayerEyeFov layer = new LayerEyeFov(); layer.Header.Type = LayerType.EyeFov; Result result; using (TestEngine testEngine = CreateTestEngine(sessionPtr)) { try { // Create a texture for the left eye. layer.ColorTextureLeft = CreateTextureSwapChain(sessionPtr, testEngine); layer.ViewportLeft.Position = new Vector2i(0, 0); layer.ViewportLeft.Size = sizeLeft; layer.FovLeft = fieldOfView; layer.RenderPoseLeft = poses[0]; // Create a texture for the right eye. layer.ColorTextureRight = CreateTextureSwapChain(sessionPtr, testEngine); layer.ViewportRight.Position = new Vector2i(0, 0); layer.ViewportRight.Size = sizeLeft; layer.FovRight = fieldOfView; layer.RenderPoseRight = poses[1]; // The created texture swap chain must be committed to the Oculus SDK, before using it in the // call to ovr_SubmitFrame, otherwise ovr_SubmitFrame will fail. result = OVR.CommitTextureSwapChain(sessionPtr, layer.ColorTextureLeft); Assert.IsTrue(result >= Result.Success); result = OVR.CommitTextureSwapChain(sessionPtr, layer.ColorTextureRight); Assert.IsTrue(result >= Result.Success); // SubmitFrame requires pointer to an array of pointers to Layer objects var layerPointers = new IntPtr[1]; GCHandle layerHandle = GCHandle.Alloc(layer, GCHandleType.Pinned); GCHandle layerPointersHandle = GCHandle.Alloc(layerPointers, GCHandleType.Pinned); layerPointers[0] = layerHandle.AddrOfPinnedObject(); result = OVR.SubmitFrame(sessionPtr, 0L, IntPtr.Zero, layerPointersHandle.AddrOfPinnedObject(), 1); Assert.IsTrue(result >= Result.Success); layerPointersHandle.Free(); layerHandle.Free(); } finally { if (layer.ColorTextureLeft != IntPtr.Zero) { OVR.DestroyTextureSwapChain(sessionPtr, layer.ColorTextureLeft); } if (layer.ColorTextureRight != IntPtr.Zero) { OVR.DestroyTextureSwapChain(sessionPtr, layer.ColorTextureRight); } } } }
public OculusTextureSwapChain(OvrWrap ovr, IntPtr sessionPtr, SharpDX.Direct3D11.Device device, EyeType eye, Format format, Sizei size, bool createDepthStencilView = false, bool isDebugDevice = false) { _ovr = ovr; _sessionPtr = sessionPtr; _size = size; _viewportSize = size; _viewport = new ViewportF(0.0f, 0.0f, (float)size.Width, (float)size.Height); Format srgbFormat = GetSRgbFormat(format); TextureFormat textureFormat = SharpDXHelpers.GetTextureFormat(srgbFormat); TextureSwapChainDesc swapChainDesc = new TextureSwapChainDesc() { ArraySize = 1, BindFlags = TextureBindFlags.DX_RenderTarget, Format = textureFormat, Height = _size.Height, MipLevels = 1, MiscFlags = TextureMiscFlags.DX_Typeless, SampleCount = 1, Width = _size.Width }; Texture2DDescription description1 = new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.DepthStencil, CpuAccessFlags = CpuAccessFlags.None, Format = Format.R24G8_Typeless, Height = _size.Height, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, Width = _size.Width }; ShaderResourceViewDescription description2 = new ShaderResourceViewDescription() { Format = srgbFormat, Dimension = ShaderResourceViewDimension.Texture2D }; description2.Texture2D.MipLevels = 1; // Create a texture swap chain, which will contain the textures to render to, for the current eye. var result = _ovr.CreateTextureSwapChainDX(_sessionPtr, device.NativePointer, ref swapChainDesc, out _textureSwapChainPtr); if (result < Ab3d.OculusWrap.Result.Success) { var lastError = _ovr.GetLastErrorInfo(); throw new OvrException("Error creating Oculus TextureSwapChain: " + lastError.ErrorString, lastError.Result); } int length; result = _ovr.GetTextureSwapChainLength(_sessionPtr, _textureSwapChainPtr, out length); if (result < Ab3d.OculusWrap.Result.Success) { var lastError = _ovr.GetLastErrorInfo(); throw new OvrException("Failed to retrieve the number of buffers of the created swap chain: " + lastError.ErrorString, lastError.Result); } _textures = new TextureItem[length]; for (int index = 0; index < length; ++index) { IntPtr bufferPtr; result = _ovr.GetTextureSwapChainBufferDX(_sessionPtr, _textureSwapChainPtr, index, typeof(Texture2D).GUID, out bufferPtr); if (result < Ab3d.OculusWrap.Result.Success) { var lastError = _ovr.GetLastErrorInfo(); throw new OvrException("Failed to retrieve a texture from the created swap chain: " + lastError.ErrorString, lastError.Result); } Texture2D texture2D1 = new Texture2D(bufferPtr); Texture2D texture2D2 = null; DepthStencilView depthStencilView = null; if (createDepthStencilView) { texture2D2 = new Texture2D(device, description1); depthStencilView = new DepthStencilView(device, texture2D2, new DepthStencilViewDescription() { Flags = DepthStencilViewFlags.None, Dimension = DepthStencilViewDimension.Texture2D, Format = Format.D24_UNorm_S8_UInt }); } _textures[index] = new TextureItem() { Texture = texture2D1, TextureDescription = texture2D1.Description, DepthBuffer = texture2D2, DepthStencilView = depthStencilView, RTView = new RenderTargetView(device, texture2D1, new RenderTargetViewDescription() { Format = format, Dimension = RenderTargetViewDimension.Texture2D }), SRView = new ShaderResourceView(device, texture2D1, description2) }; if (isDebugDevice) { var eyeTextAndIndex = eye.ToString() + index.ToString(); _textures[index].Texture.DebugName = "OculusBackBuffer" + eyeTextAndIndex; _textures[index].RTView.DebugName = "OculusRT" + eyeTextAndIndex; _textures[index].SRView.DebugName = "OculusSR" + eyeTextAndIndex; _textures[index].DepthBuffer.DebugName = "OculusDepthBuffer" + eyeTextAndIndex; _textures[index].DepthStencilView.DebugName = "OculusDepthStencilView" + eyeTextAndIndex; } } }
public GameWindow(Sizei size, string title) : this(size, title, GameWindow.None) { }
/// <summary> /// Create a new game window /// </summary> /// <param name="size">The size of the window.</param> /// <param name="title">The title of the window.</param> /// <param name="fullscreen">Define if the window is in fullscreen mode on the primary <see cref="Monitor"/>.</param> public GameWindow(Sizei size, string title, bool fullscreen) : this(size, title, fullscreen, GameWindow.None) { }
public void ImportFrames(IEnumerable <string> fileNames, int padding) { var sprites = fileNames.Select(x => { var item = new SpriteItem { Name = Path.GetFileNameWithoutExtension(x), Sprite = new BitmapImage(new Uri(x)) }; item.AreaSize = item.Sprite.PixelWidth * item.Sprite.PixelHeight; return(item); }) .OrderByDescending(x => x.AreaSize) .ThenByDescending(x => x.Sprite.PixelWidth) .ToArray(); int width = 64, height = 64; bool increaser = false; bool failed = true; do { failed = false; var packer = new ArevaloRectanglePacker(width, height); foreach (var item in sprites) { int spriteWidth = item.Sprite.PixelWidth; int spriteHeight = item.Sprite.PixelHeight; Sizei size = new Sizei { Width = spriteWidth + padding, Height = spriteHeight + padding }; if (!packer.TryPack(size.Width, size.Height, out var origin)) { failed = true; break; } item.Rectangle = Recti.FromSize(origin.X, origin.Y, spriteWidth, spriteHeight); } if (failed) { if (increaser) { height *= 2; } else { width *= 2; } increaser = !increaser; } } while (failed); var dicFrames = Frames.ToDictionary(x => x.Name, x => x); var newFramesList = new List <Frame>(Frames.Capacity); foreach (var sprite in sprites) { if (dicFrames.TryGetValue(sprite.Name, out var frame)) { frame.Left = sprite.Rectangle.Left; frame.Top = sprite.Rectangle.Top; frame.Right = sprite.Rectangle.Right; frame.Bottom = sprite.Rectangle.Bottom; } else { frame = new Frame() { Name = sprite.Name, Left = sprite.Rectangle.Left, Top = sprite.Rectangle.Top, Right = sprite.Rectangle.Right, Bottom = sprite.Rectangle.Bottom, CenterX = sprite.Rectangle.Width / 2, CenterY = sprite.Rectangle.Height / 2 }; } newFramesList.Add(frame); } var drawingVisual = new DrawingVisual(); using (var drawingContext = drawingVisual.RenderOpen()) { foreach (var sprite in sprites) { drawingContext.DrawImage(sprite.Sprite, new Rect() { X = sprite.Rectangle.X, Y = sprite.Rectangle.Y, Width = sprite.Rectangle.Width, Height = sprite.Rectangle.Height }); } } var renderTargetBitmap = new RenderTargetBitmap(width, height, 96.0f, 96.0f, PixelFormats.Pbgra32); renderTargetBitmap.Render(drawingVisual); Texture = renderTargetBitmap; Frames.Clear(); Frames.AddRange(newFramesList.OrderBy(x => x.Name)); }
public GameWindow(Sizei size, string title, Monitor monitor) : this(size, title, monitor, GameWindow.None) { }
public GameWindow(Sizei size, string title, bool fullscreen, Monitor monitor) : this(size, title, fullscreen, monitor, GameWindow.None) { }