Skip to content

Commit

Permalink
Fix build with MinGW-w64 (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalh authored Dec 8, 2020
1 parent 15b82e7 commit 8648e85
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 38 deletions.
40 changes: 28 additions & 12 deletions source/d3d8to9.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,34 @@
#include <vector>
#include "d3d8types.hpp"

class __declspec(uuid("1DD9E8DA-1C77-4D40-B0CF-98FEFDFF9512")) Direct3D8;
class __declspec(uuid("7385E5DF-8FE8-41D5-86B6-D7B48547B6CF")) Direct3DDevice8;
class __declspec(uuid("928C088B-76B9-4C6B-A536-A590853876CD")) Direct3DSwapChain8;
class __declspec(uuid("1B36BB7B-09B7-410A-B445-7D1430D7B33F")) Direct3DResource8;
class __declspec(uuid("B4211CFA-51B9-4A9F-AB78-DB99B2BB678E")) Direct3DBaseTexture8;
class __declspec(uuid("E4CDD575-2866-4F01-B12E-7EECE1EC9358")) Direct3DTexture8;
class __declspec(uuid("3EE5B968-2ACA-4C34-8BB5-7E0C3D19B750")) Direct3DCubeTexture8;
class __declspec(uuid("4B8AAAFA-140F-42BA-9131-597EAFAA2EAD")) Direct3DVolumeTexture8;
class __declspec(uuid("B96EEBCA-B326-4EA5-882F-2FF5BAE021DD")) Direct3DSurface8;
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;
class DECLSPEC_UUID("1DD9E8DA-1C77-4D40-B0CF-98FEFDFF9512") Direct3D8;
class DECLSPEC_UUID("7385E5DF-8FE8-41D5-86B6-D7B48547B6CF") Direct3DDevice8;
class DECLSPEC_UUID("928C088B-76B9-4C6B-A536-A590853876CD") Direct3DSwapChain8;
class DECLSPEC_UUID("1B36BB7B-09B7-410A-B445-7D1430D7B33F") Direct3DResource8;
class DECLSPEC_UUID("B4211CFA-51B9-4A9F-AB78-DB99B2BB678E") Direct3DBaseTexture8;
class DECLSPEC_UUID("E4CDD575-2866-4F01-B12E-7EECE1EC9358") Direct3DTexture8;
class DECLSPEC_UUID("3EE5B968-2ACA-4C34-8BB5-7E0C3D19B750") Direct3DCubeTexture8;
class DECLSPEC_UUID("4B8AAAFA-140F-42BA-9131-597EAFAA2EAD") Direct3DVolumeTexture8;
class DECLSPEC_UUID("B96EEBCA-B326-4EA5-882F-2FF5BAE021DD") Direct3DSurface8;
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;

// MinGW support
#ifdef __CRT_UUID_DECL
__CRT_UUID_DECL(Direct3D8, 0x1DD9E8DA, 0x1C77, 0x4D40, 0xB0, 0xCF, 0x98,0xFE,0xFD,0xFF,0x95,0x12)
__CRT_UUID_DECL(Direct3DDevice8, 0x7385E5DF, 0x8FE8, 0x41D5, 0x86, 0xB6, 0xD7,0xB4,0x85,0x47,0xB6,0xCF)
__CRT_UUID_DECL(Direct3DSwapChain8, 0x928C088B, 0x76B9, 0x4C6B, 0xA5, 0x36, 0xA5,0x90,0x85,0x38,0x76,0xCD)
__CRT_UUID_DECL(Direct3DResource8, 0x1B36BB7B, 0x09B7, 0x410A, 0xB4, 0x45, 0x7D,0x14,0x30,0xD7,0xB3,0x3F)
__CRT_UUID_DECL(Direct3DBaseTexture8, 0xB4211CFA, 0x51B9, 0x4A9F, 0xAB, 0x78, 0xDB,0x99,0xB2,0xBB,0x67,0x8E)
__CRT_UUID_DECL(Direct3DTexture8, 0xE4CDD575, 0x2866, 0x4F01, 0xB1, 0x2E, 0x7E,0xEC,0xE1,0xEC,0x93,0x58)
__CRT_UUID_DECL(Direct3DCubeTexture8, 0x3EE5B968, 0x2ACA, 0x4C34, 0x8B, 0xB5, 0x7E,0x0C,0x3D,0x19,0xB7,0x50)
__CRT_UUID_DECL(Direct3DVolumeTexture8, 0x4B8AAAFA, 0x140F, 0x42BA, 0x91, 0x31, 0x59,0x7E,0xAF,0xAA,0x2E,0xAD)
__CRT_UUID_DECL(Direct3DSurface8, 0xB96EEBCA, 0xB326, 0x4EA5, 0x88, 0x2F, 0x2F,0xF5,0xBA,0xE0,0x21,0xDD)
__CRT_UUID_DECL(Direct3DVolume8, 0xBD7349F5, 0x14F1, 0x42E4, 0x9C, 0x79, 0x97,0x23,0x80,0xDB,0x40,0xC0)
__CRT_UUID_DECL(Direct3DVertexBuffer8, 0x8AEEEAC7, 0x05F9, 0x44D4, 0xB5, 0x91, 0x00,0x0B,0x0D,0xF1,0xCB,0x95)
__CRT_UUID_DECL(Direct3DIndexBuffer8, 0x0E689C9A, 0x053D, 0x44A0, 0x9D, 0x92, 0xDB,0x0E,0x3D,0x75,0x0F,0x86)
#endif

#include "interface_query.hpp"

Expand Down
3 changes: 2 additions & 1 deletion source/d3d8types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "d3d8types.hpp"
#include <assert.h>
#include <algorithm>

bool SupportsPalettes()
{
Expand Down Expand Up @@ -88,7 +89,7 @@ void ConvertCaps(D3DCAPS9 &Input, D3DCAPS8 &Output)
// Set default vertex shader version to 1.1 for D3D8 compatibility
Output.VertexShaderVersion = D3DVS_VERSION(1, 1);
// D3D8 can only handle up to 256 for MaxVertexShaderConst
Output.MaxVertexShaderConst = min(256, Input.MaxVertexShaderConst);
Output.MaxVertexShaderConst = std::min(256ul, Input.MaxVertexShaderConst);
}

void ConvertVolumeDesc(D3DVOLUME_DESC &Input, D3DVOLUME_DESC8 &Output)
Expand Down
14 changes: 14 additions & 0 deletions source/d3d8types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

struct IUnknown;

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <d3d9.h>

#define D3DFMT_W11V11U10 65
Expand Down Expand Up @@ -46,10 +50,20 @@ struct IUnknown;
#define D3DVSD_CONSTADDRESSMASK (0x7F << D3DVSD_CONSTADDRESSSHIFT)
#define D3DVSD_END() 0xFFFFFFFF

// Fix for MinGW headers which are missing defines in d3d9.h...
#ifndef D3DENUM_WHQL_LEVEL
#define D3DENUM_WHQL_LEVEL 0x00000002L
#endif
// Fix for MinGW headers which have some d3d8 defines in d3d9.h...
#ifndef D3DENUM_NO_WHQL_LEVEL
#define D3DENUM_NO_WHQL_LEVEL 0x00000002L
#endif
#define D3DSWAPEFFECT_COPY_VSYNC 4
#define D3DPRESENT_RATE_UNLIMITED 0x7FFFFFFF
// Fix for MinGW headers which have some d3d8 defines in d3d9.h...
#ifndef D3DCAPS2_CANRENDERWINDOWED
#define D3DCAPS2_CANRENDERWINDOWED 0x00080000L
#endif
#define D3DPRASTERCAPS_ZBIAS 0x00004000L

typedef D3DLIGHT9 D3DLIGHT8;
Expand Down
4 changes: 4 additions & 0 deletions source/d3dx9.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <d3d9.h>

#define D3DX_FILTER_NONE 1
Expand Down
51 changes: 26 additions & 25 deletions source/interface_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,6 @@ class AddressLookupTable
{
template <typename T>
struct AddressCacheIndex;
template <>
struct AddressCacheIndex<Direct3DSurface8>
{ static constexpr UINT CacheIndex = 0; using Type9 = IDirect3DSurface9; };
template <>
struct AddressCacheIndex<Direct3DTexture8>
{ static constexpr UINT CacheIndex = 1; using Type9 = IDirect3DTexture9; };
template <>
struct AddressCacheIndex<Direct3DVolumeTexture8>
{ static constexpr UINT CacheIndex = 2; using Type9 = IDirect3DVolumeTexture9; };
template <>
struct AddressCacheIndex<Direct3DCubeTexture8>
{ static constexpr UINT CacheIndex = 3; using Type9 = IDirect3DCubeTexture9; };
template <>
struct AddressCacheIndex<Direct3DVolume8>
{ static constexpr UINT CacheIndex = 4; using Type9 = IDirect3DVolume9; };
template <>
struct AddressCacheIndex<Direct3DVertexBuffer8>
{ static constexpr UINT CacheIndex = 5; using Type9 = IDirect3DVertexBuffer9; };
template <>
struct AddressCacheIndex<Direct3DIndexBuffer8>
{ static constexpr UINT CacheIndex = 6; using Type9 = IDirect3DIndexBuffer9; };
template <>
struct AddressCacheIndex<Direct3DSwapChain8>
{ static constexpr UINT CacheIndex = 7; using Type9 = IDirect3DSwapChain9; };


public:
Expand All @@ -54,7 +30,7 @@ class AddressLookupTable
if (it != cache.end())
return static_cast<T *>(it->second);

return new T(Device, static_cast<AddressCacheIndex<T>::Type9 *>(pAddress9));
return new T(Device, static_cast<typename AddressCacheIndex<T>::Type9 *>(pAddress9));
}

template <typename T>
Expand Down Expand Up @@ -85,6 +61,31 @@ class AddressLookupTable
std::unordered_map<void *, class AddressLookupTableObject *> AddressCache[8];
};

template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DSurface8>
{ static constexpr UINT CacheIndex = 0; using Type9 = IDirect3DSurface9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DTexture8>
{ static constexpr UINT CacheIndex = 1; using Type9 = IDirect3DTexture9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DVolumeTexture8>
{ static constexpr UINT CacheIndex = 2; using Type9 = IDirect3DVolumeTexture9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DCubeTexture8>
{ static constexpr UINT CacheIndex = 3; using Type9 = IDirect3DCubeTexture9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DVolume8>
{ static constexpr UINT CacheIndex = 4; using Type9 = IDirect3DVolume9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DVertexBuffer8>
{ static constexpr UINT CacheIndex = 5; using Type9 = IDirect3DVertexBuffer9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DIndexBuffer8>
{ static constexpr UINT CacheIndex = 6; using Type9 = IDirect3DIndexBuffer9; };
template <>
struct AddressLookupTable::AddressCacheIndex<Direct3DSwapChain8>
{ static constexpr UINT CacheIndex = 7; using Type9 = IDirect3DSwapChain9; };

class AddressLookupTableObject
{
public:
Expand Down

0 comments on commit 8648e85

Please sign in to comment.