Skip to content

Commit

Permalink
add hq3x and hq4x
Browse files Browse the repository at this point in the history
  • Loading branch information
duchuule committed Sep 24, 2015
1 parent de888fc commit 568c639
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 137 deletions.
18 changes: 12 additions & 6 deletions EmulatorRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,17 +718,23 @@ namespace VBA10

//<-------begin drawing main picture

//force linear filter to disabled if using pixel shader
if (EmulatorSettings::Current->PixelShader > 0 )

if (EmulatorSettings::Current->PixelShader == 1 ) //bilinear filtering
this->dxSpriteBatch->Begin(x, true);

else //force linear filter to disabled if using pixel shader or when using nearest neighbor
this->dxSpriteBatch->Begin(x, false);
else
this->dxSpriteBatch->Begin(x, EmulatorSettings::Current->LinearFilterEnabled);

if (EmulatorSettings::Current->PixelShader != 0)

if (EmulatorSettings::Current->PixelShader > 1)
{
//custom pixel shader
this->dxSpriteBatch->SetCustomPixelShader(this->shaderManager->GetCurrentShader());

if (EmulatorSettings::Current->PixelShader == 1) //hq2x
//set look up table (for hqnx)
this->dxSpriteBatch->SetCustomShaderResourceView(this->shaderManager->GetLookUpTable());
}

Engine::Rectangle sourceRect(source.left, source.top, source.right - source.left, source.bottom - source.top);
Engine::Rectangle targetRect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);

Expand Down
24 changes: 12 additions & 12 deletions EmulatorSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ namespace VBA10
}


property bool LinearFilterEnabled
{
bool get()
{
return GetValueOrDefault<bool> (LinearFilterKey, LinearFilterDefault);
}
void set (bool value)
{
AddOrUpdateValue(LinearFilterKey, value);
}
}
//property bool LinearFilterEnabled
//{
// bool get()
// {
// return GetValueOrDefault<bool> (LinearFilterKey, LinearFilterDefault);
// }
// void set (bool value)
// {
// AddOrUpdateValue(LinearFilterKey, value);
// }
//}

