direct3d9
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
This commit is contained in:
parent
e6f1385d5e
commit
eef1c32c1b
15 changed files with 83 additions and 449 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
2
NTMakefile
generated
2
NTMakefile
generated
|
|
@ -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 =
|
||||
|
|
|
|||
2
WatMakefile
generated
2
WatMakefile
generated
|
|
@ -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
|
||||
|
|
|
|||
8
configure
vendored
8
configure
vendored
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* Adapted from:
|
||||
* https://web.archive.org/web/20211126225651/https://www.codeguru.com/multimedia/using-direct3d8-the-basics/
|
||||
*/
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/D3D8.h>
|
||||
|
||||
#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
|
||||
|
|
@ -4,11 +4,9 @@
|
|||
* http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-4
|
||||
*/
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/D3D9.h>
|
||||
#include <Mw/Widget/Direct3D9.h>
|
||||
|
||||
#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
|
||||
|
|
@ -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 <Mw/Core.h>
|
||||
#include <Mw/MachDep.h>
|
||||
#include <Mw/TypeDefs.h>
|
||||
|
||||
#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 <d3d8.h>
|
||||
#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
|
||||
|
|
@ -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 <Mw/Core.h>
|
||||
#include <Mw/MachDep.h>
|
||||
#include <Mw/TypeDefs.h>
|
||||
|
||||
#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 <d3d9.h>
|
||||
#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
|
||||
}
|
||||
18
milsko.xml
18
milsko.xml
|
|
@ -1073,28 +1073,14 @@
|
|||
</function>
|
||||
</functions>
|
||||
</widget>
|
||||
<widget name="D3D8">
|
||||
<widget name="Direct3D9">
|
||||
<functions>
|
||||
<function name="GetD3D">
|
||||
<return>
|
||||
<pointer />
|
||||
</return>
|
||||
</function>
|
||||
<function name="GetD3Dev">
|
||||
<return>
|
||||
<pointer />
|
||||
</return>
|
||||
</function>
|
||||
</functions>
|
||||
</widget>
|
||||
<widget name="D3D9">
|
||||
<functions>
|
||||
<function name="GetD3D">
|
||||
<return>
|
||||
<pointer />
|
||||
</return>
|
||||
</function>
|
||||
<function name="GetD3Dev">
|
||||
<function name="GetD3DDevice">
|
||||
<return>
|
||||
<pointer />
|
||||
</return>
|
||||
|
|
|
|||
20
pl/rules.pl
20
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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,127 +0,0 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
#ifdef MW_DIRECTX8
|
||||
#include <Mw/Widget/D3D8.h>
|
||||
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
|
||||
|
|
@ -1,19 +1,17 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
#ifdef MW_DIRECTX9
|
||||
#include <Mw/Widget/D3D9.h>
|
||||
#ifdef MW_DIRECT3D9
|
||||
#include <Mw/Widget/Direct3D9.h>
|
||||
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
|
||||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue