-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomUI.cpp
1455 lines (1204 loc) · 44.5 KB
/
CustomUI.cpp
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
//--------------------------------------------------------------------------------------
// File: CustomUI.cpp
//
// Sample to show usage of DXUT's GUI system
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "DXUT.h"
#include "DXUTgui.h"
#include "DXUTguiIME.h"
#include "DXUTcamera.h"
#include "DXUTsettingsdlg.h"
#include "SDKmesh.h"
#include "SDKmisc.h"
#include "resource.h"
#include <xaudio2.h>
#include <math.h>
#include <xmmintrin.h>
#include <emmintrin.h>
#include "common.h"
#include "cloth.h"
#include "vmath.h"
//#define DEBUG_VS // Uncomment this line to debug vertex shaders
//#define DEBUG_PS // Uncomment this line to debug pixel shaders
//#define DBUG_EDIT_BOX
//--------------------------------------------------------------------------------------
// Forward declarations
//--------------------------------------------------------------------------------------
bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed,
void* pUserContext );
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext );
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
void* pUserContext );
HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
void* pUserContext );
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext );
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext );
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,
void* pUserContext );
void CALLBACK KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext );
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext );
void CALLBACK OnLostDevice( void* pUserContext );
void CALLBACK OnDestroyDevice( void* pUserContext );
void InitApp();
void RenderText();
void UpdateStats(double totalTime);
//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
ID3DXFont* g_pFont = NULL; // Font for drawing text
ID3DXSprite* g_pTextSprite = NULL; // Sprite for batching draw text calls
ID3DXEffect* g_pEffect = NULL; // D3DX effect interface
CDXUTXFileMesh g_Mesh; // Background mesh
D3DXMATRIXA16 g_mView;
CModelViewerCamera g_Camera; // A model viewing camera
CDXUTDialogResourceManager g_DialogResourceManager; // manager for shared resources of dialogs
CD3DSettingsDlg g_SettingsDlg; // Device settings dialog
CDXUTDialog g_HUD; // dialog for standard controls
CDXUTDialog g_SampleUI; // dialog for sample specific controls
//--------------------------------------------------------------------------------------
// UI control IDs
//--------------------------------------------------------------------------------------
#define IDC_TOGGLEFULLSCREEN (100)
#define IDC_TOGGLEREF (101)
#define IDC_CHANGEDEVICE (102)
#define IDC_AUDIODEMO (103)
#define IDC_CLOTHDEMO (104)
#define IDC_RESET_STATS (105)
#define IDC_TOOGLE_LOOP_LIBS (106)
#define IDC_OUTPUT_CALC_STATS (200)
#define IDC_OUTPUT_CALC_REPS (201)
#define IDC_OUTPUT_BAYARD_TITLE (250)
#define IDC_OUTPUT_AVG_STATS_VMATH (300)
#define IDC_OUTPUT_AVG_STATS_XNAMATH (301)
#define IDC_OUTPUT_AVG_STATS_VCLASS (302)
#define IDC_OUTPUT_AVG_STATS_VCLASS_TYPEDEF (303)
#define IDC_OUTPUT_AVG_STATS_VCLASS_SIMDTYPE (304)
#define IDC_EDITBOX_DBUG (400)
#define IDC_RADIO_VMATH (500)
#define IDC_RADIO_XNAMATH (501)
#define IDC_RADIO_VCLASS (502)
#define IDC_RADIO_VCLASS_TYPEDEF (503)
#define IDC_RADIO_VCLASS_SIMDTYPE (504)
#define IDC_SLIDER_CH1_LOW (600)
#define IDC_SLIDER_CH1_MID (601)
#define IDC_SLIDER_CH1_HIGH (602)
#define IDC_SLIDER_CH2_LOW (603)
#define IDC_SLIDER_CH2_MID (604)
#define IDC_SLIDER_CH2_HIGH (605)
#define IDC_SLIDER_CH3_LOW (606)
#define IDC_SLIDER_CH3_MID (607)
#define IDC_SLIDER_CH3_HIGH (608)
#define IDC_SLIDER_CH4_LOW (609)
#define IDC_SLIDER_CH4_MID (610)
#define IDC_SLIDER_CH4_HIGH (611)
#define IDC_STATIC_CH_MIN (612)
#define IDC_STATIC_CH_MAX (IDC_STATIC_CH_MIN + g_audioSliderIdSize - 1)
#define IDC_PLAY_BTN (700)
#define IDC_PAUSE_BTN (701)
#define IDC_SLIDER_MATH_REPS (800)
#define IDC_SLIDER_CLOTH_ROT (900)
#define IDC_SLIDER_CLOTH_TRANS (901)
#define IDC_SLIDER_CLOTH_GRAVITY (902)
#define IDC_STATIC_CLOTH_MIN (903)
#define IDC_STATIC_CLOTH_MAX (IDC_STATIC_CLOTH_MIN + g_clothSliderIdSize - 1)
//--------------------------------------------------------------------------------------
// Global hacks
//--------------------------------------------------------------------------------------
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices
const unsigned int g_audioSliderId[] =
{
IDC_SLIDER_CH1_LOW,
IDC_SLIDER_CH1_MID,
IDC_SLIDER_CH1_HIGH,
IDC_SLIDER_CH2_LOW,
IDC_SLIDER_CH2_MID,
IDC_SLIDER_CH2_HIGH,
IDC_SLIDER_CH3_LOW,
IDC_SLIDER_CH3_MID,
IDC_SLIDER_CH3_HIGH,
IDC_SLIDER_CH4_LOW,
IDC_SLIDER_CH4_MID,
IDC_SLIDER_CH4_HIGH,
};
const unsigned int g_audioSliderIdSize = sizeof(g_audioSliderId)/sizeof(const unsigned int);
const unsigned int g_clothSliderId[] =
{
IDC_SLIDER_CLOTH_ROT,
IDC_SLIDER_CLOTH_TRANS,
IDC_SLIDER_CLOTH_GRAVITY,
};
const unsigned int g_clothSliderIdSize = sizeof(g_clothSliderId)/sizeof(const unsigned int);
const int cSliderX0 = 10;
const int cSliderY0 = 50;
const int cSliderWidth = 300;
const int cSliderHeight = 16;
LPCWSTR g_audioSliderText[] =
{
L"Bass Low",
L"Bass Mid",
L"Bass High",
L"Drums Low",
L"Drums Mid",
L"Drums High",
L"Guitar Low",
L"Guitar Mid",
L"Guitar High",
L"Trumpet Low",
L"Trumpet Mid",
L"Trumpet High",
};
LPCWSTR g_clothSliderText[] =
{
L"Rotation",
L"Translation",
L"Gravity",
};
//demo flags
//int g_demoType = DEMO_TYPE_CLOTH;
int g_demoType = DEMO_TYPE_AUDIO;
int g_libType = MATHLIB_TYPE_VMATH;
int g_libTypeLast = g_libType;
bool g_loopLibs = false;
//demo reps factors
float g_audioReps = 1;
float g_clothReps = 1.f/2.8f;
const int cAvgSize = 16;
double g_avgVMath[cAvgSize] = {0};
double g_avgVMathMin = 999999.f;
double g_avgXNAMath[cAvgSize] = {0};
double g_avgXNAMathMin = 999999.f;
double g_avgVClass[cAvgSize] = {0};
double g_avgVClassMin = 999999.f;
double g_avgVClassTypedef[cAvgSize] = {0};
double g_avgVClassTypedefMin = 999999.f;
double g_avgVClassSIMDType[cAvgSize] = {0};
double g_avgVClassSIMDTypeMin = 999999.f;
//--------------------------------------------------------------------------------------
// Entry point to the program. Initializes everything and goes into a message processing
// loop. Idle time is used to render the scene.
//--------------------------------------------------------------------------------------
INT WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
{
extern void TestDot(void);
extern void TestSine(void);
TestDot();
TestSine();
//more tests
{
using namespace VMATH;
Vec4 va = VLoad(1.f);
Vec4 vb = VLoad(2.f);
Vec4 vr;
VAddSlow(vr, va, vb);
printf("");
}
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
// DXUT will create and use the best device (either D3D9 or D3D10)
// that is available on the system depending on which D3D callbacks are set below
// Set DXUT callbacks
DXUTSetCallbackD3D9DeviceAcceptable( IsDeviceAcceptable );
DXUTSetCallbackD3D9DeviceCreated( OnCreateDevice );
DXUTSetCallbackD3D9DeviceReset( OnResetDevice );
DXUTSetCallbackD3D9FrameRender( OnFrameRender );
DXUTSetCallbackD3D9DeviceLost( OnLostDevice );
DXUTSetCallbackD3D9DeviceDestroyed( OnDestroyDevice );
DXUTSetCallbackMsgProc( MsgProc );
DXUTSetCallbackKeyboard( KeyboardProc );
DXUTSetCallbackFrameMove( OnFrameMove );
DXUTSetCallbackDeviceChanging( ModifyDeviceSettings );
DXUTSetCursorSettings( true, true );
InitApp();
InitXAudio2();
DXUTInit( true, true ); // Parse the command line and show msgboxes
DXUTSetHotkeyHandling( true, true, true );
DXUTCreateWindow( L"VMath Demo" );
DXUTCreateDevice( true, 640, 480 );
DXUTMainLoop();
return DXUTGetExitCode();
}
//--------------------------------------------------------------------------------------
// Helper Functions
//--------------------------------------------------------------------------------------
int GetCurrReps()
{
int reps;
float *currReps = NULL;
if( g_demoType == DEMO_TYPE_CLOTH)
{
currReps = &g_clothReps;
}
else if ( g_demoType == DEMO_TYPE_AUDIO)
{
currReps = &g_audioReps;
}
else
{
assert(false);
}
int sliderValue = g_SampleUI.GetSlider( IDC_SLIDER_MATH_REPS )->GetValue();
reps = (int)((float)sliderValue * (*currReps));
if (reps == 0)
{
//do at least one rep
reps = 1;
}
return(reps);
}
//--------------------------------------------------------------------------------------
// Helper Functions
//--------------------------------------------------------------------------------------
inline char* ConvertToASCII(LPCWSTR str)
{
static char ansi[1024];
int ii=0;
while(*str != 0)
{
ansi[ii++] = (char)*str;
str++;
}
ansi[ii] = 0x00;
return(ansi);
}
//--------------------------------------------------------------------------------------
// Helper Functions
//--------------------------------------------------------------------------------------
void ParseText(LPCWSTR str)
{
char* string1 = ConvertToASCII(str);
char seps[] = " ,\t\n";
char *token1,
*next_token1;
token1 = strtok_s( string1, seps, &next_token1);
int ii=0;
while (token1 != NULL)
{
// Get next token:
if (token1 != NULL)
{
g_intValues[ii] = (int)atoi( token1 );
g_floatValues[ii++] = (float)atof( token1 );
token1 = strtok_s( NULL, seps, &next_token1);
}
}
}
//--------------------------------------------------------------------------------------
// Turn on/off visiblity of demo controls
//--------------------------------------------------------------------------------------
void UpdateDemoUI()
{
bool audioVisible = false;
bool clothVisible = false;
if (g_demoType == DEMO_TYPE_AUDIO)
{
clothVisible = false;
audioVisible = true;
}
else if (g_demoType == DEMO_TYPE_CLOTH)
{
StopChannels();
clothVisible = true;
audioVisible = false;
}
//audio controls
for (int ii = 0; ii<g_audioSliderIdSize; ii++)
{
g_SampleUI.GetSlider( g_audioSliderId[ii] )->SetVisible(audioVisible);
int ID = IDC_STATIC_CH_MIN+ii;
g_SampleUI.GetStatic( ID )->SetVisible(audioVisible);
}
g_SampleUI.GetButton( IDC_PLAY_BTN )->SetVisible(audioVisible);
g_SampleUI.GetButton( IDC_PAUSE_BTN )->SetVisible(audioVisible);
//cloth controls
for (int ii = 0; ii<g_clothSliderIdSize; ii++)
{
g_SampleUI.GetSlider( g_clothSliderId[ii] )->SetVisible(clothVisible);
int ID = IDC_STATIC_CLOTH_MIN+ii;
g_SampleUI.GetStatic( ID )->SetVisible(clothVisible);
}
}
//--------------------------------------------------------------------------------------
// Initialize the app
//--------------------------------------------------------------------------------------
void InitApp()
{
// Initialize dialogs
g_SettingsDlg.Init( &g_DialogResourceManager );
g_HUD.Init( &g_DialogResourceManager );
g_SampleUI.Init( &g_DialogResourceManager );
g_HUD.SetCallback( OnGUIEvent ); int iY = 10;
g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 35, iY, 125, 22 );
g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 35, iY += 24, 125, 22 );
g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 35, iY += 24, 125, 22, VK_F2 );
g_HUD.AddButton( IDC_AUDIODEMO, L"Audio Demo", 35, iY += 48, 125, 22);
g_HUD.AddButton( IDC_CLOTHDEMO, L"Cloth Demo", 35, iY += 24, 125, 22);
g_HUD.AddButton( IDC_TOOGLE_LOOP_LIBS, L"Toogle Auto Test", 35, iY += 24, 125, 22);
g_HUD.AddButton( IDC_RESET_STATS, L"Reset Min", 35, iY += 24, 125, 22);
g_SampleUI.SetCallback( OnGUIEvent );
g_SampleUI.SetFont( 1, L"Courier", 20, FW_NORMAL );
g_SampleUI.SetFont( 2, L"Courier", 12, FW_NORMAL );
//audio controls
for (int ii = 0; ii<g_audioSliderIdSize; ii++)
{
int ID = IDC_STATIC_CH_MIN+ii;
g_SampleUI.AddStatic( ID, g_audioSliderText[ii],
cSliderX0, cSliderY0 + ii*(cSliderHeight),
cSliderWidth,
cSliderHeight);
g_SampleUI.GetStatic( ID )->SetTextColor( D3DCOLOR_ARGB( 255, 0, 255, 0 ) ); // Change color to green
g_SampleUI.GetControl( ID )->GetElement( 0 )->dwTextFormat = DT_LEFT | DT_TOP;
}
//cloth controls
for (int ii = 0; ii<g_clothSliderIdSize; ii++)
{
int ID = IDC_STATIC_CLOTH_MIN+ii;
g_SampleUI.AddStatic( ID, g_clothSliderText[ii],
cSliderX0, cSliderY0 + ii*(cSliderHeight),
cSliderWidth,
cSliderHeight);
g_SampleUI.GetStatic( ID )->SetTextColor( D3DCOLOR_ARGB( 255, 0, 255, 0 ) ); // Change color to green
g_SampleUI.GetControl( ID )->GetElement( 0 )->dwTextFormat = DT_LEFT | DT_TOP;
}
g_SampleUI.AddSlider( IDC_SLIDER_MATH_REPS,
cSliderX0+5, 480-30,
cSliderWidth,
cSliderHeight,
0, 100,
0, false );
WCHAR wszOutput[1024];
int reps = GetCurrReps();
swprintf_s( wszOutput, 1024, L"Calculation Repetitions: %d", reps);
g_SampleUI.AddStatic( IDC_OUTPUT_CALC_REPS, wszOutput, cSliderX0, cSliderY0, 620, 40 );
g_SampleUI.GetStatic( IDC_OUTPUT_CALC_REPS )->SetTextColor( D3DCOLOR_ARGB( 255, 255, 255, 60 ) ); // Change color to yellow
g_SampleUI.GetControl( IDC_OUTPUT_CALC_REPS )->GetElement( 0 )->dwTextFormat = DT_LEFT | DT_TOP | DT_WORDBREAK;
g_SampleUI.GetControl( IDC_OUTPUT_CALC_REPS )->GetElement( 0 )->iFont = 2;
// Static
g_SampleUI.AddStatic( IDC_OUTPUT_CALC_STATS, L"Time: ", cSliderX0+100, 480-120, 400, 30 );
g_SampleUI.GetStatic( IDC_OUTPUT_CALC_STATS )->SetTextColor( D3DCOLOR_ARGB( 255, 255, 32, 32 ) ); // Change color to red
g_SampleUI.GetControl( IDC_OUTPUT_CALC_STATS )->GetElement( 0 )->dwTextFormat = DT_LEFT | DT_TOP | DT_WORDBREAK;
g_SampleUI.GetControl( IDC_OUTPUT_CALC_STATS )->GetElement( 0 )->iFont = 2;
//avg controls
LPCWSTR avgTextArr[] =
{
L"VMath Avg: ",
L"XNAMath Avg: ",
L"VClass Avg: ",
L"VClassT Avg: ",
L"VClassS Avg: "
};
int avgTextIdArr[] =
{
IDC_OUTPUT_AVG_STATS_VMATH,
IDC_OUTPUT_AVG_STATS_XNAMATH,
IDC_OUTPUT_AVG_STATS_VCLASS,
IDC_OUTPUT_AVG_STATS_VCLASS_TYPEDEF,
IDC_OUTPUT_AVG_STATS_VCLASS_SIMDTYPE
};
for(int ii=0; ii<5; ii++)
{
g_SampleUI.AddStatic( avgTextIdArr[ii], avgTextArr[ii], 0, 0, 400, 30 );
g_SampleUI.GetStatic( avgTextIdArr[ii] )->SetTextColor( D3DCOLOR_ARGB( 255, 255, 255, 255) );
g_SampleUI.GetControl( avgTextIdArr[ii] )->GetElement( 0 )->dwTextFormat = DT_LEFT | DT_TOP | DT_WORDBREAK;
g_SampleUI.GetControl( avgTextIdArr[ii] )->GetElement( 0 )->iFont = 2;
}
g_SampleUI.AddStatic( IDC_OUTPUT_BAYARD_TITLE, L"", 0, 0, 400, 30 );
g_SampleUI.GetStatic( IDC_OUTPUT_BAYARD_TITLE )->SetTextColor( D3DCOLOR_ARGB( 255, 255, 255, 255) );
g_SampleUI.GetControl( IDC_OUTPUT_BAYARD_TITLE )->GetElement( 0 )->dwTextFormat = DT_LEFT | DT_TOP | DT_WORDBREAK;
g_SampleUI.GetControl( IDC_OUTPUT_BAYARD_TITLE )->GetElement( 0 )->iFont = 2;
g_SampleUI.AddButton( IDC_PLAY_BTN, L"Play", cSliderX0, 250, 80, 20, L'P' );
g_SampleUI.AddButton( IDC_PAUSE_BTN, L"Pause", cSliderX0+100, 250, 80, 20, L'S' );
#ifdef DBUG_EDIT_BOX
// Edit box
g_SampleUI.AddEditBox( IDC_EDITBOX_DBUG, L"", cSliderX0, 440, 600, 32 );
#endif
// audio sliders
for (int ii = 0; ii<g_audioSliderIdSize; ii++)
{
g_SampleUI.AddSlider( g_audioSliderId[ii],
cSliderX0, cSliderY0 + ii*(cSliderHeight),
cSliderWidth,
cSliderHeight,
0, 100, 100, false );
}
// cloth sliders
g_SampleUI.AddSlider( IDC_SLIDER_CLOTH_ROT, cSliderX0, cSliderY0 + 0*(cSliderHeight),
cSliderWidth, cSliderHeight,
0, 100, 0, false );
g_SampleUI.AddSlider( IDC_SLIDER_CLOTH_TRANS, cSliderX0, cSliderY0 + 1*(cSliderHeight),
cSliderWidth, cSliderHeight,
0, 100, 100, false );
g_SampleUI.AddSlider( IDC_SLIDER_CLOTH_GRAVITY, cSliderX0, cSliderY0 + 2*(cSliderHeight),
cSliderWidth, cSliderHeight,
0, 100, 100, false );
// Radio buttons
g_SampleUI.AddRadioButton( IDC_RADIO_VMATH, 1, L"VMath", 0, 50, 220, 24, true, L'1' );
g_SampleUI.AddRadioButton( IDC_RADIO_XNAMATH, 1, L"XNAMath", 0, 50, 220, 24, false, L'2' );
g_SampleUI.AddRadioButton( IDC_RADIO_VCLASS, 1, L"VClass", 0, 50, 220, 24, false, L'3' );
g_SampleUI.AddRadioButton( IDC_RADIO_VCLASS_TYPEDEF, 1, L"VClassTypedef", 0, 50, 220, 24, false, L'4' );
g_SampleUI.AddRadioButton( IDC_RADIO_VCLASS_SIMDTYPE, 1, L"VClassSIMDType", 0, 50, 220, 24, false, L'5' );
UpdateDemoUI();
}
//--------------------------------------------------------------------------------------
// Rejects any D3D9 devices that aren't acceptable to the app by returning false
//--------------------------------------------------------------------------------------
bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat,
D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext )
{
// Skip backbuffer formats that don't support alpha blending
IDirect3D9* pD3D = DXUTGetD3D9Object();
if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
return false;
// Must support pixel shader 2.0
if( pCaps->PixelShaderVersion < D3DPS_VERSION( 2, 0 ) )
return false;
return true;
}
//--------------------------------------------------------------------------------------
// Called right before creating a D3D9 or D3D10 device, allowing the app to modify the device settings as needed
//--------------------------------------------------------------------------------------
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext )
{
assert( DXUT_D3D9_DEVICE == pDeviceSettings->ver );
HRESULT hr;
IDirect3D9* pD3D = DXUTGetD3D9Object();
D3DCAPS9 caps;
V( pD3D->GetDeviceCaps( pDeviceSettings->d3d9.AdapterOrdinal,
pDeviceSettings->d3d9.DeviceType,
&caps ) );
// If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW
// then switch to SWVP.
if( ( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) == 0 ||
caps.VertexShaderVersion < D3DVS_VERSION( 1, 1 ) )
{
pDeviceSettings->d3d9.BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
// Debugging vertex shaders requires either REF or software vertex processing
// and debugging pixel shaders requires REF.
#ifdef DEBUG_VS
if( pDeviceSettings->d3d9.DeviceType != D3DDEVTYPE_REF )
{
pDeviceSettings->d3d9.BehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
pDeviceSettings->d3d9.BehaviorFlags &= ~D3DCREATE_PUREDEVICE;
pDeviceSettings->d3d9.BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
#endif
#ifdef DEBUG_PS
pDeviceSettings->d3d9.DeviceType = D3DDEVTYPE_REF;
#endif
// For the first device created if its a REF device, optionally display a warning dialog box
static bool s_bFirstTime = true;
if( s_bFirstTime )
{
s_bFirstTime = false;
if( pDeviceSettings->d3d9.DeviceType == D3DDEVTYPE_REF )
DXUTDisplaySwitchingToREFWarning( pDeviceSettings->ver );
}
return true;
}
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED)
// and aren't tied to the back buffer size
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
void* pUserContext )
{
HRESULT hr;
CDXUTIMEEditBox::Initialize( DXUTGetHWND() );
V_RETURN( g_DialogResourceManager.OnD3D9CreateDevice( pd3dDevice ) );
V_RETURN( g_SettingsDlg.OnD3D9CreateDevice( pd3dDevice ) );
// Initialize the font
V_RETURN( D3DXCreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
L"Verdana", &g_pFont ) );
DWORD dwShaderFlags = D3DXFX_NOT_CLONEABLE;
#if defined( DEBUG ) || defined( _DEBUG )
dwShaderFlags |= D3DXSHADER_DEBUG;
#endif
#ifdef DEBUG_VS
dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT;
#endif
#ifdef DEBUG_PS
dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT;
#endif
// Read the D3DX effect file
WCHAR str[MAX_PATH];
V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"CustomUI.fx" ) );
V_RETURN( D3DXCreateEffectFromFile( pd3dDevice, str, NULL, NULL, dwShaderFlags,
NULL, &g_pEffect, NULL ) );
g_Mesh.Create( pd3dDevice, L"misc\\cell.x" );
// Setup the camera's view parameters
D3DXVECTOR3 vecEye( 0.0f, 1.5f, -7.0f );
D3DXVECTOR3 vecAt ( 0.0f, 0.2f, 0.0f );
D3DXVECTOR3 vecUp ( 0.0f, 1.0f, 0.0f );
g_Camera.SetViewParams( &vecEye, &vecAt );
D3DXMatrixLookAtLH( &g_mView, &vecEye, &vecAt, &vecUp );
return S_OK;
}
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT)
// or that are tied to the back buffer size
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice,
const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
HRESULT hr;
V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() );
V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() );
if( g_pFont )
V_RETURN( g_pFont->OnResetDevice() );
if( g_pEffect )
V_RETURN( g_pEffect->OnResetDevice() );
// Create a sprite to help batch calls when drawing many lines of text
V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pTextSprite ) );
// Setup the camera's projection parameters
float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;
g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.1f, 1000.0f );
g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
g_HUD.SetSize( 170, 170 );
g_SampleUI.SetLocation( 0, 0 );
g_SampleUI.SetSize( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
g_SampleUI.GetControl( IDC_OUTPUT_CALC_REPS )->SetSize( pBackBufferSurfaceDesc->Width - 40, 30 );
g_SampleUI.GetControl( IDC_OUTPUT_CALC_REPS )->SetLocation( cSliderX0, pBackBufferSurfaceDesc->Height - 80 );
g_SampleUI.GetControl( IDC_OUTPUT_CALC_STATS )->SetSize( pBackBufferSurfaceDesc->Width - 40, 30 );
g_SampleUI.GetControl( IDC_OUTPUT_CALC_STATS )->SetLocation( cSliderX0, pBackBufferSurfaceDesc->Height - 120);
int avgTextIdArr[] =
{
IDC_OUTPUT_AVG_STATS_VMATH,
IDC_OUTPUT_AVG_STATS_XNAMATH,
IDC_OUTPUT_AVG_STATS_VCLASS,
IDC_OUTPUT_AVG_STATS_VCLASS_TYPEDEF,
IDC_OUTPUT_AVG_STATS_VCLASS_SIMDTYPE
};
for (int ii=0; ii<5; ii++)
{
g_SampleUI.GetControl( avgTextIdArr[ii] )->SetSize( pBackBufferSurfaceDesc->Width - 40, 30 );
g_SampleUI.GetControl( avgTextIdArr[ii] )->SetLocation( cSliderX0, pBackBufferSurfaceDesc->Height - (200-ii*15));
}
g_SampleUI.GetControl( IDC_OUTPUT_BAYARD_TITLE )->SetSize( pBackBufferSurfaceDesc->Width - 40, 30 );
g_SampleUI.GetControl( IDC_OUTPUT_BAYARD_TITLE )->SetLocation( cSliderX0, pBackBufferSurfaceDesc->Height - 40);
#ifdef DBUG_EDIT_BOX
g_SampleUI.GetControl( IDC_EDITBOX_DBUG )->SetLocation( cSliderX0, pBackBufferSurfaceDesc->Height -40 );
g_SampleUI.GetControl( IDC_EDITBOX_DBUG )->SetSize( pBackBufferSurfaceDesc->Width - 40, 32 );
#endif
g_SampleUI.GetControl( IDC_PLAY_BTN )->SetLocation( cSliderX0, 250 );
g_SampleUI.GetControl( IDC_PAUSE_BTN )->SetLocation( cSliderX0+100, 250 );
//g_intValues[0]
g_SampleUI.GetControl( IDC_SLIDER_MATH_REPS )->SetLocation( cSliderX0+ 5, pBackBufferSurfaceDesc->Height - 60 );
for (int ii = 0; ii<g_audioSliderIdSize; ii++)
{
g_SampleUI.GetControl( g_audioSliderId[ii] )->SetLocation
(
cSliderX0, cSliderY0 + ii*(cSliderHeight)
);
}
for (int ii = 0; ii<g_clothSliderIdSize; ii++)
{
g_SampleUI.GetControl( g_clothSliderId[ii] )->SetLocation
(
cSliderX0, cSliderY0 + ii*(cSliderHeight)
);
}
g_SampleUI.GetControl( IDC_RADIO_VMATH )->SetLocation( pBackBufferSurfaceDesc->Width - 130, 220);
g_SampleUI.GetControl( IDC_RADIO_XNAMATH )->SetLocation( pBackBufferSurfaceDesc->Width - 130, 220+24 );
g_SampleUI.GetControl( IDC_RADIO_VCLASS )->SetLocation( pBackBufferSurfaceDesc->Width - 130, 220+48 );
g_SampleUI.GetControl( IDC_RADIO_VCLASS_TYPEDEF )->SetLocation( pBackBufferSurfaceDesc->Width - 130, 220+72 );
g_SampleUI.GetControl( IDC_RADIO_VCLASS_SIMDTYPE )->SetLocation( pBackBufferSurfaceDesc->Width - 130, 220+96 );
g_Mesh.RestoreDeviceObjects( pd3dDevice );
return S_OK;
}
//--------------------------------------------------------------------------------------
// Handle updates to the scene. This is called regardless of which D3D API is used
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext )
{
D3DXMATRIXA16 m;
D3DXMatrixRotationY( &m, D3DX_PI * fElapsedTime / 40.0f );
D3DXMatrixMultiply( &g_mView, &m, &g_mView );
}
//-----------------------------------------------------------------------------
// Name: InitGeometry()
// Desc: Creates the scene geometry
//-----------------------------------------------------------------------------
HRESULT InitGeometry(IDirect3DDevice9* pd3dDevice)
{
if (g_pVB)
{
return S_OK;
}
// Initialize three vertices for rendering a triangle
CUSTOMVERTEX g_Vertices[] =
{
{ -1.0f,-1.0f, 0.0f, 0xffff0000, },
{ 1.0f,-1.0f, 0.0f, 0xff0000ff, },
{ 0.0f, 1.0f, 0.0f, 0xffffffff, },
};
// Create the vertex buffer.
if( FAILED( pd3dDevice->CreateVertexBuffer( 3 * sizeof( CUSTOMVERTEX ),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
// Fill the vertex buffer.
VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof( g_Vertices ), ( void** )&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, g_Vertices, sizeof( g_Vertices ) );
g_pVB->Unlock();
return S_OK;
}
//--------------------------------------------------------------------------------------
// Render Hack
//--------------------------------------------------------------------------------------
void RenderHack(IDirect3DDevice9* pd3dDevice, D3DXMATRIXA16* mWorld, D3DXMATRIXA16* mView, D3DXMATRIXA16* mProj)
{
InitGeometry(pd3dDevice);
if (!g_pVB)
{
return;
}
// Turn off culling, so we see the front and back of the triangle
pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Turn off D3D lighting, since we are providing our own vertex colors
pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
pd3dDevice->SetTransform( D3DTS_WORLD, mWorld );
pd3dDevice->SetTransform( D3DTS_VIEW, mView );
pd3dDevice->SetTransform( D3DTS_PROJECTION, mProj );
// Render the vertex buffer contents
pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
//pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, 2 );
pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
}
//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CleanUpHacks()
{
CLOTH_VMATH::ClothShutDown();
CLOTH_XNAMATH::ClothShutDown();
CLOTH_VCLASS::ClothShutDown();
CLOTH_VCLASS_TYPEDEF::ClothShutDown();
CLOTH_VCLASS_SIMDTYPE::ClothShutDown();
if( g_pVB != NULL )
g_pVB->Release();
g_pVB = NULL;
}
//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
if( g_SettingsDlg.IsActive() )
{
g_SettingsDlg.OnRender( fElapsedTime );
return;
}
HRESULT hr;
D3DXMATRIXA16 mWorld;
D3DXMATRIXA16 mView;
D3DXMATRIXA16 mProj;
D3DXMATRIXA16 mWorldViewProjection;
// Clear the render target and the zbuffer
V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) );
// Render the scene
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
// Get the projection & view matrix from the camera class
mWorld = *g_Camera.GetWorldMatrix();
mProj = *g_Camera.GetProjMatrix();
mView = g_mView;
mWorldViewProjection = mWorld * mView * mProj;
// Update the effect's variables. Instead of using strings, it would
// be more efficient to cache a handle to the parameter by calling
// ID3DXEffect::GetParameterByName
V( g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) );
V( g_pEffect->SetMatrix( "g_mWorld", &mWorld ) );
V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) );
g_pEffect->SetTechnique( "RenderScene" );
UINT cPasses;
g_pEffect->Begin( &cPasses, 0 );
ID3DXMesh* pMesh = g_Mesh.GetMesh();
for( UINT p = 0; p < cPasses; ++p )
{
g_pEffect->BeginPass( p );
for( UINT m = 0; m < g_Mesh.m_dwNumMaterials; ++m )
{
g_pEffect->SetTexture( "g_txScene", g_Mesh.m_pTextures[m] );
g_pEffect->CommitChanges();
pMesh->DrawSubset( m );
}
g_pEffect->EndPass();
}
g_pEffect->End();
int reps = GetCurrReps();
float fps = DXUTGetFPS();
double totalTime = 0.f;
double timeAvg = 0.f;
if (g_demoType == DEMO_TYPE_AUDIO)
{
if (g_libType == MATHLIB_TYPE_VMATH)
{
for(int ii=0; ii<reps; ii++)
{
double time = ProcessAudioVMath(2048);
totalTime += time;
}
}
else if (g_libType == MATHLIB_TYPE_XNAMATH)
{
for(int ii=0; ii<reps; ii++)
{
double time = ProcessAudioXNAMath(2048);
totalTime += time;
}
}
else if (g_libType == MATHLIB_TYPE_VCLASS)
{
for(int ii=0; ii<reps; ii++)
{
double time = ProcessAudioVClass(2048);
totalTime += time;
}
}
else if (g_libType == MATHLIB_TYPE_VCLASS_TYPEDEF)
{
for(int ii=0; ii<reps; ii++)
{
double time = ProcessAudioVClassTypedef(2048);
totalTime += time;
}
}
else if (g_libType == MATHLIB_TYPE_VCLASS_SIMDTYPE)
{
for(int ii=0; ii<reps; ii++)
{
double time = ProcessAudioVClassSIMDType(2048);
totalTime += time;
}
}
else
{
assert(false);
}
}
else if (g_demoType == DEMO_TYPE_CLOTH)
{
float timeStep = 1.f/60.f;
if (g_libType == MATHLIB_TYPE_VMATH)
{
CLOTH_VMATH::ClothAnimateAndRender(pd3dDevice, &mWorld, &mView, &mProj, timeStep, reps, &totalTime);
}
else if (g_libType == MATHLIB_TYPE_XNAMATH)
{
CLOTH_XNAMATH::ClothAnimateAndRender(pd3dDevice, &mWorld, &mView, &mProj, timeStep, reps, &totalTime);
}
else if (g_libType == MATHLIB_TYPE_VCLASS)
{
CLOTH_VCLASS::ClothAnimateAndRender(pd3dDevice, &mWorld, &mView, &mProj, timeStep, reps, &totalTime);
}
else if (g_libType == MATHLIB_TYPE_VCLASS_TYPEDEF)
{
CLOTH_VCLASS_TYPEDEF::ClothAnimateAndRender(pd3dDevice, &mWorld, &mView, &mProj, timeStep, reps, &totalTime);
}
else if (g_libType == MATHLIB_TYPE_VCLASS_SIMDTYPE)
{
CLOTH_VCLASS_SIMDTYPE::ClothAnimateAndRender(pd3dDevice, &mWorld, &mView, &mProj, timeStep, reps, &totalTime);
}
else
{