property int ControllerScale
{
Expand Down Expand Up @@ -716,7 +716,7 @@ namespace VBA10
const bool HideHamburgerDefault = false;
const int TurboBehaviorDefault = 0;
const int PixelFilterDefault = 0; //0: none
const int PixelShaderDefault = 0; //0: none
const int PixelShaderDefault = 1; //0: nearest neighbor, 1: bilinear


#pragma region button positions (in cm based on 6x10cm phone)
Expand Down
120 changes: 62 additions & 58 deletions Filter/ShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "xBR2_PS.h"
#include "xBR5_PS.h"
#include "hq2x_PS.h"
#include "hq3x_PS.h"
#include "hq4x_PS.h"

using namespace VBA10;
using namespace Microsoft::WRL;
Expand All @@ -21,74 +23,76 @@ ShaderManager *ShaderManager::GetInstance()

void ShaderManager::LoadShader(int selection)
{
HRESULT test;

//load the Look up table (texture)
LoadTextureFromFile(
this->device.Get(),
L"Filter/hq2x.dds",
this->lutResource.GetAddressOf(),
this->lutSRV.GetAddressOf()
);


//create sampler
//D3D11_SAMPLER_DESC samplerDesc;
//ZeroMemory(&samplerDesc, sizeof(D3D11_SAMPLER_DESC));

//samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;

//samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
//samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
//samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;

//samplerDesc.MaxLOD = FLT_MAX;
//samplerDesc.MaxAnisotropy = 1;
//samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;

//if (FAILED(this->device->CreateSamplerState(&samplerDesc, this->sampler.GetAddressOf())))
//{
// int test = 1;
//}

//this->context->PSSetSamplers(1, 1, this->sampler.GetAddressOf());



HRESULT test;
const BYTE* shaderByteCode;
size_t shaderSize;
this->lutSRV = nullptr;

if (selection == 1)
if (selection == 2)
{
if (FAILED(test = this->device->CreatePixelShader(
HQ2X_PS,
sizeof(HQ2X_PS),
NULL,
&this->ps)))
{
}



shaderByteCode = HQ2X_PS;
shaderSize = sizeof(HQ2X_PS);

//load the Look up table (texture)
LoadTextureFromFile(
this->device.Get(),
L"Filter/hq2x.dds",
this->lutResource.GetAddressOf(),
this->lutSRV.GetAddressOf()
);
}
else if (selection == 3)
{
shaderByteCode = XBR2_PS;
shaderSize = sizeof(XBR2_PS);
}
else if (selection == 4)
{
shaderByteCode = HQ3X_PS;
shaderSize = sizeof(HQ3X_PS);

//load the Look up table (texture)
LoadTextureFromFile(
this->device.Get(),
L"Filter/hq3x.dds",
this->lutResource.GetAddressOf(),
this->lutSRV.GetAddressOf()
);
}
else if (selection == 2) //2xbr
else if (selection == 5)
{
if (FAILED(test = this->device->CreatePixelShader(
XBR2_PS,
sizeof(XBR2_PS),
NULL,
&this->ps)))
{
}
shaderByteCode = XBR5_PS;
shaderSize = sizeof(XBR5_PS);
}
else if (selection == 3) //5xbr
else
{
if (FAILED(test = this->device->CreatePixelShader(
XBR5_PS,
sizeof(XBR5_PS),
NULL,
&this->ps)))
{
}
shaderByteCode = HQ4X_PS;
shaderSize = sizeof(HQ4X_PS);

//load the Look up table (texture)
LoadTextureFromFile(
this->device.Get(),
L"Filter/hq4x.dds",
this->lutResource.GetAddressOf(),
this->lutSRV.GetAddressOf()
);
}


if (FAILED(test = this->device->CreatePixelShader(
shaderByteCode,
shaderSize,
NULL,
&this->ps)))
{
}






}
74 changes: 39 additions & 35 deletions SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -450,70 +450,74 @@
<ComboBoxItem>9</ComboBoxItem>
</ComboBox>

<ComboBox Name="monitorComboBox" HorizontalAlignment="Stretch"
VerticalAlignment="Top"
SelectedIndex="1"
SelectionChanged="monitorComboBox_SelectionChanged_1"
Header="Display type"
Margin="0,0,0,10">
<ComboBoxItem>30 Hz</ComboBoxItem>
<ComboBoxItem>60 Hz (default)</ComboBoxItem>
<ComboBoxItem>120 Hz</ComboBoxItem>
</ComboBox>

<ComboBox Name="aspectComboBox"

<ComboBox Name="cboPixelFilter"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
SelectedIndex="0"
SelectionChanged="aspectComboBox_SelectionChanged_1"
Header="Aspect ratio"
SelectionChanged="cboPixelFilter_SelectionChanged"
Header="CPU filter (slow)"
Margin="0,0,0,10"
>
<ComboBoxItem>Original</ComboBoxItem>
<ComboBoxItem>Stretch</ComboBoxItem>
<ComboBoxItem>4:3</ComboBoxItem>
<ComboBoxItem>5:4</ComboBoxItem>
<ComboBoxItem>1:1</ComboBoxItem>
<ComboBoxItem>None</ComboBoxItem>
<ComboBoxItem>HQ2x</ComboBoxItem>
<ComboBoxItem>TV Mode</ComboBoxItem>
<ComboBoxItem>Scanlines</ComboBoxItem>
</ComboBox>


<ComboBox Name="cboPixelShader"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
SelectedIndex="0"
SelectionChanged="cboPixelShader_SelectionChanged"
Header="GPU pixel filter (fast)"
Header="GPU filter (fast)"
Margin="0,0,0,10"
>
<ComboBoxItem>None</ComboBoxItem>
<ComboBoxItem>Bilinear</ComboBoxItem>
<ComboBoxItem>HQ2x</ComboBoxItem>
<ComboBoxItem>xBr2x</ComboBoxItem>
<ComboBoxItem>xBr5x</ComboBoxItem>
<ComboBoxItem>HQ3x</ComboBoxItem>
<ComboBoxItem>xBr3x</ComboBoxItem>
<ComboBoxItem>HQ4x</ComboBoxItem>
</ComboBox>
<!--<ToggleSwitch Header="Use bilinear filter"
Name="linearFilterToggle"
IsOn="True"
Toggled="linearFilterToggle_Toggled"
/>-->



<ComboBox Name="monitorComboBox" HorizontalAlignment="Stretch"
VerticalAlignment="Top"
SelectedIndex="1"
SelectionChanged="monitorComboBox_SelectionChanged_1"
Header="Display type"
Margin="0,0,0,10">
<ComboBoxItem>30 Hz</ComboBoxItem>
<ComboBoxItem>60 Hz (default)</ComboBoxItem>
<ComboBoxItem>120 Hz</ComboBoxItem>
</ComboBox>
<ComboBox Name="cboPixelFilter"

<ComboBox Name="aspectComboBox"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
SelectedIndex="0"
SelectionChanged="cboPixelFilter_SelectionChanged"
Header="CPU pixel filter (slow)"
SelectionChanged="aspectComboBox_SelectionChanged_1"
Header="Aspect ratio"
Margin="0,0,0,10"
>
<ComboBoxItem>None</ComboBoxItem>
<ComboBoxItem>HQ2x</ComboBoxItem>
<ComboBoxItem>TV Mode</ComboBoxItem>
<ComboBoxItem>Scanlines</ComboBoxItem>

<ComboBoxItem>Original</ComboBoxItem>
<ComboBoxItem>Stretch</ComboBoxItem>
<ComboBoxItem>4:3</ComboBoxItem>
<ComboBoxItem>5:4</ComboBoxItem>
<ComboBoxItem>1:1</ComboBoxItem>
</ComboBox>

<ToggleSwitch Header="Use bilinear filter"
Name="linearFilterToggle"
IsOn="True"
Toggled="linearFilterToggle_Toggled"
/>


<ToggleSwitch Header="Show FPS"
Name="fpsToggle"
IsOn="True"
Expand Down
16 changes: 8 additions & 8 deletions SettingsPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ SettingsPage::SettingsPage()
}
this->cboPixelFilter->SelectedIndex = EmulatorSettings::Current->PixelFilter;
this->cboPixelShader->SelectedIndex = EmulatorSettings::Current->PixelShader;
this->linearFilterToggle->IsOn = EmulatorSettings::Current->LinearFilterEnabled;
//this->linearFilterToggle->IsOn = EmulatorSettings::Current->LinearFilterEnabled;
this->fullscreenToggle->IsOn = EmulatorSettings::Current->FullScreen;

//general
Expand Down Expand Up @@ -643,13 +643,13 @@ void SettingsPage::cboPixelShader_SelectionChanged(Platform::Object^ sender, Win
}
}

void SettingsPage::linearFilterToggle_Toggled(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
if (initdone)
{
EmulatorSettings::Current->LinearFilterEnabled = this->linearFilterToggle->IsOn;
}
}
//void SettingsPage::linearFilterToggle_Toggled(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
//{
// if (initdone)
// {
// EmulatorSettings::Current->LinearFilterEnabled = this->linearFilterToggle->IsOn;
// }
//}

void SettingsPage::fpsToggle_Toggled(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Expand Down
Loading

0 comments on commit 568c639

Please sign in to comment.