From 2ff2a24ad1ca42596d8e08e8adee144e14353da0 Mon Sep 17 00:00:00 2001 From: SunDaw Date: Sun, 11 Feb 2024 17:59:31 +0100 Subject: [PATCH] making kinc compile with MinGW --- .../WASAPI/Sources/kinc/backend/wasapi.c | 5 ++++ .../kinc/backend/graphics4/Direct3D11.c.h | 23 +++++++++++++++++++ .../kinc/backend/graphics4/ShaderHash.c.h | 2 +- .../kinc/backend/graphics4/d3d11unit.c | 3 +++ .../kinc/backend/graphics4/indexbuffer.c.h | 2 +- .../kinc/backend/graphics4/pipeline.c.h | 2 ++ .../kinc/backend/graphics5/Direct3D12.c.h | 2 +- .../kinc/backend/graphics5/d3d12unit.cpp | 3 +++ .../Sources/kinc/backend/windowsunit.c | 3 +++ 9 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c b/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c index 33f7e0cea..ca0aa2022 100644 --- a/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c +++ b/Backends/Audio2/WASAPI/Sources/kinc/backend/wasapi.c @@ -7,6 +7,9 @@ // Windows 7 #define WINVER 0x0601 +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif #define _WIN32_WINNT 0x0601 #define NOATOM @@ -53,6 +56,7 @@ #include #include +#ifndef __MINGW32__ // MIDL_INTERFACE("1CB9AD4C-DBFA-4c32-B178-C2F568A703B2") DEFINE_GUID(IID_IAudioClient, 0x1CB9AD4C, 0xDBFA, 0x4c32, 0xB1, 0x78, 0xC2, 0xF5, 0x68, 0xA7, 0x03, 0xB2); // MIDL_INTERFACE("F294ACFC-3146-4483-A7BF-ADDCA7C260E2") @@ -61,6 +65,7 @@ DEFINE_GUID(IID_IAudioRenderClient, 0xF294ACFC, 0x3146, 0x4483, 0xA7, 0xBF, 0xAD DEFINE_GUID(IID_IMMDeviceEnumerator, 0xA95664D2, 0x9614, 0x4F35, 0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6); // DECLSPEC_UUID("BCDE0395-E52F-467C-8E3D-C4579291692E") DEFINE_GUID(CLSID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, 0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E); +#endif // based on the implementation in soloud and Microsoft sample code static void (*volatile a2_callback)(kinc_a2_buffer_t *buffer, uint32_t samples, void *userdata) = NULL; diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h index c0423c608..ee2555516 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/Direct3D11.c.h @@ -39,6 +39,15 @@ IUnknown *kinc_winapp_internal_get_window(void); #include #endif +// MinGW workaround for missing defines +#ifndef D3D11_MIN_DEPTH +#define D3D11_MIN_DEPTH (0.0f) +#endif + +#ifndef D3D11_MAX_DEPTH +#define D3D11_MAX_DEPTH (1.0f) +#endif + extern kinc_g4_pipeline_t *currentPipeline; extern float currentBlendFactor[4]; extern bool needPipelineRebind; @@ -876,6 +885,8 @@ void kinc_g4_set_texture_magnification_filter(kinc_g4_texture_unit_t unit, kinc_ case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; break; + default: + break; } break; case KINC_G4_TEXTURE_FILTER_LINEAR: @@ -896,6 +907,8 @@ void kinc_g4_set_texture_magnification_filter(kinc_g4_texture_unit_t unit, kinc_ case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; break; + default: + break; } break; case KINC_G4_TEXTURE_FILTER_ANISOTROPIC: @@ -940,6 +953,8 @@ void kinc_g4_set_texture_minification_filter(kinc_g4_texture_unit_t unit, kinc_g case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; break; + default: + break; } break; case KINC_G4_TEXTURE_FILTER_LINEAR: @@ -961,11 +976,15 @@ void kinc_g4_set_texture_minification_filter(kinc_g4_texture_unit_t unit, kinc_g case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; break; + default: + break; } break; case KINC_G4_TEXTURE_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_ANISOTROPIC; break; + default: + break; } lastSamplers[unit.stages[KINC_G4_SHADER_TYPE_FRAGMENT]].Filter = d3d11filter; @@ -1008,6 +1027,8 @@ void kinc_g4_set_texture_mipmap_filter(kinc_g4_texture_unit_t unit, kinc_g4_mipm case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_ANISOTROPIC; break; + default: + break; } break; case KINC_G4_MIPMAP_FILTER_LINEAR: @@ -1031,6 +1052,8 @@ void kinc_g4_set_texture_mipmap_filter(kinc_g4_texture_unit_t unit, kinc_g4_mipm case D3D11_FILTER_ANISOTROPIC: d3d11filter = D3D11_FILTER_ANISOTROPIC; break; + default: + break; } break; } diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/ShaderHash.c.h b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/ShaderHash.c.h index c1114a184..bfbd458d4 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/ShaderHash.c.h +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/ShaderHash.c.h @@ -4,7 +4,7 @@ uint32_t kinc_internal_hash_name(unsigned char *str) { unsigned long hash = 5381; int c; - while (c = *str++) { + while ((c = *str++)) { hash = hash * 33 ^ c; } return hash; diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/d3d11unit.c b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/d3d11unit.c index f5e5ec745..f7a2e8060 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/d3d11unit.c +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/d3d11unit.c @@ -1,5 +1,8 @@ // Windows 7 #define WINVER 0x0601 +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif #define _WIN32_WINNT 0x0601 #define NOATOM diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/indexbuffer.c.h b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/indexbuffer.c.h index b2c5cb76a..a3d843c4d 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/indexbuffer.c.h +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/indexbuffer.c.h @@ -1,4 +1,4 @@ -#include +#include void kinc_g4_index_buffer_init(kinc_g4_index_buffer_t *buffer, int count, kinc_g4_index_buffer_format_t format, kinc_g4_usage_t usage) { buffer->impl.count = count; diff --git a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h index c05ff3b17..02ccc976f 100644 --- a/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h +++ b/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/pipeline.c.h @@ -788,6 +788,8 @@ void kinc_g4_pipeline_compile(struct kinc_g4_pipeline *state) { } break; } + default: + break; } } } diff --git a/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h b/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h index d85e5cfbf..75025ffd1 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h +++ b/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/Direct3D12.c.h @@ -424,7 +424,7 @@ static void initWindow(struct dx_window *window, int windowIndex) { swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swapChainDesc.Windowed = true; - IDXGIFactory4 *dxgiFactory; + IDXGIFactory4 *dxgiFactory = NULL; kinc_microsoft_affirm(CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory))); kinc_microsoft_affirm(dxgiFactory->CreateSwapChain((IUnknown *)commandQueue, &swapChainDesc, &window->swapChain)); diff --git a/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12unit.cpp b/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12unit.cpp index c9ccb4b2f..35b712e45 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12unit.cpp +++ b/Backends/Graphics5/Direct3D12/Sources/kinc/backend/graphics5/d3d12unit.cpp @@ -2,6 +2,9 @@ // Windows 7 #define WINVER 0x0601 +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif #define _WIN32_WINNT 0x0601 #define NOATOM diff --git a/Backends/System/Windows/Sources/kinc/backend/windowsunit.c b/Backends/System/Windows/Sources/kinc/backend/windowsunit.c index 15e09d2a9..d10f14aa4 100644 --- a/Backends/System/Windows/Sources/kinc/backend/windowsunit.c +++ b/Backends/System/Windows/Sources/kinc/backend/windowsunit.c @@ -1,5 +1,8 @@ // Windows 7 #define WINVER 0x0601 +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif #define _WIN32_WINNT 0x0601 #define NOATOM