SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Toggle main menu visibility
Loading...
Searching...
No Matches
VBF.cpp
Go to the documentation of this file.
1
#include <
vtfpp/VBF.h
>
2
3
#include <vector>
4
5
#include <BufferStream.h>
6
#include <
sourcepp/FS.h
>
7
8
using namespace
sourcepp
;
9
using namespace
vtfpp
;
10
11
VBF::VBF
(std::span<const std::byte> vbfData) {
12
BufferStreamReadOnly stream{vbfData};
13
14
if
(stream.read<uint32_t>() !=
VBF_SIGNATURE
) {
15
return
;
16
}
17
18
stream >> this->
version
;
19
if
(this->version != 3) {
20
this->version = 0;
21
return
;
22
}
23
24
stream >> this->
pageSize
[0] >> this->
pageSize
[1];
25
stream >> this->
maxGlyphSize
[0] >> this->
maxGlyphSize
[1];
26
stream >> this->
flags
>> this->
ascent
;
27
28
const
auto
glyphCount = stream.read<uint16_t>();
29
const
auto
glyphLUT = stream.read<std::array<uint8_t, 256>>();
30
31
std::vector<Glyph> glyphList;
32
glyphList.reserve(glyphCount);
33
for
(uint16_t i = 0; i < glyphCount; i++) {
34
auto
& [position, size, abcSpacing] = glyphList.emplace_back();
35
stream >> position[0] >> position[1];
36
stream >> size[0] >> size[1];
37
stream >> abcSpacing[0] >> abcSpacing[1] >> abcSpacing[2];
38
}
39
for
(
int
i = 0; i < this->
glyphs
.size(); i++) {
40
this->
glyphs
[i] = glyphList[glyphLUT[i]];
41
}
42
}
43
44
VBF::VBF
(
const
std::filesystem::path& vbfPath)
45
:
VBF
(
fs
::readFileBuffer(vbfPath)) {}
46
47
VBF::operator bool()
const
{
48
return
this->
version
== 3;
49
}
50
51
math::Vec2ui16
VBF::getPageSize
()
const
{
52
return
this->
pageSize
;
53
}
54
55
math::Vec2ui16
VBF::getMaxGlyphSize
()
const
{
56
return
this->
maxGlyphSize
;
57
}
58
59
VBF::Flags
VBF::getFlags
()
const
{
60
return
this->
flags
;
61
}
62
63
uint16_t
VBF::getAscent
()
const
{
64
return
this->
ascent
;
65
}
66
67
const
std::array<VBF::Glyph, 256>&
VBF::getGlyphs
()
const
{
68
return
this->
glyphs
;
69
}
FS.h
VBF.h
vtfpp::VBF::maxGlyphSize
sourcepp::math::Vec2ui16 maxGlyphSize
Definition
VBF.h:53
vtfpp::VBF::getFlags
Flags getFlags() const
Definition
VBF.cpp:59
vtfpp::VBF::getPageSize
sourcepp::math::Vec2ui16 getPageSize() const
Definition
VBF.cpp:51
vtfpp::VBF::Flags
Flags
Definition
VBF.h:16
vtfpp::VBF::ascent
uint16_t ascent
Definition
VBF.h:55
vtfpp::VBF::getMaxGlyphSize
sourcepp::math::Vec2ui16 getMaxGlyphSize() const
Definition
VBF.cpp:55
vtfpp::VBF::glyphs
std::array< Glyph, 256 > glyphs
Definition
VBF.h:56
vtfpp::VBF::pageSize
sourcepp::math::Vec2ui16 pageSize
Definition
VBF.h:52
vtfpp::VBF::version
uint32_t version
Definition
VBF.h:51
vtfpp::VBF::getGlyphs
const std::array< Glyph, 256 > & getGlyphs() const
Definition
VBF.cpp:67
vtfpp::VBF::getAscent
uint16_t getAscent() const
Definition
VBF.cpp:63
vtfpp::VBF::VBF
VBF(std::span< const std::byte > vbfData)
Definition
VBF.cpp:11
vtfpp::VBF::flags
Flags flags
Definition
VBF.h:54
sourcepp::fs
Definition
FS.h:9
sourcepp
Definition
LZMA.h:11
vtfpp
Definition
DistanceMapping.h:8
vtfpp::VBF_SIGNATURE
constexpr uint32_t VBF_SIGNATURE
Definition
VBF.h:12
src
vtfpp
VBF.cpp
Generated on
for SourcePP by
1.17.0