MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / Load

Method Load

src/Nazara/Utility/Formats/DDSLoader.cpp:41–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39 }
40
41 static bool Load(Image* image, Stream& stream, const ImageParams& parameters)
42 {
43 NazaraUnused(parameters);
44
45 ByteStream byteStream(&stream);
46 byteStream.SetDataEndianness(Endianness_LittleEndian);
47
48 UInt32 magic;
49 byteStream >> magic;
50 NazaraAssert(magic == DDS_Magic, "Invalid DDS file"); // The Check function should make sure this doesn't happen
51
52 DDSHeader header;
53 byteStream >> header;
54
55 DDSHeaderDX10Ext headerDX10;
56 if (header.format.flags & DDPF_FOURCC && header.format.fourCC == D3DFMT_DX10)
57 byteStream >> headerDX10;
58 else
59 {
60 headerDX10.arraySize = 1;
61 headerDX10.dxgiFormat = DXGI_FORMAT_UNKNOWN;
62 headerDX10.miscFlag = 0;
63 headerDX10.resourceDimension = D3D10_RESOURCE_DIMENSION_UNKNOWN;
64 }
65
66 if ((header.flags & DDSD_WIDTH) == 0)
67 NazaraWarning("Ill-formed DDS file, doesn't have a width flag");
68
69 unsigned int width = std::max(header.width, 1U);
70
71 unsigned int height = 1U;
72 if (header.flags & DDSD_HEIGHT)
73 height = std::max(header.height, 1U);
74
75 unsigned int depth = 1U;
76 if (header.flags & DDSD_DEPTH)
77 depth = std::max(header.depth, 1U);
78
79 unsigned int levelCount = (parameters.levelCount > 0) ? std::min(parameters.levelCount, static_cast<UInt8>(header.levelCount)) : header.levelCount;
80
81 // First, identify the type
82 ImageType type;
83 if (!IdentifyImageType(header, headerDX10, &type))
84 return false;
85
86 // Then the format
87 PixelFormatType format;
88 if (!IdentifyPixelFormat(header, headerDX10, &format))
89 return false;
90
91 image->Create(type, format, width, height, depth, levelCount);
92
93 // Read all mipmap levels
94 for (unsigned int i = 0; i < image->GetLevelCount(); i++)
95 {
96 std::size_t byteCount = PixelFormat::ComputeSize(format, width, height, depth);
97
98 UInt8* ptr = image->GetPixels(0, 0, 0, i);

Callers

nothing calls this directly

Calls 5

GetPixelsMethod · 0.80
ConvertMethod · 0.80
CreateMethod · 0.45
GetLevelCountMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected