canvas extension: ok, this works better

This commit is contained in:
zeromus 2015-03-23 03:43:39 +00:00
parent dfafee2b25
commit e77c1455b3
2 changed files with 53 additions and 46 deletions

View File

@ -182,6 +182,21 @@ namespace BizHawk.Client.EmuHawk
//add the first filter, encompassing output from the emulator core //add the first filter, encompassing output from the emulator core
chain.AddFilter(fInput, "input"); chain.AddFilter(fInput, "input");
//if a non-zero padding is required, add a filter to allow for that
if (GameExtraPadding.Vertical != 0 || GameExtraPadding.Horizontal != 0)
{
//TODO - add another filter just for this, its cumebrsome to use final presentation... I think. but maybe theres enough similarities to justify it.
Size size = chain_insize;
size.Width += GameExtraPadding.Horizontal;
size.Height += GameExtraPadding.Vertical;
Filters.FinalPresentation fPadding = new Filters.FinalPresentation(size);
chain.AddFilter(fPadding, "padding");
fPadding.GuiRenderer = Renderer;
fPadding.GL = GL;
fPadding.Config_PadOnly = true;
fPadding.Padding = GameExtraPadding;
}
//add lua layer 'emu' //add lua layer 'emu'
AppendLuaLayer(chain, "emu"); AppendLuaLayer(chain, "emu");
@ -346,13 +361,6 @@ namespace BizHawk.Client.EmuHawk
virtualHeight = Global.Config.DispCustomUserARHeight; virtualHeight = Global.Config.DispCustomUserARHeight;
} }
bufferWidth += GameExtraPadding.Left + GameExtraPadding.Right;
virtualWidth += GameExtraPadding.Left + GameExtraPadding.Right;
bufferHeight += GameExtraPadding.Top + GameExtraPadding.Bottom;
virtualHeight += GameExtraPadding.Top + GameExtraPadding.Bottom;
//Console.WriteLine("DISPZOOM " + zoom); //test //Console.WriteLine("DISPZOOM " + zoom); //test
//old stuff //old stuff
@ -443,8 +451,6 @@ namespace BizHawk.Client.EmuHawk
chain_outsize = new Size(bufferWidth * zoom, bufferHeight * zoom); chain_outsize = new Size(bufferWidth * zoom, bufferHeight * zoom);
} }
//add requested lua layer canvas extension
var job = new JobInfo var job = new JobInfo
{ {
videoProvider = fvp, videoProvider = fvp,
@ -493,18 +499,11 @@ namespace BizHawk.Client.EmuHawk
} }
} }
//vw += GameExtraPadding.Left + GameExtraPadding.Right;
//vh += GameExtraPadding.Top + GameExtraPadding.Bottom;
int[] videoBuffer = videoProvider.GetVideoBuffer(); int[] videoBuffer = videoProvider.GetVideoBuffer();
TESTEROO: TESTEROO:
int bufferWidth = videoProvider.BufferWidth; int bufferWidth = videoProvider.BufferWidth;
int bufferHeight = videoProvider.BufferHeight; int bufferHeight = videoProvider.BufferHeight;
//bufferWidth += GameExtraPadding.Left + GameExtraPadding.Right;
//bufferHeight += GameExtraPadding.Top + GameExtraPadding.Bottom;
bool isGlTextureId = videoBuffer.Length == 1; bool isGlTextureId = videoBuffer.Length == 1;
//TODO - need to do some work here for GDI+ to repair gl texture ID importing //TODO - need to do some work here for GDI+ to repair gl texture ID importing
@ -566,11 +565,13 @@ TESTEROO:
//setup the final presentation filter //setup the final presentation filter
Filters.FinalPresentation fPresent = filterProgram["presentation"] as Filters.FinalPresentation; Filters.FinalPresentation fPresent = filterProgram["presentation"] as Filters.FinalPresentation;
fPresent.InputPadding = GameExtraPadding;
fPresent.VirtualTextureSize = new Size(vw, vh); fPresent.VirtualTextureSize = new Size(vw, vh);
fPresent.TextureSize = new Size(bufferWidth, bufferHeight); fPresent.TextureSize = new Size(bufferWidth, bufferHeight);
fPresent.BackgroundColor = videoProvider.BackgroundColor; fPresent.BackgroundColor = videoProvider.BackgroundColor;
fPresent.GuiRenderer = Renderer; fPresent.GuiRenderer = Renderer;
fPresent.Config_FixAspectRatio = Global.Config.DispFixAspectRatio;
fPresent.Config_FixScaleInteger = Global.Config.DispFixScaleInteger;
fPresent.GL = GL; fPresent.GL = GL;
filterProgram.Compile("default", chain_insize, chain_outsize, !job.offscreen); filterProgram.Compile("default", chain_insize, chain_outsize, !job.offscreen);

View File

@ -34,25 +34,19 @@ namespace BizHawk.Client.EmuHawk.Filters
/// </summary> /// </summary>
public float WidthScale, HeightScale; public float WidthScale, HeightScale;
//do maths on the viewport and the native resolution and the user settings to get a display rectangle /// <summary>
public LetterboxingLogic(System.Windows.Forms.Padding inputPadding, bool maintainAspect, bool maintainInteger, int targetWidth, int targetHeight, int sourceWidth, int sourceHeight, Size textureSize, Size virtualSize) /// In case you want to do it yourself
{ /// </summary>
//when using inputPadding, the output will already be sized to accept it. the inptu size will be untouched. public LetterboxingLogic() { }
//heres how we handle it:
//1. pretend the input is larger
int padw = inputPadding.Left + inputPadding.Right;
int padh = inputPadding.Top + inputPadding.Bottom;
//do maths on the viewport and the native resolution and the user settings to get a display rectangle
public LetterboxingLogic(bool maintainAspect, bool maintainInteger, int targetWidth, int targetHeight, int sourceWidth, int sourceHeight, Size textureSize, Size virtualSize)
{
int textureWidth = textureSize.Width; int textureWidth = textureSize.Width;
int textureHeight = textureSize.Height; int textureHeight = textureSize.Height;
int virtualWidth = virtualSize.Width; int virtualWidth = virtualSize.Width;
int virtualHeight = virtualSize.Height; int virtualHeight = virtualSize.Height;
textureWidth += padw;
textureHeight += padh;
virtualWidth += padw;
virtualHeight += padh;
//zero 02-jun-2014 - we passed these in, but ignored them. kind of weird.. //zero 02-jun-2014 - we passed these in, but ignored them. kind of weird..
int oldSourceWidth = sourceWidth; int oldSourceWidth = sourceWidth;
int oldSourceHeight = sourceHeight; int oldSourceHeight = sourceHeight;
@ -139,16 +133,13 @@ namespace BizHawk.Client.EmuHawk.Filters
PS = trials[bestIndex]; PS = trials[bestIndex];
} }
//accomodate padding here to keep pixel precision vw = (int)(PS.X * textureWidth);
vw = (int)(PS.X * (textureWidth-padw)); vh = (int)(PS.Y * textureHeight);
vh = (int)(PS.Y * (textureHeight-padh));
widthScale = PS.X; widthScale = PS.X;
heightScale = PS.Y; heightScale = PS.Y;
} }
else else
{ {
widthScale /= (sourceWidth / (float)(sourceWidth - padw));
heightScale /= (sourceHeight / (float)(sourceHeight - padh));
vw = (int)(widthScale * sourceWidth); vw = (int)(widthScale * sourceWidth);
vh = (int)(heightScale * sourceHeight); vh = (int)(heightScale * sourceHeight);
} }
@ -164,13 +155,6 @@ namespace BizHawk.Client.EmuHawk.Filters
//HeightScale = heightScale; //HeightScale = heightScale;
WidthScale = (float)vw / oldSourceWidth; WidthScale = (float)vw / oldSourceWidth;
HeightScale = (float)vh / oldSourceHeight; HeightScale = (float)vh / oldSourceHeight;
//now add the padding, as best we can.
//it's a little hard because: ...
//vx += (int)(inputPadding.Left * WidthScale);
//vy += (int)(inputPadding.Top * HeightScale);
//vx += inputPadding.Left;
//vy += inputPadding.Top;
} }
} }
@ -199,10 +183,12 @@ namespace BizHawk.Client.EmuHawk.Filters
LetterboxingLogic LL; LetterboxingLogic LL;
Size ContentSize; Size ContentSize;
public bool Config_FixAspectRatio, Config_FixScaleInteger, Config_PadOnly;
/// <summary> /// <summary>
/// How much should padding should be added to the input (for canvas extension) /// only use with Config_PadOnly
/// </summary> /// </summary>
public System.Windows.Forms.Padding InputPadding; public System.Windows.Forms.Padding Padding;
public override void Initialize() public override void Initialize()
{ {
@ -226,7 +212,17 @@ namespace BizHawk.Client.EmuHawk.Filters
if (FilterOption != eFilterOption.Bicubic) if (FilterOption != eFilterOption.Bicubic)
return size; return size;
LL = new LetterboxingLogic(InputPadding, Global.Config.DispFixAspectRatio, Global.Config.DispFixScaleInteger, OutputSize.Width, OutputSize.Height, size.Width, size.Height, TextureSize, VirtualTextureSize); if (Config_PadOnly)
{
//TODO - redundant fix
LL = new LetterboxingLogic();
LL.vx += Padding.Left;
LL.vy += Padding.Right;
LL.vw = size.Width;
LL.vh = size.Height;
}
else
LL = new LetterboxingLogic(Config_FixAspectRatio, Config_FixScaleInteger, OutputSize.Width, OutputSize.Height, size.Width, size.Height, TextureSize, VirtualTextureSize);
return size; return size;
} }
@ -249,7 +245,17 @@ namespace BizHawk.Client.EmuHawk.Filters
FindInput().SurfaceDisposition = SurfaceDisposition.Texture; FindInput().SurfaceDisposition = SurfaceDisposition.Texture;
DeclareOutput(new SurfaceState(new SurfaceFormat(OutputSize), SurfaceDisposition.RenderTarget)); DeclareOutput(new SurfaceState(new SurfaceFormat(OutputSize), SurfaceDisposition.RenderTarget));
InputSize = state.SurfaceFormat.Size; InputSize = state.SurfaceFormat.Size;
LL = new LetterboxingLogic(InputPadding, Global.Config.DispFixAspectRatio, Global.Config.DispFixScaleInteger, OutputSize.Width, OutputSize.Height, InputSize.Width, InputSize.Height, TextureSize, VirtualTextureSize); if (Config_PadOnly)
{
//TODO - redundant fix
LL = new LetterboxingLogic();
LL.vx += Padding.Left;
LL.vy += Padding.Right;
LL.vw = InputSize.Width;
LL.vh = InputSize.Height;
}
else
LL = new LetterboxingLogic(Config_FixAspectRatio, Config_FixScaleInteger, OutputSize.Width, OutputSize.Height, InputSize.Width, InputSize.Height, TextureSize, VirtualTextureSize);
ContentSize = new Size(LL.vw,LL.vh); ContentSize = new Size(LL.vw,LL.vh);
} }