mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Added TextureFilter setting
This commit is contained in:
parent
a3fa5cd898
commit
bb987d25b1
@ -8,5 +8,6 @@ namespace Config
|
||||
Settings::DisplayFilter displayFilter;
|
||||
Settings::DisplayResolution displayResolution;
|
||||
Settings::SupportedResolutions supportedResolutions;
|
||||
Settings::TextureFilter textureFilter;
|
||||
Settings::ThreadPriorityBoost threadPriorityBoost;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <Config/Settings/DisplayFilter.h>
|
||||
#include <Config/Settings/DisplayResolution.h>
|
||||
#include <Config/Settings/SupportedResolutions.h>
|
||||
#include <Config/Settings/TextureFilter.h>
|
||||
#include <Config/Settings/ThreadPriorityBoost.h>
|
||||
|
||||
namespace Config
|
||||
@ -20,5 +21,6 @@ namespace Config
|
||||
extern Settings::DisplayFilter displayFilter;
|
||||
extern Settings::DisplayResolution displayResolution;
|
||||
extern Settings::SupportedResolutions supportedResolutions;
|
||||
extern Settings::TextureFilter textureFilter;
|
||||
extern Settings::ThreadPriorityBoost threadPriorityBoost;
|
||||
}
|
||||
|
22
DDrawCompat/Config/Settings/TextureFilter.cpp
Normal file
22
DDrawCompat/Config/Settings/TextureFilter.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <Config/Settings/TextureFilter.h>
|
||||
#include <D3dDdi/DeviceState.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
TextureFilter::TextureFilter()
|
||||
: MappedSetting("TextureFilter", "app", {
|
||||
{"app", {D3DTEXF_NONE, D3DTEXF_NONE, 1}},
|
||||
{"point", {D3DTEXF_POINT, D3DTEXF_POINT, 1}},
|
||||
{"bilinear", {D3DTEXF_LINEAR, D3DTEXF_POINT, 1}},
|
||||
{"trilinear", {D3DTEXF_LINEAR, D3DTEXF_LINEAR, 1}},
|
||||
{"af2x", {D3DTEXF_ANISOTROPIC, D3DTEXF_LINEAR, 2}},
|
||||
{"af4x", {D3DTEXF_ANISOTROPIC, D3DTEXF_LINEAR, 4}},
|
||||
{"af8x", {D3DTEXF_ANISOTROPIC, D3DTEXF_LINEAR, 8}},
|
||||
{"af16x", {D3DTEXF_ANISOTROPIC, D3DTEXF_LINEAR, 16}}
|
||||
})
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
21
DDrawCompat/Config/Settings/TextureFilter.h
Normal file
21
DDrawCompat/Config/Settings/TextureFilter.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include <Config/MappedSetting.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
class TextureFilter : public MappedSetting<std::tuple<UINT, UINT, UINT>>
|
||||
{
|
||||
public:
|
||||
TextureFilter();
|
||||
|
||||
UINT getFilter() const { return std::get<0>(m_value); }
|
||||
UINT getMipFilter() const { return std::get<1>(m_value); }
|
||||
UINT getMaxAnisotropy() const { return std::get<2>(m_value); }
|
||||
};
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#include <Config/Config.h>
|
||||
#include <Common/Log.h>
|
||||
#include <D3dDdi/Device.h>
|
||||
#include <D3dDdi/DeviceState.h>
|
||||
@ -116,12 +117,21 @@ namespace D3dDdi
|
||||
m_textureStageState[i][D3DDDITSS_ADDRESSU] = D3DTADDRESS_WRAP;
|
||||
m_textureStageState[i][D3DDDITSS_ADDRESSV] = D3DTADDRESS_WRAP;
|
||||
m_textureStageState[i][D3DDDITSS_BORDERCOLOR] = 0;
|
||||
m_textureStageState[i][D3DDDITSS_MAGFILTER] = D3DTEXF_POINT;
|
||||
m_textureStageState[i][D3DDDITSS_MINFILTER] = D3DTEXF_POINT;
|
||||
m_textureStageState[i][D3DDDITSS_MIPFILTER] = D3DTEXF_NONE;
|
||||
if (D3DTEXF_NONE == Config::textureFilter.getFilter())
|
||||
{
|
||||
m_textureStageState[i][D3DDDITSS_MAGFILTER] = D3DTEXF_POINT;
|
||||
m_textureStageState[i][D3DDDITSS_MINFILTER] = D3DTEXF_POINT;
|
||||
m_textureStageState[i][D3DDDITSS_MIPFILTER] = D3DTEXF_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_textureStageState[i][D3DDDITSS_MAGFILTER] = Config::textureFilter.getFilter();
|
||||
m_textureStageState[i][D3DDDITSS_MINFILTER] = Config::textureFilter.getFilter();
|
||||
m_textureStageState[i][D3DDDITSS_MIPFILTER] = Config::textureFilter.getMipFilter();
|
||||
}
|
||||
m_textureStageState[i][D3DDDITSS_MIPMAPLODBIAS] = 0;
|
||||
m_textureStageState[i][D3DDDITSS_MAXMIPLEVEL] = 0;
|
||||
m_textureStageState[i][D3DDDITSS_MAXANISOTROPY] = 1;
|
||||
m_textureStageState[i][D3DDDITSS_MAXANISOTROPY] = Config::textureFilter.getMaxAnisotropy();
|
||||
m_textureStageState[i][D3DDDITSS_TEXTURETRANSFORMFLAGS] = D3DTTFF_DISABLE;
|
||||
m_textureStageState[i][D3DDDITSS_SRGBTEXTURE] = FALSE;
|
||||
m_textureStageState[i][D3DDDITSS_ADDRESSW] = D3DTADDRESS_WRAP;
|
||||
@ -280,9 +290,20 @@ namespace D3dDdi
|
||||
|
||||
HRESULT DeviceState::pfnSetTextureStageState(const D3DDDIARG_TEXTURESTAGESTATE* data)
|
||||
{
|
||||
if (D3DDDITSS_TEXTURECOLORKEYVAL == data->State)
|
||||
switch (data->State)
|
||||
{
|
||||
case D3DDDITSS_MINFILTER:
|
||||
case D3DDDITSS_MAGFILTER:
|
||||
case D3DDDITSS_MIPFILTER:
|
||||
case D3DDDITSS_MAXANISOTROPY:
|
||||
if (D3DTEXF_NONE != Config::textureFilter.getFilter())
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
break;
|
||||
case D3DDDITSS_TEXTURECOLORKEYVAL:
|
||||
m_textureStageState[data->Stage][D3DDDITSS_DISABLETEXTURECOLORKEY] = FALSE;
|
||||
break;
|
||||
}
|
||||
return setStateArray(data, m_textureStageState[data->Stage], m_device.getOrigVtable().pfnSetTextureStageState);
|
||||
}
|
||||
@ -460,4 +481,59 @@ namespace D3dDdi
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
DeviceState::ScopedTexture::ScopedTexture(DeviceState& deviceState, UINT stage, HANDLE texture, UINT filter)
|
||||
: m_deviceState(deviceState)
|
||||
, m_stage(stage)
|
||||
, m_prevTexture(deviceState.m_textures[stage])
|
||||
, m_scopedAddressU(deviceState, { stage, D3DDDITSS_ADDRESSU, D3DTADDRESS_CLAMP })
|
||||
, m_scopedAddressV(deviceState, { stage, D3DDDITSS_ADDRESSV, D3DTADDRESS_CLAMP })
|
||||
, m_scopedMagFilter(deviceState, { stage, D3DDDITSS_MAGFILTER, filter })
|
||||
, m_scopedMinFilter(deviceState, { stage, D3DDDITSS_MINFILTER, filter })
|
||||
, m_scopedMipFilter(deviceState, { stage, D3DDDITSS_MIPFILTER, D3DTEXF_NONE })
|
||||
, m_scopedSrgbTexture(deviceState, { stage, D3DDDITSS_SRGBTEXTURE, D3DTEXF_LINEAR == filter })
|
||||
, m_scopedWrap(deviceState, { static_cast<D3DDDIRENDERSTATETYPE>(D3DDDIRS_WRAP0 + stage), 0 })
|
||||
, m_prevTextureColorKeyVal(deviceState.m_textureStageState[stage][D3DDDITSS_TEXTURECOLORKEYVAL])
|
||||
, m_prevDisableTextureColorKey(deviceState.m_textureStageState[stage][D3DDDITSS_DISABLETEXTURECOLORKEY])
|
||||
{
|
||||
m_deviceState.pfnSetTexture(stage, texture);
|
||||
|
||||
D3DDDIARG_TEXTURESTAGESTATE data = {};
|
||||
data.Stage = stage;
|
||||
data.State = D3DDDITSS_DISABLETEXTURECOLORKEY;
|
||||
data.Value = TRUE;
|
||||
m_deviceState.m_device.getOrigVtable().pfnSetTextureStageState(m_deviceState.m_device, &data);
|
||||
}
|
||||
|
||||
DeviceState::ScopedTexture::~ScopedTexture()
|
||||
{
|
||||
m_deviceState.pfnSetTexture(m_stage, m_prevTexture);
|
||||
|
||||
D3DDDIARG_TEXTURESTAGESTATE data = {};
|
||||
data.Stage = m_stage;
|
||||
if (m_prevDisableTextureColorKey)
|
||||
{
|
||||
data.State = D3DDDITSS_DISABLETEXTURECOLORKEY;
|
||||
data.Value = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.State = D3DDDITSS_TEXTURECOLORKEYVAL;
|
||||
data.Value = m_prevTextureColorKeyVal;
|
||||
}
|
||||
m_deviceState.m_device.getOrigVtable().pfnSetTextureStageState(m_deviceState.m_device, &data);
|
||||
}
|
||||
|
||||
DeviceState::ScopedTextureStageState::ScopedTextureStageState(
|
||||
DeviceState& deviceState, const D3DDDIARG_TEXTURESTAGESTATE& data)
|
||||
: m_deviceState(deviceState)
|
||||
, m_prevData{ data.Stage, data.State, deviceState.m_textureStageState[data.Stage][data.State] }
|
||||
{
|
||||
m_deviceState.m_device.getOrigVtable().pfnSetTextureStageState(m_deviceState.m_device, &data);
|
||||
}
|
||||
|
||||
DeviceState::ScopedTextureStageState::~ScopedTextureStageState()
|
||||
{
|
||||
m_deviceState.m_device.getOrigVtable().pfnSetTextureStageState(m_deviceState.m_device, &m_prevData);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3dtypes.h>
|
||||
#include <d3dumddi.h>
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@ -7,6 +10,7 @@
|
||||
const UINT D3DTEXF_NONE = 0;
|
||||
const UINT D3DTEXF_POINT = 1;
|
||||
const UINT D3DTEXF_LINEAR = 2;
|
||||
const UINT D3DTEXF_ANISOTROPIC = 3;
|
||||
|
||||
namespace D3dDdi
|
||||
{
|
||||
@ -247,17 +251,8 @@ namespace D3dDdi
|
||||
class ScopedTextureStageState
|
||||
{
|
||||
public:
|
||||
ScopedTextureStageState(DeviceState& deviceState, const D3DDDIARG_TEXTURESTAGESTATE& data)
|
||||
: m_deviceState(deviceState)
|
||||
, m_prevData{ data.Stage, data.State, deviceState.m_textureStageState[data.Stage][data.State] }
|
||||
{
|
||||
m_deviceState.pfnSetTextureStageState(&data);
|
||||
}
|
||||
|
||||
~ScopedTextureStageState()
|
||||
{
|
||||
m_deviceState.pfnSetTextureStageState(&m_prevData);
|
||||
}
|
||||
ScopedTextureStageState(DeviceState& deviceState, const D3DDDIARG_TEXTURESTAGESTATE& data);
|
||||
~ScopedTextureStageState();
|
||||
|
||||
private:
|
||||
DeviceState& m_deviceState;
|
||||
@ -267,47 +262,8 @@ namespace D3dDdi
|
||||
class ScopedTexture
|
||||
{
|
||||
public:
|
||||
ScopedTexture(DeviceState& deviceState, UINT stage, HANDLE texture, UINT filter)
|
||||
: m_deviceState(deviceState)
|
||||
, m_stage(stage)
|
||||
, m_prevTexture(deviceState.m_textures[stage])
|
||||
, m_scopedAddressU(deviceState, { stage, D3DDDITSS_ADDRESSU, D3DTADDRESS_CLAMP })
|
||||
, m_scopedAddressV(deviceState, { stage, D3DDDITSS_ADDRESSV, D3DTADDRESS_CLAMP })
|
||||
, m_scopedMagFilter(deviceState, { stage, D3DDDITSS_MAGFILTER, filter })
|
||||
, m_scopedMinFilter(deviceState, { stage, D3DDDITSS_MINFILTER, filter })
|
||||
, m_scopedMipFilter(deviceState, { stage, D3DDDITSS_MIPFILTER, D3DTEXF_NONE })
|
||||
, m_scopedSrgbTexture(deviceState, { stage, D3DDDITSS_SRGBTEXTURE, D3DTEXF_LINEAR == filter })
|
||||
, m_scopedWrap(deviceState, { static_cast<D3DDDIRENDERSTATETYPE>(D3DDDIRS_WRAP0 + stage), 0 })
|
||||
, m_prevTextureColorKeyVal(deviceState.m_textureStageState[stage][D3DDDITSS_TEXTURECOLORKEYVAL])
|
||||
, m_prevDisableTextureColorKey(deviceState.m_textureStageState[stage][D3DDDITSS_DISABLETEXTURECOLORKEY])
|
||||
{
|
||||
m_deviceState.pfnSetTexture(stage, texture);
|
||||
|
||||
D3DDDIARG_TEXTURESTAGESTATE data = {};
|
||||
data.Stage = stage;
|
||||
data.State = D3DDDITSS_DISABLETEXTURECOLORKEY;
|
||||
data.Value = TRUE;
|
||||
m_deviceState.pfnSetTextureStageState(&data);
|
||||
}
|
||||
|
||||
~ScopedTexture()
|
||||
{
|
||||
m_deviceState.pfnSetTexture(m_stage, m_prevTexture);
|
||||
|
||||
D3DDDIARG_TEXTURESTAGESTATE data = {};
|
||||
data.Stage = m_stage;
|
||||
if (m_prevDisableTextureColorKey)
|
||||
{
|
||||
data.State = D3DDDITSS_DISABLETEXTURECOLORKEY;
|
||||
data.Value = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.State = D3DDDITSS_TEXTURECOLORKEYVAL;
|
||||
data.Value = m_prevTextureColorKeyVal;
|
||||
}
|
||||
m_deviceState.pfnSetTextureStageState(&data);
|
||||
}
|
||||
ScopedTexture(DeviceState& deviceState, UINT stage, HANDLE texture, UINT filter);
|
||||
~ScopedTexture();
|
||||
|
||||
private:
|
||||
DeviceState& m_deviceState;
|
||||
|
@ -219,6 +219,7 @@
|
||||
<ClInclude Include="Config\Settings\DisplayFilter.h" />
|
||||
<ClInclude Include="Config\Settings\DisplayResolution.h" />
|
||||
<ClInclude Include="Config\Settings\SupportedResolutions.h" />
|
||||
<ClInclude Include="Config\Settings\TextureFilter.h" />
|
||||
<ClInclude Include="Config\Settings\ThreadPriorityBoost.h" />
|
||||
<ClInclude Include="D3dDdi\Adapter.h" />
|
||||
<ClInclude Include="D3dDdi\AdapterCallbacks.h" />
|
||||
@ -325,6 +326,7 @@
|
||||
<ClCompile Include="Config\Settings\DisplayFilter.cpp" />
|
||||
<ClCompile Include="Config\Settings\DisplayResolution.cpp" />
|
||||
<ClCompile Include="Config\Settings\SupportedResolutions.cpp" />
|
||||
<ClCompile Include="Config\Settings\TextureFilter.cpp" />
|
||||
<ClCompile Include="D3dDdi\Adapter.cpp" />
|
||||
<ClCompile Include="D3dDdi\AdapterCallbacks.cpp" />
|
||||
<ClCompile Include="D3dDdi\AdapterFuncs.cpp" />
|
||||
|
@ -450,6 +450,9 @@
|
||||
<ClInclude Include="Config\Settings\AlternatePixelCenter.h">
|
||||
<Filter>Header Files\Config\Settings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Config\Settings\TextureFilter.h">
|
||||
<Filter>Header Files\Config\Settings</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Gdi\Gdi.cpp">
|
||||
@ -707,6 +710,9 @@
|
||||
<ClCompile Include="Config\Settings\DisplayFilter.cpp">
|
||||
<Filter>Source Files\Config\Settings</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Config\Settings\TextureFilter.cpp">
|
||||
<Filter>Source Files\Config\Settings</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="DDrawCompat.rc">
|
||||
|
Loading…
x
Reference in New Issue
Block a user