forked from icculus/Serious-Engine
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathGfxLibrary.cpp
More file actions
executable file
·2189 lines (1868 loc) · 80.5 KB
/
GfxLibrary.cpp
File metadata and controls
executable file
·2189 lines (1868 loc) · 80.5 KB
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
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include "Engine/StdH.h"
#include <Engine/Graphics/GfxLibrary.h>
#include <Engine/Base/Translation.h>
#include <Engine/Base/ErrorReporting.h>
#include <Engine/Base/Console.h>
#include <Engine/Base/Shell.h>
#include <Engine/Base/Statistics_Internal.h>
#include <Engine/Base/ListIterator.inl>
#include <Engine/Math/Functions.h>
#include <Engine/Math/AABBox.h>
#include <Engine/Models/Normals.h>
#include <Engine/Sound/SoundLibrary.h>
#include <Engine/Templates/Stock_CModelData.h>
#include <Engine/Graphics/OpenGL.h>
#include <Engine/Graphics/Adapter.h>
#include <Engine/Graphics/ShadowMap.h>
#include <Engine/Graphics/Texture.h>
#include <Engine/Graphics/GfxProfile.h>
#include <Engine/Graphics/Raster.h>
#include <Engine/Graphics/ViewPort.h>
#include <Engine/Graphics/DrawPort.h>
#include <Engine/Graphics/Color.h>
#include <Engine/Graphics/Font.h>
#include <Engine/Graphics/MultiMonitor.h>
#include <Engine/Templates/DynamicStackArray.h>
#include <Engine/Templates/DynamicStackArray.cpp>
#include <Engine/Templates/DynamicContainer.cpp>
#include <Engine/Templates/Stock_CTextureData.h>
// !!! FIXME: rcg10112001 This just screams to be broken up into subclasses.
// !!! FIXME: rcg10112001 That would get rid of all the #ifdef'ing and
// !!! FIXME: rcg10112001 the need to continually assert that the current
// !!! FIXME: rcg10112001 driver type is valid.
// control for partial usage of compiled vertex arrays
BOOL CVA_b2D = FALSE;
BOOL CVA_bWorld = FALSE;
BOOL CVA_bModels = FALSE;
// common element arrays
CStaticStackArray<GFXVertex> _avtxCommon;
CStaticStackArray<GFXTexCoord> _atexCommon;
CStaticStackArray<GFXColor> _acolCommon;
CStaticStackArray<INDEX_T> _aiCommonElements;
CStaticStackArray<INDEX_T> _aiCommonQuads; // predefined array for rendering quads thru triangles in glDrawElements()
// global texture parameters
CTexParams _tpGlobal[GFX_MAXTEXUNITS];
// pointer to global graphics library object
CGfxLibrary *_pGfx = NULL;
// forced texture upload quality (0 = default, 16 = force 16-bit, 32 = force 32-bit)
INDEX _iTexForcedQuality = 0;
extern PIX _fog_pixSizeH;
extern PIX _fog_pixSizeL;
extern PIX _haze_pixSize;
// control for partial usage of compiled vertex arrays
extern BOOL CVA_b2D;
extern BOOL CVA_bWorld;
extern BOOL CVA_bModels;
// gamma control
static FLOAT _fLastBrightness, _fLastContrast, _fLastGamma;
static FLOAT _fLastBiasR, _fLastBiasG, _fLastBiasB;
static INDEX _iLastLevels;
#ifndef PLATFORM_PANDORA // DG: not used on other platforms
static UWORD _auwGammaTable[256*3];
#endif
// table for clipping [-512..+1024] to [0..255]
static UBYTE aubClipByte[256*2+ 256 +256*3];
const UBYTE *pubClipByte = &aubClipByte[256*2];
// fast square root and 1/sqrt tables
UBYTE aubSqrt[SQRTTABLESIZE];
UWORD auw1oSqrt[SQRTTABLESIZE];
// table for conversion from compressed 16-bit gouraud normals to 8-bit
UBYTE aubGouraudConv[16384];
// flag for scene rendering in progress (i.e. between 1st lock in frame & swap-buffers)
static BOOL GFX_bRenderingScene = FALSE;
// ID of the last drawport that has been locked
static ULONG GFX_ulLastDrawPortID = 0;
// last size of vertex buffers
INDEX _iLastVertexBufferSize = 0;
// pretouch flag
extern BOOL _bNeedPretouch;
// flat texture
CTextureData *_ptdFlat = NULL;
static ULONG _ulWhite = 0xFFFFFFFF;
// fast sin/cos table
static FLOAT afSinTable[256+256+64];
const FLOAT *pfSinTable = afSinTable +256;
const FLOAT *pfCosTable = afSinTable +256+64;
// texture/shadow control
INDEX tex_iNormalQuality = 00; // 0=optimal, 1=16bit, 2=32bit, 3=compressed (1st num=opaque tex, 2nd=alpha tex)
INDEX tex_iAnimationQuality = 11; // 0=optimal, 1=16bit, 2=32bit, 3=compressed (1st num=opaque tex, 2nd=alpha tex)
INDEX tex_iNormalSize = 9; // log2 of texture area /2 for max texture size allowed
INDEX tex_iAnimationSize = 7;
INDEX tex_iEffectSize = 7;
INDEX tex_bDynamicMipmaps = FALSE; // how many mipmaps will be bilineary filtered (0-15)
INDEX tex_iDithering = 3; // 0=none, 1-3=low, 4-7=medium, 8-10=high
INDEX tex_bCompressAlphaChannel = FALSE; // for compressed textures, compress alpha channel too
INDEX tex_bAlternateCompression = FALSE; // basically, this is fix for GFs (compress opaque texture as translucent)
INDEX tex_bFineEffect = FALSE; // 32bit effect? (works only if base texture hasn't been dithered)
INDEX tex_bFineFog = TRUE; // should fog be 8/32bit? (or just plain 4/16bit)
INDEX tex_iFogSize = 7; // limit fog texture size
INDEX tex_iFiltering = 0; // -6 - +6; negative = sharpen, positive = blur, 0 = none
INDEX tex_iEffectFiltering = +4; // filtering of fire effect textures
INDEX tex_bProgressiveFilter = FALSE; // filter mipmaps in creation time (not afterwards)
INDEX tex_bColorizeMipmaps = FALSE; // DEBUG: colorize texture's mipmap levels in various colors
INDEX shd_iStaticSize = 8;
INDEX shd_iDynamicSize = 8;
INDEX shd_bFineQuality = FALSE;
INDEX shd_iFiltering = 3; // >0 = blurring, 0 = no filtering
INDEX shd_iDithering = 1; // 0=none, 1,2=low, 3,4=medium, 5=high
INDEX shd_iAllowDynamic = 1; // 0=disallow, 1=allow on polys w/o 'NoDynamicLights' flag, 2=allow unconditionally
INDEX shd_bDynamicMipmaps = TRUE;
FLOAT shd_tmFlushDelay = 30.0f; // in seconds
FLOAT shd_fCacheSize = 8.0f; // in megabytes
INDEX shd_bCacheAll = FALSE; // cache all shadowmap at the level loading time (careful - memory eater!)
INDEX shd_bAllowFlats = TRUE; // allow optimization of single-color shadowmaps
INDEX shd_iForceFlats = 0; // force all shadowmaps to be flat (internal!) - 0=don't, 1=w/o overbrighting, 2=w/ overbrighting
INDEX shd_bShowFlats = FALSE; // show shadows that have been optimized as flat
INDEX shd_bColorize = FALSE; // colorize shadows by size (gradieng from red=big to green=little)
// OpenGL control
INDEX ogl_iTextureCompressionType = 1; // 0=none, 1=default (ARB), 2=S3TC, 3=FXT1, 4=old S3TC
INDEX ogl_bUseCompiledVertexArrays = 101; // =XYZ; X=2D, Y=world, Z=models
INDEX ogl_bAllowQuadArrays = FALSE;
INDEX ogl_bExclusive = TRUE;
INDEX ogl_bGrabDepthBuffer = FALSE;
INDEX ogl_iMaxBurstSize = 0; // unlimited
INDEX ogl_bTruformLinearNormals = TRUE;
INDEX ogl_bAlternateClipPlane = FALSE; // signal when user clip plane requires a texture unit
INDEX ogl_iTBufferEffect = 0; // 0=none, 1=partial FSAA, 2=Motion Blur
INDEX ogl_iTBufferSamples = 2; // 2, 4 or 8 (for now)
INDEX ogl_iFinish = 1; // 0=never, 1=before rendering of next frame, 2=at the end of this frame, 3=at projection change
// Direct3D control
INDEX d3d_bUseHardwareTnL = TRUE;
INDEX d3d_bAlternateDepthReads = FALSE; // should check delayed depth reads at the end of current frame (FALSE) or at begining of the next (TRUE)
INDEX d3d_bOptimizeVertexBuffers = TRUE; // enables circular buffers
INDEX d3d_iVertexBuffersSize = 1024; // KBs reserved for vertex buffers
INDEX d3d_iVertexRangeTreshold = 99; // minimum vertices in buffer that triggers range optimization
INDEX d3d_iMaxBurstSize = 0; // 0=unlimited
INDEX d3d_iFinish = 0;
// API common controls
INDEX gap_iUseTextureUnits = 4;
INDEX gap_iTextureFiltering = 21; // bilinear by default
INDEX gap_iTextureAnisotropy = 1; // 1=isotropic, 2=min anisotropy
FLOAT gap_fTextureLODBias = 0.0f;
INDEX gap_bOptimizeStateChanges = TRUE;
INDEX gap_iOptimizeDepthReads = 1; // 0=imediately, 1=after frame, 2=every 0.1 seconds
INDEX gap_iOptimizeClipping = 2; // 0=no, 1=mirror plane only, 2=mirror and frustum
INDEX gap_bAllowGrayTextures = TRUE;
INDEX gap_bAllowSingleMipmap = TRUE;
INDEX gap_iSwapInterval = 0;
INDEX gap_iRefreshRate = 0;
INDEX gap_iDithering = 2; // 16-bit dithering: 0=none, 1=no alpha, 2=all
INDEX gap_bForceTruform = 0; // 0 = only for models that allow truform, 1=for every model
INDEX gap_iTruformLevel = 3; // 0 = no tesselation
INDEX gap_iDepthBits = 0; // 0 (as color depth), 16, 24 or 32
INDEX gap_iStencilBits = 0; // 0 (no stencil buffer), 4 or 8
// models control
INDEX mdl_bShowTriangles = FALSE;
INDEX mdl_bShowStrips = FALSE;
INDEX mdl_bTruformWeapons = FALSE;
INDEX mdl_bCreateStrips = TRUE;
INDEX mdl_bRenderDetail = TRUE;
INDEX mdl_bRenderSpecular = TRUE;
INDEX mdl_bRenderReflection = TRUE;
INDEX mdl_bAllowOverbright = TRUE;
INDEX mdl_bFineQuality = TRUE;
INDEX mdl_iShadowQuality = 1;
FLOAT mdl_fLODMul = 1.0f;
FLOAT mdl_fLODAdd = 0.0f;
INDEX mdl_iLODDisappear = 1; // 0=never, 1=ignore bias, 2=with bias
// ska controls
INDEX ska_bShowSkeleton = FALSE;
INDEX ska_bShowColision = FALSE;
FLOAT ska_fLODMul = 1.0f;
FLOAT ska_fLODAdd = 0.0f;
// terrain controls
INDEX ter_bShowQuadTree = FALSE;
INDEX ter_bShowWireframe = FALSE;
INDEX ter_bLerpVertices = TRUE;
INDEX ter_bShowInfo = FALSE;
INDEX ter_bOptimizeRendering = TRUE;
INDEX ter_bTempFreezeCast = FALSE;
INDEX ter_bNoRegeneration = FALSE;
// !!! FIXME : rcg11232001 Hhmm...I'm failing an assertion in the
// !!! FIXME : rcg11232001 Advanced Rendering Options menu because
// !!! FIXME : rcg11232001 Scripts/CustomOptions/GFX-AdvancedRendering.cfg
// !!! FIXME : rcg11232001 references non-existing cvars, so I'm adding them
// !!! FIXME : rcg11232001 here for now.
static INDEX mdl_bRenderBump = TRUE;
static FLOAT ogl_fTextureAnisotropy = 0.0f;
static FLOAT tex_fNormalSize = 0.0f;
// rendering control
INDEX wld_bAlwaysAddAll = FALSE;
INDEX wld_bRenderMirrors = TRUE;
INDEX wld_bRenderEmptyBrushes = TRUE;
INDEX wld_bRenderShadowMaps = TRUE;
INDEX wld_bRenderTextures = TRUE;
INDEX wld_bRenderDetailPolygons = TRUE;
INDEX wld_bTextureLayers = 111;
INDEX wld_bShowTriangles = FALSE;
INDEX wld_bShowDetailTextures = FALSE;
INDEX wld_iDetailRemovingBias = 3;
FLOAT wld_fEdgeOffsetI = 0.0f; //0.125f;
FLOAT wld_fEdgeAdjustK = 1.0f; //1.0001f;
INDEX gfx_bRenderWorld = TRUE;
INDEX gfx_bRenderParticles = TRUE;
INDEX gfx_bRenderModels = TRUE;
INDEX gfx_bRenderPredicted = FALSE;
INDEX gfx_bRenderFog = TRUE;
INDEX gfx_iLensFlareQuality = 3; // 0=none, 1=corona only, 2=corona and reflections, 3=corona, reflections and glare
INDEX gfx_bDecoratedText = TRUE;
INDEX gfx_bClearScreen = FALSE;
FLOAT gfx_tmProbeDecay = 30.00f; // seconds
INDEX gfx_iProbeSize = 256; // in KBs
INDEX gfx_ctMonitors = 0;
INDEX gfx_bMultiMonDisabled = FALSE;
INDEX gfx_bDisableMultiMonSupport = TRUE;
INDEX gfx_bDisableWindowsKeys = TRUE;
INDEX wed_bIgnoreTJunctions = FALSE;
INDEX wed_bUseBaseForReplacement = FALSE;
// some nifty features
INDEX gfx_iHueShift = 0; // 0-359
FLOAT gfx_fSaturation = 1.0f; // 0.0f = min, 1.0f = default
// the following vars can be influenced by corresponding gfx_ vars
INDEX tex_iHueShift = 0; // added to gfx_
FLOAT tex_fSaturation = 1.0f; // multiplied by gfx_
INDEX shd_iHueShift = 0; // added to gfx_
FLOAT shd_fSaturation = 1.0f; // multiplied by gfx_
// gamma table control
FLOAT gfx_fBrightness = 0.0f; // -0.9 - 0.9
FLOAT gfx_fContrast = 1.0f; // 0.1 - 1.9
FLOAT gfx_fGamma = 1.0f; // 0.1 - 9.0
FLOAT gfx_fBiasR = 1.0f; // 0.0 - 1.0
FLOAT gfx_fBiasG = 1.0f; // 0.0 - 1.0
FLOAT gfx_fBiasB = 1.0f; // 0.0 - 1.0
INDEX gfx_iLevels = 256; // 2 - 256
// stereo rendering control
INDEX gfx_iStereo = 0; // 0=off, 1=red/cyan
INDEX gfx_bStereoInvert = FALSE; // is left eye RED or CYAN
INDEX gfx_iStereoOffset = 10; // view offset (or something:)
FLOAT gfx_fStereoSeparation = 0.25f; // distance between eyes
// cached integers for faster calculation
SLONG _slTexSaturation = 256; // 0 = min, 256 = default
SLONG _slTexHueShift = 0;
SLONG _slShdSaturation = 256;
SLONG _slShdHueShift = 0;
// 'supported' console variable flags
static INDEX sys_bHasTextureCompression = 0;
static INDEX sys_bHasTextureAnisotropy = 0;
static INDEX sys_bHasAdjustableGamma = 0;
static INDEX sys_bHasTextureLODBias = 0;
static INDEX sys_bHasMultitexturing = 0;
static INDEX sys_bHas32bitTextures = 0;
static INDEX sys_bHasSwapInterval = 0;
static INDEX sys_bHasHardwareTnL = 1;
static INDEX sys_bHasTruform = 0;
static INDEX sys_bHasCVAs = 0;
static INDEX sys_bUsingOpenGL = 0;
INDEX sys_bUsingDirect3D = 0;
/*
* Low level hook flags
*/
#define WH_KEYBOARD_LL 13
#ifdef PLATFORM_WIN32
void EnableWindowsKeys(void);
#pragma message(">> doublecheck me!!!")
// these are commented because they are already defined in winuser.h
//#define LLKHF_EXTENDED 0x00000001
//#define LLKHF_INJECTED 0x00000010
//#define LLKHF_ALTDOWN 0x00000020
//#define LLKHF_UP 0x00000080
//#define LLMHF_INJECTED 0x00000001
/*
* Structure used by WH_KEYBOARD_LL
*/
// this is commented because there's a variant for this struct in winuser.h
/*typedef struct tagKBDLLHOOKSTRUCT {
DWORD vkCode;
DWORD scanCode;
DWORD flags;
DWORD time;
DWORD dwExtraInfo;
} KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;*/
static HHOOK _hLLKeyHook = NULL;
LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LPARAM lParam)
{
// By returning a non-zero value from the hook procedure, the
// message does not get passed to the target window
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *) lParam;
BOOL bControlKeyDown = 0;
switch (nCode)
{
case HC_ACTION:
{
// Check to see if the CTRL key is pressed
bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);
// Disable CTRL+ESC
if (pkbhs->vkCode == VK_ESCAPE && bControlKeyDown)
return 1;
// Disable ALT+TAB
if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN)
return 1;
// Disable ALT+ESC
if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN)
return 1;
break;
}
default:
break;
}
return CallNextHookEx (_hLLKeyHook, nCode, wParam, lParam);
}
void DisableWindowsKeys(void)
{
//if( _hLLKeyHook!=NULL) UnhookWindowsHookEx(_hLLKeyHook);
//_hLLKeyHook = SetWindowsHookEx(WH_KEYBOARD_LL, &LowLevelKeyboardProc, NULL, GetCurrentThreadId());
INDEX iDummy;
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, &iDummy, 0);
}
void EnableWindowsKeys(void)
{
INDEX iDummy;
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, FALSE, &iDummy, 0);
// if( _hLLKeyHook!=NULL) UnhookWindowsHookEx(_hLLKeyHook);
}
#else
#define DisableWindowsKeys()
#define EnableWindowsKeys()
#endif
// texture size reporting
static CTString ReportQuality( INDEX iQuality)
{
if( iQuality==0) return "optimal";
if( iQuality==1) return "16-bit";
if( iQuality==2) return "32-bit";
if( iQuality==3) return "compressed";
ASSERTALWAYS( "Invalid texture quality.");
return "?";
}
static void TexturesInfo(void)
{
UpdateTextureSettings();
INDEX ctNo04O=0, ctNo64O=0, ctNoMXO=0;
PIX pixK04O=0, pixK64O=0, pixKMXO=0;
SLONG slKB04O=0, slKB64O=0, slKBMXO=0;
INDEX ctNo04A=0, ctNo64A=0, ctNoMXA=0;
PIX pixK04A=0, pixK64A=0, pixKMXA=0;
SLONG slKB04A=0, slKB64A=0, slKBMXA=0;
// walk thru all textures on stock
{FOREACHINDYNAMICCONTAINER( _pTextureStock->st_ctObjects, CTextureData, ittd)
{ // get texture info
CTextureData &td = *ittd;
BOOL bAlpha = td.td_ulFlags&TEX_ALPHACHANNEL;
INDEX ctFrames = td.td_ctFrames;
SLONG slBytes = td.GetUsedMemory();
ASSERT( slBytes>=0);
// get texture size
PIX pixTextureSize = td.GetPixWidth() * td.GetPixHeight();
PIX pixMipmapSize = pixTextureSize;
if( !gap_bAllowSingleMipmap || td.td_ctFineMipLevels>1) pixMipmapSize = pixMipmapSize *4/3;
// increase corresponding counters
if( pixTextureSize<4096) {
if( bAlpha) { pixK04A+=pixMipmapSize; slKB04A+=slBytes; ctNo04A+=ctFrames; }
else { pixK04O+=pixMipmapSize; slKB04O+=slBytes; ctNo04O+=ctFrames; }
} else if( pixTextureSize<=65536) {
if( bAlpha) { pixK64A+=pixMipmapSize; slKB64A+=slBytes; ctNo64A+=ctFrames; }
else { pixK64O+=pixMipmapSize; slKB64O+=slBytes; ctNo64O+=ctFrames; }
} else {
if( bAlpha) { pixKMXA+=pixMipmapSize; slKBMXA+=slBytes; ctNoMXA+=ctFrames; }
else { pixKMXO+=pixMipmapSize; slKBMXO+=slBytes; ctNoMXO+=ctFrames; }
}
}}
// report
const PIX pixNormDim = (PIX) (sqrt(TS.ts_pixNormSize));
const PIX pixAnimDim = (PIX) (sqrt(TS.ts_pixAnimSize));
const PIX pixEffDim = 1L<<tex_iEffectSize;
CTString strTmp;
strTmp = tex_bFineEffect ? "32-bit" : "16-bit";
CPrintF( "\n");
CPrintF( "Normal-opaque textures quality: %s\n", (const char *) ReportQuality(TS.ts_iNormQualityO));
CPrintF( "Normal-translucent textures quality: %s\n", (const char *) ReportQuality(TS.ts_iNormQualityA));
CPrintF( "Animation-opaque textures quality: %s\n", (const char *) ReportQuality(TS.ts_iAnimQualityO));
CPrintF( "Animation-translucent textures quality: %s\n", (const char *) ReportQuality(TS.ts_iAnimQualityA));
CPrintF( "Effect textures quality: %s\n", (const char *) strTmp);
CPrintF( "\n");
CPrintF( "Max allowed normal texture area size: %3dx%d\n", pixNormDim, pixNormDim);
CPrintF( "Max allowed animation texture area size: %3dx%d\n", pixAnimDim, pixAnimDim);
CPrintF( "Max allowed effect texture area size: %3dx%d\n", pixEffDim, pixEffDim);
CPrintF( "\n");
CPrintF( "Opaque textures memory usage:\n");
CPrintF( " <64 pix: %3d frames use %6.1f Kpix in %5d KB\n", ctNo04O, pixK04O/1024.0f, slKB04O/1024);
CPrintF( " 64-256 pix: %3d frames use %6.1f Kpix in %5d KB\n", ctNo64O, pixK64O/1024.0f, slKB64O/1024);
CPrintF( " >256 pix: %3d frames use %6.1f Kpix in %5d KB\n", ctNoMXO, pixKMXO/1024.0f, slKBMXO/1024);
CPrintF( "Translucent textures memory usage:\n");
CPrintF( " <64 pix: %3d frames use %6.1f Kpix in %5d KB\n", ctNo04A, pixK04A/1024.0f, slKB04A/1024);
CPrintF( " 64-256 pix: %3d frames use %6.1f Kpix in %5d KB\n", ctNo64A, pixK64A/1024.0f, slKB64A/1024);
CPrintF( " >256 pix: %3d frames use %6.1f Kpix in %5d KB\n", ctNoMXA, pixKMXA/1024.0f, slKBMXA/1024);
CPrintF("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n");
}
// reformat an extensions string to cross multiple lines
extern CTString ReformatExtensionsString( CTString strUnformatted)
{
CTString strTmp, strDst = "\n";
char *pcSrc = (char*)(const char*)strUnformatted;
FOREVER {
char *pcSpace = strchr( pcSrc, ' ');
if( pcSpace==NULL) break;
*pcSpace = 0;
strTmp.PrintF( " %s\n", pcSrc);
strDst += strTmp;
*pcSpace = ' ';
pcSrc = pcSpace +1;
}
if(strDst=="\n") {
strDst = "none\n";
}
// done
return strDst;
}
// printout extensive OpenGL/Direct3D info to console
static void GAPInfo(void)
{
// check API
const GfxAPIType eAPI = _pGfx->gl_eCurrentAPI;
CPrintF( "\n");
ASSERT( GfxValidApi(eAPI) );
// in case of driver hasn't been initialized yet
if( (_pGfx->go_hglRC==NULL
#ifdef SE1_D3D
&& _pGfx->gl_pd3dDevice==NULL
#endif // SE1_D3D
) || eAPI==GAT_NONE) {
// be brief, be quick
CPrintF( TRANS("Display driver hasn't been initialized.\n\n"));
return;
}
// report API
CPrintF( "- Graphics API: ");
if( eAPI==GAT_OGL) CPrintF( "OpenGL\n");
else CPrintF( "Direct3D\n");
// and number of adapters
CPrintF( "- Adapters found: %d\n", _pGfx->gl_gaAPI[eAPI].ga_ctAdapters);
CPrintF( "\n");
// report renderer
CDisplayAdapter &da = _pGfx->gl_gaAPI[eAPI].ga_adaAdapter[_pGfx->gl_iCurrentAdapter];
if( eAPI==GAT_OGL) CPrintF( "- Vendor: %s\n", (const char *) da.da_strVendor);
CPrintF( "- Renderer: %s\n", (const char *) da.da_strRenderer);
CPrintF( "- Version: %s\n", (const char *) da.da_strVersion);
CPrintF( "\n");
// Z-buffer depth
CPrintF( "- Z-buffer precision: ");
if( _pGfx->gl_iCurrentDepth==0) CPrintF( "default\n");
else CPrintF( "%d bits\n", _pGfx->gl_iCurrentDepth);
// 32-bit textures
CPrintF( "- 32-bit textures: ");
if( _pGfx->gl_ulFlags & GLF_32BITTEXTURES) CPrintF( "supported\n");
else CPrintF( "not supported\n");
// grayscale textures
CPrintF( "- Grayscale textures: ");
if( gap_bAllowGrayTextures) CPrintF( "allowed\n");
else CPrintF( "not allowed\n");
// report maximum texture dimension
CPrintF( "- Max texture dimension: %d pixels\n", _pGfx->gl_pixMaxTextureDimension);
// report multitexturing capabilities
CPrintF( "- Multi-texturing: ");
if( _pGfx->gl_ctRealTextureUnits<2) CPrintF( "not supported\n");
else {
if( gap_iUseTextureUnits>1) CPrintF( "enabled (using %d texture units)\n", gap_iUseTextureUnits);
else CPrintF( "disabled\n");
CPrintF( "- Texture units: %d", _pGfx->gl_ctRealTextureUnits);
if( _pGfx->gl_ctTextureUnits < _pGfx->gl_ctRealTextureUnits) {
CPrintF(" (%d can be used)\n", _pGfx->gl_ctTextureUnits);
} else CPrintF("\n");
}
// report texture anisotropy degree
if( _pGfx->gl_iMaxTextureAnisotropy>=2) {
CPrintF( "- Texture anisotropy: %d of %d\n", _tpGlobal[0].tp_iAnisotropy, _pGfx->gl_iMaxTextureAnisotropy);
} else CPrintF( "- Anisotropic texture filtering: not supported\n");
// report texture LOD bias range
const FLOAT fMaxLODBias = _pGfx->gl_fMaxTextureLODBias;
if( fMaxLODBias>0) {
CPrintF( "- Texture LOD bias: %.1f of +/-%.1f\n", _pGfx->gl_fTextureLODBias, fMaxLODBias);
} else CPrintF( "- Texture LOD biasing: not supported\n");
// OpenGL only stuff ...
if( eAPI==GAT_OGL)
{
// report truform tessellation
CPrintF( "- Truform tessellation: ");
if( _pGfx->gl_iMaxTessellationLevel>0) {
if( _pGfx->gl_iTessellationLevel>0) {
CPrintF( "enabled ");
if( gap_bForceTruform) CPrintF( "(for all models)\n");
else CPrintF( "(only for Truform-ready models)\n");
CTString strNormalMode = ogl_bTruformLinearNormals ? "linear" : "quadratic";
CPrintF( "- Tesselation level: %d of %d (%s normals)\n", _pGfx->gl_iTessellationLevel, _pGfx->gl_iMaxTessellationLevel, (const char *) strNormalMode);
} else CPrintF( "disabled\n");
} else CPrintF( "not supported\n");
// report current swap interval (only if fullscreen)
STUBBED("Swap interval shouldn't just be for fullscreen"); // !!! FIXME --ryan.
if( _pGfx->gl_ulFlags&GLF_FULLSCREEN) {
// report current swap interval
STUBBED("I don't think the non-D3D path sets GLF_VSYNC anywhere. Mismerge?"); // !!! FIXME --ryan.
CPrintF( "- Swap interval: ");
if( _pGfx->gl_ulFlags&GLF_VSYNC) {
#if PLATFORM_WIN32
const int gliWaits = (int) pwglGetSwapIntervalEXT();
if( gliWaits>=0) {
ASSERT( gliWaits==_pGfx->gl_iSwapInterval);
CPrintF( "%d frame(s)\n", gliWaits);
} else CPrintF( "not readable\n");
#else
const int gliWaits = SDL_GL_GetSwapInterval();
if( gliWaits>=0) {
ASSERT( gliWaits==_pGfx->gl_iSwapInterval);
CPrintF( "%d frame(s)\n", gliWaits);
} else CPrintF( "adaptive vsync\n");
#endif
} else CPrintF( "not adjustable\n");
}
// report T-Buffer support
if( _pGfx->gl_ulFlags & GLF_EXT_TBUFFER) {
CPrintF( "- T-Buffer effect: ");
if( _pGfx->go_ctSampleBuffers==0) CPrintF( "disabled\n");
else {
ogl_iTBufferEffect = Clamp( ogl_iTBufferEffect, 0, 2);
CTString strEffect = "Partial anti-aliasing";
if( ogl_iTBufferEffect<1) strEffect = "none";
if( ogl_iTBufferEffect>1) strEffect = "Motion blur";
CPrintF( "%s (%d buffers used)\n", (const char *) strEffect, _pGfx->go_ctSampleBuffers);
}
}
// compiled vertex arrays support
CPrintF( "- Compiled Vertex Arrays: ");
if( _pGfx->gl_ulFlags & GLF_EXT_COMPILEDVERTEXARRAY) {
extern BOOL CVA_b2D;
extern BOOL CVA_bWorld;
extern BOOL CVA_bModels;
if( ogl_bUseCompiledVertexArrays) {
CTString strSep="";
CPrintF( "enabled (for ");
if( CVA_bWorld) { CPrintF( "world"); strSep="/"; }
if( CVA_bModels) { CPrintF( "%smodels", (const char *) strSep); strSep="/"; }
if( CVA_b2D) { CPrintF( "%sparticles", (const char *) strSep); }
CPrintF( ")\n");
} else CPrintF( "disabled\n");
} else CPrintF( "not supported\n");
// report texture compression type
CPrintF( "- Supported texture compression system(s): ");
if( !(_pGfx->gl_ulFlags&GLF_TEXTURECOMPRESSION)) CPrintF( "none\n");
else {
CTString strSep="";
if( _pGfx->gl_ulFlags & GLF_EXTC_ARB) { CPrintF( "ARB"); strSep=", "; }
if( _pGfx->gl_ulFlags & GLF_EXTC_S3TC) { CPrintF( "%sS3TC", (const char *) strSep); strSep=", "; }
if( _pGfx->gl_ulFlags & GLF_EXTC_FXT1) { CPrintF( "%sFTX1", (const char *) strSep); strSep=", "; }
if( _pGfx->gl_ulFlags & GLF_EXTC_LEGACY) { CPrintF( "%sold S3TC", (const char *) strSep); }
CPrintF( "\n- Current texture compression system: ");
switch( ogl_iTextureCompressionType) {
case 0: CPrintF( "none\n"); break;
case 1: CPrintF( "ARB wrapper\n"); break;
case 2: CPrintF( "S3TC\n"); break;
case 3: CPrintF( "FXT1\n"); break;
default: CPrintF( "old S3TC\n"); break;
}
}
/* if exist, report vertex array range extension usage
if( ulExt & GOEXT_VERTEXARRAYRANGE) {
extern BOOL VB_bSetupFailed;
extern SLONG VB_slVertexBufferSize;
extern INDEX VB_iVertexBufferType;
extern INDEX ogl_iVertexBuffers;
if( VB_bSetupFailed) { // didn't manage to setup vertex buffers
CPrintF( "- Enhanced HW T&L: fail\n");
} else if( VB_iVertexBufferType==0) { // not used
CPrintF( "- Enhanced HW T&L: disabled\n");
} else { // works! :)
CTString strBufferType("AGP");
if( VB_iVertexBufferType==2) strBufferType = "video";
const SLONG slMemSize = VB_slVertexBufferSize/1024;
CPrintF( "- Enhanced hardware T&L: %d buffers in %d KB of %s memory",
ogl_iVertexBuffers, slMemSize, strBufferType);
}
} */
// report OpenGL externsions
CPrintF("\n");
CPrintF("- Published extensions: %s", (const char *) ReformatExtensionsString(_pGfx->go_strExtensions));
if( _pGfx->go_strWinExtensions != "") CPrintF("%s", (const char *) ReformatExtensionsString(_pGfx->go_strWinExtensions));
CPrintF("\n- Supported extensions: %s\n", (const char *) ReformatExtensionsString(_pGfx->go_strSupportedExtensions));
}
#ifdef SE1_D3D
// Direct3D only stuff
if( eAPI==GAT_D3D)
{
// HW T&L
CPrintF( "- Hardware T&L: ");
if( _pGfx->gl_ulFlags&GLF_D3D_HASHWTNL) {
if( _pGfx->gl_ctMaxStreams<GFX_MINSTREAMS) CPrintF( "cannot be used\n");
else if( _pGfx->gl_ulFlags&GLF_D3D_USINGHWTNL) CPrintF( "enabled (%d streams)\n", _pGfx->gl_ctMaxStreams);
else CPrintF( "disabled\n");
} else CPrintF( "not present\n");
// report vtx/idx buffers size
extern SLONG SizeFromVertices_D3D( INDEX ctVertices);
const SLONG slMemoryUsed = SizeFromVertices_D3D(_pGfx->gl_ctVertices);
CPrintF( "- Vertex buffer size: %.1f KB (%d vertices)\n", slMemoryUsed/1024.0f, _pGfx->gl_ctVertices);
// N-Patches tessellation (Truform)
CPrintF( "- N-Patches: ");
if( _pGfx->gl_iMaxTessellationLevel>0) {
if( !(_pGfx->gl_ulFlags&GLF_D3D_USINGHWTNL)) CPrintF( "not possible with SW T&L\n");
else if( _pGfx->gl_iTessellationLevel>0) {
CPrintF( "enabled ");
if( gap_bForceTruform) CPrintF( "(for all models)\n");
else CPrintF( "(only for Truform-ready models)\n");
CPrintF( "- Tesselation level: %d of %d\n", _pGfx->gl_iTessellationLevel, _pGfx->gl_iMaxTessellationLevel);
} else CPrintF( "disabled\n");
} else CPrintF( "not supported\n");
// texture compression
CPrintF( "- Texture compression: ");
if( _pGfx->gl_ulFlags&GLF_TEXTURECOMPRESSION) CPrintF( "supported\n");
else CPrintF( "not supported\n");
// custom clip plane support
CPrintF( "- Custom clip plane: ");
if( _pGfx->gl_ulFlags&GLF_D3D_CLIPPLANE) CPrintF( "supported\n");
else CPrintF( "not supported\n");
// color buffer writes enable/disable support
CPrintF( "- Color masking: ");
if( _pGfx->gl_ulFlags&GLF_D3D_COLORWRITES) CPrintF( "supported\n");
else CPrintF( "not supported\n");
// depth (Z) bias support
CPrintF( "- Depth biasing: ");
if( _pGfx->gl_ulFlags&GLF_D3D_ZBIAS) CPrintF( "supported\n");
else CPrintF( "not supported\n");
// current swap interval (only if fullscreen)
if( _pGfx->gl_ulFlags&GLF_FULLSCREEN) {
CPrintF( "- Swap interval: ");
if( _pGfx->gl_ulFlags&GLF_VSYNC) {
CPrintF( "%d frame(s)\n", _pGfx->gl_iSwapInterval);
} else CPrintF( "not adjustable\n");
}
}
#endif // SE1_D3D
}
// update console system vars
extern void UpdateGfxSysCVars(void)
{
sys_bHasTextureCompression = 0;
sys_bHasTextureAnisotropy = 0;
sys_bHasAdjustableGamma = 0;
sys_bHasTextureLODBias = 0;
sys_bHasMultitexturing = 0;
sys_bHas32bitTextures = 0;
sys_bHasSwapInterval = 0;
sys_bHasHardwareTnL = 1;
sys_bHasTruform = 0;
sys_bHasCVAs = 1;
sys_bUsingOpenGL = 0;
sys_bUsingDirect3D = 0;
if( _pGfx->gl_iMaxTextureAnisotropy>1) sys_bHasTextureAnisotropy = 1;
if( _pGfx->gl_fMaxTextureLODBias>0) sys_bHasTextureLODBias = 1;
if( _pGfx->gl_ctTextureUnits>1) sys_bHasMultitexturing = 1;
if( _pGfx->gl_iMaxTessellationLevel>0) sys_bHasTruform = 1;
if( _pGfx->gl_ulFlags & GLF_TEXTURECOMPRESSION) sys_bHasTextureCompression = 1;
if( _pGfx->gl_ulFlags & GLF_ADJUSTABLEGAMMA) sys_bHasAdjustableGamma = 1;
if( _pGfx->gl_ulFlags & GLF_32BITTEXTURES) sys_bHas32bitTextures = 1;
if( _pGfx->gl_ulFlags & GLF_VSYNC) sys_bHasSwapInterval = 1;
if( _pGfx->gl_eCurrentAPI==GAT_OGL && !(_pGfx->gl_ulFlags&GLF_EXT_COMPILEDVERTEXARRAY)) sys_bHasCVAs = 0;
#ifdef SE1_D3D
if( _pGfx->gl_eCurrentAPI==GAT_D3D && !(_pGfx->gl_ulFlags&GLF_D3D_HASHWTNL)) sys_bHasHardwareTnL = 0;
#endif // SE1_D3D
if( _pGfx->gl_eCurrentAPI==GAT_OGL) sys_bUsingOpenGL = 1;
#ifdef SE1_D3D
if( _pGfx->gl_eCurrentAPI==GAT_D3D) sys_bUsingDirect3D = 1;
#endif // SE1_D3D
}
// determine whether texture or shadowmap needs probing
extern BOOL ProbeMode( CTimerValue tvLast)
{
// probing off ?
if( !_pGfx->gl_bAllowProbing) return FALSE;
if( gfx_tmProbeDecay<1) {
gfx_tmProbeDecay = 0;
return FALSE;
}
// clamp and determine probe mode
if( gfx_tmProbeDecay>999) gfx_tmProbeDecay = 999;
CTimerValue tvNow = _pTimer->GetLowPrecisionTimer();
const TIME tmDelta = (tvNow-tvLast).GetSeconds();
if( tmDelta>gfx_tmProbeDecay) return TRUE;
return FALSE;
}
// uncache all cached shadow maps
extern void UncacheShadows(void)
{
// mute all sounds
if(_pSound != NULL) _pSound->Mute();
// prepare new saturation factors for shadowmaps
gfx_fSaturation = ClampDn( gfx_fSaturation, 0.0f);
shd_fSaturation = ClampDn( shd_fSaturation, 0.0f);
gfx_iHueShift = Clamp( gfx_iHueShift, 0, 359);
shd_iHueShift = Clamp( shd_iHueShift, 0, 359);
_slShdSaturation = (SLONG)( gfx_fSaturation*shd_fSaturation*256.0f);
_slShdHueShift = Clamp( (gfx_iHueShift+shd_iHueShift)*255/359, 0, 255);
CListHead &lhOriginal = _pGfx->gl_lhCachedShadows;
// while there is some shadow in main list
while( !lhOriginal.IsEmpty()) {
CShadowMap &sm = *LIST_HEAD( lhOriginal, CShadowMap, sm_lnInGfx);
sm.Uncache();
}
// mark that we need pretouching
_bNeedPretouch = TRUE;
}
// refresh (uncache and eventually cache) all cached shadow maps
extern void CacheShadows(void);
static void RecacheShadows(void)
{
// mute all sounds
_pSound->Mute();
UncacheShadows();
if( shd_bCacheAll) CacheShadows();
else CPrintF( TRANS("All shadows uncached.\n"));
}
// reload all textures that were loaded
extern void ReloadTextures(void)
{
// mute all sounds
_pSound->Mute();
// prepare new saturation factors for textures
gfx_fSaturation = ClampDn( gfx_fSaturation, 0.0f);
tex_fSaturation = ClampDn( tex_fSaturation, 0.0f);
gfx_iHueShift = Clamp( gfx_iHueShift, 0, 359);
tex_iHueShift = Clamp( tex_iHueShift, 0, 359);
_slTexSaturation = (SLONG)( gfx_fSaturation*tex_fSaturation*256.0f);
_slTexHueShift = Clamp( (gfx_iHueShift+tex_iHueShift)*255/359, 0, 255);
// update texture settings
UpdateTextureSettings();
// loop thru texture stock
{FOREACHINDYNAMICCONTAINER( _pTextureStock->st_ctObjects, CTextureData, ittd) {
CTextureData &td = *ittd;
td.Reload();
td.td_tpLocal.Clear();
}}
// reset fog/haze texture
_fog_pixSizeH = 0;
_fog_pixSizeL = 0;
_haze_pixSize = 0;
// reinit flat texture
ASSERT( _ptdFlat!=NULL);
_ptdFlat->td_tpLocal.Clear();
_ptdFlat->Unbind();
_ptdFlat->td_ulFlags = TEX_ALPHACHANNEL | TEX_32BIT | TEX_STATIC;
_ptdFlat->td_mexWidth = 1;
_ptdFlat->td_mexHeight = 1;
_ptdFlat->td_iFirstMipLevel = 0;
_ptdFlat->td_ctFineMipLevels = 1;
_ptdFlat->td_slFrameSize = 1*1* BYTES_PER_TEXEL;
_ptdFlat->td_ctFrames = 1;
_ptdFlat->td_ulInternalFormat = TS.ts_tfRGBA8;
_ptdFlat->td_pulFrames = &_ulWhite;
_ptdFlat->SetAsCurrent();
/*
// reset are renderable textures, too
CListHead &lhOriginal = _pGfx->gl_lhRenderTextures;
while( !lhOriginal.IsEmpty()) {
CRenderTexture &rt = *LIST_HEAD( lhOriginal, CRenderTexture, rt_lnInGfx);
rt.Reset();
}
*/
// mark that we need pretouching
_bNeedPretouch = TRUE;
CPrintF( TRANS("All textures reloaded.\n"));
}
// refreshes all textures and shadow maps
static void RefreshTextures(void)
{
// refresh
ReloadTextures();
RecacheShadows();
}
// reload all models that were loaded
static void ReloadModels(void)
{
// mute all sounds
_pSound->Mute();
// loop thru model stock
{FOREACHINDYNAMICCONTAINER( _pModelStock->st_ctObjects, CModelData, itmd) {
CModelData &md = *itmd;
md.Reload();
}}
// mark that we need pretouching
_bNeedPretouch = TRUE;
// all done
CPrintF( TRANS("All models reloaded.\n"));
}
// variable change post functions
static BOOL _bLastModelQuality = -1;
static void MdlPostFunc(void *pvVar)
{
mdl_bFineQuality = Clamp( mdl_bFineQuality, 0, 1);
if( _bLastModelQuality!=mdl_bFineQuality) {
_bLastModelQuality = mdl_bFineQuality;
ReloadModels();
}
}
/*
* GfxLibrary functions
*/
static void PrepareTables(void)
{
INDEX i;
// prepare array for fast clamping to 0..255
for( i=-256*2; i<256*4; i++) aubClipByte[i+256*2] = (UBYTE)Clamp( i, 0, 255);
// prepare fast sqrt tables
for( i=0; i<SQRTTABLESIZE; i++) aubSqrt[i] = (UBYTE)(sqrt((FLOAT)(i*65536/SQRTTABLESIZE)));
for( i=1; i<SQRTTABLESIZE; i++) auw1oSqrt[i] = (UWORD)(sqrt((FLOAT)(SQRTTABLESIZE-1)/i)*255.0f);
auw1oSqrt[0] = MAX_UWORD;
// prepare fast sin/cos table
for( i=-256; i<256+64; i++) afSinTable[i+256] = Sin((i-128)/256.0f*360.0f);
// prepare gouraud conversion table
for( INDEX h=0; h<128; h++) {
for( INDEX p=0; p<128; p++) {
const FLOAT fSinH = pfSinTable[h*2];
const FLOAT fSinP = pfSinTable[p*2];
const FLOAT fCosH = pfCosTable[h*2];
const FLOAT fCosP = pfCosTable[p*2];
const FLOAT3D v( -fSinH*fCosP, +fSinP, -fCosH*fCosP);
aubGouraudConv[h*128+p] = (UBYTE)GouraudNormal(v);
}
}
// !!! FIXME: rcg01082002
// You can't count on these arrays to be identical on every system, due to
// floating point unit differences. This includes Linux and win32 on the
// x86 platform, and win32 debug builds vs. win32 release builds. Hell, I
// wouldn't be surprised if they gave different values between AMD and Intel
// processors. The tables generate identically between a win32 release and
// Linux release build at this point...except the Gouraud table, which has
// several minor variances. I recommend you get a table you like, use the
// below code to dump it to disk, and then make it a static array that you
// never need to calculate at runtime in the first place. Then you can remove
// this code and this godawful long comment. :)
#if 0
FILE *feh;
feh = fopen("aubClipByte.bin", "wb");
fwrite(aubClipByte, sizeof (aubClipByte), 1, feh);
fclose(feh);
feh = fopen("aubSqrt.bin", "wb");
fwrite(aubSqrt, sizeof (aubSqrt), 1, feh);
fclose(feh);
feh = fopen("auw1oSqrt.bin", "wb");
fwrite(auw1oSqrt, sizeof (auw1oSqrt), 1, feh);
fclose(feh);
feh = fopen("afSinTable.bin", "wb");
fwrite(afSinTable, sizeof (afSinTable), 1, feh);
fclose(feh);
feh = fopen("aubGouraudConv.bin", "wb");
fwrite(aubGouraudConv, sizeof (aubGouraudConv), 1, feh);
fclose(feh);
printf("w00t.\n");
exit(0);
#endif