-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3d.c
755 lines (608 loc) · 20.4 KB
/
d3d.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
/******************************************************************************
* Copyright (c) 2024 Jaroslav Hensl *
* *
* Permission is hereby granted, free of charge, to any person *
* obtaining a copy of this software and associated documentation *
* files (the "Software"), to deal in the Software without *
* restriction, including without limitation the rights to use, *
* copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, *
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
* OTHER DEALINGS IN THE SOFTWARE. *
* *
******************************************************************************/
#include <windows.h>
#include <initguid.h> /* this is only one file using GUID */
#include <ddraw.h>
#include <ddrawi.h>
#include "d3dhal_ddk.h"
#include <stddef.h>
#include <stdint.h>
#include "vmdahal32.h"
#include "vmhal9x.h"
#include "mesa3d.h"
#include "nocrt.h"
/* FROM ddrvmem.h */
typedef DWORD HDDRVITEM, * LPHDDRVITEM;
enum DDRV_RETURN {
DDRV_SUCCESS_STOP,
DDRV_SUCCESS_CONTINUE,
DDRV_ERROR_CONTINUE,
DDRV_ERROR_STOP
};
#ifndef D3DHAL2_CB32_SETRENDERTARGET
#define D3DHAL2_CB32_SETRENDERTARGET 0x00000001L
#define D3DHAL2_CB32_CLEAR 0x00000002L
#define D3DHAL2_CB32_DRAWONEPRIMITIVE 0x00000004L
#define D3DHAL2_CB32_DRAWONEINDEXEDPRIMITIVE 0x00000008L
#define D3DHAL2_CB32_DRAWPRIMITIVES 0x00000010L
#endif
extern HANDLE hSharedHeap;
static BOOL ValidateCtx(DWORD dwhContext)
{
if(dwhContext != 0)
{
mesa3d_ctx_t *ctx = MESA_HANDLE_TO_CTX(dwhContext);
VMDAHAL_t *dd = GetHAL(ctx->dd);
if(!dd->invalid)
{
return TRUE;
}
}
return FALSE;
}
#define VALIDATE(_d3d) if(!ValidateCtx((_d3d)->dwhContext)){ \
(_d3d)->ddrval = D3DHAL_CONTEXT_BAD; \
return DDHAL_DRIVER_HANDLED;}
DWORD __stdcall SetRenderTarget32(LPD3DHAL_SETRENDERTARGETDATA lpSetRenderData)
{
TRACE_ENTRY
VALIDATE(lpSetRenderData)
TOPIC("GL", "SetRenderTarget32(0x%X, 0x%X)",
lpSetRenderData->lpDDS,
lpSetRenderData->lpDDSZ
);
GL_BLOCK_BEGIN(lpSetRenderData->dwhContext)
MesaSetTarget(ctx,
(LPDDRAWI_DDRAWSURFACE_INT)lpSetRenderData->lpDDS,
(LPDDRAWI_DDRAWSURFACE_INT)lpSetRenderData->lpDDSZ
);
GL_BLOCK_END
lpSetRenderData->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall Clear32(LPD3DHAL_CLEARDATA lpClearData)
{
TRACE_ENTRY
VALIDATE(lpClearData)
lpClearData->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall DrawOnePrimitive32(LPD3DHAL_DRAWONEPRIMITIVEDATA lpDrawData)
{
TRACE_ENTRY
VALIDATE(lpDrawData)
GL_BLOCK_BEGIN(lpDrawData->dwhContext)
MesaDraw(ctx, lpDrawData->PrimitiveType, lpDrawData->VertexType, lpDrawData->lpvVertices, lpDrawData->dwNumVertices);
GL_BLOCK_END
lpDrawData->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall DrawOneIndexedPrimitive32(LPD3DHAL_DRAWONEINDEXEDPRIMITIVEDATA lpDrawData)
{
TRACE_ENTRY
VALIDATE(lpDrawData)
GL_BLOCK_BEGIN(lpDrawData->dwhContext)
MesaDrawIndex(ctx, lpDrawData->PrimitiveType, lpDrawData->VertexType,
lpDrawData->lpvVertices, lpDrawData->dwNumVertices,
lpDrawData->lpwIndices, lpDrawData->dwNumIndices
);
GL_BLOCK_END
lpDrawData->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
/**
* From DDK98:
* Data block:
*
* Consists of interleaved D3DHAL_DRAWPRIMCOUNTS, state change pairs,
* and primitive drawing commands.
*
* D3DHAL_DRAWPRIMCOUNTS: gives number of state change pairs and
* the information on the primitive to draw.
* wPrimitiveType is of type D3DPRIMITIVETYPE. Drivers
* must support all 7 of the primitive types specified
* in the DrawPrimitive API.
* Currently, wVertexType will always be D3DVT_TLVERTEX.
* If the wNumVertices member is 0, then the driver should
* return after doing the state changing. This is the
* terminator for the command stream.
* state change pairs: DWORD pairs specify the state changes that
* the driver should effect before drawing the primitive.
* wNumStateChanges can be 0, in which case the next primitive
* should be drawn without any state changes in between.
* If present, the state change pairs are NOT aligned, they
* immediately follow the PRIMCOUNTS structure.
* vertex data (if any): is 32-byte aligned.
*
* If a primcounts structure follows (i.e. if wNumVertices was nonzero
* in the previous one), then it will immediately follow the state
* changes or vertex data with no alignment padding.
**/
DWORD __stdcall DrawPrimitives32(LPD3DHAL_DRAWPRIMITIVESDATA lpDrawData)
{
TRACE_ENTRY
VALIDATE(lpDrawData)
LPBYTE lpData = (LPBYTE)lpDrawData->lpvData;
LPD3DHAL_DRAWPRIMCOUNTS drawPrimitiveCounts;
int j;
GL_BLOCK_BEGIN(lpDrawData->dwhContext)
TOPIC("TEX", "DrawPrimitives32");
do
{
drawPrimitiveCounts = (LPD3DHAL_DRAWPRIMCOUNTS)(lpData);
lpData += sizeof(D3DHAL_DRAWPRIMCOUNTS);
/* state block */
LPD3DSTATE state;
for(j = drawPrimitiveCounts->wNumStateChanges; j > 0; j--)
{
state = (LPD3DSTATE)lpData;
MesaSetRenderState(ctx, state);
lpData += sizeof(D3DSTATE);
}
/* padding */
lpData += 31;
lpData = (LPBYTE)((ULONG)lpData & (~31));
/* draw block */
if(drawPrimitiveCounts->wNumVertices)
{
TOPIC("TEX", "batch %d, type: %d", drawPrimitiveCounts->wNumVertices, drawPrimitiveCounts->wPrimitiveType);
MesaDraw(ctx, drawPrimitiveCounts->wPrimitiveType, drawPrimitiveCounts->wVertexType, (LPD3DTLVERTEX)lpData, drawPrimitiveCounts->wNumVertices);
/* wVertexType should be only D3DVT_TLVERTEX, but for all cases... */
switch(drawPrimitiveCounts->wVertexType)
{
case D3DVT_VERTEX:
lpData += drawPrimitiveCounts->wNumVertices * sizeof(D3DVERTEX);
break;
case D3DVT_LVERTEX:
lpData += drawPrimitiveCounts->wNumVertices * sizeof(D3DLVERTEX);
break;
case D3DVT_TLVERTEX:
default:
lpData += drawPrimitiveCounts->wNumVertices * sizeof(D3DTLVERTEX);
break;
}
}
} while(drawPrimitiveCounts->wNumVertices);
GL_BLOCK_END
lpDrawData->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
/**
* From DDK98:
* DESCRIPTION: DirectDraw has had many compatability problems
* in the past, particularly from adding or modifying
* members of public structures. GetDriverInfo is an extension
* architecture that intends to allow DirectDraw to
* continue evolving, while maintaining backward compatability.
* This function is passed a GUID which represents some DirectDraw
* extension. If the driver recognises and supports this extension,
* it fills out the required data and returns.
*
**/
DWORD __stdcall GetDriverInfo32(LPDDHAL_GETDRIVERINFODATA lpInput)
{
TRACE_ENTRY
lpInput->ddRVal = DDERR_CURRENTLYNOTAVAIL;
if(IsEqualIID(&lpInput->guidInfo, &GUID_D3DCallbacks2))
{
DWORD dwSize;
D3DHAL_CALLBACKS2 D3DCallbacks2;
TRACE("D3DHAL_CALLBACKS2 size %d/%d", lpInput->dwExpectedSize, sizeof(D3DHAL_CALLBACKS2));
memset(&D3DCallbacks2, 0, sizeof(D3DHAL_CALLBACKS2));
dwSize = min(lpInput->dwExpectedSize, sizeof(D3DHAL_CALLBACKS2));
lpInput->dwActualSize = sizeof(D3DHAL_CALLBACKS2);
D3DCallbacks2.dwSize = dwSize;
D3DCallbacks2.dwFlags = D3DHAL2_CB32_SETRENDERTARGET | D3DHAL2_CB32_DRAWONEPRIMITIVE | D3DHAL2_CB32_DRAWONEINDEXEDPRIMITIVE | D3DHAL2_CB32_DRAWPRIMITIVES;
D3DCallbacks2.SetRenderTarget = SetRenderTarget32;
D3DCallbacks2.DrawOnePrimitive = DrawOnePrimitive32;
D3DCallbacks2.DrawOneIndexedPrimitive = DrawOneIndexedPrimitive32;
D3DCallbacks2.DrawPrimitives = DrawPrimitives32;
//D3DCallbacks2.Clear = Clear32;
memcpy(lpInput->lpvData, &D3DCallbacks2, dwSize);
lpInput->ddRVal = DD_OK;
TRACE("GUID_D3DCallbacks2 success");
}
else if(IsEqualIID(&lpInput->guidInfo, &GUID_D3DExtendedCaps))
{
D3DHAL_D3DEXTENDEDCAPS dx5caps;
DWORD dwSize = sizeof(D3DHAL_D3DEXTENDEDCAPS);
memset(&dx5caps, 0, dwSize);
dx5caps.dwSize = dwSize;
dx5caps.dwMinTextureWidth = 1;
dx5caps.dwMinTextureHeight = 1;
dx5caps.dwMaxTextureWidth = 2048; // TODO: query by GL_MAX_TEXTURE_SIZE
dx5caps.dwMaxTextureHeight = 2048;
dx5caps.dwMinStippleWidth = 32;
dx5caps.dwMinStippleHeight = 32;
dx5caps.dwMaxStippleWidth = 32;
dx5caps.dwMaxStippleHeight = 32;
memcpy(lpInput->lpvData, &dx5caps, dwSize);
lpInput->ddRVal = DD_OK;
TRACE("GUID_D3DExtendedCaps success");
}
else
{
TRACE("Not handled GUID: %08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X",
lpInput->guidInfo.Data1,
lpInput->guidInfo.Data2,
lpInput->guidInfo.Data3,
lpInput->guidInfo.Data4[0],
lpInput->guidInfo.Data4[1],
lpInput->guidInfo.Data4[2],
lpInput->guidInfo.Data4[3],
lpInput->guidInfo.Data4[4],
lpInput->guidInfo.Data4[5],
lpInput->guidInfo.Data4[6],
lpInput->guidInfo.Data4[7]
);
}
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall ContextCreate32(LPD3DHAL_CONTEXTCREATEDATA pccd)
{
TRACE_ENTRY
pccd->ddrval = D3DHAL_OUTOFCONTEXTS; /* error state */
mesa3d_entry_t *entry = Mesa3DGet(GetCurrentProcessId());
if(entry)
{
LPDDRAWI_DDRAWSURFACE_INT dss = (LPDDRAWI_DDRAWSURFACE_INT)pccd->lpDDS;
LPDDRAWI_DDRAWSURFACE_INT dsz = (LPDDRAWI_DDRAWSURFACE_INT)pccd->lpDDSZ;
mesa3d_ctx_t *ctx = MesaCreateCtx(entry, dss, dsz);
if(ctx)
{
TOPIC("GL", "MesaCreateCtx(entry, %X, %X)", dss, dsz);
pccd->dwhContext = MESA_CTX_TO_HANDLE(ctx);
pccd->ddrval = DD_OK;
ctx->dd = pccd->lpDDGbl;
}
}
if(pccd->ddrval != DD_OK)
{
ERR("ContextCreate32 FAILED");
}
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall ContextDestroy32(LPD3DHAL_CONTEXTDESTROYDATA pcdd)
{
TRACE_ENTRY
MesaDestroyCtx(MESA_HANDLE_TO_CTX(pcdd->dwhContext));
pcdd->dwhContext = 0;
pcdd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall ContextDestroyAllCallback32(LPVOID lpData, HDDRVITEM hItem, DWORD dwData)
{
TRACE_ENTRY
return DDRV_SUCCESS_CONTINUE;
}
DWORD __stdcall ContextDestroyAll32(LPD3DHAL_CONTEXTDESTROYALLDATA pcdd)
{
TRACE_ENTRY
pcdd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall RenderState32(LPD3DHAL_RENDERSTATEDATA prd)
{
TRACE_ENTRY
VALIDATE(prd)
int i;
GL_BLOCK_BEGIN(prd->dwhContext)
LPBYTE lpData = (LPBYTE)(((LPDDRAWI_DDRAWSURFACE_INT)prd->lpExeBuf)->lpLcl->lpGbl->fpVidMem);
LPD3DSTATE lpState = (LPD3DSTATE) (lpData + prd->dwOffset);
for(i = 0; i < prd->dwCount; i++)
{
MesaSetRenderState(ctx, lpState);
lpState++;
}
GL_BLOCK_END
prd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall RenderPrimitive32(LPD3DHAL_RENDERPRIMITIVEDATA prd)
{
TRACE_ENTRY
VALIDATE(prd)
GL_BLOCK_BEGIN(prd->dwhContext)
LPBYTE lpData = (LPBYTE)(((LPDDRAWI_DDRAWSURFACE_INT)prd->lpExeBuf)->lpLcl->lpGbl->fpVidMem);
LPD3DINSTRUCTION lpIns = &prd->diInstruction;
LPBYTE prim = lpData + prd->dwOffset;
if(ctx->state.zvisible)
{
/* DDK98: If you don't implement Z visibility testing, just do this. */
prd->dwStatus &= ~D3DSTATUS_ZNOTVISIBLE;
break;
}
switch (lpIns->bOpcode)
{
case D3DOP_POINT:
LPD3DPOINT point = (LPD3DPOINT)prim;
break;
case D3DOP_SPAN:
LPD3DSPAN span = (LPD3DSPAN)prim;
break;
case D3DOP_LINE:
break;
case D3DOP_TRIANGLE:
D3DTRIANGLE *triPtr = (D3DTRIANGLE *)prim;
break;
}
GL_BLOCK_END
prd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall TextureCreate32(LPD3DHAL_TEXTURECREATEDATA ptcd)
{
TRACE_ENTRY
VALIDATE(ptcd)
ptcd->ddrval = DDERR_OUTOFVIDEOMEMORY;
GL_BLOCK_BEGIN(ptcd->dwhContext)
mesa3d_texture_t *tex = MesaCreateTexture(ctx, (LPDDRAWI_DDRAWSURFACE_INT)ptcd->lpDDS);
if(tex)
{
ptcd->dwHandle = MESA_TEX_TO_HANDLE(tex);
TRACE("new texture: %X", ptcd->dwHandle);
ptcd->ddrval = DD_OK;
}
else
{
/* set NULL handle */
ptcd->dwHandle = 0;
ptcd->ddrval = DDERR_GENERIC;
}
GL_BLOCK_END
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall TextureDestroy32(LPD3DHAL_TEXTUREDESTROYDATA ptcd)
{
TRACE_ENTRY
VALIDATE(ptcd)
if(!ptcd->dwHandle)
{
ptcd->ddrval = DDERR_GENERIC;
return DDHAL_DRIVER_HANDLED;
}
GL_BLOCK_BEGIN(ptcd->dwhContext)
MesaDestroyTexture(MESA_HANDLE_TO_TEX(ptcd->dwHandle));
GL_BLOCK_END
ptcd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall TextureSwap32(LPD3DHAL_TEXTURESWAPDATA ptsd)
{
TRACE_ENTRY
VALIDATE(ptsd)
mesa3d_texture_t *tex1 = MESA_HANDLE_TO_TEX(ptsd->dwHandle1);
mesa3d_texture_t *tex2 = MESA_HANDLE_TO_TEX(ptsd->dwHandle2);
if(tex1 && tex2)
{
mesa3d_texture_t cp = *tex1;
*tex1 = *tex2;
*tex2 = cp;
ptsd->ddrval = DD_OK;
}
else
{
ptsd->ddrval = DDERR_INVALIDPARAMS;
}
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall TextureGetSurf32(LPD3DHAL_TEXTUREGETSURFDATA ptgd)
{
TRACE_ENTRY
VALIDATE(ptgd)
mesa3d_texture_t *tex = MESA_HANDLE_TO_TEX(ptgd->dwHandle);
if(tex)
{
ptgd->lpDDS = (DWORD)tex->ddsurf;
ptgd->ddrval = DD_OK;
}
else
{
ptgd->ddrval = DDERR_INVALIDPARAMS;
}
return DDHAL_DRIVER_HANDLED;
}
#if 0
/* Templates for DDI 3, not ever called! */
#define GL_MATRIX_SIZE sizeof(GLfloat[16])
DWORD __stdcall MatrixCreate32(LPD3DHAL_MATRIXCREATEDATA pmcd)
{
TRACE_ENTRY
GLfloat *ptr = HeapAlloc(hSharedHeap, HEAP_ZERO_MEMORY, GL_MATRIX_SIZE);
if(ptr)
{
pmcd->ddrval = DD_OK;
pmcd->dwHandle = MESA_MTX_TO_HANDLE(ptr);
}
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall MatrixDestroy32(LPD3DHAL_MATRIXDESTROYDATA pmdd)
{
TRACE_ENTRY
GLfloat *ptr = MESA_HANDLE_TO_MTX(pmdd->dwHandle);
if(ptr)
{
pmdd->ddrval = DD_OK;
HeapFree(hSharedHeap, 0, ptr);
}
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall MatrixSetData32(LPD3DHAL_MATRIXSETDATADATA pmsd)
{
TRACE_ENTRY
GLfloat *ptr = MESA_HANDLE_TO_MTX(pmsd->dwHandle);
if(ptr)
{
memcpy(ptr, &pmsd->dmMatrix._11, GL_MATRIX_SIZE);
pmsd->ddrval = DD_OK;
}
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall MatrixGetData32(LPD3DHAL_MATRIXGETDATADATA pmsd)
{
TRACE_ENTRY
GLfloat *ptr = MESA_HANDLE_TO_MTX(pmsd->dwHandle);
if(ptr)
{
memcpy(&pmsd->dmMatrix._11, ptr, GL_MATRIX_SIZE);
pmsd->ddrval = DD_OK;
}
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall SetViewportData32(LPD3DHAL_SETVIEWPORTDATADATA psvd)
{
TRACE_ENTRY
psvd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall MaterialCreate32(LPD3DHAL_MATERIALCREATEDATA pmcd)
{
TRACE_ENTRY
pmcd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall MaterialDestroy32(LPD3DHAL_MATERIALDESTROYDATA pmdd)
{
TRACE_ENTRY
pmdd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall MaterialSetData32(LPD3DHAL_MATERIALSETDATADATA pmsd)
{
TRACE_ENTRY
pmsd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall MaterialGetData32(LPD3DHAL_MATERIALGETDATADATA pmgd)
{
TRACE_ENTRY
pmgd->ddrval = DD_OK;
return (DDHAL_DRIVER_HANDLED);
}
#endif /* unused templates */
DWORD __stdcall GetState32(LPD3DHAL_GETSTATEDATA pgsd)
{
TRACE_ENTRY
VALIDATE(pgsd)
if (pgsd->dwWhich != D3DHALSTATE_GET_RENDER)
{
// You must be able to do transform/lighting
}
// JH: ^this is REAL code from S3 driver inclusing the comment
pgsd->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
DWORD __stdcall SceneCapture32(LPD3DHAL_SCENECAPTUREDATA scdata)
{
TRACE_ENTRY
VALIDATE(scdata)
TOPIC("GL", "SceneCapture32: %d", scdata->dwFlag);
TOPIC("TEX", "SceneCapture32: %d", scdata->dwFlag);
GL_BLOCK_BEGIN(scdata->dwhContext)
switch(scdata->dwFlag)
{
case D3DHAL_SCENE_CAPTURE_START:
// TODO: reload system memory surfaces here?
//MesaReadback(ctx);
break;
case D3DHAL_SCENE_CAPTURE_END:
MesaRender(ctx);
break;
}
GL_BLOCK_END
scdata->ddrval = DD_OK;
return DDHAL_DRIVER_HANDLED;
}
/* GLOBAL hal */
static D3DHAL_GLOBALDRIVERDATA myGlobalD3DHal;
static D3DHAL_CALLBACKS myD3DHALCallbacks = {
sizeof(D3DHAL_CALLBACKS),
// Device context
ContextCreate32, // Required.
ContextDestroy32, // Required.
ContextDestroyAll32, // Required.
// Scene capture
SceneCapture32, // Optional. (JH: required when driver or HW do some buffering)
// Execution
#ifdef IMPLEMENT_EXECUTE
Execute32,
#else
NULL, // Optional. Don't implement if just rasterization.
#endif
NULL,
RenderState32, // Required if no Execute
RenderPrimitive32, // Required if no Execute
0L, // Reserved, must be zero
// Textures
TextureCreate32, // If any of these calls are supported,
TextureDestroy32, // they must all be.
TextureSwap32, // ditto - but can always fail.
TextureGetSurf32, // ditto - but can always fail.
/* For next exports is important this DDK98s note:
* No driver currently exports this function and no run-time file ever call it.
* Future Direct3D exports will be done through the GetDriverInfo mechanism.
*/
// Transform - must be supported if lighting is supported.
NULL, //MatrixCreate32, // If any of these calls are supported,
NULL, //MatrixDestroy32, // they must all be.
NULL, //MatrixSetData32, // ditto
NULL, //MatrixGetData32, // ditto
NULL, //SetViewportData32, // ditto
// Lighting
NULL, // If any of these calls are supported,
NULL, //myMaterialCreate, // they must all be.
NULL, //myMaterialDestroy, // ditto
NULL, //myMaterialSetData, // ditto
NULL, //myMaterialGetData, // ditto
// Pipeline state
GetState32, // Required if implementing Execute.
0L, // Reserved, must be zero
0L, // Reserved, must be zero
0L, // Reserved, must be zero
0L, // Reserved, must be zero
0L, // Reserved, must be zero
0L, // Reserved, must be zero
0L, // Reserved, must be zero
0L, // Reserved, must be zero
0L, // Reserved, must be zero
0L, // Reserved, must be zero
};
#include "d3d_caps.h"
BOOL __stdcall D3DHALCreateDriver(DWORD *lplpGlobal, DWORD *lplpHALCallbacks, VMDAHAL_D3DCAPS_t *lpHALFlags)
{
memset(&myGlobalD3DHal, 0, sizeof(D3DHAL_GLOBALDRIVERDATA));
myGlobalD3DHal.dwSize = sizeof(D3DHAL_GLOBALDRIVERDATA);
myGlobalD3DHal.hwCaps = myCaps;
myGlobalD3DHal.dwNumVertices = 0;
myGlobalD3DHal.dwNumClipVertices = 0;
myGlobalD3DHal.dwNumTextureFormats = (sizeof(myTextureFormats) / sizeof(DDSURFACEDESC));
myGlobalD3DHal.lpTextureFormats = &myTextureFormats[0];
*lplpGlobal = (DWORD)&myGlobalD3DHal;
*lplpHALCallbacks = (DWORD)&myD3DHALCallbacks;
lpHALFlags->ddscaps = DDSCAPS_3DDEVICE | DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER | DDSCAPS_MIPMAP;
lpHALFlags->zcaps = DDBD_16 | DDBD_24; // | DDBD_32;
return TRUE;
}