-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGUIs_DebugWindow.cpp
5631 lines (4663 loc) · 156 KB
/
GUIs_DebugWindow.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
/* Version: MPL 1.1/LGPL 3.0
*
* "The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is the Oblivion Graphics Extender, short OBGE.
*
* The Initial Developer of the Original Code is
* Ethatron <[email protected]>. Portions created by The Initial
* Developer are Copyright (C) 2011 The Initial Developer.
* All Rights Reserved.
*
* Contributor(s):
* Timeslip (Version 1)
* scanti (Version 2)
* IlmrynAkios (Version 3)
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU Library General Public License Version 3 license (the
* "LGPL License"), in which case the provisions of LGPL License are
* applicable instead of those above. If you wish to allow use of your
* version of this file only under the terms of the LGPL License and not
* to allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL License.
* If you do not delete the provisions above, a recipient may use your
* version of this file under either the MPL or the LGPL License."
*/
#ifndef OBGE_NOSHADER
#include <assert.h>
#include "obse/Utilities.h"
#include "GlobalSettings.h"
#include "D3D9.hpp"
#include "D3D9Device.hpp"
#include "GUIs_DebugWindow.hpp"
#ifdef OBGE_DEVLING
#include "EffectManager.h"
#include "ShaderManager.h"
#include "TextureConversions.h"
#include "TextureManager.h"
#include "TextureIOHook.hpp"
#include "Half.hpp"
static global<bool> DWEnabled(false, NULL, "General", "bEnabledDW");
static global<bool> FullScreen(0, "Oblivion.ini", "Display", "bFull Screen");
#define OBGE_wx
#ifndef OBGE_wx
DebugWindow::DebugWindow()
:m_window(NULL), m_parent(NULL), m_master(NULL), m_button(NULL), m_editText(NULL), m_editText2(NULL)
{
m_master = GetActiveWindow();
// register our window class
WNDCLASS windowClass =
{
0, // style
_WindowProc, // window proc
0, 0, // no extra memory required
GetModuleHandle(NULL), // instance
NULL, NULL, // icon, cursor
(HBRUSH)(COLOR_BACKGROUND + 1), // background brush
NULL, // menu name
"OBGEWindow" // class name
};
ATOM classAtom = RegisterClass(&windowClass);
ASSERT(classAtom);
CreateWindow(
(LPCTSTR)classAtom, // class
"OBGE Frame-Walker", // name
WS_OVERLAPPEDWINDOW | WS_SIZEBOX | WS_VISIBLE, // style
-100, 0, // x y
300, 300, // width height
NULL/*GetActiveWindow()*/, // parent
NULL, // menu
GetModuleHandle(NULL), // instance
(LPVOID)this);
}
DebugWindow::~DebugWindow()
{
if(m_window)
DestroyWindow(m_window);
}
void DebugWindow::PumpEvents(void)
{
MSG msg;
m_done = false;
while(!m_done)
{
BOOL result = GetMessage(&msg, m_window, 0, 0);
if(result == -1)
{
_MESSAGE("message pump error");
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
if(result == 0)
break;
}
}
LRESULT DebugWindow::WindowProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
// _MESSAGE("windowproc: %08X %08X %08X", msg, wParam, lParam);
switch(msg)
{
case WM_CREATE:
m_button = CreateWindow(
"BUTTON",
"Push Button", // receive bacon
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0,
100, 30,
m_window,
NULL,
GetModuleHandle(NULL),
NULL);
m_editText = CreateWindow(
"EDIT",
NULL,
WS_CHILD | WS_VISIBLE | ES_LEFT,
0, 30,
100, 30,
m_window,
NULL,
GetModuleHandle(NULL),
NULL);
m_editText2 = CreateWindow(
"EDIT",
NULL,
WS_CHILD | WS_VISIBLE | ES_LEFT,
110, 30,
100, 30,
m_window,
NULL,
GetModuleHandle(NULL),
NULL);
ASSERT(m_button && m_editText);
break;
case WM_COMMAND:
{
HWND source = (HWND)lParam;
if(source == m_button)
{
OnButtonHit();
}
}
break;
case WM_ACTIVATE:
// if (m_parent)
// SendMessage(m_parent, msg, wParam, lParam);
// if (m_master)
// SendMessage(m_master, msg, wParam, lParam);
if (wParam == WA_ACTIVE) {
SetCursor(LoadCursor(NULL, IDC_ARROW));
ShowCursor(TRUE);
}
break;
case WM_SETFOCUS:
// if (m_parent)
// SetFocus(m_parent);
// if (m_master)
// SetFocus(m_master);
ShowCursor(TRUE);
// SetFocus(m_window);
break;
case WM_DESTROY:
m_done = true;
break;
};
return DefWindowProc(m_window, msg, wParam, lParam);
}
LRESULT DebugWindow::_WindowProc(HWND window, UINT msg, WPARAM wParam, LPARAM lParam)
{
DebugWindow * _this = NULL;
if(msg == WM_CREATE)
{
CREATESTRUCT * info = (CREATESTRUCT *)lParam;
_this = (DebugWindow *)info->lpCreateParams;
SetWindowLongPtr(window, GWLP_USERDATA, (LONG_PTR)_this);
_this->m_window = window;
_this->m_parent = GetParent(window);
}
else
{
_this = (DebugWindow *)GetWindowLongPtr(window, GWLP_USERDATA);
}
LRESULT result;
if(_this)
result = _this->WindowProc(msg, wParam, lParam);
else
result = DefWindowProc(window, msg, wParam, lParam);
return result;
}
void DebugWindow::OnButtonHit(void)
{
}
HWND DebugWindow::ControlActiveWindow(HWND org) {
if ((org == m_master) && (m_window != NULL))
return m_window;
return org;
}
#else
/* ---------------------------------------- */
#include <msvc/wx/setup.h>
#include <wx/init.h>
#include <wx/app.h>
#include <wx/dialog.h>
#include <wx/dirdlg.h>
#include <wx/filedlg.h>
#include <wx/filename.h>
#include <wx/string.h>
#include <wx/gauge.h>
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#pragma comment(lib,"Comctl32")
#pragma comment(lib,"Rpcrt4")
#if defined(OGBE_PROFILE) || 1
#include <wx/xy/xyplot.h>
#include <wx/xy/xysimpledataset.h>
#include <wx/xy/xydynamicdataset.h>
#include <wx/xy/xylinerenderer.h>
#include <wx/xy/xyarearenderer.h>
#include <wx/chart.h>
#include <wx/chartpanel.h>
#ifndef NDEBUG
#pragma comment(lib,"wxcode_msw28d_freechart")
#else
#pragma comment(lib,"wxcode_msw28_freechart")
#endif
#endif
#include "EffectManager.h"
#define RETURN_RGB(r,g,b) (((int)(r * 0xFF) & 0xFF) | ((int)(g * 0xFFFF) & 0xFF00) | ((int)(b * 0xFFFFFF) & 0xFF0000))
static int POStoRGB(int pos, int max) {
// RGB are each returned on [0, 1].
float h = (6.0 * pos) / max, s = 1.0, v = 1.0, m, n, f;
int i;
i = floor(h);
f = h - i;
if ( !(i&1) ) f = 1 - f; // if i is even
m = v * (1 - s);
n = v * (1 - s * f);
switch (i) {
case 6:
case 0: return RETURN_RGB(v, n, m);
case 1: return RETURN_RGB(n, v, m);
case 2: return RETURN_RGB(m, v, n);
case 3: return RETURN_RGB(m, n, v);
case 4: return RETURN_RGB(n, m, v);
case 5: return RETURN_RGB(v, m, n);
}
return 0;
}
#include "GUIs_ShaderDeveloper.h"
#include "GUIs_ShaderDeveloper.cpp"
#define SDVIEW_SHADER 0
#define SDVIEW_EFFECT 1
#define SDVIEW_SCENES 2
#define SDVIEW_STATS 3
#define SDSURF_PRIMARY 0
#define SDSURF_GRABBED 1
#define SDSURF_DEPTH 2
#define wxBName wxString((*BShader)->Name)
#define wxMName wxString((*MEffect)->Name)
#define wxBMError wxBitmap(wxT("#107"), wxBITMAP_TYPE_RESOURCE)
#define wxBMWarning wxBitmap(wxT("#108"), wxBITMAP_TYPE_RESOURCE)
#define wxBMMissing wxBitmap(wxT("#110"), wxBITMAP_TYPE_RESOURCE)
#define wxBMUnhooked wxBitmap(wxT("#109"), wxBITMAP_TYPE_RESOURCE)
#define wxBMApplied wxBitmap(wxT("#106"), wxBITMAP_TYPE_RESOURCE)
///////////////////////////////////////////////////////////////////////////////
/// Class wxShaderDeveloper
///////////////////////////////////////////////////////////////////////////////
class GUIs_ShaderDeveloper : public wxShaderDeveloper
{
public:
GUIs_ShaderDeveloper(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 630,704 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL) :
wxShaderDeveloper(parent, id, title, pos, size, style) {
DefaultStyle.SetTextColour(wxColour("BLACK"));
CommentStyle.SetTextColour(wxColour("SEA GREEN"));
KeywordStyle.SetTextColour(wxColour("BLUE"));
FunctionStyle.SetTextColour(wxColour("RED"));
DeclaresStyle.SetTextColour(wxColour("ORANGE"));
/* start enabling these functions */
SDButtonEffectNew->Enable();
SDToolsSettings->FindChildItem(wxID_MIPGAMMA, NULL)->Check(true);
SDToolsSettings->FindChildItem(wxID_AMPLIFY, NULL)->Check(true);
SDTweaks->FindChildItem(wxID_LINEAR, NULL)->Enable(true);
SDTweaks->FindChildItem(wxID_LINEAR, NULL)->Check(DeGamma && ReGamma);
if (1 > lastOBGEDirect3D9CAPS.MaxAnisotropy)
SDTweaksAF->FindChildItem(wxID_AF1, NULL)->Enable(false);
else if (1 == Anisotropy)
SDTweaksAF->FindChildItem(wxID_AF1, NULL)->Check(true);
if (2 > lastOBGEDirect3D9CAPS.MaxAnisotropy)
SDTweaksAF->FindChildItem(wxID_AF2, NULL)->Enable(false);
else if (2 == Anisotropy)
SDTweaksAF->FindChildItem(wxID_AF2, NULL)->Check(true);
if (4 > lastOBGEDirect3D9CAPS.MaxAnisotropy)
SDTweaksAF->FindChildItem(wxID_AF4, NULL)->Enable(false);
else if (4 == Anisotropy)
SDTweaksAF->FindChildItem(wxID_AF4, NULL)->Check(true);
if (8 > lastOBGEDirect3D9CAPS.MaxAnisotropy)
SDTweaksAF->FindChildItem(wxID_AF8, NULL)->Enable(false);
else if (8 == Anisotropy)
SDTweaksAF->FindChildItem(wxID_AF8, NULL)->Check(true);
if (16 > lastOBGEDirect3D9CAPS.MaxAnisotropy)
SDTweaksAF->FindChildItem(wxID_AF16, NULL)->Enable(false);
else if (16 == Anisotropy)
SDTweaksAF->FindChildItem(wxID_AF16, NULL)->Check(true);
if (32 > lastOBGEDirect3D9CAPS.MaxAnisotropy)
SDTweaksAF->FindChildItem(wxID_AF32, NULL)->Enable(false);
else if (32 == Anisotropy)
SDTweaksAF->FindChildItem(wxID_AF32, NULL)->Check(true);
#if 0
SDStatusGauge = new wxGauge(SDStatusBar, wxID_ANY, 100);
SDStatusGauge->SetValue(50);
SDStatusGauge->SetSize(400, 8);
SDStatusText = new wxStaticText(SDStatusBar, wxID_ANY, wxT("..."), wxDefaultPosition, wxDefaultSize, 0);
SDStatusSizerV = new wxBoxSizer( wxVERTICAL );
SDStatusSizerH = new wxBoxSizer( wxHORIZONTAL );
SDStatusSizerH->Add(SDStatusText, 1, wxALL | wxALIGN_CENTER_VERTICAL, 0);
SDStatusSizerH->Add(SDStatusGauge, 1, wxALL | wxALIGN_CENTER_VERTICAL, 0);
SDStatusSizerV->Add(SDStatusSizerH, 0, wxEXPAND | wxLEFT | wxRIGHT, 5);
SDStatusBar->SetSizer(SDStatusSizerV);
SDStatusBar->Layout();
SDStatusSizerV->Fit(SDStatusBar);
#endif
SDStatusBar->SetStatusText(wxT("Ready"), 0);
#if defined(OGBE_PROFILE) || 1
memset(hist, 0, sizeof(hist));
// assert(NULL);
// first step: create plot
plot = new XYPlot();
// set line renderer to dataset & prevent deletion
// rndr = new XYLineStepRenderer();
// rndr = new XYLineRenderer();
rndrP = new XYAreaRenderer(); rndrP->AddRef();
rndrS = new XYAreaRenderer(); rndrS->AddRef();
// create dataset
vset = new XYDynamicDataset();
vset->AddRef();
// set line renderer to dataset
vset->SetRenderer(rndrP);
// add our dataset to plot
plot->AddDataset(vset);
// create dataset
hist[OBGEPASS_ANY].dset = new XYDynamicDataset();
hist[OBGEPASS_ANY].dset->AddRef();
// set line renderer to dataset
hist[OBGEPASS_ANY].dset->SetRenderer(rndrP);
for (int p = OBGEPASS_MAX; p >= OBGEPASS_MIN; p--) {
// create dataset
hist[p].dset = new XYDynamicDataset();
hist[p].dset->AddRef();
// set line renderer to dataset
hist[p].dset->SetRenderer(rndrS);
}
aset = NULL;
// create left and bottom number axes
leftAxis = new NumberAxis(AXIS_LEFT);
bottomAxis = new NumberAxis(AXIS_BOTTOM);
// optional: set axis titles
leftAxis->SetTitle(wxT("ms"));
bottomAxis->SetTitle(wxT("Frame"));
// add axes to plot
plot->AddAxis(leftAxis);
plot->AddAxis(bottomAxis);
// link axes and dataset
plot->LinkDataVerticalAxis(0, 0);
plot->LinkDataHorizontalAxis(0, 0);
// set legend to plot
plot->SetLegend(new Legend(wxTOP, wxLEFT));
// and finally create chart
chrt = new Chart(plot, wxString("Performance Graph"));
// And finally create chart panel to display it:
st = new wxChartPanel(SDStatsView, wxID_ANY, chrt, wxPoint(0,0), wxSize(256, 256));
st->SetAntialias(true);
ChartSizer = new wxBoxSizer( wxVERTICAL );
ChartSizer->Add(st, 1, wxEXPAND | wxALL, 0);
SDStatsView->SetSizer(ChartSizer);
// SDStatsView->Layout();
ChartSizer->Fit(SDStatsView);
// ChartSizer->Layout();
SDPanelStatsTop->Layout();
normed = false;
#endif
ProgressSubject = "...";
}
//wxGauge *SDStatusGauge;
//wxStaticText *SDStatusText;
//wxBoxSizer *SDStatusSizerV;
//wxBoxSizer *SDStatusSizerH;
ShaderManager *sm;
EffectManager *em;
wxImage rt, gt, ds;
wxMemoryDC crt, grt, cds, sts;
wxString ProgressSubject;
#if defined(OGBE_PROFILE) || 1
NumberAxis *leftAxis, *bottomAxis;
XYAreaRenderer *rndrP;
XYAreaRenderer *rndrS;
XYPlot *plot;
Chart *chrt;
wxChartPanel *st;
wxBoxSizer *ChartSizer;
XYDynamicDataset *vset, *aset;
bool normed;
struct history {
int hconsm, maxcol;
XYDynamicDataset *dset;
XYDynamicSerie *series[OBGESCENE_NUM + 1];
} hist[OBGEPASS_NUM];
#endif
ShaderRecord *currs;
EffectRecord *currx;
int currv, currh;
int fs[4];
int pass;
int scene;
/* --------------------------------------------------------------
*/
std::vector<wxString> keywordsHLSL;
std::vector<wxString> keywordsAsm;
std::vector<char> symbols;
wxTextAttr DefaultStyle;
wxTextAttr CommentStyle;
wxTextAttr KeywordStyle;
wxTextAttr FunctionStyle;
wxTextAttr DeclaresStyle;
wxTextAttr PreprocessorStyle;
wxTextAttr SymbolStyle;
/* --------------------------------------------------------------
*/
IDirect3DSurface9 *FindGrabbedRT(int offs = 0) {
if (pass == OBGEPASS_EFFECTS) {
if (em && em->CurrDS.Srf[0])
return em->CurrDS.Srf[0];
}
/* search shader render-targets */
RuntimeShaderList::iterator RS = sm->RuntimeShaders.begin();
while (RS != sm->RuntimeShaders.end()) {
if (pass == OBGEPASS_ANY) {
for (int p = OBGEPASS_MIN; p < OBGEPASS_NUM; p++)
if ((*RS)->rsb[p].pTextRT && (*RS)->rsb[p].pGrabRT)
if (--offs < 0)
return (*RS)->rsb[p].pGrabRT;
}
else {
if ((*RS)->rsb[pass].pTextRT && (*RS)->rsb[pass].pGrabRT)
return (*RS)->rsb[pass].pGrabRT;
}
RS++;
}
return NULL;
}
IDirect3DSurface9 *FindGrabbedDS(int offs = 0) {
if (pass == OBGEPASS_EFFECTS) {
if (em && em->CurrDS.Srf[0])
return em->CurrDS.Srf[0];
}
/* search shader render-targets */
RuntimeShaderList::iterator RS = sm->RuntimeShaders.begin();
while (RS != sm->RuntimeShaders.end()) {
if (pass == OBGEPASS_ANY) {
for (int p = OBGEPASS_MIN; p < OBGEPASS_NUM; p++)
if ((*RS)->rsb[p].pTextDS && (*RS)->rsb[p].pGrabDS)
if (--offs < 0)
return (*RS)->rsb[p].pGrabDS;
}
else {
if ((*RS)->rsb[pass].pTextDS && (*RS)->rsb[pass].pGrabDS)
return (*RS)->rsb[pass].pGrabDS;
}
RS++;
}
return NULL;
}
/* --------------------------------------------------------------
*/
const char *DescribeTexture(IDirect3DBaseTexture9 *tex) {
static char buf[256];
buf[0] = '\0';
if (tex) {
/* search alternate render targets */
if (em) {
if (em->OrigRT.IsTexture(tex))
return "Incoming effects-rendertarget";
if (em->TrgtRT.IsTexture(tex))
return "Outgoing effects-rendertarget";
if (em->CopyRT.IsTexture(tex))
return "Alternating[0] effects-rendertarget";
if (em->LastRT.IsTexture(tex))
return "Alternating[1] effects-rendertarget";
if (em->PrevRT.IsTexture(tex))
return "Last pass effects-rendertarget copy";
if (em->PastRT.IsTexture(tex))
return "Last frame effects-rendertarget copy";
if (em->OrigDS.IsTexture(tex))
return "Incoming effects-zbuffer";
if (em->CurrDS.IsTexture(tex))
return "Converted effects-zbuffer";
/* search shader render-targets */
ManagedQueueList::iterator RS = em->CustomQueues.begin();
while (RS != em->CustomQueues.end()) {
if (RS->second.OrigRT.IsTexture(tex))
return "Incoming effects-customtarget";
if (RS->second.TrgtRT.IsTexture(tex))
return "Outgoing effects-customtarget";
if (RS->second.LastRT.IsTexture(tex))
return "Alternating effects-customtarget";
RS++;
}
}
/* search render targets */
if (sm) {
for (int p = OBGEPASS_MIN; p < OBGEPASS_NUM; p++)
for (int s = 0; s < sm->trackd[p].frame_cntr; s++) {
IDirect3DSurface9 *pRenderTarget;
textureSurface *pTextureSurface;
if ((pRenderTarget = sm->trackd[p].rt[s]) && ((int)pRenderTarget != -1)) {
if ((pTextureSurface = surfaceTexture[pRenderTarget])) {
if (pTextureSurface->tex == tex) {
sprintf(buf, "RT of pass %d, scene %d", p, s);
return buf;
}
}
}
}
/* search shader render-targets */
RuntimeShaderList::iterator RS = sm->RuntimeShaders.begin();
while (RS != sm->RuntimeShaders.end()) {
for (int p = OBGEPASS_MIN; p < OBGEPASS_NUM; p++) {
if ((*RS)->rsb[p].pTextRT == tex) {
if ((*RS)->pAssociate)
sprintf(buf, "%s pass %d rendertarget copy", (*RS)->pAssociate->Name, p);
else
sprintf(buf, "Unknown shader pass %d rendertarget copy", p);
return buf;
}
if ((*RS)->rsb[p].pTextDS == tex) {
if ((*RS)->pAssociate)
sprintf(buf, "%s pass %d depth-stencil copy", (*RS)->pAssociate->Name, p);
else
sprintf(buf, "Unknown shader pass %d depth-stencil copy", p);
return buf;
}
if ((*RS)->rsb[p].pTextDZ == tex) {
if ((*RS)->pAssociate)
sprintf(buf, "%s pass %d depth-stencil", (*RS)->pAssociate->Name, p);
else
sprintf(buf, "Unknown shader pass %d depth-stencil", p);
return buf;
}
}
RS++;
}
}
/* search other render-targets */
std::map <void *, struct textureMap *>::iterator TRT = textureMaps.begin();
while (TRT != textureMaps.end()) {
if (TRT->second && (TRT->second->Usage & D3DUSAGE_RENDERTARGET))
if (TRT->first == tex) {
sprintf(buf, "Unidentified rendertarget");
return buf;
}
TRT++;
}
/* search loaded texture files */
std::map<std::string, IDirect3DBaseTexture9 *>::iterator TFile = textureFiles.begin();
while (TFile != textureFiles.end()) {
if ((*TFile).second == tex) {
std::string str = (*TFile).first;
const char *ptr = str.data(), *ofs;
if ((ofs = strstr(ptr, "Textures\\")) ||
(ofs = strstr(ptr, "textures\\")) ||
(ofs = strstr(ptr, "textures/"))) {
sprintf(buf, "%s", ofs + 9);
}
else
sprintf(buf, "%s", ptr);
return buf;
}
TFile++;
}
/* search managed texture files */
TextureManager *tm = TextureManager::GetSingleton();
int TexNum = tm->FindTexture(tex); ManagedTextureRecord *Tex;
if ((TexNum != -1) && (Tex = tm->GetTexture(TexNum))) {
const char *ptr = Tex->GetPath(), *ofs;
if ((ofs = strstr(ptr, "Textures\\")) ||
(ofs = strstr(ptr, "textures\\")) ||
(ofs = strstr(ptr, "textures/"))) {
sprintf(buf, "%s", ofs + 9);
}
else
sprintf(buf, "%s", ptr);
return buf;
}
sprintf(buf, "0x%p", tex);
}
else
strcpy(buf, "cleared");
return buf;
}
/* --------------------------------------------------------------
*/
void SetShaderConstantTable(wxGrid *gt, bool prefix, LPD3DXCONSTANTTABLE c, int len, int col, int offs) {
D3DXCONSTANTTABLE_DESC desc;
D3DXCONSTANT_DESC cnst;
UINT count = 1;
char buf[256];
if (gt && c) {
if (c->GetDesc(&desc) == D3D_OK) {
if (prefix) {
gt->SetCellValue(offs + 0, col, wxString(desc.Creator));
gt->SetCellTextColour(offs + 0, col, wxColour("BLACK"));
sprintf(buf, "%d.%d", (desc.Version >> 8) & 0xFF, desc.Version & 0xFF);
gt->SetCellValue(offs + 1, col, wxString(buf));
gt->SetCellTextColour(offs + 1, col, wxColour("BLACK"));
sprintf(buf, "%d", len);
gt->SetCellValue(offs + 2, col, wxString(buf));
gt->SetCellTextColour(offs + 2, col, wxColour("BLACK"));
sprintf(buf, "%d", desc.Constants);
gt->SetCellValue(offs + 3, col, wxString(buf));
gt->SetCellTextColour(offs + 3, col, wxColour("BLACK"));
}
for (int f = D3DXRS_BOOL; f <= D3DXRS_SAMPLER; f++) {
int pos = offs + (prefix ? 4 : 0);
for (int s = D3DXRS_BOOL; s < f; s++)
pos += fs[s];
for (int r = 0; r < desc.Constants; r++) {
D3DXHANDLE handle = c->GetConstant(NULL, r);
c->GetConstantDesc(handle, &cnst, &count);
D3DXREGISTER_SET rs = cnst.RegisterSet;
// switch (cnst.Type) {
// case D3DXPT_BOOL: rs = D3DXRS_BOOL; break;
// case D3DXPT_INT: rs = D3DXRS_INT4; break;
// case D3DXPT_FLOAT: rs = D3DXRS_FLOAT4; break;
// case D3DXPT_SAMPLER:
// case D3DXPT_SAMPLER1D:
// case D3DXPT_SAMPLER2D:
// case D3DXPT_SAMPLER3D:
// case D3DXPT_SAMPLERCUBE: rs = D3DXRS_SAMPLER; break;
// }
if (rs != f)
continue;
char c = ' ';
wxColour clr;
switch (f) {
case D3DXRS_BOOL: c = 'b'; clr = wxColour("GREY"); break;
case D3DXRS_INT4: c = 'i'; clr = wxColour("SIENNA"); break;
case D3DXRS_FLOAT4: c = 'c'; clr = wxColour("BLUE"); break;
case D3DXRS_SAMPLER: c = 's'; clr = wxColour("DARK GREEN"); break;
}
/* TODO: fix up vertex-shader sampler positions */
int range = cnst.RegisterIndex + cnst.RegisterCount;
int delta = fs[f];
if (range > fs[f]) {
gt->InsertRows(pos + fs[f], range - fs[f]);
fs[f] = range;
}
for (int d = delta; d < fs[f]; d++) {
sprintf(buf, "%c%d", c, d);
gt->SetRowLabelValue(pos + d, wxString(buf));
}
for (int x = cnst.RegisterIndex, i = 0; x < range; x++, i++) {
if (cnst.Name[0]) {
if (cnst.RegisterCount > 1)
sprintf(buf, "%s[%d]", cnst.Name, i);
else
sprintf(buf, "%s", cnst.Name);
}
else {
if (cnst.RegisterCount > 1)
sprintf(buf, "c%d[%d]", x, i);
else
sprintf(buf, "c%d", x);
}
gt->SetCellTextColour(pos + x, col, clr);
gt->SetCellValue(pos + x, col, wxString(buf));
}
}
}
}
}
}
void SetShaderConstSetTable(wxGrid *gt, bool prefix, struct RuntimeShaderRecord::trace *t, int len, int col, int offs) {
char buf[256];
if (gt && t) {
{
int f = D3DXRS_BOOL; {
int pos = offs + (prefix ? 4 : 0);
for (int s = D3DXRS_BOOL; s < f; s++)
pos += fs[s];
wxColour clr = wxColour("GREY");
for (int x = 0; x < fs[f]; x++) {
assert(x < 256);
if (*((char *)&t->values_b[x]) != -1) {
sprintf(buf, "%d", t->values_b[x]);
gt->SetCellTextColour(pos + x, col, clr);
gt->SetCellValue(pos + x, col, wxString(buf));
/* non-editable cell */
wxString Description = gt->GetCellValue(pos + x, col - 1);
if ((Description.GetData() == strstr(Description.GetData(), "glob_"))) {
gt->SetReadOnly(pos + x, col, false);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ));
}
else if ((Description.GetData() == strstr(Description.GetData(), "cust_"))) {
gt->SetReadOnly(pos + x, col, false);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ));
}
else {
gt->SetReadOnly(pos + x, col, true);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ));
}
}
}
}
f = D3DXRS_INT4; {
int pos = offs + (prefix ? 4 : 0);
for (int s = D3DXRS_BOOL; s < f; s++)
pos += fs[s];
wxColour clr = wxColour("SIENNA");
for (int x = 0; x < fs[f]; x++) {
assert(x < 256);
if (*((int *)&t->values_i[x][0]) != -1) {
sprintf(buf, "%d, %d, %d, %d", t->values_i[x][0], t->values_i[x][1], t->values_i[x][2], t->values_i[x][3]);
gt->SetCellTextColour(pos + x, col, clr);
gt->SetCellValue(pos + x, col, wxString(buf));
/* non-editable cell */
wxString Description = gt->GetCellValue(pos + x, col - 1);
if ((Description.GetData() == strstr(Description.GetData(), "glob_"))) {
gt->SetReadOnly(pos + x, col, false);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ));
}
else if ((Description.GetData() == strstr(Description.GetData(), "cust_"))) {
gt->SetReadOnly(pos + x, col, false);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ));
}
else {
gt->SetReadOnly(pos + x, col, true);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ));
}
}
}
}
f = D3DXRS_FLOAT4; {
int pos = offs + (prefix ? 4 : 0);
for (int s = D3DXRS_BOOL; s < f; s++)
pos += fs[s];
wxColour clr = wxColour("BLUE");
for (int x = 0; x < fs[f]; x++) {
assert(x < 256);
if (*((int *)&t->values_c[x][0]) != -1) {
sprintf(buf, "%f, %f, %f, %f", t->values_c[x][0], t->values_c[x][1], t->values_c[x][2], t->values_c[x][3]);
gt->SetCellValue(pos + x, col, wxString(buf));
/* non-editable cell */
wxString Description = gt->GetCellValue(pos + x, col - 1);
if ((Description.GetData() == strstr(Description.GetData(), "glob_"))) {
gt->SetReadOnly(pos + x, col, false);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ));
}
else if ((Description.GetData() == strstr(Description.GetData(), "cust_"))) {
gt->SetReadOnly(pos + x, col, false);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ));
}
else {
gt->SetReadOnly(pos + x, col, true);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ));
}
wxString meaning0 = gt->GetCellValue(pos + x, col - 2);
wxString meaning1 = gt->GetCellValue(pos + x, col - 1);
if (strstr(meaning0.GetData(), "color") ||
strstr(meaning0.GetData(), "Color") ||
strstr(meaning1.GetData(), "color") ||
strstr(meaning1.GetData(), "Color")) {
unsigned long b = (unsigned long)(t->values_c[x][0] * 255);
unsigned long g = (unsigned long)(t->values_c[x][1] * 255);
unsigned long r = (unsigned long)(t->values_c[x][2] * 255);
gt->SetCellBackgroundColour(pos + x, col,
wxColour((r << 16) | (g << 8) | (b << 0)));
gt->SetCellTextColour(pos + x, col,
wxColour(((255 - r) << 16) | ((255 - g) << 8) | ((255 - b) << 0)));
}
else
gt->SetCellTextColour(pos + x, col, clr);
}
}
}
f = D3DXRS_SAMPLER; {
int pos = offs + (prefix ? 4 : 0);
for (int s = D3DXRS_BOOL; s < f; s++)
pos += fs[s];
wxColour clr = wxColour("DARK GREEN");
for (int x = 0; x < fs[f]; x++) {
assert(x < OBGESAMPLER_NUM);
if (*((int *)&t->values_s[x]) != -1) {
const char *dt = DescribeTexture(t->values_s[x]);
gt->SetCellTextColour(pos + x, col, clr);
gt->SetCellValue(pos + x, col, wxString(dt));
/* non-editable cell */
wxString Description = gt->GetCellValue(pos + x, col - 1);
if ((Description.GetData() == strstr(Description.GetData(), "glob_"))) {
gt->SetReadOnly(pos + x, col, false);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ));
}
else if ((Description.GetData() == strstr(Description.GetData(), "cust_"))) {
gt->SetReadOnly(pos + x, col, false);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ));
}
else {
gt->SetReadOnly(pos + x, col, true);
gt->SetCellBackgroundColour(pos + x, col + 0, wxSystemSettings::GetColour( wxSYS_COLOUR_3DLIGHT ));
}
}
}
}
}
}
}
void SetShaderSamplerTable(wxGrid *gt, bool prefix, struct RuntimeShaderRecord::trace *t, int len, int col, int offs) {
char buf[256];
if (gt && t) {
int pos = offs + 0, d = 0;
for (int x = 0; x < OBGESAMPLER_NUM; x++) {
/* no -1 (never set), and no 0 (cleared) */
if (*((int *)&t->values_s[x]) != -1) {
{
gt->InsertRows(pos + d, 1);
sprintf(buf, "s%d", x);
gt->SetRowLabelValue(pos + d, wxString(buf));
wxColour clr = wxColour("DARK GREEN");
gt->SetCellTextColour(pos + d, col + 0, clr);
gt->SetCellValue(pos + d, col + 0, wxString("Texture"));
gt->SetReadOnly(pos + d, col + 0, true);
const char *dt = DescribeTexture(t->values_s[x]);
gt->SetCellValue(pos + d, col + 1, wxString(dt));
gt->SetReadOnly(pos + d, col + 1, true);
d++;
}
for (int y = 0; y < 14; y++) {
if (*((int *)&t->states_s[x][y]) != -1) {
gt->InsertRows(pos + d, 1);
sprintf(buf, "s%d", x);