-
Notifications
You must be signed in to change notification settings - Fork 13
/
device_windows.go
2164 lines (2034 loc) · 51.1 KB
/
device_windows.go
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
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package d3d9
import (
"math"
"syscall"
"unsafe"
)
// Device and its methods are used to perform DrawPrimitive-based rendering,
// create resources, work with system-level variables, adjust gamma ramp levels,
// work with palettes and create shaders.
type Device struct {
vtbl *deviceVtbl
}
type deviceVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
TestCooperativeLevel uintptr
GetAvailableTextureMem uintptr
EvictManagedResources uintptr
GetDirect3D uintptr
GetDeviceCaps uintptr
GetDisplayMode uintptr
GetCreationParameters uintptr
SetCursorProperties uintptr
SetCursorPosition uintptr
ShowCursor uintptr
CreateAdditionalSwapChain uintptr
GetSwapChain uintptr
GetNumberOfSwapChains uintptr
Reset uintptr
Present uintptr
GetBackBuffer uintptr
GetRasterStatus uintptr
SetDialogBoxMode uintptr
SetGammaRamp uintptr
GetGammaRamp uintptr
CreateTexture uintptr
CreateVolumeTexture uintptr
CreateCubeTexture uintptr
CreateVertexBuffer uintptr
CreateIndexBuffer uintptr
CreateRenderTarget uintptr
CreateDepthStencilSurface uintptr
UpdateSurface uintptr
UpdateTexture uintptr
GetRenderTargetData uintptr
GetFrontBufferData uintptr
StretchRect uintptr
ColorFill uintptr
CreateOffscreenPlainSurface uintptr
SetRenderTarget uintptr
GetRenderTarget uintptr
SetDepthStencilSurface uintptr
GetDepthStencilSurface uintptr
BeginScene uintptr
EndScene uintptr
Clear uintptr
SetTransform uintptr
GetTransform uintptr
MultiplyTransform uintptr
SetViewport uintptr
GetViewport uintptr
SetMaterial uintptr
GetMaterial uintptr
SetLight uintptr
GetLight uintptr
LightEnable uintptr
GetLightEnable uintptr
SetClipPlane uintptr
GetClipPlane uintptr
SetRenderState uintptr
GetRenderState uintptr
CreateStateBlock uintptr
BeginStateBlock uintptr
EndStateBlock uintptr
SetClipStatus uintptr
GetClipStatus uintptr
GetTexture uintptr
SetTexture uintptr
GetTextureStageState uintptr
SetTextureStageState uintptr
GetSamplerState uintptr
SetSamplerState uintptr
ValidateDevice uintptr
SetPaletteEntries uintptr
GetPaletteEntries uintptr
SetCurrentTexturePalette uintptr
GetCurrentTexturePalette uintptr
SetScissorRect uintptr
GetScissorRect uintptr
SetSoftwareVertexProcessing uintptr
GetSoftwareVertexProcessing uintptr
SetNPatchMode uintptr
GetNPatchMode uintptr
DrawPrimitive uintptr
DrawIndexedPrimitive uintptr
DrawPrimitiveUP uintptr
DrawIndexedPrimitiveUP uintptr
ProcessVertices uintptr
CreateVertexDeclaration uintptr
SetVertexDeclaration uintptr
GetVertexDeclaration uintptr
SetFVF uintptr
GetFVF uintptr
CreateVertexShader uintptr
SetVertexShader uintptr
GetVertexShader uintptr
SetVertexShaderConstantF uintptr
GetVertexShaderConstantF uintptr
SetVertexShaderConstantI uintptr
GetVertexShaderConstantI uintptr
SetVertexShaderConstantB uintptr
GetVertexShaderConstantB uintptr
SetStreamSource uintptr
GetStreamSource uintptr
SetStreamSourceFreq uintptr
GetStreamSourceFreq uintptr
SetIndices uintptr
GetIndices uintptr
CreatePixelShader uintptr
SetPixelShader uintptr
GetPixelShader uintptr
SetPixelShaderConstantF uintptr
GetPixelShaderConstantF uintptr
SetPixelShaderConstantI uintptr
GetPixelShaderConstantI uintptr
SetPixelShaderConstantB uintptr
GetPixelShaderConstantB uintptr
DrawRectPatch uintptr
DrawTriPatch uintptr
DeletePatch uintptr
CreateQuery uintptr
}
// AddRef increments the reference count for an interface on an object. This
// method should be called for every new copy of a pointer to an interface on an
// object.
func (obj *Device) AddRef() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.AddRef,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// Release has to be called when finished using the object to free its
// associated resources.
func (obj *Device) Release() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// TestCooperativeLevel reports the current cooperative-level status of the
// Direct3D device for a windowed or full-screen application.
func (obj *Device) TestCooperativeLevel() Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.TestCooperativeLevel,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return toErr(ret)
}
// GetAvailableTextureMem returns an estimate of the amount of available texture
// memory.
func (obj *Device) GetAvailableTextureMem() uint {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetAvailableTextureMem,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint(ret)
}
// EvictManagedResources evicts all managed resources, including both Direct3D
// and driver-managed resources.
func (obj *Device) EvictManagedResources() Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.EvictManagedResources,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return toErr(ret)
}
// GetDirect3D returns an interface to the instance of the Direct3D object that
// created the device.
// Call Release on the returned object when finished using it.
func (obj *Device) GetDirect3D() (d3d *Direct3D, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDirect3D,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&d3d)),
0,
)
err = toErr(ret)
return
}
// GetDeviceCaps retrieves the capabilities of the rendering device.
func (obj *Device) GetDeviceCaps() (CAPS, Error) {
var caps CAPS
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDeviceCaps,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&caps)),
0,
)
return caps, toErr(ret)
}
// GetDisplayMode retrieves the display mode's spatial resolution, color
// resolution, and refresh frequency.
func (obj *Device) GetDisplayMode(swapChain uint) (DISPLAYMODE, Error) {
var mode DISPLAYMODE
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDisplayMode,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(swapChain),
uintptr(unsafe.Pointer(&mode)),
)
return mode, toErr(ret)
}
// GetCreationParameters retrieves the creation parameters of the device.
func (obj *Device) GetCreationParameters() (DEVICE_CREATION_PARAMETERS, Error) {
var params DEVICE_CREATION_PARAMETERS
ret, _, _ := syscall.Syscall(
obj.vtbl.GetCreationParameters,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(¶ms)),
0,
)
return params, toErr(ret)
}
// SetCursorProperties sets properties for the cursor.
func (obj *Device) SetCursorProperties(
xHotSpot uint,
yHotSpot uint,
cursorBitmap *Surface,
) Error {
ret, _, _ := syscall.Syscall6(
obj.vtbl.SetCursorProperties,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(xHotSpot),
uintptr(yHotSpot),
uintptr(unsafe.Pointer(cursorBitmap)),
0,
0,
)
return toErr(ret)
}
// SetCursorPosition sets the cursor position and update options.
func (obj *Device) SetCursorPosition(x int, y int, flags uint32) {
syscall.Syscall6(
obj.vtbl.SetCursorPosition,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(x),
uintptr(y),
uintptr(flags),
0,
0,
)
}
// ShowCursor displays or hides the cursor.
func (obj *Device) ShowCursor(show bool) bool {
ret, _, _ := syscall.Syscall(
obj.vtbl.ShowCursor,
2,
uintptr(unsafe.Pointer(obj)),
uintptrBool(show),
0,
)
return ret != 0
}
// CreateAdditionalSwapChain creates an additional swap chain for rendering
// multiple views.
func (obj *Device) CreateAdditionalSwapChain(params PRESENT_PARAMETERS) (
*SwapChain, PRESENT_PARAMETERS, Error,
) {
var chain *SwapChain
ret, _, _ := syscall.Syscall(
obj.vtbl.CreateAdditionalSwapChain,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(¶ms)),
uintptr(unsafe.Pointer(&chain)),
)
return chain, params, toErr(ret)
}
// GetSwapChain returns a pointer to a swap chain.
func (obj *Device) GetSwapChain(swapChain uint) (*SwapChain, Error) {
var chain *SwapChain
ret, _, _ := syscall.Syscall(
obj.vtbl.GetSwapChain,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(swapChain),
uintptr(unsafe.Pointer(&chain)),
)
return chain, toErr(ret)
}
// GetNumberOfSwapChains returns the number of implicit swap chains.
func (obj *Device) GetNumberOfSwapChains() uint {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetNumberOfSwapChains,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint(ret)
}
// Reset resets the type, size, and format of the swap chain.
func (obj *Device) Reset(params PRESENT_PARAMETERS) (PRESENT_PARAMETERS, Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.Reset,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(¶ms)),
0,
)
return params, toErr(ret)
}
// Present presents the contents of the next buffer in the sequence of back
// buffers owned by the device.
func (obj *Device) Present(
sourceRect *RECT,
destRect *RECT,
destWindowOverride HWND,
dirtyRegion *RGNDATA,
) Error {
ret, _, _ := syscall.Syscall6(
obj.vtbl.Present,
5,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(sourceRect)),
uintptr(unsafe.Pointer(destRect)),
uintptr(destWindowOverride),
uintptr(unsafe.Pointer(dirtyRegion)),
0,
)
return toErr(ret)
}
// GetBackBuffer retrieves a back buffer from the device's swap chain.
// Call Release on the returned surface when finished using it.
func (obj *Device) GetBackBuffer(
swapChain uint,
backBuffer uint,
typ BACKBUFFER_TYPE,
) (*Surface, Error) {
var surface *Surface
ret, _, _ := syscall.Syscall6(
obj.vtbl.GetBackBuffer,
5,
uintptr(unsafe.Pointer(obj)),
uintptr(swapChain),
uintptr(backBuffer),
uintptr(typ),
uintptr(unsafe.Pointer(&surface)),
0,
)
return surface, toErr(ret)
}
// GetRasterStatus returns information describing the raster of the monitor on
// which the swap chain is presented.
func (obj *Device) GetRasterStatus(swapChain uint) (RASTER_STATUS, Error) {
var status RASTER_STATUS
ret, _, _ := syscall.Syscall(
obj.vtbl.GetRasterStatus,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(swapChain),
uintptr(unsafe.Pointer(&status)),
)
return status, toErr(ret)
}
// SetDialogBoxMode allows the use of GDI dialog boxes in full-screen mode
// applications.
func (obj *Device) SetDialogBoxMode(enableDialogs bool) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetDialogBoxMode,
2,
uintptr(unsafe.Pointer(obj)),
uintptrBool(enableDialogs),
0,
)
return toErr(ret)
}
// SetGammaRamp sets the gamma correction ramp for the implicit swap chain. This
// method will affect the entire screen (not just the active window if you are
// running in windowed mode).
func (obj *Device) SetGammaRamp(swapChain uint, flags uint32, ramp GAMMARAMP) {
syscall.Syscall6(
obj.vtbl.SetGammaRamp,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(swapChain),
uintptr(flags),
uintptr(unsafe.Pointer(&ramp)),
0,
0,
)
}
// GetGammaRamp retrieves the gamma correction ramp for the swap chain.
func (obj *Device) GetGammaRamp(swapChain uint) GAMMARAMP {
var ramp GAMMARAMP
syscall.Syscall(
obj.vtbl.GetGammaRamp,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(swapChain),
uintptr(unsafe.Pointer(&ramp)),
)
return ramp
}
// CreateTexture creates a texture resource.
func (obj *Device) CreateTexture(
width uint,
height uint,
levels uint,
usage uint32,
format FORMAT,
pool POOL,
sharedHandle uintptr,
) (*Texture, Error) {
var tex *Texture
ret, _, _ := syscall.Syscall9(
obj.vtbl.CreateTexture,
9,
uintptr(unsafe.Pointer(obj)),
uintptr(width),
uintptr(height),
uintptr(levels),
uintptr(usage),
uintptr(format),
uintptr(pool),
uintptr(unsafe.Pointer(&tex)),
sharedHandle,
)
return tex, toErr(ret)
}
// CreateVolumeTexture creates a volume texture resource.
func (obj *Device) CreateVolumeTexture(
width uint,
height uint,
depth uint,
levels uint,
usage uint32,
format FORMAT,
pool POOL,
sharedHandle uintptr,
) (*VolumeTexture, Error) {
var tex *VolumeTexture
ret, _, _ := syscall.Syscall12(
obj.vtbl.CreateVolumeTexture,
10,
uintptr(unsafe.Pointer(obj)),
uintptr(width),
uintptr(height),
uintptr(depth),
uintptr(levels),
uintptr(usage),
uintptr(format),
uintptr(pool),
uintptr(unsafe.Pointer(&tex)),
sharedHandle,
0,
0,
)
return tex, toErr(ret)
}
// CreateCubeTexture creates a cube texture resource.
func (obj *Device) CreateCubeTexture(
edgeLength uint,
levels uint,
usage uint32,
format FORMAT,
pool POOL,
sharedHandle uintptr,
) (*CubeTexture, Error) {
var tex *CubeTexture
ret, _, _ := syscall.Syscall9(
obj.vtbl.CreateCubeTexture,
8,
uintptr(unsafe.Pointer(obj)),
uintptr(edgeLength),
uintptr(levels),
uintptr(usage),
uintptr(format),
uintptr(pool),
uintptr(unsafe.Pointer(&tex)),
sharedHandle,
0,
)
return tex, toErr(ret)
}
// CreateVertexBuffer creates a vertex buffer.
func (obj *Device) CreateVertexBuffer(
length uint,
usage uint32,
fvf uint32,
pool POOL,
sharedHandle uintptr,
) (*VertexBuffer, Error) {
var buf *VertexBuffer
ret, _, _ := syscall.Syscall9(
obj.vtbl.CreateVertexBuffer,
7,
uintptr(unsafe.Pointer(obj)),
uintptr(length),
uintptr(usage),
uintptr(fvf),
uintptr(pool),
uintptr(unsafe.Pointer(&buf)),
sharedHandle,
0,
0,
)
return buf, toErr(ret)
}
// CreateIndexBuffer creates an index buffer.
func (obj *Device) CreateIndexBuffer(
length uint,
usage uint32,
format FORMAT,
pool POOL,
sharedHandle uintptr,
) (*IndexBuffer, Error) {
var buf *IndexBuffer
ret, _, _ := syscall.Syscall9(
obj.vtbl.CreateIndexBuffer,
7,
uintptr(unsafe.Pointer(obj)),
uintptr(length),
uintptr(usage),
uintptr(format),
uintptr(pool),
uintptr(unsafe.Pointer(&buf)),
sharedHandle,
0,
0,
)
return buf, toErr(ret)
}
// CreateRenderTarget creates a render-target surface.
func (obj *Device) CreateRenderTarget(
width uint,
height uint,
format FORMAT,
multiSample MULTISAMPLE_TYPE,
multisampleQuality uint32,
lockable bool,
sharedHandle uintptr,
) (*Surface, Error) {
var surface *Surface
ret, _, _ := syscall.Syscall9(
obj.vtbl.CreateRenderTarget,
9,
uintptr(unsafe.Pointer(obj)),
uintptr(width),
uintptr(height),
uintptr(format),
uintptr(multiSample),
uintptr(multisampleQuality),
uintptrBool(lockable),
uintptr(unsafe.Pointer(&surface)),
sharedHandle,
)
return surface, toErr(ret)
}
// CreateDepthStencilSurface creates a depth-stencil resource.
func (obj *Device) CreateDepthStencilSurface(
width uint,
height uint,
format FORMAT,
multiSample MULTISAMPLE_TYPE,
multisampleQuality uint32,
discard bool,
sharedHandle uintptr,
) (*Surface, Error) {
var surface *Surface
ret, _, _ := syscall.Syscall9(
obj.vtbl.CreateDepthStencilSurface,
9,
uintptr(unsafe.Pointer(obj)),
uintptr(width),
uintptr(height),
uintptr(format),
uintptr(multiSample),
uintptr(multisampleQuality),
uintptrBool(discard),
uintptr(unsafe.Pointer(&surface)),
sharedHandle,
)
return surface, toErr(ret)
}
// UpdateSurface copies rectangular subsets of pixels from one surface to another.
func (obj *Device) UpdateSurface(
sourceSurface *Surface,
sourceRect *RECT,
destSurface *Surface,
destPoint *POINT,
) Error {
ret, _, _ := syscall.Syscall6(
obj.vtbl.UpdateSurface,
5,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(sourceSurface)),
uintptr(unsafe.Pointer(sourceRect)),
uintptr(unsafe.Pointer(destSurface)),
uintptr(unsafe.Pointer(destPoint)),
0,
)
return toErr(ret)
}
// UpdateTexture updates the dirty portions of a texture.
func (obj *Device) UpdateTexture(sourceTexture, destTexture *BaseTexture) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.UpdateTexture,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(sourceTexture)),
uintptr(unsafe.Pointer(destTexture)),
)
return toErr(ret)
}
// GetRenderTargetData copies the render-target data from device memory to
// system memory.
func (obj *Device) GetRenderTargetData(renderTarget, destSurface *Surface) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetRenderTargetData,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(renderTarget)),
uintptr(unsafe.Pointer(destSurface)),
)
return toErr(ret)
}
// GetFrontBufferData generates a copy of the device's front buffer and places
// that copy in a system memory buffer provided by the application.
func (obj *Device) GetFrontBufferData(swapChain uint, destSurface *Surface) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetFrontBufferData,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(swapChain),
uintptr(unsafe.Pointer(destSurface)),
)
return toErr(ret)
}
// StretchRect copies the contents of the source rectangle to the destination
// rectangle. The source rectangle can be stretched and filtered by the copy.
// This function is often used to change the aspect ratio of a video stream.
func (obj *Device) StretchRect(
sourceSurface *Surface,
sourceRect *RECT,
destSurface *Surface,
destRect *RECT,
filter TEXTUREFILTERTYPE,
) Error {
ret, _, _ := syscall.Syscall6(
obj.vtbl.StretchRect,
6,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(sourceSurface)),
uintptr(unsafe.Pointer(sourceRect)),
uintptr(unsafe.Pointer(destSurface)),
uintptr(unsafe.Pointer(destRect)),
uintptr(filter),
)
return toErr(ret)
}
// ColorFill allows an application to fill a rectangular area of a
// POOL_DEFAULT surface with a specified color.
func (obj *Device) ColorFill(
surface *Surface,
rect *RECT,
color COLOR,
) Error {
ret, _, _ := syscall.Syscall6(
obj.vtbl.ColorFill,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(surface)),
uintptr(unsafe.Pointer(rect)),
uintptr(color),
0,
0,
)
return toErr(ret)
}
// CreateOffscreenPlainSurface creates an off-screen surface.
func (obj *Device) CreateOffscreenPlainSurface(
width uint,
height uint,
format FORMAT,
pool POOL,
sharedHandle uintptr,
) (*Surface, Error) {
var surface *Surface
ret, _, _ := syscall.Syscall9(
obj.vtbl.CreateOffscreenPlainSurface,
7,
uintptr(unsafe.Pointer(obj)),
uintptr(width),
uintptr(height),
uintptr(format),
uintptr(pool),
uintptr(unsafe.Pointer(&surface)),
sharedHandle,
0,
0,
)
return surface, toErr(ret)
}
// SetRenderTarget sets a new color buffer for the device.
func (obj *Device) SetRenderTarget(
renderTargetIndex uint32,
renderTarget *Surface,
) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetRenderTarget,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(renderTargetIndex),
uintptr(unsafe.Pointer(renderTarget)),
)
return toErr(ret)
}
// GetRenderTarget retrieves a render-target surface.
func (obj *Device) GetRenderTarget(renderTargetIndex uint32) (*Surface, Error) {
var surface *Surface
ret, _, _ := syscall.Syscall(
obj.vtbl.GetRenderTarget,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(renderTargetIndex),
uintptr(unsafe.Pointer(surface)),
)
return surface, toErr(ret)
}
// SetDepthStencilSurface sets the depth stencil surface.
func (obj *Device) SetDepthStencilSurface(newZStencil *Surface) (err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetDepthStencilSurface,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(newZStencil)),
0,
)
return toErr(ret)
}
// GetDepthStencilSurface returns the depth-stencil surface owned by the
// Direct3DDevice object.
// Call Release on the returned surface when finished using it.
func (obj *Device) GetDepthStencilSurface() (*Surface, Error) {
var surface *Surface
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDepthStencilSurface,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&surface)),
0,
)
return surface, toErr(ret)
}
// BeginScene begins a scene.
// Applications must call BeginScene before performing any rendering and must
// call EndScene when rendering is complete and before calling BeginScene again.
func (obj *Device) BeginScene() Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.BeginScene,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return toErr(ret)
}
// EndScene ends a scene that was begun by calling BeginScene.
func (obj *Device) EndScene() (err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.EndScene,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return toErr(ret)
}
// Clear clears one or more surfaces such as a render target, multiple render
// targets, a stencil buffer, and a depth buffer.
func (obj *Device) Clear(
rects []RECT,
flags uint32,
color COLOR,
z float32,
stencil uint32,
) Error {
var rectPtr *RECT
if len(rects) > 0 {
rectPtr = &rects[0]
}
ret, _, _ := syscall.Syscall9(
obj.vtbl.Clear,
7,
uintptr(unsafe.Pointer(obj)),
uintptr(len(rects)),
uintptr(unsafe.Pointer(rectPtr)),
uintptr(flags),
uintptr(color),
uintptr(math.Float32bits(z)),
uintptr(stencil),
0,
0,
)
return toErr(ret)
}
// SetTransform sets a single device transformation-related state.
func (obj *Device) SetTransform(state TRANSFORMSTATETYPE, matrix MATRIX) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetTransform,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(state),
uintptr(unsafe.Pointer(&matrix[0])),
)
return toErr(ret)
}
// GetTransform retrieves a matrix describing a transformation state.
func (obj *Device) GetTransform(state TRANSFORMSTATETYPE) (m MATRIX, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetTransform,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(state),
uintptr(unsafe.Pointer(&m[0])),
)
err = toErr(ret)
return
}
// MultiplyTransform multiplies a device's world, view, or projection matrices
// by a specified matrix.
func (obj *Device) MultiplyTransform(state TRANSFORMSTATETYPE, m MATRIX) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.MultiplyTransform,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(state),
uintptr(unsafe.Pointer(&m[0])),
)
return toErr(ret)
}
// SetViewport sets the viewport parameters for the device.
func (obj *Device) SetViewport(v VIEWPORT) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetViewport,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&v)),
0,
)
return toErr(ret)
}
// GetViewport retrieves the viewport parameters currently set for the device.
func (obj *Device) GetViewport() (v VIEWPORT, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetViewport,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&v)),
0,
)
err = toErr(ret)
return
}
// SetMaterial sets the material properties for the device.
func (obj *Device) SetMaterial(m MATERIAL) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetMaterial,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&m)),
0,
)
return toErr(ret)
}
// GetMaterial retrieves the current material properties for the device.
func (obj *Device) GetMaterial() (m MATERIAL, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetMaterial,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&m)),
0,
)
err = toErr(ret)
return
}
// SetLight assigns a set of lighting properties for this device.
func (obj *Device) SetLight(index uint32, light LIGHT) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetLight,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(index),
uintptr(unsafe.Pointer(&light)),
)
return toErr(ret)
}
// GetLight retrieves a set of lighting properties that this device uses.
func (obj *Device) GetLight(index uint32) (light LIGHT, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetLight,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(index),
uintptr(unsafe.Pointer(&light)),
)
err = toErr(ret)
return
}
// LightEnable enables or disables a set of lighting parameters within a device.
func (obj *Device) LightEnable(lightIndex uint32, enable bool) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.LightEnable,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(lightIndex),
uintptrBool(enable),