wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
texture.hpp
Go to the documentation of this file.
1#pragma once
2
9
10#include <array>
11#include <cstdint>
12#include <utility>
13
14#include <welder/vocabulary.hpp>
15
16#include <wowlib/core/lang.hpp>
18
20 enum class [[
21 =welder::weld,
22 =welder::flags,
23 =welder::doc(
24 "Per-cell texture-layer flag bits (SMLayer.flags). The low 6 bits "
25 "hold the animation rotation (0x7) and speed (0x38); see "
26 "SMLayer.animation_rotation()/animation_speed().")
27 ]] LayerFlags : std::uint32_t {
28 AnimationEnabled [[=welder::doc("Texture-coordinate animation is on.")]] = 0x40,
29 Overbright [[=welder::doc("Render much brighter (used for glowing lava).")]] = 0x80,
30 UseAlphaMap [[=welder::doc(
31 "This layer blends through an MCAL alpha map (set on every "
32 "layer after the first).")]] = 0x100,
33 AlphaMapCompressed [[=welder::doc(
34 "The layer's MCAL alpha map is RLE-compressed on "
35 "disk. wowlib decodes it either way; on write it "
36 "re-compresses when this bit is set.")]] = 0x200,
37 UseCubeMapReflection [[=welder::doc(
38 "Treat the ground layer as a skybox reflection "
39 "(needs an MTXF entry).")]] = 0x400,
40 unknown_0x800 [[=welder::doc(
41 "WoD?+ with 0x1000: apply the texture-effect texture "
42 "scale.")]] = 0x800,
43 unknown_0x1000 [[=welder::doc("WoD?+; see 0x800.")]] = 0x1000
44 };
45
48 struct [[
49 =welder::weld,
50 =welder::weld_as("SMLayer"),
51 =welder::doc(R"(
52 A terrain texture layer (MCLY, 16 bytes): which tileset texture, the
53 blend/animation flags and the ground-effect link. Layers after the first
54 blend through an alpha map (see MapChunk.alphaMaps). The MCAL offset is
55 derived on write and not exposed.)")
56 ]] SMLayer {
57 [[=welder::doc(
58 "The texture: an index into the tile's texture list (MTEX names, or "
59 "the MDID FileDataID table since 8.1).")]]
60 std::uint32_t textureId = 0;
61
62 [[=welder::doc(
63 "Flags; LayerFlags bits (the low 6 bits are animation rotation/speed).")]]
65
66 [[=welder::mark::exclude]] std::uint32_t offsetInMcal = 0;
67
68 [[=welder::doc(
69 "The ground-effect link (a GroundEffectTexture foreign key), or -1 for "
70 "none (in the alpha clients, a u16 + padding).")]]
71 std::int32_t effectId = -1;
72
73 [[nodiscard]]
74 [[=welder::getter, =welder::doc(
75 "The animation direction in 45-degree steps (flag bits "
76 "0x7).")]]
77 std::uint32_t animationRotation() const { return std::to_underlying(flags) & 0x7; }
78
79 [[nodiscard]]
80 [[=welder::getter, =welder::doc("The animation speed (flag bits 0x38).")]]
81 std::uint32_t animationSpeed() const {
82 return (std::to_underlying(flags) >> 3) & 0x7;
83 }
84
85 bool operator==(const SMLayer&) const = default;
86 };
87
88 static_assert(sizeof(SMLayer) == 0x10);
89
91
94 struct [[
95 =welder::weld,
96 =welder::weld_as("SMTextureFlags"),
97 =welder::doc(R"(
98 Flags for a tileset texture (MTXF, WotLK+): one per MTEX entry. Bit 0
99 disables specular/height shading and uses a cube map; bits 4-7 hold the
100 texture scale exponent (UVs are divided by 1 << that nibble, so the
101 texture appears 2^n times larger).)")
102 ]] SMTextureFlags {
103 [[=welder::doc(
104 "Flags: bit 0 = use cube map (no _s/_h shading); bits 4-7 = texture "
105 "scale exponent (UVs are divided by 1 << n).")]]
106 std::uint32_t flags = 0;
107
108 bool operator==(const SMTextureFlags&) const = default;
109 };
110
111 static_assert(sizeof(SMTextureFlags) == 0x4);
115 struct [[
116 =welder::weld,
117 =welder::weld_as("SMTextureParams"),
118 =welder::doc(R"(
119 Height-blend parameters for a tileset texture (MTXP, MoP+): the same flags
120 as MTXF plus the _h texture's height scale and offset. Scale 0.0 / offset
121 1.0 means no _h texture is loaded.)")
123 [[=welder::doc("Flags, as in MTXF.")]]
124 std::uint32_t flags = 0;
125
126 [[=welder::doc(
127 "Height scale: _h values map to [0, height_scale) as the blend height "
128 "(default 0.0).")]]
129 float heightScale = 0;
131 [[=welder::doc("Height offset added to the scaled _h value (default 1.0).")]
132 ]
133 float heightOffset = 1;
134
135 [[=welder::doc("Padding.")]]
136 std::uint32_t padding = 0;
137
138 bool operator==(const SMTextureParams&) const = default;
139 };
140
141 static_assert(sizeof(SMTextureParams) == 0x10);
142
144 struct [[
145 =welder::weld,
146 =welder::weld_as("SMTerrainMaterial"),
147 =welder::doc(
148 "Per-layer terrain material ids (MCMT, Cata+): four TerrainMaterial "
149 "foreign keys, one per MCLY layer.")
151 [[=welder::doc("The four per-layer material ids.")]]
152 std::array<std::uint8_t, 4> materialId{};
153
154 bool operator==(const SMTerrainMaterial&) const = default;
155 };
157 static_assert(sizeof(SMTerrainMaterial) == 0x4);
160
161 struct [[
162 =welder::weld,
163 =welder::weld_as("SMTextureColorGrading"),
164 =welder::doc(R"(
165 Color-grading info for a tileset texture (MTCG, Shadowlands+): a start
166 distance pair and the color-grading LUT / ramp FileDataIDs applied to the
167 diffuse texture at the same index.)")
169 [[=welder::doc(
170 "Start distance (the record is used when this or _04 is non-zero).")]]
171 std::uint32_t startDistance = 0;
172
173 // C# ONLY: a leading underscore survives the PascalCase transform, and that
174 // namespace is reserved for welder's generated scaffolding (`_h_*`, `_owner`),
175 // so it is diagnosed at generation. The name is the client-struct offset, so
176 // spell it out rather than inventing meaning we do not have.
177 [[=welder::weld_as(wowlib::lang::Cs, "Unknown04"),
178 =welder::doc("Unknown companion of start_distance.")]]
179 std::uint32_t _04 = 0;
180
181 [[=welder::doc("The color-grading LUT FileDataID.")]]
182 std::uint32_t colorGradingFdid = 0;
183
184 [[=welder::doc("The color-grading ramp FileDataID.")]]
185 std::uint32_t colorGradingRampFdid = 0;
186
187 bool operator==(const SMTextureColorGrading&) const = default;
188 };
189
190 static_assert(sizeof(SMTextureColorGrading) == 0x10);
191
192 // --- terrain grid element types --------------------------------------------
193
196 struct [[
197 =welder::weld,
198 =welder::doc(R"(
199 A terrain vertex normal (MCNR entry, 3 signed bytes): the X, Z, Y
200 components, 127 == 1.0. One per MCVT height vertex (9x9 + 8x8 = 145).)")
201 ]] MCNREntry {
202 [[=welder::doc(
203 "The normal components, plain X, Y, Z order; 127 == 1.0, -127 == -1.0. (The often-quoted X, Z, Y layout is wrong: verified empirically against MCVT-derived gradients, wrender 2026-08.)")
204 ]]
205 std::array<std::int8_t, 3> normal{};
206
207 bool operator==(const MCNREntry&) const = default;
208 };
209
210 static_assert(sizeof(MCNREntry) == 3);
211}
Binding-language identities welder's core does not name.
ADT chunk binary structs (the MCNK cell header, texture layers, liquid records, flying bounds) and th...
Definition header.hpp:22
LayerFlags
Per-cell texture-layer flag bits (SMLayer.flags).
Definition texture.hpp:21
@ Overbright
Render much brighter (used for glowing lava).
Definition texture.hpp:23
@ UseCubeMapReflection
Treat the ground layer as a skybox reflection (needs an MTXF entry).
Definition texture.hpp:26
@ UseAlphaMap
This layer blends through an MCAL alpha map (set on every layer after the first).
Definition texture.hpp:24
@ AnimationEnabled
Texture-coordinate animation is on.
Definition texture.hpp:22
@ AlphaMapCompressed
The layer's MCAL alpha map is RLE-compressed on disk.
Definition texture.hpp:25
constexpr welder::lang Cs
C#/.NET — the welder-csharp rod's identity (user-range slot 0), respelled for wowlib's annotation sit...
Definition lang.hpp:23
One MCNR normal (3 signed bytes, x Z Y; 127 == 1.0).
Definition texture.hpp:152
std::array< std::int8_t, 3 > normal
Definition texture.hpp:156
bool operator==(const MCNREntry &) const =default
A per-cell texture layer (MCLY, 16 bytes).
Definition texture.hpp:33
std::uint32_t animationRotation() const
The animation direction in 45-degree steps (flag bits 0x7).
Definition texture.hpp:47
std::uint32_t animationSpeed() const
The animation speed (flag bits 0x38).
Definition texture.hpp:51
bool operator==(const SMLayer &) const =default
std::uint32_t textureId
The texture: an index into the tile's texture list (MTEX names, or the MDID FileDataID table since 8....
Definition texture.hpp:35
std::int32_t effectId
The ground-effect link (a GroundEffectTexture foreign key), or -1 for none (in the alpha clients,...
Definition texture.hpp:43
LayerFlags flags
Flags; LayerFlags bits (the low 6 bits are animation rotation/speed).
Definition texture.hpp:38
One MCMT terrain-material record (Cata+): a TerrainMaterial id per layer.
Definition texture.hpp:101
bool operator==(const SMTerrainMaterial &) const =default
std::array< std::uint8_t, 4 > materialId
Definition texture.hpp:103
One MTCG color-grading record (Shadowlands+): the color-grading LUT FileDataIDs for the same-index di...
Definition texture.hpp:119
bool operator==(const SMTextureColorGrading &) const =default
One MTXF texture-flags record (WotLK+): flags for the same-index MTEX texture.
Definition texture.hpp:64
std::uint32_t flags
Flags: bit 0 = use cube map (no _s/_h shading); bits 4-7 = texture scale exponent (UVs are divided by...
Definition texture.hpp:66
bool operator==(const SMTextureFlags &) const =default
One MTXP texture-parameter record (MoP+): the MTXF flags plus the _h height-texture scale/offset that...
Definition texture.hpp:75
std::uint32_t flags
Flags, as in MTXF.
Definition texture.hpp:77
float heightScale
Height scale: _h values map to [0, height_scale) as the blend height (default 0.0).
Definition texture.hpp:80
The binary-level math and color primitives shared across WoW file formats (wowdev....