From eef1c32c1b3905e6c68264c972ae774d3b6fcce2 Mon Sep 17 00:00:00 2001 From: Nishi Date: Fri, 18 Sep 2026 16:43:15 +0900 Subject: [PATCH] direct3d9 --- CMakeLists.txt | 29 ++--- NTMakefile | 2 +- WatMakefile | 2 +- configure | 8 +- examples/CMakeLists.txt | 2 +- examples/dxdemos/d3d8.c | 95 ---------------- examples/dxdemos/{d3d9.c => direct3d9.c} | 27 ++--- include/Mw/Widget/D3D8.h | 67 ------------ include/Mw/Widget/{D3D9.h => Direct3D9.h} | 34 ++---- milsko.xml | 18 +-- pl/rules.pl | 20 +--- src/backend/cairo.c | 12 +- src/widget/d3d8.c | 127 ---------------------- src/widget/{d3d9.c => direct3d9.c} | 59 +++++----- tools/genmk.pl | 30 +---- 15 files changed, 83 insertions(+), 449 deletions(-) delete mode 100644 examples/dxdemos/d3d8.c rename examples/dxdemos/{d3d9.c => direct3d9.c} (90%) delete mode 100644 include/Mw/Widget/D3D8.h rename include/Mw/Widget/{D3D9.h => Direct3D9.h} (53%) delete mode 100644 src/widget/d3d8.c rename src/widget/{d3d9.c => direct3d9.c} (65%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8863d43..462643e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,8 +34,9 @@ else() endif() if(${CMAKE_SYSTEM_NAME} MATCHES Windows) - option(MW_TRY_D3D8 "Try to compile D3D8 widget or not" ON) - option(MW_TRY_D3D9 "Try to compile D3D9 widget or not" ON) + option(MW_TRY_DIRECT3D9 "Try to compile Direct3D9 widget or not" ON) +else() + option(MW_TRY_DIRECT3D9 "Try to compile Direct3D9 widget or not" OFF) endif() @@ -96,16 +97,12 @@ if(MW_TRY_VULKAN) endif() endif() -if(MW_TRY_D3D8 OR MW_TRY_D3D9) +if(MW_TRY_DIRECT3D9) include(${CMAKE_CURRENT_SOURCE_DIR}/resource/FindDirectX.cmake) if(DIRECTX_FOUND) - if(MW_TRY_D3D8) - set(MW_BUILD_D3D8 ON) - message(STATUS "D3D8 widget has been enabled") - endif() - if(MW_TRY_D3D9) - set(MW_BUILD_D3D9 ON) - message(STATUS "D3D9 widget has been enabled") + if(MW_TRY_DIRECT3D9) + set(MW_BUILD_DIRECT3D9 ON) + message(STATUS "Direct3D9 widget has been enabled") endif() else() message(STATUS "DirectX widgets have been disabled (DirectX not found)") @@ -499,19 +496,11 @@ if(MW_BUILD_VULKAN) endif() endif() -if(MW_BUILD_D3D8) +if(MW_BUILD_DIRECT3D9) target_compile_definitions( Mw PUBLIC - MW_DIRECTX8 - ) -endif() - -if(MW_BUILD_D3D9) - target_compile_definitions( - Mw - PUBLIC - MW_DIRECTX9 + MW_DIRECT3D9 ) endif() diff --git a/NTMakefile b/NTMakefile index f42873b..a549015 100644 --- a/NTMakefile +++ b/NTMakefile @@ -14,7 +14,7 @@ LD = link /nologo DX9_FLAGS = !endif -MW_CFLAGS = /Iinclude /Iexternal\libz\include /D_MILSKO /D_MILSKO_BUILD /DUSE_GDI /DUSE_STB_IMAGE /DSTBI_NO_SIMD /DUSE_GDI_TEXT /DMW_OPENGL $(DX8_FLAGS) $(DX9_FLAGS) +MW_CFLAGS = /Iinclude /Iexternal\libz\include /D_MILSKO /D_MILSKO_BUILD /DUSE_GDI /DUSE_STB_IMAGE /DSTBI_NO_SIMD /DUSE_GDI_TEXT /DMW_OPENGL $(DX9_FLAGS) MW_LDFLAGS = /DLL EXE_CFLAGS = /Iinclude EXE_LDFLAGS = diff --git a/WatMakefile b/WatMakefile index 02205a7..99334e5 100644 --- a/WatMakefile +++ b/WatMakefile @@ -14,7 +14,7 @@ LD = wlink option quiet DX9_FLAGS = !endif -MW_CFLAGS = -bd -i=include -i=external/libz/include -d_MILSKO -d_MILSKO_BUILD -dUSE_GDI -dUSE_STB_IMAGE -dSTBI_NO_SIMD -dUSE_GDI_TEXT -dMW_OPENGL $(DX8_FLAGS) $(DX9_FLAGS) +MW_CFLAGS = -bd -i=include -i=external/libz/include -d_MILSKO -d_MILSKO_BUILD -dUSE_GDI -dUSE_STB_IMAGE -dSTBI_NO_SIMD -dUSE_GDI_TEXT -dMW_OPENGL $(DX9_FLAGS) MW_LDFLAGS = system nt_dll EXE_CFLAGS = -i=include EXE_LDFLAGS = system nt diff --git a/configure b/configure index 5463444..025b265 100755 --- a/configure +++ b/configure @@ -70,8 +70,7 @@ my %features = ( "gnustep" => "use gnustep", "dbus" => "use DBus on supported platform", "allow-sloppy-focus" => "prevent the x11 backend from using XSetInputFocus to enforce click-to-focus", - "directx8" => "(Windows only) build DXD8 widget", - "directx9" => "(Windows only) build DXD9 widget" + "direct3d9" => "(Windows only) build Direct3D9 widget" ); my @features_keys = ( "1classic-theme", "1stb-image", @@ -80,15 +79,14 @@ my @features_keys = ( "1vulkan", "2vulkan-string-helper", "1shared", "1static", "1wayland", "1gnustep", - "1dbus", "1direct8", "1directx9" + "1dbus", "1direct3d9" ); sub def_platform { if($target eq "Windows") { param_set("freetype2", 0); param_set("stb-truetype", 0); - param_set("d3d8", 1); - param_set("d3d9", 1); + param_set("direct3d9", 1); } elsif($target ne "Darwin" and $target ne "ClassicMacOS" and $target ne "Haiku") { param_set("freetype2", 1); param_set("stb-truetype", 0); diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 87225f1..821516f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,7 +7,7 @@ if(${MW_TRY_VULKAN}) endif() if(WIN32) - if(${MW_TRY_D3D8} OR ${MW_BUILD_D3D8}) + if(${MW_TRY_DIRECT3D9}) add_subdirectory(dxdemos) endif() endif() diff --git a/examples/dxdemos/d3d8.c b/examples/dxdemos/d3d8.c deleted file mode 100644 index c5d65d9..0000000 --- a/examples/dxdemos/d3d8.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Adapted from: - * https://web.archive.org/web/20211126225651/https://www.codeguru.com/multimedia/using-direct3d8-the-basics/ - */ -#include -#include - -#ifdef MW_DIRECTX8 - -MwWidget window, d3d8; -LPDIRECT3D8 d3d; -LPDIRECT3DDEVICE8 d3ddev; -LPDIRECT3DVERTEXBUFFER8 v_buffer; - -struct CUSTOMVERTEX { - FLOAT x, y, z, rhw; // from the D3DFVF_XYZRHW flag - DWORD color; // from the D3DFVF_DIFFUSE flag -}; -#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) - -static void MWAPI draw(MwWidget handle, void* user, void* client) { - // clear the window to a deep blue - d3ddev->lpVtbl->Clear(d3ddev, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); - - d3ddev->lpVtbl->BeginScene(d3ddev); // begins the 3D scene - - // select which vertex format we are using - d3ddev->lpVtbl->SetVertexShader(d3ddev, CUSTOMFVF); - - // select the vertex buffer to display - d3ddev->lpVtbl->SetStreamSource(d3ddev, 0, v_buffer, sizeof(struct CUSTOMVERTEX)); - - // // copy the vertex buffer to the back buffer - d3ddev->lpVtbl->DrawPrimitive(d3ddev, D3DPT_TRIANGLELIST, 0, 1); - - d3ddev->lpVtbl->EndScene(d3ddev); // ends the 3D scene - - d3ddev->lpVtbl->Present(d3ddev, NULL, NULL, NULL, NULL); // displays the created frame -} - -int main() { - BYTE* pVoid; - - MwLibraryInit(); - - window = MwCreateWidget(MwWindowClass, NULL, NULL, MwDEFAULT, MwDEFAULT, 1024, 768); - - d3d8 = MwCreateWidget(MwD3D8Class, NULL, window, (1024 - 800) / 2, (768 - 600) / 2, 800, 600); - - d3d = MwD3D8GetD3D(d3d8); - d3ddev = MwD3D8GetD3Dev(d3d8); - - // create three vertices using the CUSTOMVERTEX struct built earlier - struct CUSTOMVERTEX vertices[] = - { - { - 400.0f, - 0.0f, - 0.5f, - 1.0f, - D3DCOLOR_XRGB(0, 0, 255), - }, - { - 800.0f, - 600.0f, - 0.5f, - 1.0f, - D3DCOLOR_XRGB(0, 255, 0), - }, - { - 0.0f, - 600.0f, - 0.5f, - 1.0f, - D3DCOLOR_XRGB(255, 0, 0), - }, - }; - - d3ddev->lpVtbl->CreateVertexBuffer(d3ddev, - 3 * sizeof(struct CUSTOMVERTEX), - 0, - CUSTOMFVF, - D3DPOOL_MANAGED, - &v_buffer); - - v_buffer->lpVtbl->Lock(v_buffer, 0, 0, (BYTE**)&pVoid, 0); // lock the vertex buffer - memcpy(pVoid, vertices, sizeof(vertices)); // copy the vertices to the locked buffer - v_buffer->lpVtbl->Unlock(v_buffer); // unlock the vertex buffer - - MwAddUserHandler(window, MwNtickHandler, draw, NULL); - - MwLoop(window); -} - -#endif diff --git a/examples/dxdemos/d3d9.c b/examples/dxdemos/direct3d9.c similarity index 90% rename from examples/dxdemos/d3d9.c rename to examples/dxdemos/direct3d9.c index 86186ae..47a2609 100644 --- a/examples/dxdemos/d3d9.c +++ b/examples/dxdemos/direct3d9.c @@ -4,11 +4,9 @@ * http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-4 */ #include -#include +#include -#ifdef MW_DIRECTX9 - -MwWidget window, d3d8; +MwWidget window, d3d9; LPDIRECT3D9 d3d; LPDIRECT3DDEVICE9 d3ddev; LPDIRECT3DVERTEXBUFFER9 v_buffer; @@ -41,16 +39,6 @@ static void MWAPI draw(MwWidget handle, void* user, void* client) { int main() { VOID* pVoid; - - MwLibraryInit(); - - window = MwCreateWidget(MwWindowClass, NULL, NULL, MwDEFAULT, MwDEFAULT, 1024, 768); - - d3d8 = MwCreateWidget(MwD3D9Class, NULL, window, (1024 - 800) / 2, (768 - 600) / 2, 800, 600); - - d3d = MwD3D9GetD3D(d3d8); - d3ddev = MwD3D9GetD3Dev(d3d8); - // create three vertices using the CUSTOMVERTEX struct built earlier struct CUSTOMVERTEX vertices[] = { @@ -77,6 +65,15 @@ int main() { }, }; + MwLibraryInit(); + + window = MwCreateWidget(MwWindowClass, NULL, NULL, MwDEFAULT, MwDEFAULT, 1024, 768); + + d3d9 = MwCreateWidget(MwDirect3D9Class, NULL, window, (1024 - 800) / 2, (768 - 600) / 2, 800, 600); + + d3d = MwDirect3D9GetD3D(d3d9); + d3ddev = MwDirect3D9GetD3DDevice(d3d9); + d3ddev->lpVtbl->CreateVertexBuffer(d3ddev, 3 * sizeof(struct CUSTOMVERTEX), 0, @@ -93,5 +90,3 @@ int main() { MwLoop(window); } - -#endif diff --git a/include/Mw/Widget/D3D8.h b/include/Mw/Widget/D3D8.h deleted file mode 100644 index 9b0ae6e..0000000 --- a/include/Mw/Widget/D3D8.h +++ /dev/null @@ -1,67 +0,0 @@ -/*! - * @file Mw/Widget/D3D8.h - * @brief D3D8 widget. - * @warning Only avaliable on Windows. - */ -#ifndef __MW_WIDGET_D3D8_H__ -#define __MW_WIDGET_D3D8_H__ - -#include -#include -#include - -#if !defined(MW_D3D8_NO_INCLUDE) - -/* https://github.com/microsoft/Windows-classic-samples/issues/317 */ -#if defined(__MINGW32__) || defined(__MINGW64__) -#define NTDDI_VERSION 0x07000000 -#define _WIN32_WINNT 0x0A00 - -#endif -#endif - -#ifndef _WIN32 -#error D3D8 widget only avaliable for Win32 backends -#undef MW_DIRECTX8 -#else -#ifdef MW_DIRECTX8 -#include -#endif -#endif - -/*! - * @brief D3D8 widget class - */ -MWDECL MwClass MwD3D8Class; - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef MW_DIRECTX8 -MwInline LPDIRECT3D8 MwD3D8GetD3D(MwWidget handle) { - LPDIRECT3D8 out = NULL; - MwVaWidgetExecute(handle, "mwDirectXGetD3D8", &out, NULL); - return out; -}; -MwInline LPDIRECT3DDEVICE8 MwD3D8GetD3Dev(MwWidget handle) { - LPDIRECT3DDEVICE8 out = NULL; - MwVaWidgetExecute(handle, "mwDirectXGetD3Dev8", &out); - return out; -}; -#else -MwInline void* MwD3D8GetD3D(MwWidget handle) { - (void)handle; - return NULL; -}; -MwInline void* MwD3D8GetD3Dev(MwWidget handle) { - (void)handle; - return NULL; -}; -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/Mw/Widget/D3D9.h b/include/Mw/Widget/Direct3D9.h similarity index 53% rename from include/Mw/Widget/D3D9.h rename to include/Mw/Widget/Direct3D9.h index 3831301..f31e247 100644 --- a/include/Mw/Widget/D3D9.h +++ b/include/Mw/Widget/Direct3D9.h @@ -3,61 +3,51 @@ * @brief DirectX widget. * @warning Only avaliable on Windows. */ -#ifndef __MW_WIDGET_D3D9_H__ -#define __MW_WIDGET_D3D9_H__ +#ifndef __MW_WIDGET_DIRECT3D9_H__ +#define __MW_WIDGET_DIRECT3D9_H__ #include #include #include -#if !defined(MW_D3D9_NO_INCLUDE) +#if !defined(MW_DIRECT3D9_NO_INCLUDE) /* https://github.com/microsoft/Windows-classic-samples/issues/317 */ #if defined(__MINGW32__) || defined(__MINGW64__) +#undef NTDDI_VERSION +#undef _WIN32_WINNT + #define NTDDI_VERSION 0x07000000 #define _WIN32_WINNT 0x0A00 #endif #ifndef _WIN32 #error D3D9 widget only avaliable for Win32 backends -#undef MW_DIRECTX9 +#undef MW_DIRECT3D9 #else -#ifdef MW_DIRECTX9 #include #endif #endif -#endif /*! * @brief D3D9 widget class */ -MWDECL MwClass MwD3D9Class; +MWDECL MwClass MwDirect3D9Class; #ifdef __cplusplus extern "C" { #endif -#ifdef MW_DIRECTX9 -MwInline LPDIRECT3D9 MwD3D9GetD3D(MwWidget handle) { +MwInline LPDIRECT3D9 MwDirect3D9GetD3D(MwWidget handle) { LPDIRECT3D9 out = NULL; - MwVaWidgetExecute(handle, "mwDirectXGetD3D9", &out, NULL); + MwVaWidgetExecute(handle, "mwDirect3D9GetD3D9", &out, NULL); return out; }; -MwInline LPDIRECT3DDEVICE9 MwD3D9GetD3Dev(MwWidget handle) { +MwInline LPDIRECT3DDEVICE9 MwDirect3D9GetD3DDevice(MwWidget handle) { LPDIRECT3DDEVICE9 out = NULL; - MwVaWidgetExecute(handle, "mwDirectXGetD3Dev9", &out); + MwVaWidgetExecute(handle, "mwDirect3D9GetD3DDevice9", &out); return out; }; -#else -MwInline void* MwD3D9GetD3D(MwWidget handle) { - (void)handle; - return NULL; -}; -MwInline void* MwD3D9GetD3Dev(MwWidget handle) { - (void)handle; - return NULL; -}; -#endif #ifdef __cplusplus } diff --git a/milsko.xml b/milsko.xml index 2ff60c7..77ace6b 100644 --- a/milsko.xml +++ b/milsko.xml @@ -1073,28 +1073,14 @@ - + - - - - - - - - - - - - - - - + diff --git a/pl/rules.pl b/pl/rules.pl index 8e4a611..276eb88 100644 --- a/pl/rules.pl +++ b/pl/rules.pl @@ -66,7 +66,7 @@ if (grep(/^wayland$/, @backends)) { scan_wayland_protocol("unstable", "primary-selection", "-unstable-v1"); scan_wayland_protocol("unstable", "pointer-constraints", "-unstable-v1"); scan_wayland_protocol("unstable", "relative-pointer", "-unstable-v1"); - scan_wayland_protocol("staging", "fifo", "-v1"); + scan_wayland_protocol("staging", "fifo", "-v1"); scan_wayland_protocol_from_file("wlr-layer-shell", "wlr-layer-shell-unstable-v1.xml"); @@ -178,8 +178,7 @@ new_object("src/widget/window.c"); new_object("src/widget/opengl.c"); new_object("src/widget/vulkan.c"); -new_object("src/widget/d3d8.c"); -new_object("src/widget/d3d9.c"); +new_object("src/widget/direct3d9.c"); if (param_get("opengl")) { add_cflags("-DMW_OPENGL"); @@ -187,11 +186,8 @@ if (param_get("opengl")) { if (param_get("vulkan")) { add_cflags("-DMW_VULKAN"); } -if (param_get("d3d8")) { - add_cflags("-DMW_DIRECTX8"); -} -if (param_get("d3d9")) { - add_cflags("-DMW_DIRECTX9"); +if (param_get("direct3d9")) { + add_cflags("-DMW_DIRECT3D9"); } new_object("src/dialog/*.c"); @@ -238,12 +234,8 @@ if (param_get("vulkan")) { new_example("examples/vkdemos/vulkan"); } -if (param_get("d3d8")) { - new_example("examples/dxdemos/d3d8"); -} - -if (param_get("d3d9")) { - new_example("examples/dxdemos/d3d9"); +if (param_get("direct3d9")) { + new_example("examples/dxdemos/direct3d9"); } 1; diff --git a/src/backend/cairo.c b/src/backend/cairo.c index 9dab1c1..3f1e18c 100644 --- a/src/backend/cairo.c +++ b/src/backend/cairo.c @@ -219,8 +219,8 @@ static void MwLLFreeColorImpl(MwLLColor color) {} static MwBool lmao = MwFALSE; static int MwLLPendingImpl(MwLL handle) { - lmao = !lmao; - return lmao; + lmao = !lmao; + return lmao; } static void MwLLNextEventImpl(MwLL handle) { MwLLDispatch(handle, draw, NULL); @@ -264,10 +264,10 @@ static void MwLLRaiseImpl(MwLL handle) {} static void MwLLClipImpl(MwLL handle, MwRect* rect) {} static void MwLLSetupDragAndDropImpl(MwLL handle) {} static int MwLLCairoCallInitImpl(void) { - if(cairo_load_funcs() != 0) { - return 1; - } - return 0; + if(cairo_load_funcs() != 0) { + return 1; + } + return 0; } #include "call.c" CALL(Cairo); diff --git a/src/widget/d3d8.c b/src/widget/d3d8.c deleted file mode 100644 index d569f53..0000000 --- a/src/widget/d3d8.c +++ /dev/null @@ -1,127 +0,0 @@ -#include - -#ifdef MW_DIRECTX8 -#include -typedef struct gdid3d8 { - void* d3d8dll; - IDirect3D8* (*Direct3DCreate8)(UINT sdk_version); - - LPDIRECT3D8 d3d; // the pointer to our Direct3D interface - LPDIRECT3DDEVICE8 d3ddev; // the pointer to the device class\ - -} gdid3d8_t; - -static int wcreate_d3d8(MwWidget handle) { - void* r = NULL; - MwWidget w = handle; - gdid3d8_t* o = malloc(sizeof(gdid3d8_t)); - D3DPRESENT_PARAMETERS d3dpp; - D3DDISPLAYMODE dispMode; - HRESULT hr; - char errbuf[2048] = {0}; - - o->d3d8dll = LoadLibrary("d3d8.dll"); - if(!o->d3d8dll) { - MwDispatchError(1, "d3d8.dll not found! Is DirectX8 installed?"); - return 1; - } - o->Direct3DCreate8 = (void*)GetProcAddress(o->d3d8dll, "Direct3DCreate8"); - if(!o->Direct3DCreate8) { - MwDispatchError(1, "Direct3DCreate8 not found! Is DirectX8 installed properly?"); - return 1; - } - - o->d3d = o->Direct3DCreate8(D3D_SDK_VERSION); - if(!o->Direct3DCreate8) { - MwStringPrintIntoBuffer(errbuf, sizeof(errbuf) - 1, "Direct3DCreate8 NULL: %s", hr); - MwDispatchError(1, errbuf); - return 1; - } - - hr = o->d3d->lpVtbl->GetAdapterDisplayMode(o->d3d, D3DADAPTER_DEFAULT, &dispMode); - if(hr != D3D_OK) { - MwStringPrintIntoBuffer(errbuf, sizeof(errbuf) - 1, "GetAdapterDisplayMode ERROR: %s", hr); - MwDispatchError(1, errbuf); - return 1; - } - - ZeroMemory(&d3dpp, sizeof(d3dpp)); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.hDeviceWindow = handle->lowlevel->gdi.hWnd; - d3dpp.BackBufferFormat = dispMode.Format; - d3dpp.EnableAutoDepthStencil = TRUE; - d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - - // create a device class using this information and information from the d3dpp stuct - o->d3d->lpVtbl->CreateDevice(o->d3d, - D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, - handle->lowlevel->gdi.hWnd, - D3DCREATE_MIXED_VERTEXPROCESSING, - &d3dpp, - &o->d3ddev); - if(hr != D3D_OK) { - MwStringPrintIntoBuffer(errbuf, sizeof(errbuf) - 1, "CreateDevice ERROR: %s", hr); - MwDispatchError(1, errbuf); - return 1; - } - - o->d3ddev->lpVtbl->SetRenderState(o->d3ddev, D3DRS_LIGHTING, FALSE); - if(hr != D3D_OK) { - MwStringPrintIntoBuffer(errbuf, sizeof(errbuf) - 1, "SetRenderState ERROR: %s", hr); - MwDispatchError(1, errbuf); - return 1; - } - - handle->internal = o; - - return 0; -} - -static void destroy_d3d8(MwWidget handle) { - MwWidget w = handle; - gdid3d8_t* o = handle->internal; - - o->d3ddev->lpVtbl->Release(o->d3ddev); // close and release the 3D device - o->d3d->lpVtbl->Release(o->d3d); // close and release Direct3D - - free(handle->internal); -} - -static void func_handler_d3d8(MwWidget handle, const char* name, void* out, - va_list va) { - gdid3d8_t* o = handle->internal; - - if(strcmp(name, "mwDirectXGetD3D8") == 0) { - *(LPDIRECT3D8*)out = o->d3d; - } - if(strcmp(name, "mwDirectXGetD3Dev8") == 0) { - *(LPDIRECT3DDEVICE8*)out = o->d3ddev; - } -} - -MwClassRec MwDX8ClassRec = {wcreate_d3d8, /* create */ - destroy_d3d8, /* destroy */ - NULL, /* draw */ - NULL, /* click */ - NULL, /* parent_resize */ - NULL, /* prop_change */ - NULL, /* mouse_move */ - NULL, /* mouse_up */ - NULL, /* mouse_down */ - NULL, /* key */ - func_handler_d3d8, /* execute */ - NULL, /* tick */ - NULL, /* resize */ - NULL, /* children_update */ - NULL, /* children_prop_change */ - NULL, /* clipboard */ - NULL, /* props_change */ - NULL, NULL, NULL}; -MwClass MwD3D8Class = &MwDX8ClassRec; -#else -MWDECL MwClass MwDX8Class; - -MwClass MwDX8Class = NULL; -#endif diff --git a/src/widget/d3d9.c b/src/widget/direct3d9.c similarity index 65% rename from src/widget/d3d9.c rename to src/widget/direct3d9.c index 7219e58..da77041 100644 --- a/src/widget/d3d9.c +++ b/src/widget/direct3d9.c @@ -1,19 +1,17 @@ #include -#ifdef MW_DIRECTX9 -#include +#ifdef MW_DIRECT3D9 +#include typedef struct gdid3d9 { void* d3d9dll; IDirect3D9* (*Direct3DCreate9)(UINT sdk_version); LPDIRECT3D9 d3d; // the pointer to our Direct3D interface - LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class\ + LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class } gdid3d9_t; static int wcreate_d3d9(MwWidget handle) { - void* r = NULL; - MwWidget w = handle; gdid3d9_t* o = malloc(sizeof(gdid3d9_t)); HRESULT hr; char errbuf[2048]; @@ -27,7 +25,7 @@ static int wcreate_d3d9(MwWidget handle) { o->Direct3DCreate9 = (void*)GetProcAddress(o->d3d9dll, "Direct3DCreate9"); o->d3d = o->Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface - if(hr != D3D_OK) { + if(o->d3d == NULL) { MwDispatchError(1, "Direct3DCreate9 NULL"); return 1; } @@ -57,7 +55,6 @@ static int wcreate_d3d9(MwWidget handle) { } static void destroy_d3d9(MwWidget handle) { - MwWidget w = handle; gdid3d9_t* o = handle->internal; o->d3ddev->lpVtbl->Release(o->d3ddev); // close and release the 3D device @@ -70,35 +67,35 @@ static void func_handler_d3d9(MwWidget handle, const char* name, void* out, va_list va) { gdid3d9_t* o = handle->internal; - if(strcmp(name, "mwDirectXGetD3D9") == 0) { + (void)va; + + if(strcmp(name, "mwDirect3D9GetD3D9") == 0) { *(LPDIRECT3D9*)out = o->d3d; } - if(strcmp(name, "mwDirectXGetD3Dev9") == 0) { + if(strcmp(name, "mwDirect3D9GetD3DDevice9") == 0) { *(LPDIRECT3DDEVICE9*)out = o->d3ddev; } } -MwClassRec MwDX9ClassRec = {wcreate_d3d9, /* create */ - destroy_d3d9, /* destroy */ - NULL, /* draw */ - NULL, /* click */ - NULL, /* parent_resize */ - NULL, /* prop_change */ - NULL, /* mouse_move */ - NULL, /* mouse_up */ - NULL, /* mouse_down */ - NULL, /* key */ - func_handler_d3d9, /* execute */ - NULL, /* tick */ - NULL, /* resize */ - NULL, /* children_update */ - NULL, /* children_prop_change */ - NULL, /* clipboard */ - NULL, /* props_change */ - NULL, NULL, NULL}; -MwClass MwD3D9Class = &MwDX9ClassRec; +MwClassRec MwDirect3D9ClassRec = {wcreate_d3d9, /* create */ + destroy_d3d9, /* destroy */ + NULL, /* draw */ + NULL, /* click */ + NULL, /* parent_resize */ + NULL, /* prop_change */ + NULL, /* mouse_move */ + NULL, /* mouse_up */ + NULL, /* mouse_down */ + NULL, /* key */ + func_handler_d3d9, /* execute */ + NULL, /* tick */ + NULL, /* resize */ + NULL, /* children_update */ + NULL, /* children_prop_change */ + NULL, /* clipboard */ + NULL, /* props_change */ + NULL, NULL, NULL}; +MwClass MwDirect3D9Class = &MwDirect3D9ClassRec; #else -MWDECL MwClass MwDX9Class; - -MwClass MwDX9Class = NULL; +MwClass MwDirect3D9Class = NULL; #endif diff --git a/tools/genmk.pl b/tools/genmk.pl index 9f45add..369ed58 100755 --- a/tools/genmk.pl +++ b/tools/genmk.pl @@ -42,24 +42,6 @@ sub cobjs { return $r; } - -sub dx8_detect_block { - return <<'EOF'; -!if [where d3d8.h >nul 2>nul] -!if [for /f "delims=" %P in ('where d3d8.h 2^>nul') do @echo DX8_FLAGS = /DMW_DIRECTX8 /I"%~dpP">dx8flags.mk] -!endif -!else -!if [echo DX8_FLAGS =>dx9flags.mk] -!endif -!endif -!if exist("dx8flags.mk") -!include "dx8flags.mk" -!else -DX8_FLAGS = -!endif -EOF -} - sub dx9_detect_block { return <<'EOF'; !if [where d3d9.h >nul 2>nul] @@ -100,10 +82,8 @@ sub generate { my $lib = ""; my $c_dllout = ""; my $c_dllafter = ""; - my $dx8_flags = ""; - my $dx8_block = ""; - my $dx9_flags = ""; - my $dx9_block = ""; + my $dx9_flags = ""; + my $dx9_block = ""; if ($type eq "Borland") { $cc = "bcc32 -c"; @@ -128,8 +108,6 @@ sub generate { $inc = "/I"; $dll = "/DLL"; - $dx8_flags = "\$(DX8_FLAGS)"; - $dx8_block = dx8_detect_block(); $dx9_flags = "\$(DX9_FLAGS)"; $dx9_block = dx9_detect_block(); } @@ -154,8 +132,6 @@ sub generate { $needlibs = "${lib}clib3r.lib"; $c_dllout = "option implib=src${dir}Mw.lib"; - $dx8_flags = "\$(DX8_FLAGS)"; - $dx8_block = dx8_detect_block(); $dx9_flags = "\$(DX9_FLAGS)"; $dx9_block = dx9_detect_block(); } @@ -169,7 +145,7 @@ sub generate { print(OUT "\n"); } print(OUT -"MW_CFLAGS = ${cdll} ${inc}include ${inc}external${dir}libz${dir}include ${def}_MILSKO ${def}_MILSKO_BUILD ${def}USE_GDI ${def}USE_STB_IMAGE ${def}STBI_NO_SIMD ${def}USE_GDI_TEXT ${def}MW_OPENGL ${dx8_flags} ${dx9_flags}\n" +"MW_CFLAGS = ${cdll} ${inc}include ${inc}external${dir}libz${dir}include ${def}_MILSKO ${def}_MILSKO_BUILD ${def}USE_GDI ${def}USE_STB_IMAGE ${def}STBI_NO_SIMD ${def}USE_GDI_TEXT ${def}MW_OPENGL ${dx9_flags}\n" ); print(OUT "MW_LDFLAGS = $dll\n"); print(OUT "EXE_CFLAGS = ${inc}include\n");