From 578bb546f3cc4bbbda1f0c26acf06d9f4b3d8800 Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 18 Jan 2019 01:00:07 -0500 Subject: [PATCH] bad attempt at implementing user crop area. need to do differently. needs to happen.. like... as soon as we get the video provider. --- .../DisplayManager/DisplayManager.cs | 56 +++++++++++++++++-- .../DisplayManager/Filters/Gui.cs | 27 +++++++-- 2 files changed, 73 insertions(+), 10 deletions(-) diff --git a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index fc7ccbc84b..b1fa0804f1 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -222,6 +222,30 @@ namespace BizHawk.Client.EmuHawk //add the first filter, encompassing output from the emulator core chain.AddFilter(fInput, "input"); + Size currSize = chain_insize; + + //apply user's choice of cropping + //NOTE 1. this is going to break the positioning of elements in lua + //we COULD change how this works to apply it at a different point; but let's wait for someone to ask for it + //we can offer "fix the lua script" as a response, as well, to rebuff them + //NOTE 2. this is an inefficient way of doing it. this could be done if we use 'art' everywhere instead of textures. + //then, we could adjust the uv coords and carry on, rather than doing this extra resolving step. + //Well.... not today + int cropX = Global.Config.DispCropLeft + Global.Config.DispCropRight; + int cropY = Global.Config.DispCropTop + Global.Config.DispCropBottom; + if (cropX != 0 || cropY != 0) + { + currSize.Width -= cropX; + currSize.Height -= cropY; + + Filters.FinalPresentation fCrop = new Filters.FinalPresentation(currSize); + fCrop.Config_Crop = true; + fCrop.Crop = new Rectangle(Global.Config.DispCropLeft, Global.Config.DispCropTop, cropX, cropY); + fCrop.GuiRenderer = Renderer; + fCrop.GL = GL; + chain.AddFilter(fCrop, "crop"); + } + //if a non-zero padding is required, add a filter to allow for that //note, we have two sources of padding right now.. one can come from the videoprovider and one from the user. //we're combining these now and just using black, for sake of being lean, despite the discussion below: @@ -231,7 +255,7 @@ namespace BizHawk.Client.EmuHawk if (padding.Vertical != 0 || padding.Horizontal != 0) { //TODO - add another filter just for this, its cumbersome to use final presentation... I think. but maybe theres enough similarities to justify it. - Size size = chain_insize; + Size size = currSize; size.Width += padding.Horizontal; size.Height += padding.Vertical; Filters.FinalPresentation fPadding = new Filters.FinalPresentation(size); @@ -628,10 +652,18 @@ namespace BizHawk.Client.EmuHawk bool simulate = job.simulate; Size chain_outsize = job.chain_outsize; + int vpWidth = videoProvider.BufferWidth; + int vpHeight = videoProvider.BufferHeight; + + //the easiest way to implement crop now is to do it early by adapting the videoprovider + //it might be more performant to integrate it into the filter chain somehow, but that's hard + int cropX = Global.Config.DispCropLeft + Global.Config.DispCropRight; + int cropY = Global.Config.DispCropTop + Global.Config.DispCropBottom; + //simulate = true; - int vw = videoProvider.BufferWidth; - int vh = videoProvider.BufferHeight; + int vw = vpWidth; + int vh = vpHeight; if (Global.Config.DispFixAspectRatio) { @@ -647,7 +679,7 @@ namespace BizHawk.Client.EmuHawk } if (Global.Config.DispManagerAR == Config.EDispManagerAR.CustomRatio) { - FixRatio(Global.Config.DispCustomUserARX, Global.Config.DispCustomUserARY, videoProvider.BufferWidth, videoProvider.BufferHeight, out vw, out vh); + FixRatio(Global.Config.DispCustomUserARX, Global.Config.DispCustomUserARY, vpWidth, vpHeight, out vw, out vh); } } @@ -657,8 +689,8 @@ namespace BizHawk.Client.EmuHawk int[] videoBuffer = videoProvider.GetVideoBuffer(); - int bufferWidth = videoProvider.BufferWidth; - int bufferHeight = videoProvider.BufferHeight; + int bufferWidth = vpWidth; + int bufferHeight = vpHeight; bool isGlTextureId = videoBuffer.Length == 1; BitmapBuffer bb = null; @@ -669,6 +701,7 @@ namespace BizHawk.Client.EmuHawk { //FYI: this is a million years from happening on n64, since it's all geriatric non-FBO code //is it workable for saturn? + //TODO - this won't respect the user's selected crop. please don't crop this platform or else I'll have to implement this through the videoTexture = GL.WrapGLTexture2d(new IntPtr(videoBuffer[0]), bufferWidth, bufferHeight); } else @@ -685,6 +718,17 @@ namespace BizHawk.Client.EmuHawk } } + ////apply user's choice of cropping + //int cropX = Global.Config.DispCropLeft + Global.Config.DispCropRight; + //int cropY = Global.Config.DispCropTop + Global.Config.DispCropBottom; + //bufferWidth -= cropX; + //bufferHeight -= cropY; + + //Art videoTextureArt = new Art(videoTexture); + //videoTextureArt.Width -= cropX; + //videoTextureArt.Height -= cropY; + //videoTextureArt.u + //record the size of what we received, since lua and stuff is gonna want to draw onto it currEmuWidth = bufferWidth; currEmuHeight = bufferHeight; diff --git a/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs b/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs index 0e12282bd8..1ca514506f 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/Filters/Gui.cs @@ -181,9 +181,9 @@ namespace BizHawk.Client.EmuHawk.Filters public eFilterOption FilterOption = eFilterOption.None; public RetroShaderChain BicubicFilter; - public FinalPresentation(Size size) + public FinalPresentation(Size outputSize) { - this.OutputSize = size; + this.OutputSize = outputSize; } Size OutputSize, InputSize; @@ -194,11 +194,14 @@ namespace BizHawk.Client.EmuHawk.Filters public bool Flip; public IGL GL; bool nop; + public Rectangle Crop; LetterboxingLogic LL; Size ContentSize; public bool Config_FixAspectRatio, Config_FixScaleInteger, Config_PadOnly; + public bool Config_Crop; + /// /// only use with Config_PadOnly /// @@ -223,6 +226,15 @@ namespace BizHawk.Client.EmuHawk.Filters public override Size PresizeInput(string channel, Size size) { + if (Config_Crop) + { + LL = new LetterboxingLogic(); + LL.vx += -Crop.Left; + LL.vy += -Crop.Top; + LL.vw = size.Width - Crop.Width; + LL.vh = size.Height - Crop.Height; + } + if (FilterOption != eFilterOption.Bicubic) return size; @@ -265,7 +277,11 @@ namespace BizHawk.Client.EmuHawk.Filters FindInput().SurfaceDisposition = SurfaceDisposition.Texture; DeclareOutput(new SurfaceState(new SurfaceFormat(OutputSize), SurfaceDisposition.RenderTarget)); InputSize = state.SurfaceFormat.Size; - if (Config_PadOnly) + if (Config_Crop) + { + int zzz = 9; + } + else if (Config_PadOnly) { //TODO - redundant fix LL = new LetterboxingLogic(); @@ -286,6 +302,7 @@ namespace BizHawk.Client.EmuHawk.Filters LL.vx += Padding.Left; LL.vy += Padding.Top; } + ContentSize = new Size(LL.vw,LL.vh); if (InputSize == OutputSize) //any reason we need to check vx and vy? @@ -343,7 +360,9 @@ namespace BizHawk.Client.EmuHawk.Filters GuiRenderer.Modelview.Scale(1, -1); GuiRenderer.Modelview.Translate(0, -LL.vh); } - GuiRenderer.Draw(InputTexture,0,0,LL.vw,LL.vh); + if (Config_Crop) + GuiRenderer.Draw(InputTexture, 0, 0, InputSize.Width, InputSize.Height); + else GuiRenderer.Draw(InputTexture, 0, 0, LL.vw, LL.vh); GuiRenderer.End(); }