2
Free Pascal port of the OpenPTC C++ library.
3
Copyright (C) 2001-2003 Nikolay Nikolov (nickysn@users.sourceforge.net)
4
Original C++ version by Glenn Fiedler (ptc@gaffer.org)
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
Constructor TDirectXPrimary.Create;
29
m_area := TPTCArea.Create;
30
m_clip := TPTCArea.Create;
31
m_format := TPTCFormat.Create;
32
m_clear := TPTCClear.Create;
33
m_palette := TPTCPalette.Create;
44
m_lpDDS_primary := Nil;
45
m_lpDDS_primary_back := Nil;
46
m_lpDDS_secondary := Nil;
50
m_synchronize := True;
51
m_fullscreen := False;
53
m_primary_height := 0;
54
m_secondary_width := 0;
55
m_secondary_height := 0;
56
FillChar(m_lpDDS_primary_page, SizeOf(m_lpDDS_primary_page), 0);
59
Destructor TDirectXPrimary.Destroy;
72
Procedure TDirectXPrimary.initialize(window : TWin32Window; lpDD2 : LPDIRECTDRAW2);
75
LOG('initializing primary surface');
81
Procedure TDirectXPrimary.primary(_pages : Integer; video, fullscreen, _palette, complex : Boolean);
84
attach_primary_pages : Boolean;
85
descriptor : DDSURFACEDESC;
87
capabilities : DDSCAPS;
94
LOG('creating primary surface');
97
LOG('fullscreen', fullscreen);
98
LOG('palette', _palette);
99
LOG('complex', complex);
101
Raise TPTCError.Create('invalid number of pages');
102
m_fullscreen := fullscreen;
103
attach_primary_pages := False;
104
If complex Or (Not _palette) Or (_pages = 1) Then
106
LOG('creating a complex primary flipping surface');
107
FillChar(descriptor, SizeOf(descriptor), 0);
108
descriptor.dwSize := SizeOf(descriptor);
109
descriptor.dwFlags := DDSD_CAPS;
111
descriptor.dwFlags := descriptor.dwFlags Or DDSD_BACKBUFFERCOUNT;
112
descriptor.dwBackBufferCount := _pages - 1;
113
descriptor.ddsCaps.dwCaps := DDSCAPS_PRIMARYSURFACE;
115
descriptor.ddsCaps.dwCaps := descriptor.ddsCaps.dwCaps Or DDSCAPS_VIDEOMEMORY;
117
descriptor.ddsCaps.dwCaps := descriptor.ddsCaps.dwCaps Or DDSCAPS_COMPLEX Or DDSCAPS_FLIP;
118
DirectXCheck(m_lpDD2^.lpVtbl^.CreateSurface(m_lpDD2, @descriptor, @m_lpDDS_primary, Nil), 'm_lpDD2^.CreateSurface failed in TDirectXPrimary.primary');
122
LOG('creating a simple primary surface');
123
FillChar(descriptor, SizeOf(descriptor), 0);
124
descriptor.dwSize := SizeOf(descriptor);
125
descriptor.dwFlags := DDSD_CAPS;
126
descriptor.ddsCaps.dwCaps := DDSCAPS_PRIMARYSURFACE;
128
descriptor.ddsCaps.dwCaps := descriptor.ddsCaps.dwCaps Or DDSCAPS_VIDEOMEMORY;
129
DirectXCheck(m_lpDD2^.lpVtbl^.CreateSurface(m_lpDD2, @descriptor, @m_lpDDS_primary, Nil), 'm_lpDD2^.CreateSurface failed in TDirectXPrimary.primary (palette)');
130
attach_primary_pages := True;
132
FillChar(descriptor, SizeOf(descriptor), 0);
133
descriptor.dwSize := SizeOf(descriptor);
134
DirectXCheck(m_lpDDS_primary^.lpVtbl^.GetSurfaceDesc(m_lpDDS_primary, @descriptor), 'm_lpDDS_primary^.GetSurfaceDesc failed in TDirectXPrimary.primary');
135
If (descriptor.ddsCaps.dwCaps And DDSCAPS_VIDEOMEMORY) <> 0 Then
137
LOG('primary surface is in video memory');
141
LOG('primary surface is in system memory');
143
FillChar(ddpf, SizeOf(ddpf), 0);
144
ddpf.dwSize := SizeOf(ddpf);
145
DirectXCheck(m_lpDDS_primary^.lpVtbl^.GetPixelFormat(m_lpDDS_primary, @ddpf), 'm_lpDDS_primary^.GetPixelFormat failed in TDirectXPrimary.primary');
146
m_front := m_lpDDS_primary;
148
m_width := descriptor.dwWidth;
149
m_height := descriptor.dwHeight;
150
FreeAndNil(m_format);
151
m_format := DirectXTranslate(ddpf);
152
LOG('primary width', m_width);
153
LOG('primary height', m_height);
154
LOG('primary pages', m_pages);
155
LOG('primary format', m_format);
158
LOG('clearing primary palette');
159
tmp := TPTCPalette.Create;
166
If attach_primary_pages Then
168
If (_pages - 1) > High(m_lpDDS_primary_page) Then
169
Raise TPTCError.Create('too many primary pages');
170
For i := 0 To _pages - 2 Do
172
LOG('creating primary page surface');
173
FillChar(descriptor, SizeOf(descriptor), 0);
174
descriptor.dwSize := SizeOf(descriptor);
175
descriptor.dwFlags := DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT;
176
descriptor.dwWidth := m_width;
177
descriptor.dwHeight := m_height;
178
descriptor.ddsCaps.dwCaps := DDSCAPS_OFFSCREENPLAIN;
180
descriptor.ddsCaps.dwCaps := descriptor.ddsCaps.dwCaps Or DDSCAPS_VIDEOMEMORY;
181
DirectXCheck(m_lpDD2^.lpVtbl^.CreateSurface(m_lpDD2, @descriptor, @m_lpDDS_primary_page[i], Nil), 'm_lpDD2^.CreateSurface failed in TDirectXPrimary.primary (primary page)');
183
FillChar(descriptor, SizeOf(descriptor), 0);
184
descriptor.dwSize := SizeOf(descriptor);
185
DirectXCheck(m_lpDDS_primary_page[i]^.lpVtbl^.GetSurfaceDesc(m_lpDDS_primary_page[i], @descriptor), 'm_lpDDS_primary_page^.GetSurfaceDesc failed in TDirectXPrimary.primary');
187
If (descriptor.ddsCaps.dwCaps And DDSCAPS_VIDEOMEMORY) <> 0 Then
189
LOG('primary surface page is in video memory');
193
LOG('primary surface page is in system memory');
195
LOG('attaching page to primary surface');
196
DirectXCheck(m_lpDDS_primary^.lpVtbl^.AddAttachedSurface(m_lpDDS_primary, m_lpDDS_primary_page[i]), 'm_lpDDS_primary^.AddAttachedSurface failed in TDirectXPrimary.primary');
199
m_primary_width := m_width;
200
m_primary_height := m_height;
201
If Not fullscreen Then
203
GetClientRect(m_window.handle, rectangle);
204
m_width := rectangle.right;
205
m_height := rectangle.bottom;
208
m_area := TPTCArea.Create(0, 0, m_width, m_height);
210
m_clip := TPTCArea.Create(m_area);
213
capabilities.dwCaps := DDSCAPS_BACKBUFFER;
214
DirectXCheck(m_front^.lpVtbl^.GetAttachedSurface(m_front, @capabilities, @m_lpDDS_primary_back), 'm_front^.GetAttachedSurface failed in TDirectXPrimary.primary');
216
FillChar(descriptor, SizeOf(descriptor), 0);
217
descriptor.dwSize := SizeOf(descriptor);
218
DirectXCheck(m_lpDDS_primary_back^.lpVtbl^.GetSurfaceDesc(m_lpDDS_primary_back, @descriptor), 'm_lpDDS_primary_back^.GetSurfaceDesc failed in TDirectXPrimary.primary');
220
If (descriptor.ddsCaps.dwCaps And DDSCAPS_VIDEOMEMORY) <> 0 Then
222
LOG('primary back surface is in video memory');
226
LOG('primary back surface is in system memory');
230
m_lpDDS_primary_back := m_front;
231
m_back := m_lpDDS_primary_back;
236
LOG('clearing primary page');
241
On error : TPTCError Do
243
If m_lpDDS_primary <> Nil Then
245
m_lpDDS_primary^.lpVtbl^.Release(m_lpDDS_primary);
246
m_lpDDS_primary := Nil;
248
Raise TPTCError.Create('could not create primary surface', error);
253
Procedure TDirectXPrimary.secondary(_width, _height : Integer);
256
descriptor : DDSURFACEDESC;
259
capabilities : DDSCAPS;
262
LOG('creating secondary surface');
263
LOG('width', _width);
264
LOG('height', _height);
265
FillChar(descriptor, SizeOf(descriptor), 0);
266
descriptor.dwSize := SizeOf(descriptor);
267
descriptor.dwFlags := DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH;
268
descriptor.ddsCaps.dwCaps := DDSCAPS_OFFSCREENPLAIN;
269
descriptor.dwHeight := _height;
270
descriptor.dwWidth := _width;
271
DirectXCheck(m_lpDD2^.lpVtbl^.CreateSurface(m_lpDD2, @descriptor, @m_lpDDS_secondary, Nil), 'm_lpDD2^.CreateSurface failed in TDirectXPrimary.secondary');
273
FillChar(descriptor, SizeOf(descriptor), 0);
274
descriptor.dwSize := SizeOf(descriptor);
275
DirectXCheck(m_lpDDS_secondary^.lpVtbl^.GetSurfaceDesc(m_lpDDS_secondary, @descriptor), 'm_lpDDS_secondary^.GetSurfaceDesc failed in TDirectXPrimary.secondary');
277
If (descriptor.ddsCaps.dwCaps And DDSCAPS_VIDEOMEMORY) <> 0 Then
279
LOG('secondary surface is in video memory');
283
LOG('secondary surface is in system memory');
286
If Not m_fullscreen Then
288
LOG('attaching clipper to primary surface');
289
DirectXCheck(m_lpDD2^.lpVtbl^.CreateClipper(m_lpDD2, 0, @m_lpDDC, Nil), 'm_lpDD2^.CreateClipper failed in TDirectXPrimary.secondary');
290
DirectXCheck(m_lpDDC^.lpVtbl^.SetHWnd(m_lpDDC, 0, m_window.handle), 'm_lpDDC^.SetHWnd failed in TDirectXPrimary.secondary');
291
DirectXCheck(m_lpDDS_primary^.lpVtbl^.SetClipper(m_lpDDS_primary, m_lpDDC), 'm_lpDDS_primary^.SetClipper failed in TDirectXPrimary.secondary');
296
m_area := TPTCArea.Create(0, 0, m_width, m_height);
298
m_clip := TPTCArea.Create(m_area);
299
m_secondary_width := m_width;
300
m_secondary_height := m_height;
301
m_back := m_lpDDS_secondary;
303
{ hel.dwSize := SizeOf(hel);
304
driver.dwSize := SizeOf(driver);
305
DirectXCheck(m_lpDD2^.GetCaps(@driver, @hel));}
307
auto stretching support is disabled below because in almost 100% of cases
308
centering is faster and we must choose the fastest option by default!
310
{todo: DDCAPS!!!!!!!!!!!}
311
{ If ((driver.dwCaps And DDCAPS_BLTSTRETCH) <> 0) And
312
((driver.dwFXCaps And DDFXCAPS_BLTSTRETCHY) <> 0) Then
314
LOG('found hardware stretching support');
318
LOG('no hardware stretching support');
321
m_lpDDS_secondary^.lpVtbl^.GetCaps(m_lpDDS_secondary, @capabilities);
322
If (capabilities.dwCaps And DDSCAPS_SYSTEMMEMORY) <> 0 Then
324
LOG('secondary surface is in system memory');
329
LOG('clearing secondary page');
336
Procedure TDirectXPrimary.synchronize(_update : Boolean);
339
m_synchronize := _update;
341
m_synchronize := False;
342
LOG('primary synchronize', _update);
345
Procedure TDirectXPrimary.centering(center : Boolean);
348
m_centering := center;
349
LOG('primary centering', m_centering);
352
Procedure TDirectXPrimary.close;
361
LOG('closing primary surface');
363
If (m_lpDDS_primary <> Nil) And (m_lpDDS_primary^.lpVtbl^.IsLost(m_lpDDS_primary) <> DD_OK) Then
365
If (m_lpDDS_secondary <> Nil) And (m_lpDDS_secondary^.lpVtbl^.IsLost(m_lpDDS_secondary) <> DD_OK) Then
367
If (m_back <> Nil) And (m_lpDDS_primary <> Nil) And m_fullscreen And (Not lost) Then
369
tmp := TPTCPalette.Create;
371
LOG('clearing primary palette');
376
LOG('clearing primary pages');
377
For i := 0 To m_pages - 1 Do
386
LOG('primary close clearing failed');
390
If m_lpDDC <> Nil Then
392
LOG('releasing clipper');
393
m_lpDDC^.lpVtbl^.Release(m_lpDDC);
396
If m_lpDDS_secondary <> Nil Then
398
LOG('releasing secondary surface');
399
m_lpDDS_secondary^.lpVtbl^.Release(m_lpDDS_secondary);
400
m_lpDDS_secondary := Nil;
403
While m_lpDDS_primary_page[i] <> Nil Do
405
LOG('releasing attached primary surface page');
406
m_lpDDS_primary_page[i]^.lpVtbl^.Release(m_lpDDS_primary_page[i]);
407
m_lpDDS_primary_page[i] := Nil;
410
If m_lpDDS_primary <> Nil Then
412
LOG('releasing primary surface');
413
m_lpDDS_primary^.lpVtbl^.Release(m_lpDDS_primary);
414
m_lpDDS_primary := Nil;
419
m_lpDDS_primary_back := Nil;
422
Procedure TDirectXPrimary.update;
428
DirectXCheck(m_front^.lpVtbl^.Flip(m_front, Nil, DDFLIP_WAIT), 'm_front^.Flip failed in TDirectXPrimary.update');
431
Function TDirectXPrimary.lock : Pointer;
434
descriptor : DDSURFACEDESC;
440
descriptor.dwSize := SizeOf(descriptor);
441
If m_fullscreen Or (m_back = m_lpDDS_secondary) Then
443
DirectXCheck(m_back^.lpVtbl^.Lock(m_back, Nil, @descriptor, DDLOCK_WAIT, 0), 'm_back^.Lock failed in TDirectXPrimary.lock');
444
m_locked := descriptor.lpSurface;
450
ClientToScreen(m_window.handle, pnt);
453
rct.right := pnt.x + m_width;
454
rct.bottom := pnt.y + m_height;
455
DirectXCheck(m_back^.lpVtbl^.Lock(m_back, @rct, @descriptor, DDLOCK_WAIT, 0), 'm_back^.Lock(rect) failed in TDirectXPrimary.lock');
456
m_locked := descriptor.lpSurface;
461
Procedure TDirectXPrimary.unlock;
465
DirectXCheck(m_back^.lpVtbl^.Unlock(m_back, m_locked), 'm_back^.Unlock failed in TDirectXPrimary.unlock');
468
Procedure TDirectXPrimary.clear;
476
If m_fullscreen Or (m_back = m_lpDDS_secondary) Then
478
fx.dwSize := SizeOf(fx);
480
DirectXCheck(m_back^.lpVtbl^.Blt(m_back, Nil, Nil, Nil, DDBLT_COLORFILL Or DDBLT_WAIT, @fx), 'm_back^.Blt failed in TDirectXPrimary.clear');
484
{ todo: replace with hardware clear! }
485
If format.direct Then
487
tmp := TPTCColor.Create(0, 0, 0, 0);
496
tmp := TPTCColor.Create(0);
506
Procedure TDirectXPrimary.clear(Const color : TPTCColor; Const _area : TPTCArea);
509
clipped, clipped_area : TPTCArea;
518
If m_fullscreen Or (m_back = m_lpDDS_secondary) Then
520
clipped := TPTCClipper.clip(_area, m_clip);
522
clear_color := pack(color, m_format);
525
left := clipped.left;
527
right := clipped.right;
528
bottom := clipped.bottom;
530
fx.dwSize := SizeOf(fx);
531
fx.dwFillColor := clear_color;
532
DirectXCheck(m_back^.lpVtbl^.Blt(m_back, @rct, Nil, Nil, DDBLT_COLORFILL Or DDBLT_WAIT, @fx), 'm_back^.Blt(rect) failed in TDirectXPrimary.clear');
539
{ todo: replace with accelerated clearing code! }
544
clipped_area := TPTCClipper.clip(_area, clip);
545
m_clear.request(format);
546
m_clear.clear(pixels, clipped_area.left, clipped_area.right, clipped_area.width, clipped_area.height, pitch, color);
549
On error : TPTCError Do
552
Raise TPTCError.Create('failed to clear console area', error);
556
If clipped_area <> Nil Then
562
Procedure TDirectXPrimary.palette(Const _palette : TPTCPalette);
566
temp : Array[0..255] Of PALETTEENTRY;
568
lpDDP : LPDIRECTDRAWPALETTE;
573
m_palette.load(_palette.data);
574
If Not m_format.indexed Then
576
LOG('palette set in direct color');
580
data := _palette.data;
583
temp[i].peRed := (data[i] And $00FF0000) Shr 16;
584
temp[i].peGreen := (data[i] And $0000FF00) Shr 8;
585
temp[i].peBlue := data[i] And $000000FF;
586
temp[i].peFlags := 0;
589
If m_lpDDS_primary^.lpVtbl^.GetPalette(m_lpDDS_primary, @lpDDP) <> DD_OK Then
591
DirectXCheck(m_lpDD2^.lpVtbl^.CreatePalette(m_lpDD2, DDPCAPS_8BIT Or DDPCAPS_ALLOW256 Or DDPCAPS_INITIALIZE, @temp, @lpDDP, Nil), 'm_lpDD2^.CreatePalette failed in TDirectXPrimary.palette');
592
DirectXCheck(m_lpDDS_primary^.lpVtbl^.SetPalette(m_lpDDS_primary, lpDDP), 'm_lpDDS_primary^.SetPalette failed in TDirectXPrimary.palette');
595
DirectXCheck(lpDDP^.lpVtbl^.SetEntries(lpDDP, 0, 0, 256, @temp), 'lpDDP^.SetEntries failed in TDirectXPrimary.palette');
599
Function TDirectXPrimary.palette : TPTCPalette;
602
palette := m_palette;
605
Procedure TDirectXPrimary.clip(Const _area : TPTCArea);
611
tmp := TPTCClipper.clip(_area, m_area);
619
Function TDirectXPrimary.width : Integer;
625
Function TDirectXPrimary.height : Integer;
631
Function TDirectXPrimary.pages : Integer;
637
Function TDirectXPrimary.pitch : Integer;
640
descriptor : DDSURFACEDESC;
644
descriptor.dwSize := SizeOf(descriptor);
645
DirectXCheck(m_back^.lpVtbl^.GetSurfaceDesc(m_back, @descriptor), 'm_back^.GetSurfaceDesc failed in TDirectXPrimary.pitch');
646
pitch := descriptor.lPitch;
649
Function TDirectXPrimary.area : TPTCArea;
655
Function TDirectXPrimary.clip : TPTCArea;
661
Function TDirectXPrimary.format : TPTCFormat;
667
Function TDirectXPrimary.lpDDS : LPDIRECTDRAWSURFACE;
670
If m_lpDDS_secondary <> Nil Then
671
lpDDS := m_lpDDS_secondary
673
lpDDS := m_lpDDS_primary_back;
676
Function TDirectXPrimary.lpDDS_primary : LPDIRECTDRAWSURFACE;
679
lpDDS_primary := m_lpDDS_primary;
682
Function TDirectXPrimary.lpDDS_secondary : LPDIRECTDRAWSURFACE;
685
lpDDS_secondary := m_lpDDS_secondary;
688
Procedure TDirectXPrimary.activate;
691
LOG('primary activated');
695
Procedure TDirectXPrimary.deactivate;
698
LOG('primary deactivated');
702
{no deactivation when not blocking};
705
Function TDirectXPrimary.active : Boolean;
711
Procedure TDirectXPrimary.block;
717
If Not m_blocking Then
722
While Not restored Do
724
LOG('blocking until activated');
727
m_window.update(True);
730
LOG('primary is active');
731
m_window.update(True);
735
LOG('successful restore');
739
LOG('application is active but cannot restore');
745
If m_lpDDS_primary^.lpVtbl^.IsLost(m_lpDDS_primary) <> DD_OK Then
746
Raise TPTCError.Create('primary surface lost unexpectedly!');
747
If (m_lpDDS_secondary <> Nil) And (m_lpDDS_secondary^.lpVtbl^.IsLost(m_lpDDS_secondary) <> DD_OK) Then
748
Raise TPTCError.Create('secondary surface lost unexpectedly!');
751
Procedure TDirectXPrimary.save;
754
If m_lpDDS_primary^.lpVtbl^.IsLost(m_lpDDS_primary) = DD_OK Then
756
LOG('saving contents of primary surface');
758
{ todo: save contents of primary surface }
762
LOG('could not save primary surface');
765
If (m_lpDDS_secondary <> Nil) And (m_lpDDS_secondary^.lpVtbl^.IsLost(m_lpDDS_secondary) = DD_OK) Then
767
LOG('saving contents of secondary surface');
769
{ todo: save contents of secondary surface }
772
If m_lpDDS_secondary <> Nil Then
774
LOG('could not save secondary surface');
778
Procedure TDirectXPrimary.restore;
786
DirectXCheck(m_lpDDS_primary^.lpVtbl^.Restore(m_lpDDS_primary), 'm_lpDDS_primary^.Restore failed in TDirectXConsole.restore');
787
If m_lpDDS_secondary <> Nil Then
788
DirectXCheck(m_lpDDS_secondary^.lpVtbl^.Restore(m_lpDDS_secondary), 'm_lpDDS_secondary^.Restore failed in TDirectXConsole.restore');
789
LOG('restoring contents of primary surface');
790
{ todo: restore palette object on primary surface ? }
791
{ todo: restore contents of primary surface }
792
If m_lpDDS_primary_page[0] <> Nil Then
794
LOG('restoring attached pages');
795
For i := 0 To m_pages - 2 Do
796
DirectXCheck(m_lpDDS_primary_page[i]^.lpVtbl^.Restore(m_lpDDS_primary_page[i]), 'm_lpDDS_primary_page^.Restore failed in TDirectXConsole.restore');
799
If m_lpDDS_secondary <> Nil Then
803
LOG('temporary primary surface clear');
805
{ temporary: clear primary surface }
810
right := m_primary_width;
811
bottom := m_primary_height;
813
fx.dwSize := SizeOf(fx);
815
DirectXCheck(m_lpDDS_primary^.lpVtbl^.Blt(m_lpDDS_primary, @rct, Nil, Nil, DDBLT_COLORFILL Or DDBLT_WAIT, @fx), 'm_lpDDS_primary^.Blt failed in TDirectXPrimary.restore');
817
LOG('restoring contents of secondary surface');
818
{ todo: restore contents of secondary surface }
822
Procedure TDirectXPrimary.paint;
825
source, destination : RECT;
833
LOG('paint when not active');
836
If m_lpDDS_secondary <> Nil Then
838
If (m_lpDDS_primary^.lpVtbl^.IsLost(m_lpDDS_primary) <> DD_OK) Or
839
(m_lpDDS_secondary^.lpVtbl^.IsLost(m_lpDDS_secondary) <> DD_OK) Then
841
LOG('paint when surfaces are lost');
846
source.right := m_secondary_width;
847
source.bottom := m_secondary_height;
848
destination.left := 0;
849
destination.top := 0;
850
destination.right := m_primary_width;
851
destination.bottom := m_primary_height;
853
{ note: code below assumes secondary is smaller than primary }
854
If m_centering And m_fullscreen Then
856
x := (destination.right - source.right) Div 2;
857
y := (destination.bottom - source.bottom) Div 2;
859
destination.left := x;
860
destination.top := y;
861
destination.right := x + source.right;
862
destination.bottom := y + source.bottom;
864
If Not m_fullscreen Then
868
ClientToScreen(m_window.handle, pnt);
870
GetClientRect(m_window.handle, destination);
871
Inc(destination.left, pnt.x);
872
Inc(destination.top, pnt.y);
873
Inc(destination.right, pnt.x);
874
Inc(destination.bottom, pnt.y);
877
If ((source.right - source.left) = 0) Or
878
((source.bottom - source.top) = 0) Or
879
((destination.right - destination.left) = 0) Or
880
((destination.bottom - destination.top) = 0) Then
882
LOG('zero area in primary paint');
886
If m_synchronize Then
888
fx.dwSize := SizeOf(fx);
889
fx.dwDDFX := DDBLTFX_NOTEARING;
891
DirectXCheck(m_lpDDS_primary_back^.lpVtbl^.Blt(m_lpDDS_primary_back, @destination, m_lpDDS_secondary, @source, DDBLT_WAIT Or DDBLT_DDFX, @fx), 'm_lpDDS_primary^.Blt (synchronized) failed in TDirectXPrimary.paint');
895
LOG('falling back to unsynchronized blt');
896
m_synchronize := False;
900
If Not m_synchronize Then
901
DirectXCheck(m_lpDDS_primary_back^.lpVtbl^.Blt(m_lpDDS_primary_back, @destination, m_lpDDS_secondary, @source, DDBLT_WAIT, Nil), 'm_lpDDS_primary^.Blt (unsynchronized) failed in TDirectXPrimary.paint');
905
Procedure TDirectXPrimary.blocking(_blocking : Boolean);
908
m_blocking := _blocking;
911
Function TDirectXPrimary.pack(Const color : TPTCColor; Const _format : TPTCFormat) : int32;
914
r_base, g_base, b_base, a_base : Integer;
915
r_size, g_size, b_size, a_size : Integer;
916
r_scale, g_scale, b_scale, a_scale : Single;
919
If color.direct And _format.direct Then
929
analyse(_format.r, r_base, r_size);
930
analyse(_format.g, g_base, g_size);
931
analyse(_format.b, b_base, b_size);
932
analyse(_format.a, a_base, a_size);
933
r_scale := 1 Shl r_size;
934
g_scale := 1 Shl g_size;
935
b_scale := 1 Shl b_size;
936
a_scale := 1 Shl a_size;
937
pack := (Trunc(color.r * r_scale) Shl r_base) Or
938
(Trunc(color.g * g_scale) Shl g_base) Or
939
(Trunc(color.b * b_scale) Shl b_base) Or
940
(Trunc(color.a * a_scale) Shl a_base);
943
If color.indexed And _format.indexed Then
946
Raise TPTCError.Create('color format type mismatch');
949
Procedure TDirectXPrimary.analyse(mask : int32; Var base, size : Integer);
956
While (mask And 1) = 0 Do
961
While (mask And 1) <> 0 Do