forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_viewer.cpp
More file actions
649 lines (563 loc) · 20.7 KB
/
image_viewer.cpp
File metadata and controls
649 lines (563 loc) · 20.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2014-2017 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "common/dds_readwrite.h"
#include "core/core.h"
#include "replay/replay_driver.h"
#include "replay/type_helpers.h"
#include "stb/stb_image.h"
#include "tinyexr/tinyexr.h"
class ImageViewer : public IReplayDriver
{
public:
ImageViewer(IReplayDriver *proxy, const char *filename)
: m_Proxy(proxy), m_Filename(filename), m_TextureID()
{
if(m_Proxy == NULL)
RDCERR("Unexpectedly NULL proxy at creation of ImageViewer");
// start with props so that m_Props.localRenderer is correct
m_Props = m_Proxy->GetAPIProperties();
m_Props.pipelineType = GraphicsAPI::D3D11;
m_Props.degraded = false;
m_FrameRecord.frameInfo.fileOffset = 0;
m_FrameRecord.frameInfo.frameNumber = 1;
RDCEraseEl(m_FrameRecord.frameInfo.stats);
create_array_uninit(m_FrameRecord.drawcallList, 1);
DrawcallDescription &d = m_FrameRecord.drawcallList[0];
d.drawcallID = 1;
d.eventID = 1;
d.name = filename;
RefreshFile();
create_array_uninit(m_PipelineState.m_OM.RenderTargets, 1);
m_PipelineState.m_OM.RenderTargets[0].Resource = m_TextureID;
}
virtual ~ImageViewer()
{
m_Proxy->Shutdown();
m_Proxy = NULL;
}
bool IsRemoteProxy() { return true; }
void Shutdown() { delete this; }
// pass through necessary operations to proxy
vector<WindowingSystem> GetSupportedWindowSystems()
{
return m_Proxy->GetSupportedWindowSystems();
}
uint64_t MakeOutputWindow(WindowingSystem system, void *data, bool depth)
{
return m_Proxy->MakeOutputWindow(system, data, depth);
}
void DestroyOutputWindow(uint64_t id) { m_Proxy->DestroyOutputWindow(id); }
bool CheckResizeOutputWindow(uint64_t id) { return m_Proxy->CheckResizeOutputWindow(id); }
void GetOutputWindowDimensions(uint64_t id, int32_t &w, int32_t &h)
{
m_Proxy->GetOutputWindowDimensions(id, w, h);
}
void ClearOutputWindowColor(uint64_t id, FloatVector col)
{
m_Proxy->ClearOutputWindowColor(id, col);
}
void ClearOutputWindowDepth(uint64_t id, float depth, uint8_t stencil)
{
m_Proxy->ClearOutputWindowDepth(id, depth, stencil);
}
void BindOutputWindow(uint64_t id, bool depth) { m_Proxy->BindOutputWindow(id, depth); }
bool IsOutputWindowVisible(uint64_t id) { return m_Proxy->IsOutputWindowVisible(id); }
void FlipOutputWindow(uint64_t id) { m_Proxy->FlipOutputWindow(id); }
void RenderCheckerboard() { m_Proxy->RenderCheckerboard(); }
void RenderHighlightBox(float w, float h, float scale)
{
m_Proxy->RenderHighlightBox(w, h, scale);
}
bool GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, uint32_t sample,
CompType typeHint, float *minval, float *maxval)
{
return m_Proxy->GetMinMax(m_TextureID, sliceFace, mip, sample, typeHint, minval, maxval);
}
bool GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mip, uint32_t sample,
CompType typeHint, float minval, float maxval, bool channels[4],
vector<uint32_t> &histogram)
{
return m_Proxy->GetHistogram(m_TextureID, sliceFace, mip, sample, typeHint, minval, maxval,
channels, histogram);
}
bool RenderTexture(TextureDisplay cfg)
{
cfg.texid = m_TextureID;
return m_Proxy->RenderTexture(cfg);
}
void PickPixel(ResourceId texture, uint32_t x, uint32_t y, uint32_t sliceFace, uint32_t mip,
uint32_t sample, CompType typeHint, float pixel[4])
{
m_Proxy->PickPixel(m_TextureID, x, y, sliceFace, mip, sample, typeHint, pixel);
}
uint32_t PickVertex(uint32_t eventID, const MeshDisplay &cfg, uint32_t x, uint32_t y)
{
return m_Proxy->PickVertex(eventID, cfg, x, y);
}
void BuildCustomShader(string source, string entry, const ShaderCompileFlags &compileFlags,
ShaderStage type, ResourceId *id, string *errors)
{
m_Proxy->BuildCustomShader(source, entry, compileFlags, type, id, errors);
}
void FreeCustomShader(ResourceId id) { m_Proxy->FreeTargetResource(id); }
ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx,
uint32_t sampleIdx, CompType typeHint)
{
return m_Proxy->ApplyCustomShader(shader, m_TextureID, mip, arrayIdx, sampleIdx, typeHint);
}
vector<ResourceId> GetTextures() { return {m_TextureID}; }
TextureDescription GetTexture(ResourceId id) { return m_Proxy->GetTexture(m_TextureID); }
byte *GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip,
const GetTextureDataParams ¶ms, size_t &dataSize)
{
return m_Proxy->GetTextureData(m_TextureID, arrayIdx, mip, params, dataSize);
}
// handle a couple of operations ourselves to return a simple fake log
APIProperties GetAPIProperties() { return m_Props; }
FrameRecord GetFrameRecord() { return m_FrameRecord; }
const D3D11Pipe::State &GetD3D11PipelineState() { return m_PipelineState; }
// other operations are dropped/ignored, to avoid confusion
void ReadLogInitialisation() {}
void RenderMesh(uint32_t eventID, const vector<MeshFormat> &secondaryDraws, const MeshDisplay &cfg)
{
}
vector<ResourceId> GetBuffers() { return vector<ResourceId>(); }
vector<DebugMessage> GetDebugMessages() { return vector<DebugMessage>(); }
BufferDescription GetBuffer(ResourceId id)
{
BufferDescription ret;
RDCEraseEl(ret);
return ret;
}
void SavePipelineState() {}
const D3D12Pipe::State &GetD3D12PipelineState() { return m_D3D12State; }
const GLPipe::State &GetGLPipelineState() { return m_GLState; }
const VKPipe::State &GetVulkanPipelineState() { return m_VKState; }
void ReplayLog(uint32_t endEventID, ReplayLogType replayType) {}
vector<uint32_t> GetPassEvents(uint32_t eventID) { return vector<uint32_t>(); }
vector<EventUsage> GetUsage(ResourceId id) { return vector<EventUsage>(); }
bool IsRenderOutput(ResourceId id) { return false; }
ResourceId GetLiveID(ResourceId id) { return id; }
vector<GPUCounter> EnumerateCounters() { return vector<GPUCounter>(); }
void DescribeCounter(GPUCounter counterID, CounterDescription &desc)
{
RDCEraseEl(desc);
desc.counterID = counterID;
}
vector<CounterResult> FetchCounters(const vector<GPUCounter> &counters)
{
return vector<CounterResult>();
}
void FillCBufferVariables(ResourceId shader, string entryPoint, uint32_t cbufSlot,
vector<ShaderVariable> &outvars, const vector<byte> &data)
{
}
void GetBufferData(ResourceId buff, uint64_t offset, uint64_t len, vector<byte> &retData) {}
void InitPostVSBuffers(uint32_t eventID) {}
void InitPostVSBuffers(const vector<uint32_t> &eventID) {}
MeshFormat GetPostVSBuffers(uint32_t eventID, uint32_t instID, MeshDataStage stage)
{
MeshFormat ret;
RDCEraseEl(ret);
return ret;
}
ResourceId RenderOverlay(ResourceId texid, CompType typeHint, DebugOverlay overlay,
uint32_t eventID, const vector<uint32_t> &passEvents)
{
return ResourceId();
}
ShaderReflection *GetShader(ResourceId shader, string entryPoint) { return NULL; }
vector<string> GetDisassemblyTargets() { return {"N/A"}; }
string DisassembleShader(const ShaderReflection *refl, const string &target) { return ""; }
bool HasCallstacks() { return false; }
void InitCallstackResolver() {}
Callstack::StackResolver *GetCallstackResolver() { return NULL; }
void FreeTargetResource(ResourceId id) {}
vector<PixelModification> PixelHistory(vector<EventUsage> events, ResourceId target, uint32_t x,
uint32_t y, uint32_t slice, uint32_t mip,
uint32_t sampleIdx, CompType typeHint)
{
return vector<PixelModification>();
}
ShaderDebugTrace DebugVertex(uint32_t eventID, uint32_t vertid, uint32_t instid, uint32_t idx,
uint32_t instOffset, uint32_t vertOffset)
{
ShaderDebugTrace ret;
RDCEraseEl(ret);
return ret;
}
ShaderDebugTrace DebugPixel(uint32_t eventID, uint32_t x, uint32_t y, uint32_t sample,
uint32_t primitive)
{
ShaderDebugTrace ret;
RDCEraseEl(ret);
return ret;
}
ShaderDebugTrace DebugThread(uint32_t eventID, const uint32_t groupid[3],
const uint32_t threadid[3])
{
ShaderDebugTrace ret;
RDCEraseEl(ret);
return ret;
}
void BuildTargetShader(string source, string entry, const ShaderCompileFlags &compileFlags,
ShaderStage type, ResourceId *id, string *errors)
{
}
void ReplaceResource(ResourceId from, ResourceId to) {}
void RemoveReplacement(ResourceId id) {}
// these are proxy functions, and will never be used
ResourceId CreateProxyTexture(const TextureDescription &templateTex)
{
RDCERR("Calling proxy-render functions on an image viewer");
return ResourceId();
}
void SetProxyTextureData(ResourceId texid, uint32_t arrayIdx, uint32_t mip, byte *data,
size_t dataSize)
{
RDCERR("Calling proxy-render functions on an image viewer");
}
bool IsTextureSupported(const ResourceFormat &format) { return true; }
bool NeedRemapForFetch(const ResourceFormat &format) { return false; }
ResourceId CreateProxyBuffer(const BufferDescription &templateBuf)
{
RDCERR("Calling proxy-render functions on an image viewer");
return ResourceId();
}
void SetProxyBufferData(ResourceId bufid, byte *data, size_t dataSize)
{
RDCERR("Calling proxy-render functions on an image viewer");
}
void FileChanged() { RefreshFile(); }
private:
void RefreshFile();
APIProperties m_Props;
FrameRecord m_FrameRecord;
D3D11Pipe::State m_PipelineState;
D3D12Pipe::State m_D3D12State;
VKPipe::State m_VKState;
GLPipe::State m_GLState;
IReplayDriver *m_Proxy;
string m_Filename;
ResourceId m_TextureID;
TextureDescription m_TexDetails;
};
ReplayStatus IMG_CreateReplayDevice(const char *logfile, IReplayDriver **driver)
{
FILE *f = FileIO::fopen(logfile, "rb");
if(!f)
return ReplayStatus::FileIOFailed;
// make sure the file is a type we recognise before going further
if(is_exr_file(f))
{
const char *err = NULL;
FileIO::fseek64(f, 0, SEEK_END);
uint64_t size = FileIO::ftell64(f);
FileIO::fseek64(f, 0, SEEK_SET);
std::vector<byte> buffer;
buffer.resize((size_t)size);
FileIO::fread(&buffer[0], 1, buffer.size(), f);
EXRImage exrImage;
InitEXRImage(&exrImage);
int ret = ParseMultiChannelEXRHeaderFromMemory(&exrImage, &buffer[0], &err);
FreeEXRImage(&exrImage);
// could be an unsupported form of EXR, like deep image or other
if(ret != 0)
{
FileIO::fclose(f);
RDCERR(
"EXR file detected, but couldn't load with ParseMultiChannelEXRHeaderFromMemory %d: '%s'",
ret, err);
return ReplayStatus::ImageUnsupported;
}
}
else if(stbi_is_hdr_from_file(f))
{
FileIO::fseek64(f, 0, SEEK_SET);
int ignore = 0;
float *data = stbi_loadf_from_file(f, &ignore, &ignore, &ignore, 4);
if(!data)
{
FileIO::fclose(f);
RDCERR("HDR file recognised, but couldn't load with stbi_loadf_from_file");
return ReplayStatus::ImageUnsupported;
}
free(data);
}
else if(is_dds_file(f))
{
FileIO::fseek64(f, 0, SEEK_SET);
dds_data read_data = load_dds_from_file(f);
if(read_data.subdata == NULL)
{
FileIO::fclose(f);
RDCERR("DDS file recognised, but couldn't load");
return ReplayStatus::ImageUnsupported;
}
for(int i = 0; i < read_data.slices * read_data.mips; i++)
delete[] read_data.subdata[i];
delete[] read_data.subdata;
delete[] read_data.subsizes;
}
else
{
int width = 0, height = 0;
int ignore = 0;
int ret = stbi_info_from_file(f, &width, &height, &ignore);
// just in case (we shouldn't have come in here if this weren't true), make sure
// the format is supported
if(ret == 0 || width <= 0 || width >= 65536 || height <= 0 || height >= 65536)
{
FileIO::fclose(f);
return ReplayStatus::ImageUnsupported;
}
byte *data = stbi_load_from_file(f, &ignore, &ignore, &ignore, 4);
if(!data)
{
FileIO::fclose(f);
RDCERR("File recognised, but couldn't load with stbi_load_from_file");
return ReplayStatus::ImageUnsupported;
}
free(data);
}
FileIO::fclose(f);
IReplayDriver *proxy = NULL;
auto status = RenderDoc::Inst().CreateReplayDriver(RDC_Unknown, NULL, &proxy);
if(status != ReplayStatus::Succeeded || !proxy)
{
if(proxy)
proxy->Shutdown();
return status;
}
*driver = new ImageViewer(proxy, logfile);
return ReplayStatus::Succeeded;
}
void ImageViewer::RefreshFile()
{
FILE *f = NULL;
for(int attempt = 0; attempt < 10 && f == NULL; attempt++)
{
f = FileIO::fopen(m_Filename.c_str(), "rb");
if(f)
break;
Threading::Sleep(40);
}
if(!f)
{
RDCERR("Couldn't open %s! Exclusive lock elsewhere?", m_Filename.c_str());
return;
}
TextureDescription texDetails;
ResourceFormat rgba8_unorm;
rgba8_unorm.compByteWidth = 1;
rgba8_unorm.compCount = 4;
rgba8_unorm.compType = CompType::UNorm;
rgba8_unorm.type = ResourceFormatType::Regular;
ResourceFormat rgba32_float = rgba8_unorm;
rgba32_float.compByteWidth = 4;
rgba32_float.compType = CompType::Float;
texDetails.creationFlags = TextureCategory::SwapBuffer | TextureCategory::ColorTarget;
texDetails.cubemap = false;
texDetails.customName = true;
texDetails.name = m_Filename;
texDetails.ID = m_TextureID;
texDetails.byteSize = 0;
texDetails.msQual = 0;
texDetails.msSamp = 1;
texDetails.format = rgba8_unorm;
// reasonable defaults
texDetails.dimension = 2;
texDetails.arraysize = 1;
texDetails.width = 1;
texDetails.height = 1;
texDetails.depth = 1;
texDetails.mips = 1;
byte *data = NULL;
size_t datasize = 0;
bool dds = false;
if(is_exr_file(f))
{
texDetails.format = rgba32_float;
FileIO::fseek64(f, 0, SEEK_END);
uint64_t size = FileIO::ftell64(f);
FileIO::fseek64(f, 0, SEEK_SET);
std::vector<byte> buffer;
buffer.resize((size_t)size);
FileIO::fread(&buffer[0], 1, buffer.size(), f);
EXRImage exrImage;
InitEXRImage(&exrImage);
const char *err = NULL;
int ret = ParseMultiChannelEXRHeaderFromMemory(&exrImage, &buffer[0], &err);
if(ret != 0)
{
RDCERR(
"EXR file detected, but couldn't load with ParseMultiChannelEXRHeaderFromMemory %d: '%s'",
ret, err);
FileIO::fclose(f);
return;
}
texDetails.width = exrImage.width;
texDetails.height = exrImage.height;
datasize = texDetails.width * texDetails.height * 4 * sizeof(float);
data = (byte *)malloc(datasize);
for(int i = 0; i < exrImage.num_channels; i++)
exrImage.requested_pixel_types[i] = TINYEXR_PIXELTYPE_FLOAT;
ret = LoadMultiChannelEXRFromMemory(&exrImage, &buffer[0], &err);
int channels[4] = {-1, -1, -1, -1};
for(int i = 0; i < exrImage.num_channels; i++)
{
switch(exrImage.channel_names[i][0])
{
case 'R': channels[0] = i; break;
case 'G': channels[1] = i; break;
case 'B': channels[2] = i; break;
case 'A': channels[3] = i; break;
}
}
float *rgba = (float *)data;
float **src = (float **)exrImage.images;
for(uint32_t i = 0; i < texDetails.width * texDetails.height; i++)
{
for(int c = 0; c < 4; c++)
{
if(channels[c] >= 0)
rgba[i * 4 + c] = src[channels[c]][i];
else if(c < 3) // RGB channels default to 0
rgba[i * 4 + c] = 0.0f;
else // alpha defaults to 1
rgba[i * 4 + c] = 1.0f;
}
}
FreeEXRImage(&exrImage);
// shouldn't get here but let's be safe
if(ret != 0)
{
free(data);
RDCERR("EXR file detected, but couldn't load with LoadEXRFromMemory %d: '%s'", ret, err);
FileIO::fclose(f);
return;
}
}
else if(stbi_is_hdr_from_file(f))
{
texDetails.format = rgba32_float;
FileIO::fseek64(f, 0, SEEK_SET);
int ignore = 0;
data = (byte *)stbi_loadf_from_file(f, (int *)&texDetails.width, (int *)&texDetails.height,
&ignore, 4);
datasize = texDetails.width * texDetails.height * 4 * sizeof(float);
}
else if(is_dds_file(f))
{
dds = true;
}
else
{
int ignore = 0;
int ret = stbi_info_from_file(f, (int *)&texDetails.width, (int *)&texDetails.height, &ignore);
// just in case (we shouldn't have come in here if this weren't true), make sure
// the format is supported
if(ret == 0 || texDetails.width == 0 || texDetails.width == ~0U || texDetails.height == 0 ||
texDetails.height == ~0U)
{
FileIO::fclose(f);
return;
}
texDetails.format = rgba8_unorm;
data = stbi_load_from_file(f, (int *)&texDetails.width, (int *)&texDetails.height, &ignore, 4);
datasize = texDetails.width * texDetails.height * 4 * sizeof(byte);
}
// if we don't have data at this point (and we're not a dds file) then the
// file was corrupted and we failed to load it
if(!dds && data == NULL)
{
FileIO::fclose(f);
return;
}
m_FrameRecord.frameInfo.initDataSize = 0;
m_FrameRecord.frameInfo.persistentSize = 0;
m_FrameRecord.frameInfo.uncompressedFileSize = datasize;
dds_data read_data = {0};
if(dds)
{
FileIO::fseek64(f, 0, SEEK_SET);
read_data = load_dds_from_file(f);
if(read_data.subdata == NULL)
{
FileIO::fclose(f);
return;
}
texDetails.cubemap = read_data.cubemap;
texDetails.arraysize = read_data.slices;
texDetails.width = read_data.width;
texDetails.height = read_data.height;
texDetails.depth = read_data.depth;
texDetails.mips = read_data.mips;
texDetails.format = read_data.format;
texDetails.dimension = 1;
if(texDetails.width > 1)
texDetails.dimension = 2;
if(texDetails.depth > 1)
texDetails.dimension = 3;
m_FrameRecord.frameInfo.uncompressedFileSize = 0;
for(uint32_t i = 0; i < texDetails.arraysize * texDetails.mips; i++)
m_FrameRecord.frameInfo.uncompressedFileSize += read_data.subsizes[i];
}
m_FrameRecord.frameInfo.compressedFileSize = m_FrameRecord.frameInfo.uncompressedFileSize;
// recreate proxy texture if necessary.
// we rewrite the texture IDs so that the
// outside world doesn't need to know about this
// (we only ever have one texture in the image
// viewer so we can just set all texture IDs
// used to that).
if(m_TextureID != ResourceId())
{
if(m_TexDetails.width != texDetails.width || m_TexDetails.height != texDetails.height ||
m_TexDetails.depth != texDetails.depth || m_TexDetails.cubemap != texDetails.cubemap ||
m_TexDetails.mips != texDetails.mips || m_TexDetails.arraysize != texDetails.arraysize ||
m_TexDetails.width != texDetails.width || m_TexDetails.format != texDetails.format)
{
m_TextureID = ResourceId();
}
}
if(m_TextureID == ResourceId())
m_TextureID = m_Proxy->CreateProxyTexture(texDetails);
if(!dds)
{
m_Proxy->SetProxyTextureData(m_TextureID, 0, 0, data, datasize);
free(data);
}
else
{
for(uint32_t i = 0; i < texDetails.arraysize * texDetails.mips; i++)
{
m_Proxy->SetProxyTextureData(m_TextureID, i / texDetails.mips, i % texDetails.mips,
read_data.subdata[i], (size_t)read_data.subsizes[i]);
delete[] read_data.subdata[i];
}
delete[] read_data.subdata;
delete[] read_data.subsizes;
}
FileIO::fclose(f);
}