Skip to content

Commit

Permalink
Lots of work on DX11 console
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterTh committed Feb 7, 2016
1 parent b10cb37 commit 95de708
Show file tree
Hide file tree
Showing 16 changed files with 342 additions and 125 deletions.
18 changes: 11 additions & 7 deletions GeDoSaTo.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,22 @@
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\Debug\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">ext;include;defs;C:\dev\steamworks_sdk_135\sdk\public;C:\dev\boost_1_59_0;D:\dev\nvapi-337;D:\dev\Selene\Selene-0.3.1\include;D:\dev\lua\32\include;D:\dev\minhook\include;$(IncludePath)</IncludePath>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ext;include;defs;$(WindowsSDK_IncludePath);C:\dev\steamworks_sdk_135\sdk\public;C:\dev\boost_1_59_0;D:\dev\nvapi-337;D:\dev\Selene\Selene-0.3.1\include;D:\dev\lua\32\include;D:\dev\minhook\include;$(IncludePath)</IncludePath>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">ext;include;defs;C:\dev\FX11-master\inc;C:\dev\steamworks_sdk_135\sdk\public;C:\dev\boost_1_59_0;D:\dev\nvapi-337;D:\dev\Selene\Selene-0.3.1\include;D:\dev\lua\32\include;D:\dev\minhook\include;$(IncludePath)</IncludePath>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ext;include;defs;$(WindowsSDK_IncludePath);C:\dev\FX11-master\inc;C:\dev\steamworks_sdk_135\sdk\public;C:\dev\boost_1_59_0;D:\dev\nvapi-337;D:\dev\Selene\Selene-0.3.1\include;D:\dev\lua\32\include;D:\dev\minhook\include;$(IncludePath)</IncludePath>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">GeDoSaTo</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">GeDoSaTo64</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">GeDoSaTo</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">d3d9</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LibraryPath>C:\dev\minhook\build\VC14\lib\Release;D:\dev\nvapi-337\x86;D:\dev\lua\32;D:\Program Files (x86)\Microsoft DirectX SDK (August 2009)\Lib\x86;$(LibraryPath)</LibraryPath>
<LibraryPath>$(WindowsSDK_LibraryPath_x86);C:\dev\FX11-master\Bin\Desktop_2015\Win32\Release;C:\dev\minhook\build\VC14\lib\Release;D:\dev\nvapi-337\x86;D:\dev\lua\32;D:\Program Files (x86)\Microsoft DirectX SDK (August 2009)\Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>include;defs;C:\dev\boost\boost_1_55_0\;C:\Users\Peter\Documents\GitHub\Selene\include;C:\dev\lua\32\include;C:\dev\minhook\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\dev\boost\boost_1_55_0\stage\lib;C:\dev\lua\32;C:\dev\minhook\lib;C:\Program Files (x86)\Microsoft DirectX SDK (August 2009)\Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LibraryPath>C:\dev\minhook\build\VC14\lib\Release;D:\dev\nvapi-337\amd64;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x64;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);C:\dev\boost_1_59_0\stage\lib\64;$(NETFXKitsDir)Lib\um\x64</LibraryPath>
<LibraryPath>$(WindowsSDK_LibraryPath_x64);C:\dev\FX11-master\Bin\Desktop_2015\x64\Release;C:\dev\minhook\build\VC14\lib\Release;D:\dev\nvapi-337\amd64;C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x64;$(VC_LibraryPath_x64);C:\dev\boost_1_59_0\stage\lib\64;$(NETFXKitsDir)Lib\um\x64</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand All @@ -115,8 +115,9 @@
<ImportLibrary>
</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
<ModuleDefinitionFile>GeDoSaTo.def</ModuleDefinitionFile>
<AdditionalDependencies>legacy_stdio_definitions.lib;nvapi.lib;Xinput.lib;libMinHook.x86.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>
</ModuleDefinitionFile>
<AdditionalDependencies>d3d11.lib;d3dx11.lib;D3DCompiler.lib;Effects11.lib;legacy_stdio_definitions.lib;nvapi.lib;Xinput.lib;libMinHook.x86.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down Expand Up @@ -163,11 +164,13 @@
</ClCompile>
<Link>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalDependencies>legacy_stdio_definitions.lib;nvapi64.lib;Xinput.lib;libMinHook.x64.lib;winmm.lib;psapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>d3d11.lib;d3dx11.lib;D3DCompiler.lib;Effects11.lib;legacy_stdio_definitions.lib;nvapi64.lib;Xinput.lib;libMinHook.x64.lib;winmm.lib;psapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<MinimumRequiredVersion>
</MinimumRequiredVersion>
<LinkTimeCodeGeneration>UseFastLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<ModuleDefinitionFile>
</ModuleDefinitionFile>
</Link>
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -283,6 +286,7 @@
<ClCompile Include="source\d3d9\d3d9swap.cpp" />
<ClCompile Include="source\d3d9\d3d9tex.cpp" />
<ClCompile Include="source\d3dperf.cpp" />
<ClCompile Include="source\dxgi\dxgifactory2.cpp" />
<ClCompile Include="source\perf_monitor.cpp" />
<ClCompile Include="source\plugins\dw8.cpp" />
<ClCompile Include="source\plugins\ff13.cpp" />
Expand Down
39 changes: 37 additions & 2 deletions include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ using std::string;
using std::vector;
#include <memory>

