102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
com_direct3d7.c
Go to the documentation of this file.
1// IDirect3D7 COM translator that creates Device7 instances
2// https://archive.org/details/dx7sdk-7001
3
4#define INITGUID
6#include <stdlib.h>
7#include <string.h>
8
9static const DWORD D3D7_MAX_TEXTURE_REPEAT = 1u << 15;
10
12
20
22
24
26
27static HRESULT __stdcall d3d7_enum_devices(
29 void *cb,
30 void *ctx
31) {
32 const LPD3DENUMDEVICESCALLBACK7 callback = (LPD3DENUMDEVICESCALLBACK7)cb;
33
34 if (!callback) {
35 return S_OK;
36 }
37
38 // Advertise one HAL-style hardware T&L device
39 D3DDEVICEDESC7 desc;
40 memset(&desc, 0, sizeof(desc));
41
42 desc.dwDevCaps = D3DDEVCAPS_FLOATTLVERTEX | D3DDEVCAPS_EXECUTEVIDEOMEMORY
43 | D3DDEVCAPS_TLVERTEXVIDEOMEMORY | D3DDEVCAPS_TEXTUREVIDEOMEMORY
44 | D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_CANRENDERAFTERFLIP
45 | D3DDEVCAPS_DRAWPRIMITIVES2 | D3DDEVCAPS_DRAWPRIMITIVES2EX
46 | D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_HWRASTERIZATION;
47
48 desc.dwMinTextureWidth = 1;
49 desc.dwMinTextureHeight = 1;
50 desc.dwMaxTextureWidth = 4096;
51 desc.dwMaxTextureHeight = 4096;
52 desc.dwMaxTextureRepeat = D3D7_MAX_TEXTURE_REPEAT;
53 desc.dwMaxTextureAspectRatio = 4096;
54 desc.dwMaxAnisotropy = 16;
55
56 desc.wMaxTextureBlendStages = 8;
57 desc.wMaxSimultaneousTextures = 8;
58
59 desc.dwMaxActiveLights = 8;
60
61 desc.wMaxUserClipPlanes = 6;
62 desc.wMaxVertexBlendMatrices = 4;
63
64 desc.deviceGUID = IID_IDirect3DHALDevice;
65
66 desc.dwDeviceRenderBitDepth = DTTR_DDBD_16 | DTTR_DDBD_32;
67 desc.dwDeviceZBufferBitDepth = DTTR_DDBD_16 | DTTR_DDBD_32;
68
69 callback("DTTR Hardware Accelerated Device", "HAL", &desc, ctx);
70
71 return S_OK;
72}
73
74static HRESULT __stdcall d3d7_createdevice(
76 void *guid,
77 void *surf,
78 void **dev
79) {
81
82 if (dev) {
83 *dev = device;
84 }
85
86 return S_OK;
87}
88
89static HRESULT __stdcall d3d7_createvertexbuffer(
91 void *desc,
92 void **vb,
94) {
95 if (vb) {
96 *vb = NULL;
97 }
98
99 return S_OK;
100}
101
102static HRESULT __stdcall d3d7_enumzbufferformats(
104 void *guid,
105 void *cb,
106 void *ctx
107) {
108 const LPD3DENUMPIXELFORMATSCALLBACK callback = (LPD3DENUMPIXELFORMATSCALLBACK)cb;
109
110 if (!callback) {
111 return S_OK;
112 }
113
114 DDPIXELFORMAT fmt16;
115 memset(&fmt16, 0, sizeof(fmt16));
116 fmt16.dwSize = sizeof(DDPIXELFORMAT);
117 fmt16.dwFlags = DDPF_ZBUFFER;
118 fmt16.dwZBufferBitDepth = 16;
119 fmt16.dwZBitMask = 0xFFFF;
120
121 const HRESULT result = callback(&fmt16, ctx);
122
123 if (result != D3DENUMRET_OK) {
124 return S_OK;
125 }
126
127 DDPIXELFORMAT fmt24s8;
128 memset(&fmt24s8, 0, sizeof(fmt24s8));
129 fmt24s8.dwSize = sizeof(DDPIXELFORMAT);
130 fmt24s8.dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
131 fmt24s8.dwZBufferBitDepth = 32;
132 fmt24s8.dwStencilBitDepth = 8;
133 fmt24s8.dwZBitMask = 0x00FFFFFF;
134 fmt24s8.dwStencilBitMask = 0xFF000000;
135
136 callback(&fmt24s8, ctx);
137
138 return S_OK;
139}
140
141DTTR_COM_NOOP_HRESULT(d3d7_evict_managed_textures, DTTR_Graphics_COM_Direct3D7 *self)
142
144 .QueryInterface = d3d7_query_interface,
145 .AddRef = d3d7_addref,
146 .Release = d3d7_release,
147 .EnumDevices = d3d7_enum_devices,
148 .CreateDevice = d3d7_createdevice,
149 .CreateVertexBuffer = d3d7_createvertexbuffer,
150 .EnumZBufferFormats = d3d7_enumzbufferformats,
151 .EvictManagedTextures = d3d7_evict_managed_textures,
152};
153
156 if (d3d) {
157 d3d->vtbl = &vtbl;
158 }
159
160 return d3d;
161}
static DTTR_Graphics_COM_Direct3D7_VT vtbl
DTTR_Graphics_COM_Direct3D7 * dttr_graphics_com_create_direct3d7()
static HRESULT d3d7_enumzbufferformats(DTTR_Graphics_COM_Direct3D7 *self, void *guid, void *cb, void *ctx)
static DTTR_Graphics_COM_Direct3DDevice7 * d3d7_device
static DTTR_Graphics_COM_Direct3DDevice7 * d3d7_get_device()
static HRESULT d3d7_createvertexbuffer(DTTR_Graphics_COM_Direct3D7 *self, void *desc, void **vb, DWORD flags)
static HRESULT d3d7_enum_devices(DTTR_Graphics_COM_Direct3D7 *self, void *cb, void *ctx)
static HRESULT d3d7_createdevice(DTTR_Graphics_COM_Direct3D7 *self, void *guid, void *surf, void **dev)
static const DWORD D3D7_MAX_TEXTURE_REPEAT
void * cb
DTTR_Graphics_COM_Direct3DDevice7 * self
return S_OK
DTTR_Graphics_COM_Direct3DDevice7 * dttr_graphics_com_create_direct3ddevice7()
void void * ctx
DTTR_Graphics_COM_Direct3DDevice7 void *status DTTR_Graphics_COM_Direct3DDevice7 DWORD DWORD void DWORD DWORD f DTTR_Graphics_COM_Direct3DDevice7 DWORD void * vb
DTTR_Graphics_COM_Direct3DDevice7 void DWORD flags DWORD void DWORD flags
DTTR_Graphics_COM_DirectDraw7 DWORD void * desc
DTTR_Graphics_COM_DirectDrawSurface7 DWORD flags void NULL
#define DTTR_COM_NOOP_HRESULT(fn,...)
#define DTTR_COM_ADDREF(fn, type)
#define DTTR_DDBD_32
#define DTTR_COM_QI_SELF(fn, type)
#define DTTR_DDBD_16
#define DTTR_COM_RELEASE(fn, type)
DTTR_Graphics_COM_Direct3D7_VT * vtbl