Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
crosire committed Sep 5, 2020
1 parent a1f11b3 commit b26452e
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 616 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A quick overview of what some of the source code files contain:
|[d3d8to9_base.cpp](source/d3d8to9_base.cpp) | Implementation of the `IDirect3D8` interface, including device creation |
|[d3d8to9_device.cpp](source/d3d8to9_device.cpp) | Implementation of the `IDirect3DDevice8` interface, including shader conversion |
|[d3d8types.hpp](source/d3d8types.hpp) | Declaration of all used D3D8 types one would otherwise find in d3d8.h |
|[lookup_table.hpp](source/lookup_table.hpp) | Table to map D3D9 interface addresses to their matching D3D8 implementations |
|[interface_query.hpp](source/interface_query.hpp) | Table to map D3D9 interface addresses to their matching D3D8 implementations |

## Contributing

Expand Down
3 changes: 1 addition & 2 deletions d3d8to9.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@
<ClCompile Include="source\d3d8to9_volume.cpp" />
<ClCompile Include="source\d3d8types.cpp" />
<ClCompile Include="source\interface_query.cpp" />
<ClCompile Include="source\lookup_table.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="res\resource.h" />
<ClInclude Include="source\d3d8to9.hpp" />
<ClInclude Include="source\d3d8types.hpp" />
<ClInclude Include="source\d3dx9.hpp" />
<ClInclude Include="source\lookup_table.hpp" />
<ClInclude Include="source\interface_query.hpp" />
</ItemGroup>
<ItemGroup>
<None Include="res\d3d8.def" />
Expand Down
17 changes: 7 additions & 10 deletions d3d8to9.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\d3d8types.cpp">
<Filter>helpers</Filter>
</ClCompile>
<ClCompile Include="source\d3d8to9.cpp" />
<ClCompile Include="source\d3d8to9_base.cpp" />
<ClCompile Include="source\d3d8to9_device.cpp" />
Expand All @@ -21,25 +18,25 @@
<ClCompile Include="source\d3d8to9_texture.cpp" />
<ClCompile Include="source\d3d8to9_vertex_buffer.cpp" />
<ClCompile Include="source\d3d8to9_volume.cpp" />
<ClCompile Include="source\lookup_table.cpp">
<ClCompile Include="source\d3d8types.cpp">
<Filter>helpers</Filter>
</ClCompile>
<ClCompile Include="source\interface_query.cpp">
<Filter>helpers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="source\d3dx9.hpp">
<Filter>helpers</Filter>
<ClInclude Include="res\resource.h">
<Filter>resources</Filter>
</ClInclude>
<ClInclude Include="source\d3d8to9.hpp" />
<ClInclude Include="source\d3d8types.hpp">
<Filter>helpers</Filter>
</ClInclude>
<ClInclude Include="res\resource.h">
<Filter>resources</Filter>
<ClInclude Include="source\d3dx9.hpp">
<Filter>helpers</Filter>
</ClInclude>
<ClInclude Include="source\d3d8to9.hpp" />
<ClInclude Include="source\lookup_table.hpp">
<ClInclude Include="source\interface_query.hpp">
<Filter>helpers</Filter>
</ClInclude>
</ItemGroup>
Expand Down
7 changes: 2 additions & 5 deletions source/d3d8to9.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#pragma once

#include "d3d8types.hpp"
#include <vector>
#include "d3d8types.hpp"

class __declspec(uuid("1DD9E8DA-1C77-4D40-B0CF-98FEFDFF9512")) Direct3D8;
class __declspec(uuid("7385E5DF-8FE8-41D5-86B6-D7B48547B6CF")) Direct3DDevice8;
Expand All @@ -21,7 +21,7 @@ class __declspec(uuid("BD7349F5-14F1-42E4-9C79-972380DB40C0")) Direct3DVolume8;
class __declspec(uuid("8AEEEAC7-05F9-44D4-B591-000B0DF1CB95")) Direct3DVertexBuffer8;
class __declspec(uuid("0E689C9A-053D-44A0-9D92-DB0E3D750F86")) Direct3DIndexBuffer8;

#include "lookup_table.hpp"
#include "interface_query.hpp"

class Direct3D8 : public IUnknown
{
Expand Down Expand Up @@ -475,6 +475,3 @@ class Direct3DIndexBuffer8 : public Direct3DResource8, public AddressLookupTable
#ifndef D3D8TO9NOLOG
extern std::ofstream LOG;
#endif

REFIID ConvertREFIID(REFIID riid);
void genericQueryInterface(REFIID riid, LPVOID *ppvObj, Direct3DDevice8* pDevice);
34 changes: 6 additions & 28 deletions source/d3d8to9_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ static const D3DFORMAT AdapterFormats[] = {
D3DFMT_A1R5G5B5
};

// IDirect3D8
Direct3D8::Direct3D8(IDirect3D9 *ProxyInterface) :
ProxyInterface(ProxyInterface)
{
D3DDISPLAYMODE pMode;

CurrentAdapterCount = ProxyInterface->GetAdapterCount();

if (CurrentAdapterCount > MaxAdapters)
{
CurrentAdapterCount = MaxAdapters;
}

for (UINT Adapter = 0; Adapter < CurrentAdapterCount; Adapter++)
{
Expand All @@ -48,15 +44,12 @@ Direct3D8::~Direct3D8()
HRESULT STDMETHODCALLTYPE Direct3D8::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
{
return E_POINTER;
}

if (riid == __uuidof(this) ||
riid == __uuidof(IUnknown))
{
AddRef();

*ppvObj = this;

return S_OK;
Expand All @@ -73,9 +66,7 @@ ULONG STDMETHODCALLTYPE Direct3D8::Release()
const ULONG LastRefCount = ProxyInterface->Release();

if (LastRefCount == 0)
{
delete this;
}

return LastRefCount;
}
Expand All @@ -91,9 +82,7 @@ UINT STDMETHODCALLTYPE Direct3D8::GetAdapterCount()
HRESULT STDMETHODCALLTYPE Direct3D8::GetAdapterIdentifier(UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier)
{
if (pIdentifier == nullptr)
{
return D3DERR_INVALIDCALL;
}

D3DADAPTER_IDENTIFIER9 AdapterIndentifier;

Expand All @@ -107,11 +96,8 @@ HRESULT STDMETHODCALLTYPE Direct3D8::GetAdapterIdentifier(UINT Adapter, DWORD Fl
}

const HRESULT hr = ProxyInterface->GetAdapterIdentifier(Adapter, Flags, &AdapterIndentifier);

if (FAILED(hr))
{
return hr;
}

ConvertAdapterIdentifier(AdapterIndentifier, *pIdentifier);

Expand All @@ -124,9 +110,7 @@ UINT STDMETHODCALLTYPE Direct3D8::GetAdapterModeCount(UINT Adapter)
HRESULT STDMETHODCALLTYPE Direct3D8::EnumAdapterModes(UINT Adapter, UINT Mode, D3DDISPLAYMODE *pMode)
{
if (pMode == nullptr || !(Adapter < CurrentAdapterCount && Mode < CurrentAdapterModeCount[Adapter]))
{
return D3DERR_INVALIDCALL;
}

pMode->Format = CurrentAdapterModes[Adapter].at(Mode).Format;
pMode->Height = CurrentAdapterModes[Adapter].at(Mode).Height;
Expand All @@ -145,10 +129,14 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CheckDeviceType(UINT Adapter, D3DDEVTYPE Ch
}
HRESULT STDMETHODCALLTYPE Direct3D8::CheckDeviceFormat(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)
{
if (CheckFormat == D3DFMT_UYVY || CheckFormat == D3DFMT_YUY2 || CheckFormat == MAKEFOURCC('Y', 'V', '1', '2') || CheckFormat == MAKEFOURCC('N', 'V', '1', '2'))
if (CheckFormat == D3DFMT_UYVY ||
CheckFormat == D3DFMT_YUY2 ||
CheckFormat == MAKEFOURCC('Y', 'V', '1', '2') ||
CheckFormat == MAKEFOURCC('N', 'V', '1', '2'))
{
return D3DERR_NOTAVAILABLE;
}

return ProxyInterface->CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
}
HRESULT STDMETHODCALLTYPE Direct3D8::CheckDeviceMultiSampleType(UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType)
Expand All @@ -162,18 +150,13 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CheckDepthStencilMatch(UINT Adapter, D3DDEV
HRESULT STDMETHODCALLTYPE Direct3D8::GetDeviceCaps(UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8 *pCaps)
{
if (pCaps == nullptr)
{
return D3DERR_INVALIDCALL;
}

D3DCAPS9 DeviceCaps;

const HRESULT hr = ProxyInterface->GetDeviceCaps(Adapter, DeviceType, &DeviceCaps);

if (FAILED(hr))
{
return hr;
}

ConvertCaps(DeviceCaps, *pCaps);

Expand All @@ -190,9 +173,7 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE Devic
#endif

if (pPresentationParameters == nullptr || ppReturnedDeviceInterface == nullptr)
{
return D3DERR_INVALIDCALL;
}

*ppReturnedDeviceInterface = nullptr;

Expand All @@ -216,12 +197,9 @@ HRESULT STDMETHODCALLTYPE Direct3D8::CreateDevice(UINT Adapter, D3DDEVTYPE Devic

IDirect3DDevice9 *DeviceInterface = nullptr;

HRESULT hr = ProxyInterface->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &PresentParams, &DeviceInterface);

const HRESULT hr = ProxyInterface->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &PresentParams, &DeviceInterface);
if (FAILED(hr))
{
return hr;
}

*ppReturnedDeviceInterface = new Direct3DDevice8(this, DeviceInterface, (PresentParams.Flags & D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL) != 0);

Expand Down
Loading

0 comments on commit b26452e

Please sign in to comment.