-
Notifications
You must be signed in to change notification settings - Fork 9
/
UIElements.cpp
3882 lines (3332 loc) · 170 KB
/
UIElements.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: UIElements.cpp
//
// User interface elements for CubeMapGen
//
//--------------------------------------------------------------------------------------
// (C) 2005 ATI Research, Inc., All rights reserved.
//--------------------------------------------------------------------------------------
#include "resource.h"
#include "CCubeGenApp.h"
#include "CGeom.h"
#include "ErrorMsg.h"
#include "UIRegionManager.h"
#include "Version.h"
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <wincon.h>
#include <stdarg.h>
#include <wtypes.h>
#include <commctrl.h>
//do not allow "dxstdafx.h" to depricate any core string functions
#pragma warning( disable : 4995 )
#define COMBO_MOVE_EYE 0
#define COMBO_MOVE_LIGHT_SOURCE 1
#define COMBO_MOVE_OBJECT 2
#define COMBO_LAYOUT_EYE 0
//#define COMBO_LAYOUT_EYE_PANEL 1
//#define COMBO_LAYOUT_EYE_PINGPONGBUFFERS 2
//#define COMBO_LAYOUT_EYE_SMOOTHIEMAP 3
//requirements: pixel shader version uses lower 4 bits
#define PS_VERSION_REQUIREMENT_MASK 0x0f
#define REQUIRES_PS20 0
#define REQUIRES_PS2A 1
#define REQUIRES_PS2B 2
#define REQUIRES_PS30 3
#define REQUIRES_DEPTH24_TEXTURE (1<<8)
//doublewidth
#define UI_REGION_WIDTH 200
#define UI_ELEMENT_WIDTH 190
#define UI_ELEMENT_HEIGHT 16
#define UI_ELEMENT_COLUMN_WIDTH 198
#define UI_ELEMENT_VERTICAL_SPACING 18
#define UI_TECH_DROPHEIGHT 400
//maximum message length output to message box
#define UI_MAX_MESSAGE_LENGTH 65536
#define UI_MAX_FILENAME 4096
#define UI_EDITBOX_BORDER_WIDTH 1
#define UI_EDITBOX_SPACING 0
#define UI_EDITBOX_TEXTCOLOR D3DCOLOR_RGBA(255, 255, 255, 255 )
#define UI_EXIT_CODE_ERROR -15
//casting void pointer to int (required when using D3DXUI)
#pragma warning(disable: 4311)
typedef BOOL (APIENTRY * ATTACHCONSOLEPROC) (DWORD dwProcessId);
//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
ID3DXFont* g_pFont = NULL; // Font for drawing text
ID3DXSprite* g_pTextSprite = NULL; // Sprite for batching draw text calls
CModelViewerCamera g_Camera; // The camera used to view the scene
//CModelViewerCamera g_Object; // arcball used to store the current rotation of the object
int32 g_DisplayLayoutSelect = COMBO_LAYOUT_EYE; //
int32 g_fEyeViewport[4]; // x, y, width, height
int32 g_fUIViewport[4]; // x, y, width, height
//UI regions for grouping UI options
UIRegionManager* g_pRegionManager = UIRegionManager::GetInstance();
#ifdef _TEST
UIRegion* g_pFaceManipUIRegion;
#endif // _TEST
UIRegion* g_pLoadSaveUIRegion; // UI for loading and saving
UIRegion* g_pDisplayUIRegion; // UI region for setting display options
UIRegion* g_pFilterUIRegion; // UI region for setting filter setting and filtering
UIRegion* g_pAdjustOutputUIRegion; // UI region for adjusting output cubemap settings
//CDXUTDialog g_HUD; // dialog for standard controls
//CDXUTDialog g_SampleUI; // dialog for sample specific controls
CCubeGenApp g_CubeGenApp; // shadowmapping application
bool g_bShowUI = true; // Show UI
bool g_bShowHelp = true; // If true, it renders the help text
bool g_bHasEyeViewport = true; // layout has region to render scene from eye's point of view?
bool g_bProcessedCommandLine = false; // has the commandline been processed yet?
bool g_bForceRefRast = false; // force reference rasterizer?
bool g_bEnableHotKeys = true; // ability to turn hotkeys off when typing into edit box
bool g_bOldModeWindowed = false; // whether or not old mode is windowed
float32 g_FOV = 90.0f; // 90 degree field of view
D3DSURFACE_DESC* g_pBackBufferSurfaceDesc; // backbuffer description
IDirect3DDevice9* g_pDevice; // d3d device
int32 g_ArgC; // Number of arguements (same usage as argc)
LPWSTR* g_pArgVList; // Arguementlist for command line processing (same usage as argv)
WCHAR g_LoadCubeCrossFilename[UI_MAX_FILENAME] = L""; // last loaded cubecross filename
WCHAR g_LoadCubeFaceFilename[UI_MAX_FILENAME] = L""; // last loaded cubeface filename
WCHAR g_SaveCubeCrossPrefix[UI_MAX_FILENAME] = L""; // last saved cubecross prefix
WCHAR g_SaveCubeFacesPrefix[UI_MAX_FILENAME] = L""; // last saved cubeface prefix
HANDLE g_ConsoleHandle; // Console handle
//--------------------------------------------------------------------------------------
// UI control IDs
//--------------------------------------------------------------------------------------
#define IDC_TOGGLEFULLSCREEN 1
#define IDC_VIEWWHITEPAPER 2
#define IDC_TOGGLEREF 3
#define IDC_CHANGEDEVICE 4
#define IDC_RELOAD_SHADERS 5
#define IDC_LOAD_OBJECT 6
#define IDC_LOAD_CUBEMAP 7
#define IDC_LOAD_CUBEMAP_FROM_IMAGES 8
#define IDC_LOAD_CUBE_CROSS 9
#define IDC_SAVE_CUBEMAP 10
#define IDC_SAVE_CUBEMAP_TO_IMAGES 11
#define IDC_SAVE_CUBE_CROSS 12
#define IDC_FACE_EXPORT_LAYOUT 13
#define IDC_LOAD_BASEMAP 14
#define IDC_SAVE_MIPCHAIN_CHECKBOX 15
#define IDC_SET_SPHERE_OBJECT 16
#define IDC_SET_COLORCUBE 17
//gui elements for layout select
#define IDC_LAYOUT_SELECT 20
//gui elements for rendering options
#define IDC_RENDER_MODE 30
#define IDC_CUBE_SOURCE 31
#define IDC_SELECT_MIP_CHECKBOX 32
#define IDC_MIP_LEVEL 33
#define IDC_CLAMP_MIP_CHECKBOX 34
#define IDC_SHOW_ALPHA_CHECKBOX 35
#define IDC_SKYBOX_CHECKBOX 36
#define IDC_FOV 37
#define IDC_CENTER_OBJECT 38
//gui elements for filtering options
#define IDC_FILTER_CUBEMAP 40
#define IDC_BASE_FILTER_ANGLE 41
#define IDC_MIP_INITIAL_FILTER_ANGLE 42
#define IDC_MIP_FILTER_ANGLE_SCALE 43
#define IDC_EDGE_FIXUP_CHECKBOX 44
#define IDC_EDGE_FIXUP_WIDTH 45
#define IDC_EDGE_FIXUP_TYPE 46
#define IDC_USE_SOLID_ANGLE_WEIGHTING 47
#define IDC_FILTER_TYPE 48
//gui elements for manipulating faces
#define IDC_CUBE_FACE_SELECT 50
#define IDC_CUBE_LOAD_FACE 51
#define IDC_CUBE_FLIP_FACE_UV 52
#define IDC_CUBE_FLIP_FACE_VERTICAL 53
#define IDC_CUBE_FLIP_FACE_HORIZONTAL 54
#define IDC_INPUT_SCALE 60
#define IDC_INPUT_DEGAMMA 61
#define IDC_OUTPUT_SCALE 62
#define IDC_OUTPUT_GAMMA 63
#define IDC_OUTPUT_CUBEMAP_SIZE 64
#define IDC_OUTPUT_CUBEMAP_FORMAT 65
#define IDC_REFRESH_OUTPUT_CUBEMAP 66
#define IDC_INPUT_CLAMP 67
//output packing options
#define IDC_PACK_MIPLEVEL_IN_ALPHA_CHECKBOX 70
#define IDC_OUTPUT_PERIODIC_REFRESH_CHECKBOX 80
#define IDC_OUTPUT_AUTO_REFRESH_CHECKBOX 82
#define IDC_ABOUT 100
#define IDC_FOV_STATICTEXT 1032
#define IDC_BASE_FILTER_ANGLE_STATICTEXT 1041
#define IDC_MIP_INITIAL_FILTER_ANGLE_STATICTEXT 1042
#define IDC_MIP_FILTER_ANGLE_SCALE_STATICTEXT 1043
#define IDC_EDGE_FIXUP_WIDTH_STATICTEXT 1045
#define IDC_INPUT_SCALE_STATICTEXT 1060
#define IDC_INPUT_DEGAMMA_STATICTEXT 1061
#define IDC_OUTPUT_SCALE_STATICTEXT 1062
#define IDC_OUTPUT_GAMMA_STATICTEXT 1063
#define IDC_INPUT_CLAMP_STATICTEXT 1067
#define IDC_BASE_FILTER_ANGLE_EDITBOX 2041
#define IDC_MIP_INITIAL_FILTER_ANGLE_EDITBOX 2042
#define IDC_MIP_FILTER_ANGLE_SCALE_EDITBOX 2043
#define IDC_INPUT_DEGAMMA_EDITBOX 2061
#define IDC_OUTPUT_SCALE_EDITBOX 2062
#define IDC_OUTPUT_GAMMA_EDITBOX 2063
#define IDC_INPUT_CLAMP_EDITBOX 2067
// SL BEGIN
#define IDC_SPECULAR_POWER_EDITBOX 2100
#define IDC_SPECULAR_POWER_STATICTEXT 2101
#define IDC_MULTITHREAD_CHECKBOX 2102
#define IDC_IRRADIANCE_CUBEMAP_CHECKBOX 2104
#define IDC_SPECULAR_POWER_DROP_PER_MIP_EDITBOX 2105
#define IDC_SPECULAR_POWER_MIP_DROP_STATICTEXT 2106
#define IDC_LIGHTINGMODEL_TYPE 2107
#define IDC_EXCLUDEBASE_CHECKBOX 2108
#define IDC_GLOSS_SCALE_STATICTEXT 2109
#define IDC_GLOSS_BIAS_STATICTEXT 2110
#define IDC_GLOSS_SCALE_EDITBOX 2111
#define IDC_GLOSS_BIAS_EDITBOX 2112
#define IDC_NUM_MIPMAP_STATICTEXT 2113
#define IDC_NUM_MIPMAP_EDITBOX 2114
#define IDC_COSINEPOWER_CHAIN_TYPE 2115
#define IDC_FIX_SEAMS_CHECKBOX 2116
// SL END
//--------------------------------------------------------------------------------------
// Forward declarations
//--------------------------------------------------------------------------------------
void OutputMessage(WCHAR *a_Title, WCHAR *a_Message, ...);
void ProcessCommandLineForHelpOptions(void);
void ProcessCommandLineArguements(void);
bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed );
void CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps );
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc );
HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc );
void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime );
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime );
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing );
void CALLBACK KeyboardProc( UINT nChar, bool bKeyDown, bool bAltDown );
void CALLBACK MouseProc( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos );
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl );
void CALLBACK OnLostDevice();
void CALLBACK OnDestroyDevice();
void SetupGUI();
void AddComboBoxItemIfCapable(CDXUTDialog *pUIDialog, UINT nElementID, const WCHAR* strText, void* pData, UINT nRequirement);
void RenderText();
void SetUIElementsUsingCurrentSettings(void);
//--------------------------------------------------------------------------------------
// Entry point to the program. Initializes everything and goes into a message processing
// loop. Idle time is used to render the scene.
//--------------------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
//get command line arguements and convert into argc and argv format for later processing
// after D3D is fully initialized
g_pArgVList = CommandLineToArgvW(GetCommandLineW(), &g_ArgC );
//output any help text if --help or -help command line options are specified
ProcessCommandLineForHelpOptions();
// Set the callback functions. These functions allow the sample framework to notify
// the application about device changes, user input, and windows messages. The
// callbacks are optional so you need only set callbacks for events you're interested
// in. However, if you don't handle the device reset/lost callbacks then the sample
// framework won't be able to reset your device since the application must first
// release all device resources before resetting. Likewise, if you don't handle the
// device created/destroyed callbacks then the sample framework won't be able to
// recreate your device resources.
DXUTSetCallbackDeviceCreated( OnCreateDevice );
DXUTSetCallbackDeviceReset( OnResetDevice );
DXUTSetCallbackDeviceLost( OnLostDevice );
DXUTSetCallbackDeviceDestroyed( OnDestroyDevice );
DXUTSetCallbackMsgProc( MsgProc );
DXUTSetCallbackKeyboard( KeyboardProc );
DXUTSetCallbackMouse( MouseProc, true );
DXUTSetCallbackFrameRender( OnFrameRender );
DXUTSetCallbackFrameMove( OnFrameMove );
// Show the cursor and clip it when in full screen
DXUTSetCursorSettings( true, true );
// Initialize the sample framework and create the desired Win32 window and Direct3D
// device for the application. Calling each of these functions is optional, but they
// allow you to set several options which control the behavior of the framework.
// Note that the framework should not parse the
DXUTInit( false, true, true ); // Do not parse the command line, handle the default hotkeys, and show msgboxes
// SL BEGIN
DXUTCreateWindow( L"TalanSoft CubeMapGen v1.7"
#if defined _M_IX86
L" (x86)"
#elif defined _M_X64
L" (x64)"
#else
#error "Unknown architecture !"
#endif
);
// SL END
DXUTCreateDevice( D3DADAPTER_DEFAULT, true, 1024, 768, IsDeviceAcceptable, ModifyDeviceSettings );
//initialize ui elements
SetupGUI();
// Pass control to the sample framework for handling the message pump and
// dispatching render calls. The sample framework will call your FrameMove
// and FrameRender callback when there is idle time between handling window messages.
DXUTMainLoop();
// Perform any application-level cleanup here. Direct3D device resources are released within the
// appropriate callback functions and therefore don't require any cleanup code here.
return DXUTGetExitCode();
}
//---------------------------------------------------------------------------------------------
// Stores the Current Mode and then Sets Windowed Mode
//
// needed to display windows common dialogs
//---------------------------------------------------------------------------------------------
void StoreCurrentModeThenSetWindowedMode(void)
{
if(DXUTIsWindowed() == true)
{
g_bOldModeWindowed = true;
}
else
{
g_bOldModeWindowed = false;
DXUTToggleFullScreen();
}
}
//---------------------------------------------------------------------------------------------
// resore old mode (windowed, or full screen)
//
//---------------------------------------------------------------------------------------------
void RestoreOldMode(void)
{
if((g_bOldModeWindowed == true) && (DXUTIsWindowed() == false))
{
DXUTToggleFullScreen();
}
else if ((g_bOldModeWindowed == false) && (DXUTIsWindowed() == true))
{
DXUTToggleFullScreen();
}
}
//------------------------------------------------------------------------------------------
// Compares a string a_Str to see if it contains the prefix a_Prefix
//
// If so the function returns true, and a pointer to the first character after the prefix
//------------------------------------------------------------------------------------------
bool WCPrefixCmp(WCHAR *a_Str, WCHAR *a_Prefix, WCHAR **a_AfterPrefix)
{
if( wcsncmp(a_Str, a_Prefix, wcslen(a_Prefix)) == 0 )
{
*a_AfterPrefix = (a_Str + wcslen(a_Prefix));
return true;
}
//a_AfterPrefix unchanged when prefix doesn't match
return false;
}
//-------------------------------------------------------------------------------------------
// Writes out to console, (used for GUI based apps which are launched from a console window)
//
//-------------------------------------------------------------------------------------------
void ConsoleOutput(HANDLE a_ConsoleHandle, char *a_ConsoleStr)
{
DWORD consoleCharWritten;
//When this app is run from the command line, this function writes text to the command line
if(a_ConsoleHandle != NULL)
{
WriteConsoleA(a_ConsoleHandle, a_ConsoleStr, (DWORD)strlen(a_ConsoleStr), &consoleCharWritten, NULL );
}
//Note that this app communicates with HDR shop via stderr, and because it is a windowed app,
// this statement does nothing when run from the command line
fprintf(stderr, "%s", a_ConsoleStr);
}
//-------------------------------------------------------------------------------------------
// Writes out to console , (used for GUI based apps which are launched from a console window)
// (wide character version)
//-------------------------------------------------------------------------------------------
void ConsoleOutputW(HANDLE a_ConsoleHandle, WCHAR *a_ConsoleStr)
{
DWORD consoleCharWritten;
//When this app is run from the command line, this function writes text to the command line
WriteConsoleW(a_ConsoleHandle, a_ConsoleStr, (DWORD)wcslen(a_ConsoleStr), &consoleCharWritten, NULL );
//Note that this app communicates with HDR shop via stderr, and because it is a windowed app,
// this statement does nothing when run from the command line, only when launched from HDR shop
fwprintf(stderr, L"%s", a_ConsoleStr);
}
//-------------------------------------------------------------------------------------------
//callback function for cubemap gen error reporting to write errors out to the console
//
//-------------------------------------------------------------------------------------------
void ConsoleOutputMessageCallback(WCHAR *a_TitleStr, WCHAR *a_MessageStr)
{
// DWORD consoleCharWritten;
WCHAR messageString[4096];
//title
_snwprintf_s(messageString, 4096, 4096, L"%s: %s", a_TitleStr, a_MessageStr );
//console output
ConsoleOutputW(g_ConsoleHandle, messageString);
}
//-------------------------------------------------------------------------------------------
//message handler for progress dialog box
//-------------------------------------------------------------------------------------------
INT_PTR CALLBACK ProgressDialogMsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_CANCEL_FILTERING_BUTTON:
//cancel filtering;
fwprintf(stderr, L"User Terminated Filtering!");
exit(EM_FATAL_ERROR);
return TRUE;
break;
}
break;
}
return FALSE;
}
//--------------------------------------------------------------------------------------
// ProcessCommandLineForHelpOptions
//
// This function is called before window instantiation in order to print out help options
// from the command line interface if needed without popping up the application window.
//
//--------------------------------------------------------------------------------------
void ProcessCommandLineForHelpOptions(void)
{
int32 iCmdLine;
WCHAR *cmdArg;
HANDLE consoleStdErr = NULL;
WCHAR *suffixStr;
g_pArgVList = CommandLineToArgvW(GetCommandLineW(), &g_ArgC );
//if there is a list of command line arguements, then attach the console that launched the app
// in order to display text based output
for(iCmdLine=1; iCmdLine < g_ArgC; iCmdLine++)
{
cmdArg = g_pArgVList[iCmdLine];
//help string for HDR shop
if( WCPrefixCmp(cmdArg, L"--help", &suffixStr) || WCPrefixCmp(cmdArg, L"-help", &suffixStr) )
{
ATTACHCONSOLEPROC AttachConsoleFunc;
AttachConsoleFunc = (ATTACHCONSOLEPROC)GetProcAddress(GetModuleHandle(L"Kernel32.dll"), "AttachConsole");
//AttachConsole only supported in WinXP, Win2K does not support it.
if(AttachConsoleFunc != NULL)
{
AttachConsoleFunc(ATTACH_PARENT_PROCESS);
}
else
{ //for win2k and less just create another console
AllocConsole();
}
consoleStdErr = GetStdHandle(STD_ERROR_HANDLE);
ConsoleOutput(consoleStdErr,
// SL BEGIN
"TalanSoft CubeMapGen: A Cubemap Filtering, Mipchain Generation, and Realtime Preview Tool\n"
// SL END
"AMD 3D Application Research Group\n"
"\n"
);
if( WCPrefixCmp(cmdArg, L"--help", &suffixStr) )
{ //if HDRShop help command
ConsoleOutput(consoleStdErr,
"Notes: There seems to be an HDRShop issue where if the filtering takes too long, HDRShop\n"
" will overwrite the filtering results. In this case, the message box pops up a warning\n"
" stating that ''The plugin does not exit when queried for parameters.'' If this happens\n"
" CubeMapGen writes out a backup file cube cross named ''HDRShopBackupCross.pfm''\n"
" that can be loaded back into HDRShop once the filtering is complete.\n"
"HDRSHOPVERSION: 1.0.1 \n\n"
"HDRSHOPFLAGS:\n\n"
"USAGE: CubeMapGen [input.pfm] [output.pfm] [options] \n\n"
"\n"
);
}
ConsoleOutput(consoleStdErr,
"OPTIONS:\n"
" -baseFilterAngle:[float=0.0] Initial filtering angle for base level of cubemap.\n"
" -initialMipFilterAngle:[float=0.2] Filtering angle to generate second mip-level of cubemap.\n"
" -perLevelMipFilterScale:[float=2.0] Filtering angle scale to generate succesive cubemap miplevels.\n"
// SL BEGIN
" -filterTech:{Disc|Cone|Cosine|AngularGaussian|CosinePower} Technique used for filtering. \n"
" -edgeFixupTech:{None|LinearPull|HermitePull|LinearAverage|HermiteAverage|Bent|Warp} Technique used for cubemap edge fixup \n"
// SL END
" -edgeFixupWidth:[int=1] Width in texels for edge fixup. (0 = no edge fixup) \n"
" -solidAngleWeighting Use each texels solid angle to compute tap weights in the filtering kernel.\n"
// SL BEGIN
" -CosinePower: define the specular power to use when Cosine power filtering is used.\n"
" -CosinePowerDropPerMip: allow to specify the specular power scale to generate successive cubemap miplevels with CosinePowerMipmapChainMode Drop mode.\n"
" -NumMipmap: allow to specify the number of mipmap of the final chain to generate successive cubemap miplevels with CosinePowerMipmapChainMode Mipmap mode .\n"
" -CosinePowerMipmapChainMode:{Mipmap|Drop} Mode to use to generate Mipmap chain SpecularPower value with CosinePower filtering \n"
" -ExcludeBase Wheter the first level of mipmap will be convolved or not"
" -IrradianceCubemap specify that the Base filtering is a diffuse convolution (like a cosinus filter with a Base angle of 180).\n"
" -LightingModel:{Phong|PhongBRDF|Blinn|BlinnBRDF} Lighing model that the cubemap should match. \n"
" -GlossScale: Specify the scale component of the gloss decompression for calc specular power with CosinePowerFiltering and CosinePowerMipmapChainMode set to Mipmap"
" -GlossBias: Specify the bias component of the gloss decompression for calc specular power with CosinePowerFiltering and CosinePowerMipmapChainMode set to Mipmap"
// SL END
" -writeMipLevelIntoAlpha Encode the miplevel in the alpha channel. \n"
" -importDegamma:[float=1.0] Gamma of cube map to import. \n"
" -importMaxClamp:[float=10e30] Value to clamp input intensity values to. \n"
" -exportSize:[int=128] Size of cubemap to export\n"
" -exportScaleFactor:[float=1.0] Scale factor to apply to intensity values prior to export gamma. \n"
" -exportGamma:[float=1.0] Gamma to apply to filtered and intensity scaled cubemap prior to export. \n"
" -exportFilename:[string=Cube.dds] Filename for saving all cube faces to a single .dds file. \n"
" -exportPixelFormat:{R8G8B8|A8R8G8B8|A16B16G16R16|A16B16G16R16F|A32B32G32R32F} Output pixel encoding (.DDS files) \n"
" -exportCubeDDS Export all cube map faces within a single .dds file. \n"
" -exportMipChain Export entire mipchain when exporting cubemap. \n"
" -numFilterThreads:{1|2} Set number of filtering threads\n"
" -forceRefRast Force software rasterization for non ps.2.0+ hardware. \n"
" -exit Close CubeMapGen window after processing. \n"
);
//if not called from HDR shop e.g. --help, output additional help options
if( WCPrefixCmp(cmdArg, L"-help", &suffixStr) )
{
ConsoleOutput(consoleStdErr,
" -exportFileFormat:{BMP|JPG|PNG|DDS|DIB|HDR|PFM} Export File Format\n"
" -exportFacePrefix:[string=CubeFace] Filename prefix for series of face images. \n"
" -exportCrossPrefix:[string=CubeCross] Filename prefix for cubecross image(s). \n"
" -exportCubeFaces Export cube map as a series of face images. \n"
" -exportCubeCross Export all cube map faces in an HDRShop cube cross layout. \n"
" -importCubeDDS:[string=cube.dds] Import entire cube map from a single dds file \n"
" -importCubeCross:[string=cubecross.hdr] Import Cube Cross \n"
" -importFaceXPos:[string=xpos.hdr] Load image into the X positive cube map face of the input cubemap.\n"
" -importFaceXNeg:[string=xneg.hdr] Load image into the X negative cube map face of the input cubemap.\n"
" -importFaceYPos:[string=ypos.hdr] Load image into the Y positive cube map face of the input cubemap.\n"
" -importFaceYNeg:[string=yneg.hdr] Load image into the Y negative cube map face of the input cubemap.\n"
" -importFaceZPos:[string=zpos.hdr] Load image into the Z positive cube map face of the input cubemap.\n"
" -importFaceZNeg:[string=zneg.hdr] Load image into the Z negative cube map face of the input cubemap.\n"
" -flipFaceXPos:{H|V|D|HV|HD|VD|HVD} Flip XPos Cubemap faces {V}ertically, {H}orizontally, and/or {D}iagonally\n"
" -flipFaceXNeg:{H|V|D|HV|HD|VD|HVD} Flip XNeg Cubemap faces {V}ertically, {H}orizontally, and/or {D}iagonally\n"
" -flipFaceYPos:{H|V|D|HV|HD|VD|HVD} Flip YPos Cubemap faces {V}ertically, {H}orizontally, and/or {D}iagonally\n"
" -flipFaceYNeg:{H|V|D|HV|HD|VD|HVD} Flip YNeg Cubemap faces {V}ertically, {H}orizontally, and/or {D}iagonally\n"
" -flipFaceZPos:{H|V|D|HV|HD|VD|HVD} Flip ZPos Cubemap faces {V}ertically, {H}orizontally, and/or {D}iagonally\n"
" -flipFaceZNeg:{H|V|D|HV|HD|VD|HVD} Flip ZNeg Cubemap faces {V}ertically, {H}orizontally, and/or {D}iagonally\n"
" -consoleErrorOutput Output error messages to console. \n"
" Press any key to exit.\n\n"
);
DWORD numEvents = 0;
HANDLE conin;
conin = GetStdHandle(STD_INPUT_HANDLE);
//wait for keypress if console is activated
if(conin != NULL)
{
while(numEvents < 3)
{
GetNumberOfConsoleInputEvents(
conin,
&numEvents
);
}
}
}
exit(EM_EXIT_NO_ERROR );
}
else if( wcscmp(cmdArg, L"-forceRefRast") == 0 )
{
g_bForceRefRast = true;
}
}
//free arguement list
if(g_pArgVList != NULL)
{
GlobalFree(g_pArgVList);
}
}
//--------------------------------------------------------------------------------------
// ProcessCommandLineArguements
//--------------------------------------------------------------------------------------
void ProcessCommandLineArguements(void)
{
HWND progressDialogWnd; //progress dialog for running in HDRShopMode
WCHAR outputStr[4096];
int32 iCmdLine;
WCHAR *cmdArg;
WCHAR *suffixStr;
HANDLE consoleStdErr = NULL; //console std out handle
bool bHasBeenFiltered = false;
bool bExit = false;
bool bInvalidOption = false;
//was the export size set via the command line
bool bExportSizeSet = false;
//options to export
bool bExportCross = false;
bool bExportCubeDDS = false;
bool bExportCubeFaces = false;
bool bExportHDRShopCross = false;
bool bImportCross = false;
bool bImportCubeDDS = false;
//bool bExportCubeFaces = false;
bool m_bHDRShopMode = false;
if(g_bProcessedCommandLine == true)
{
return;
}
g_bProcessedCommandLine = true;
g_pArgVList = CommandLineToArgvW(GetCommandLineW(), &g_ArgC );
//if there is a list of command line arguements, then attach the console that launched the app
// in order to send text based output to the console
// PIERRE: At least 2 args needed, arg 0 is the process' path.
if(g_ArgC >= 2)
{
//set hourglass if command line options are being processed
SetCursor(LoadCursor(NULL, IDC_WAIT));
//AttachConsole only supported in WinXP, Win2K does not support it.
// so attach console if function pointer exists... otherwise allocate ne console
ATTACHCONSOLEPROC AttachConsoleFunc;
AttachConsoleFunc = (ATTACHCONSOLEPROC)GetProcAddress( GetModuleHandle(L"Kernel32.dll"), "AttachConsole");
//AttachConsole only supported in WinXP, Win2K does not support it.
if(AttachConsoleFunc != NULL)
{
AttachConsoleFunc(ATTACH_PARENT_PROCESS);
}
else
{ //for win2k and less just create another console
AllocConsole();
}
consoleStdErr = GetStdHandle(STD_ERROR_HANDLE);
//do not export mipchain by default in CLI mode
g_CubeGenApp.m_bExportMipChain = false;
//hide main application window during command line driven processing
ShowWindow(DXUTGetHWND(), SW_HIDE);
}
//local storage arguements specified on command line
WCHAR exportFacePrefix[_MAX_PATH] = L"CubeFace";
WCHAR exportCrossPrefix[_MAX_PATH] = L"CubeCross";
D3DXIMAGE_FILEFORMAT exportFileFormat = D3DXIFF_PFM;
WCHAR importCubeCrossFilename[_MAX_PATH] = L"input.pfm";
WCHAR HDRShopExportCubeCrossPrefix[_MAX_PATH] = L"output";
//iterate over command line arguments, note that g_pArgVList[0]
// contains the executable filename, so the list of options start at 1
for(iCmdLine=1; (iCmdLine < g_ArgC); iCmdLine++)
{
cmdArg = g_pArgVList[iCmdLine];
if( WCPrefixCmp(cmdArg, L"-consoleErrorOutput", &suffixStr) )
{ //output all error messages to the console
g_ConsoleHandle = consoleStdErr;
SetErrorMessageCallback( ConsoleOutputMessageCallback );
}
else if( WCPrefixCmp(cmdArg, L"-baseFilterAngle:", &suffixStr) )
{
g_CubeGenApp.m_BaseFilterAngle = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-initialMipFilterAngle:", &suffixStr) )
{
g_CubeGenApp.m_MipInitialFilterAngle = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-perLevelMipFilterScale:", &suffixStr) )
{
g_CubeGenApp.m_MipFilterAngleScale = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-solidAngleWeighting", &suffixStr) )
{
g_CubeGenApp.m_bUseSolidAngleWeighting = TRUE;
}
// SL BEGIN
else if( WCPrefixCmp(cmdArg, L"-CosinePower:", &suffixStr) )
{
g_CubeGenApp.m_SpecularPower = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-CosinePowerDropPerMip:", &suffixStr) )
{
g_CubeGenApp.m_CosinePowerDropPerMip = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-NumMipmap:", &suffixStr) )
{
g_CubeGenApp.m_NumMipmap = (uint32)_wtoi(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-CosinePowerMipmapChainMode:", &suffixStr) )
{
if( wcscmp(L"Mipmap", suffixStr) == 0 )
{
g_CubeGenApp.m_CosinePowerMipmapChainMode = CP_COSINEPOWER_CHAIN_MIPMAP;
}
else if( wcscmp(L"Drop", suffixStr) == 0 )
{
g_CubeGenApp.m_CosinePowerMipmapChainMode = CP_COSINEPOWER_CHAIN_DROP;
}
else
{
bInvalidOption = true;
break;
}
}
else if ( WCPrefixCmp(cmdArg, L"-ExcludeBase", &suffixStr) )
{
g_CubeGenApp.m_bExcludeBase = TRUE;
}
else if ( WCPrefixCmp(cmdArg, L"-IrradianceCubemap", &suffixStr) )
{
g_CubeGenApp.m_bIrradianceCubemap = TRUE;
}
else if( WCPrefixCmp(cmdArg, L"-LightingModel:", &suffixStr) )
{
if( wcscmp(L"Phong", suffixStr) == 0 )
{
g_CubeGenApp.m_LightingModel = CP_LIGHTINGMODEL_PHONG;
}
else if( wcscmp(L"PhongBRDF", suffixStr) == 0 )
{
g_CubeGenApp.m_LightingModel = CP_LIGHTINGMODEL_PHONG_BRDF;
}
else if( wcscmp(L"Blinn", suffixStr) == 0 )
{
g_CubeGenApp.m_LightingModel = CP_LIGHTINGMODEL_BLINN;
}
else if( wcscmp(L"BlinnBRDF", suffixStr) == 0 )
{
g_CubeGenApp.m_LightingModel = CP_LIGHTINGMODEL_BLINN_BRDF;
}
else
{
bInvalidOption = true;
break;
}
}
else if( WCPrefixCmp(cmdArg, L"-GlossScale:", &suffixStr) )
{
g_CubeGenApp.m_GlossScale = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-GlossBias:", &suffixStr) )
{
g_CubeGenApp.m_GlossBias = (float32)_wtof(suffixStr);
}
// SL END
else if( WCPrefixCmp(cmdArg, L"-writeMipLevelIntoAlpha", &suffixStr) )
{
g_CubeGenApp.m_bWriteMipLevelIntoAlpha = TRUE;
}
else if( WCPrefixCmp(cmdArg, L"-filterTech:", &suffixStr) )
{ //{Disc|Cone|AngularGaussian}\n"
if( wcscmp(L"Disc", suffixStr) == 0 )
{
g_CubeGenApp.m_FilterTech = CP_FILTER_TYPE_DISC;
}
else if( wcscmp(L"Cone", suffixStr) == 0 )
{
g_CubeGenApp.m_FilterTech = CP_FILTER_TYPE_CONE;
}
else if( wcscmp(L"Cosine", suffixStr) == 0 )
{
g_CubeGenApp.m_FilterTech = CP_FILTER_TYPE_COSINE;
}
else if( wcscmp(L"AngularGaussian", suffixStr) == 0 )
{
g_CubeGenApp.m_FilterTech = CP_FILTER_TYPE_ANGULAR_GAUSSIAN;
}
// SL BEGIN
else if( wcscmp(L"CosinePower", suffixStr) == 0 )
{
g_CubeGenApp.m_FilterTech = CP_FILTER_TYPE_COSINE_POWER;
}
// SL END
else
{
bInvalidOption = true;
break;
}
}
else if( WCPrefixCmp(cmdArg, L"-edgeFixupTech:", &suffixStr) )
{ //{None|LinearPull|HermitePull|LinearAverage|HermiteAverage} Technique used for cubemap edge fixup \n"
if( wcscmp(L"None", suffixStr) == 0 )
{
g_CubeGenApp.m_EdgeFixupTech = CP_FIXUP_NONE;
}
else if( wcscmp(L"LinearPull", suffixStr) == 0 )
{
g_CubeGenApp.m_EdgeFixupTech = CP_FIXUP_PULL_LINEAR;
}
else if( wcscmp(L"HermitePull", suffixStr) == 0 )
{
g_CubeGenApp.m_EdgeFixupTech = CP_FIXUP_PULL_HERMITE;
}
else if( wcscmp(L"LinearAverage", suffixStr) == 0 )
{
g_CubeGenApp.m_EdgeFixupTech = CP_FIXUP_AVERAGE_LINEAR;
}
else if( wcscmp(L"HermiteAverage", suffixStr) == 0 )
{
g_CubeGenApp.m_EdgeFixupTech = CP_FIXUP_AVERAGE_HERMITE;
}
// SL BEGIN
else if( wcscmp(L"Bent", suffixStr) == 0 )
{
g_CubeGenApp.m_EdgeFixupTech = CP_FIXUP_BENT;
}
else if( wcscmp(L"Warp", suffixStr) == 0 )
{
g_CubeGenApp.m_EdgeFixupTech = CP_FIXUP_WARP;
}
else if( wcscmp(L"Stretch", suffixStr) == 0 )
{
g_CubeGenApp.m_EdgeFixupTech = CP_FIXUP_STRETCH;
}
// SL END
else
{
bInvalidOption = true;
break;
}
}
else if( WCPrefixCmp(cmdArg, L"-edgeFixupWidth:", &suffixStr) )
{
g_CubeGenApp.m_EdgeFixupWidth = (int32)_wtoi(suffixStr);
if(g_CubeGenApp.m_EdgeFixupWidth == 0)
{
g_CubeGenApp.m_bCubeEdgeFixup = FALSE;
}
else
{
g_CubeGenApp.m_bCubeEdgeFixup = TRUE;
}
}
else if( WCPrefixCmp(cmdArg, L"-importMaxClamp:", &suffixStr) )
{
g_CubeGenApp.m_InputMaxClamp = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-importDegamma:", &suffixStr) )
{
g_CubeGenApp.m_InputDegamma = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-exportSize:", &suffixStr) )
{
bExportSizeSet = true;
g_CubeGenApp.SetOutputCubeMapSize((int32)_wtoi(suffixStr));
}
else if( WCPrefixCmp(cmdArg, L"-exportScaleFactor:", &suffixStr) )
{
g_CubeGenApp.m_OutputScaleFactor = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-exportGamma:", &suffixStr) )
{
g_CubeGenApp.m_OutputGamma = (float32)_wtof(suffixStr);
}
else if( WCPrefixCmp(cmdArg, L"-importFilename:", &suffixStr) )
{
wcsncpy_s(g_CubeGenApp.m_InputCubeMapFilename, CG_MAX_FILENAME_LENGTH, suffixStr, _MAX_PATH);
}
else if( WCPrefixCmp(cmdArg, L"-exportFilename:", &suffixStr) )
{
wcsncpy_s(g_CubeGenApp.m_OutputCubeMapFilename, CG_MAX_FILENAME_LENGTH, suffixStr, _MAX_PATH);
}
else if( WCPrefixCmp(cmdArg, L"-exportFacePrefix:", &suffixStr) )
{
wcsncpy_s(exportFacePrefix, _MAX_PATH, suffixStr, _MAX_PATH);
}
else if( WCPrefixCmp(cmdArg, L"-exportCrossPrefix:", &suffixStr) )
{
wcsncpy_s(exportCrossPrefix, _MAX_PATH, suffixStr, _MAX_PATH);
}
else if( WCPrefixCmp(cmdArg, L"-exportFileFormat:", &suffixStr) )
{ //{BMP|JPG|TGA|PNG|DDS|PPM|DIB|HDR|PFM}
if( wcscmp(L"BMP", suffixStr) == 0 )
{
exportFileFormat = D3DXIFF_BMP;
}
else if( wcscmp(L"JPG", suffixStr) == 0 )
{
exportFileFormat = D3DXIFF_JPG;
}
//targa not supported on export
//else if( wcscmp(L"TGA", suffixStr) == 0 )
// {
// exportFileFormat = D3DXIFF_TGA;
//}
else if( wcscmp(L"PNG", suffixStr) == 0 )
{
exportFileFormat = D3DXIFF_PNG;
}
else if( wcscmp(L"DDS", suffixStr) == 0 )
{
exportFileFormat = D3DXIFF_DDS;
}
else if( wcscmp(L"DIB", suffixStr) == 0 )
{
exportFileFormat = D3DXIFF_DIB;
}
else if( wcscmp(L"HDR", suffixStr) == 0 )
{
exportFileFormat = D3DXIFF_HDR;
}
else if( wcscmp(L"PFM", suffixStr) == 0 )
{
exportFileFormat = D3DXIFF_PFM;
}
else
{
bInvalidOption = true;
break;
}
}
else if( WCPrefixCmp(cmdArg, L"-exportPixelFormat:", &suffixStr) )
{ //{R8G8B8| 8B8G8R8|A16R16G16B16|A16R16G16B16F|A32R32G32B32F} Output pixel encoding (.DDS files)\n"
if( wcscmp(L"A8R8G8B8", suffixStr) == 0 )
{
g_CubeGenApp.SetOutputCubeMapTexelFormat(D3DFMT_A8R8G8B8);
}
else if( wcscmp(L"R8G8B8", suffixStr) == 0 )
{
g_CubeGenApp.SetOutputCubeMapTexelFormat(D3DFMT_R8G8B8);
}
else if( wcscmp(L"A16B16G16R16", suffixStr) == 0 )
{
g_CubeGenApp.SetOutputCubeMapTexelFormat(D3DFMT_A16B16G16R16);
}