#include <d3d11.h>

//////////////////////////////////////////////////////////////////// API independent

class ConsoleLine {
Expand Down Expand Up @@ -44,6 +46,8 @@ class Console {

stbtt_bakedchar cdata[96]; // ASCII 32..126 is 95 glyphs

Console(int w, int h);

virtual void beginDrawing() = 0;
virtual void beginText() = 0;
virtual void endText() = 0;
Expand All @@ -65,19 +69,21 @@ class Console {

int getW();
int getH();

virtual ~Console() {}
};

//////////////////////////////////////////////////////////////////// DirectX 9

class ConsoleDX9 : public Console {
protected:
IDirect3DDevice9* device = nullptr;
IDirect3DVertexDeclaration9* vertexDeclaration = nullptr;
IDirect3DTexture9* fontTex = nullptr;
LPD3DXEFFECT effect = nullptr;
D3DXHANDLE rectColorHandle, textTex2DHandle;
static const D3DVERTEXELEMENT9 vertexElements[3];

protected:
virtual void beginDrawing() override;
virtual void beginText() override;
virtual void endText() override;
Expand All @@ -90,4 +96,33 @@ class ConsoleDX9 : public Console {
public:
ConsoleDX9(IDirect3DDevice9* device, int w, int h);
virtual ~ConsoleDX9();
};
};


//////////////////////////////////////////////////////////////////// DirectX 11

class RSManagerDX11;
struct ID3DX11Effect;

class ConsoleDX11 : public Console {
ID3D11Texture2D* fontTex = nullptr;
ID3D11ShaderResourceView* fontTexView = nullptr;
ID3D11Buffer *vertexBuffer = nullptr, *indexBuffer = nullptr;
ID3DX11Effect *effect = nullptr;

protected:
ID3D11Device* device = nullptr;

virtual void beginDrawing() override;
virtual void beginText() override;
virtual void endText() override;
virtual void quad(float x, float y, float w, float h) override;
virtual void quad(const stbtt_aligned_quad& q) override;
virtual void drawBGQuad(float x0, float y0, float x1, float y1) override;

virtual bool hasDevice() override;

public:
ConsoleDX11(ID3D11Device* device, RSManagerDX11* manager, int w, int h);
virtual ~ConsoleDX11();
};
4 changes: 4 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ using std::string;
#define FLT_EQ(__a, __b) (std::abs((__a) - (__b)) <= EPSILON * (std::max)(1.0f, (std::max)(std::abs(__a), std::abs(__b))))
#define FLT_EPS(__a, __b, __eps) (std::abs((__a) - (__b)) <= __eps)

#define CHECKHR(__hresult, __message, ...) if(FAILED(__hresult)) { SDLOG(-1, "ERROR: " __message, __VA_ARGS__) }
#define SDASSERT(__cond, __message, ...) if(!(__cond)) { SDLOG(-1, "ERROR: " __message, __VA_ARGS__) }

#include "d3d9/d3d9.h"

bool fileExists(const char *filename);
Expand All @@ -66,6 +69,7 @@ string getInstalledFileName(string filename);
string getAssetFileName(string filename);
string getConfigFileName(string filename);
string getTimeString(bool forDisplay = false);
std::wstring strToWStr(const string& input);

extern FILE* g_oFile;
inline void sdlog(const char *fmt) {
Expand Down
43 changes: 41 additions & 2 deletions include/renderstate_manager_dx11.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,37 @@ class RSManagerDX11 : public RSManager {

ID3D11Texture2D* backBuffers[10];

ULONG internalRefCount = 0;

public:
RSManagerDX11(ID3D11Device* d3ddev) : RSManager(), d3ddev(d3ddev) {
rtMan.reset(new RenderTargetManager(d3ddev));
console.reset(new ConsoleDX11(d3ddev, this, renderWidth, renderHeight));
Console::setLatest(console.get());
}

~RSManagerDX11() {
SDLOG(-1, "~RSManagerDX11\n");
}

void addInternalReferences(ULONG count) {
internalRefCount += count;
}

static ULONG getInternalRefCount() {
if(latest == nullptr) return 0;
return getDX11().internalRefCount;
}

HRESULT redirectCreateSwapChain(IDXGIFactory* factory, IUnknown *pDevice, DXGI_SWAP_CHAIN_DESC *pDesc, IDXGISwapChain **ppSwapChain) {
dxgiFactory = factory;
HRESULT ret;
renderWidth = pDesc->BufferDesc.Width;
renderHeight = pDesc->BufferDesc.Height;
SDLOG(2, "RedirectCreateSwapChain dev: %p | RSDev: %p\n", pDevice, d3ddev);
if(Settings::getResSettings().setDSRes(pDesc->BufferDesc.Width, pDesc->BufferDesc.Height)) {
SDLOG(1, " -> Downsampling resolution!\n");
downsampling = true;
renderWidth = pDesc->BufferDesc.Width;
renderHeight = pDesc->BufferDesc.Height;
numBackBuffers = pDesc->BufferCount;
// modify swap chain settings
DXGI_SWAP_CHAIN_DESC copy = *pDesc;
Expand Down Expand Up @@ -65,6 +82,7 @@ class RSManagerDX11 : public RSManager {
}

HRESULT redirectPresent(UINT SyncInterval, UINT Flags) {
SDLOG(-1, "RSManagerDX11::redirectPresent\n");
if(downsampling) {
ID3D11DeviceContext *context;
d3ddev->GetImmediateContext(&context);
Expand All @@ -78,8 +96,29 @@ class RSManagerDX11 : public RSManager {

context->Release();
}
if(console->needsDrawing()) console->draw();
return dxgiSwapChain->Present(SyncInterval, Flags);
}

virtual void showStatus() {
console->add("Hello DX11 World");
}
};


class DX11InternalRefHelper {
ID3D11Device* device;
RSManagerDX11* manager;
ULONG startCount;
public:
DX11InternalRefHelper(ID3D11Device* device, RSManagerDX11* manager) : device(device), manager(manager) {
device->AddRef();
startCount = device->Release();
}
~DX11InternalRefHelper() {
device->AddRef();
ULONG newRefs = device->Release() - startCount;
SDASSERT(newRefs >= 0, "DX11InternalRefHelper: lower final ref count")
manager->addInternalReferences(newRefs);
}
};
Binary file modified pack/GeDoSaTo64.dll
Binary file not shown.
Binary file modified pack/shim64.dll
Binary file not shown.
Loading

0 comments on commit 95de708

Please sign in to comment.