11.3 像素格式
交换链把帧送到屏幕,屏幕上的每个像素都得有确定的存储格式。这一节看 OGRE 怎么描述「一个像素在内存里长什么样」:PixelFormat 枚举列出所有格式,OgrePixelFormatDescriptions.h 里一张静态表逐条记录每种格式的元素字节数、标志位、分量类型与 RGBA 位深/掩码/位移,PixelUtil 在这张表上提供全部查询。像素格式是纹理、渲染目标、帧缓冲三者共同依赖的基础设施。
本章与站内既有内容的分工
helio 四卷在各平台直接面对 Vulkan/Metal 的原生格式枚举;OGRE 的 PixelFormat 是跨后端的统一抽象——后端拿到 PixelFormat 后用各自的 D3D11Mappings::_getGammaFormat、VulkanMappings::get 等映射到原生格式(11.2 已见)。这节聚焦描述表与 PixelUtil 的查询/内存计算机制。
PixelFormat 枚举与标志位
PixelFormat 枚举位于 OgreMain/include/OgrePixelFormat.h 第 54 行,覆盖从 8 位亮度到 128 位浮点、从 DXT 到 ASTC 的压缩族。开头几项就能看出设计:
// OgreMain/include/OgrePixelFormat.h:PixelFormat 枚举(v14.6.3 源码摘录,已删减)
enum PixelFormat
{
/// Unknown pixel format.
PF_UNKNOWN = 0,
/// 8-bit pixel format, all bits luminance.
PF_L8,
PF_BYTE_L = PF_L8,
/// 16-bit pixel format, all bits luminance.
PF_L16,
PF_SHORT_L = PF_L16,
/// 8-bit pixel format, all bits alpha.
PF_A8,
PF_BYTE_A = PF_A8,
...
/// 16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
PF_R5G6B5,
...
/// 32-bit pixel format, 8 bits for alpha, red, green and blue.
PF_A8R8G8B8,
...
/// DDS (DirectDraw Surface) DXT1 format
PF_DXT1,
...
/// Depth texture format with 24-bit unsigned integer and 8-bit stencil
PF_DEPTH24_STENCIL8,
/// Number of pixel formats currently defined
PF_COUNT,
PF_BYTE_L = PF_L8 这类别名让调用方可以用语义名(PF_BYTE_RGBA、PF_BYTE_BGRA 等),实际都指向同一个枚举值。PF_COUNT 是「当前定义了多少格式」,也用作描述表数组的长度。每种格式的特性用位标志描述:
// OgreMain/include/OgrePixelFormat.h:PixelFormatFlags(v14.6.3 源码摘录)
enum PixelFormatFlags {
/// This format has an alpha channel
PFF_HASALPHA = 0x00000001,
/** This format is compressed. This invalidates the values in elemBytes,
elemBits and the bit counts as these might not be fixed in a compressed format. */
PFF_COMPRESSED = 0x00000002,
/// This is a floating point format
PFF_FLOAT = 0x00000004,
/// This is a depth format (for depth textures)
PFF_DEPTH = 0x00000008,
/** Format is in native endian. Generally true for the 16, 24 and 32 bits
formats which can be represented as machine integers. */
PFF_NATIVEENDIAN = 0x00000010,
/** This is an intensity format instead of a RGB one. The luminance
replaces R,G and B. (but not A) */
PFF_LUMINANCE = 0x00000020,
/// This is an integer format
PFF_INTEGER = 0x00000040
};
一条标志可能同时成立多个:PF_DXT5 是 PFF_COMPRESSED | PFF_HASALPHA,PF_DEPTH24_STENCIL8 是 PFF_LUMINANCE | PFF_DEPTH | PFF_NATIVEENDIAN(深度当作亮度通道,stencil 那 8 位不单独建模)。
描述表:一条记录一个格式
每种格式的完整细节存在 OgrePixelFormatDescriptions.h 的 PixelFormatDescription 结构里,_pixelFormats[PF_COUNT] 是按枚举下标排列的静态数组:
// OgreMain/src/OgrePixelFormatDescriptions.h:PixelFormatDescription(v14.6.3 源码摘录)
struct PixelFormatDescription {
/* Name of the format, as in the enum */
const String name;
/* Number of bytes one element (colour value) takes. */
unsigned char elemBytes;
/* Pixel format flags, see enum PixelFormatFlags for the bit field
* definitions
*/
uint32 flags;
/** Component type
*/
PixelComponentType componentType;
/** Component count
*/
unsigned char componentCount;
/* Number of bits for red(or luminance), green, blue, alpha
*/
unsigned char rbits, gbits, bbits, abits; /*, ibits, dbits, ... */
/* Masks and shifts as used by packers/unpackers */
uint64 rmask, gmask, bmask, amask;
unsigned char rshift, gshift, bshift, ashift;
};
elemBytes 是单个元素(颜色值)占的字节数;rbits/gbits/bbits/abits 是 RGBA 各通道位深;rmask/gmask/bmask/amask 与 rshift/gshift/bshift/ashift 是打包/解包用的掩码与位移。看两个典型 16/32 位格式的记录:
// OgreMain/src/OgrePixelFormatDescriptions.h:R5G6B5 与 A8R8G8B8 记录(v14.6.3 源码摘录,已删减)
{"PF_R5G6B5",
/* Bytes per element */
2,
/* Flags */
PFF_NATIVEENDIAN,
/* Component type and count */
PCT_BYTE, 3,
/* rbits, gbits, bbits, abits */
5, 6, 5, 0,
/* Masks and shifts */
0xF800, 0x07E0, 0x001F, 0,
11, 5, 0, 0
},
...
{"PF_A8R8G8B8",
/* Bytes per element */
4,
/* Flags */
PFF_HASALPHA | PFF_NATIVEENDIAN,
/* Component type and count */
PCT_BYTE, 4,
/* rbits, gbits, bbits, abits */
8, 8, 8, 8,
/* Masks and shifts */
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
16, 8, 0, 24
},
PF_A8R8G8B8 的掩码/位移自洽可验证:R 在 0x00FF0000 偏移 16 位,G 在 0x0000FF00 偏移 8 位,B 在 0x000000FF 偏移 0,A 在 0xFF000000 偏移 24——打包 (0x40,0x80,0xC0,0xFF) 得到整数 0xFF4080C0。压缩格式(如 PF_DXT1)的 elemBytes 是 0,rbits 全 0,只有 PFF_COMPRESSED 标志,因为块压缩格式没有固定每像素字节数。
PixelUtil:查表即所得
PixelUtil 的全部查询都是一行查表——getNumElemBytes 返回 getDescriptionFor(format).elemBytes,getFlags 返回 flags,各种 is* 判断只是对 flags 做位与:
// OgreMain/src/OgrePixelFormat.cpp:PixelUtil 查询(v14.6.3 源码摘录,已删减)
uint8 PixelUtil::getNumElemBytes( PixelFormat format )
{
return getDescriptionFor(format).elemBytes;
}
...
unsigned int PixelUtil::getFlags( PixelFormat format )
{
return getDescriptionFor(format).flags;
}
...
bool PixelUtil::hasAlpha(PixelFormat format)
{
return (PixelUtil::getFlags(format) & PFF_HASALPHA) > 0;
}
...
bool PixelUtil::isCompressed(PixelFormat format)
{
return (PixelUtil::getFlags(format) & PFF_COMPRESSED) > 0;
}
位深、掩码、位移的取值函数把描述表字段拷进调用方数组:
// OgreMain/src/OgrePixelFormat.cpp:getBitDepths(v14.6.3 源码摘录)
void PixelUtil::getBitDepths(PixelFormat format, int rgba[4])
{
const PixelFormatDescription &des = getDescriptionFor(format);
rgba[0] = des.rbits;
rgba[1] = des.gbits;
rgba[2] = des.bbits;
rgba[3] = des.abits;
}
getBitMasks/getBitShifts 与它同构,只是读 rmask/gmask/bmask/amask 与 rshift/gshift/bshift/ashift。这套「描述表 + 查询函数」的模式把格式信息收敛到一处,PixelUtil::packColour/unpackColour/bulkPixelConversion 都建立在它的掩码/位移之上。
压缩格式的内存计算
getMemorySize 是最有意思的一个函数:非压缩格式直接 width*height*depth*elemBytes,压缩格式则按块计算。DXT 家族把图像切成 4x4 块,每块固定若干字节:
// OgreMain/src/OgrePixelFormat.cpp:getMemorySize(v14.6.3 源码摘录,已删减)
if(isCompressed(format))
{
switch(format)
{
// DXT formats work by dividing the image into 4x4 blocks, then encoding each
// 4x4 block with a certain number of bytes.
case PF_DXT1:
return ((width+3)/4)*((height+3)/4)*8 * depth;
case PF_DXT2:
case PF_DXT3:
case PF_DXT4:
case PF_DXT5:
return ((width+3)/4)*((height+3)/4)*16 * depth;
...
}
}
else
{
return size_t(width)*height*depth*getNumElemBytes(format);
}
(width+3)/4 是向上取整的块数(宽度不是 4 的倍数时多算一块);DXT1 每块 8 字节、DXT2-5 每块 16 字节。同一函数还处理 BC4-BC7、PVRTC、ETC、ASTC 等压缩族——ASTC 用 astc_slice_size 按块尺寸计算。注意压缩格式的 elemBytes 为 0,所以不能用非压缩公式,这正是 PFF_COMPRESSED 标志存在的意义。
PixelBox:带 pitch 的内存布局
描述表回答「一个像素占多少字节」,PixelBox 回答「一堆像素在内存里怎么排」。它的核心是 rowPitch(行间距)与 slicePitch(切片间距):
// OgreMain/include/OgrePixelFormat.h:PixelBox 布局字段(v14.6.3 教学示意,参照上游同名实现,已删减)
/// The data pointer
uchar* data;
/** Number of elements between the leftmost pixel of one row and the left
pixel of the next. ... */
size_t rowPitch;
/** Number of elements between the top left pixel of one (depth) slice and
the top left pixel of the next. ... */
size_t slicePitch;
/// The pixel format
PixelFormat format;
...
void setConsecutive()
{
rowPitch = getWidth();
slicePitch = getWidth()*getHeight();
}
...
size_t getRowSkip() const { return rowPitch - getWidth(); }
...
size_t getSliceSkip() const { return slicePitch - (getHeight() * rowPitch); }
默认 setConsecutive() 让布局紧凑连续;如果纹理每行有对齐填充(rowPitch > width),getRowSkip() 就返回非零值。getConsecutiveSize() 调 PixelUtil::getMemorySize 得到整块数据尺寸——渲染目标、纹理上传都靠它分配内存。
源码定位
OgreMain/include/OgrePixelFormat.h:enum PixelFormat(54-304)、enum PixelFormatFlags(310-328)、enum PixelComponentType(331-340)、class PixelBox(349-458)、class PixelUtil(464-657)OgreMain/src/OgrePixelFormatDescriptions.h:struct PixelFormatDescription(36-58)、PixelFormatDescription _pixelFormats[PF_COUNT](61-1542)OgreMain/src/OgrePixelFormat.cpp:getNumElemBytes(95-98)、getMemorySize(105-190)、getNumElemBits(192-195)、getFlags(197-200)、hasAlpha/isFloatingPoint/isInteger/isCompressed/isDepth/isNativeEndian/isLuminance(202-235)、getBitDepths/getBitMasks/getBitShifts(237-262)、getFormatName(264-267)、isAccessible(269-272)、getComponentType/getComponentCount(274-284)
上游引用固定到 OGRE v14.6.3 源码 。
可运行产物:C++ 最小验证
下面用纯 C++ 复现像素格式描述表与 PixelUtil 查询:_pixelFormats 静态表、getNumElemBytes/getFlags/is* 查表函数、位深/掩码/位移的打包验证、压缩格式按块计算内存、PixelBox 的 pitch 布局。它与 src/11-3-pixel-format.cpp 逐字节一致:
// file: src/11-3-pixel-format.cpp
// tier: L1
// verify: clang++ -std=c++20 -I. src/11-3-pixel-format.cpp -o bin/11-3-pixel-format && ./bin/11-3-pixel-format
//
// 复现像素格式描述表与 PixelUtil 查询(对应 OgreMain/include/OgrePixelFormat.h 54-328、
// OgreMain/src/OgrePixelFormatDescriptions.h 36-58、61-1542 与
// OgreMain/src/OgrePixelFormat.cpp 95-284、105-190):
// PixelFormatDescription 记录每格式的元素字节数、flags、分量类型/个数、
// RGBA 位深与掩码/位移;_pixelFormats 是 PF_COUNT 项的静态表;
// PixelUtil::getNumElemBytes/getFlags/hasAlpha/isCompressed 等直接查表,
// getMemorySize 对压缩格式按块计算(DXT1 8B/块、DXT5 16B/块),
// 非压缩格式 = w*h*d*elemBytes;PixelBox 用 rowPitch/slicePitch 表达内存布局。
// 独立最小验证,非 OGRE 源码。
#include "verify.h"
#include <cstdint>
#include <string>
namespace ogre_repro {
using String = std::string;
enum PixelFormat : uint8_t {
PF_UNKNOWN = 0,
PF_L8,
PF_R5G6B5,
PF_A8R8G8B8,
PF_FLOAT32_RGBA,
PF_DXT1,
PF_DXT5,
PF_DEPTH24_STENCIL8,
PF_COUNT
};
// 对应 PixelFormatFlags(OgrePixelFormat.h 310-328)
enum PixelFormatFlags : uint32_t {
PFF_HASALPHA = 0x00000001,
PFF_COMPRESSED = 0x00000002,
PFF_FLOAT = 0x00000004,
PFF_DEPTH = 0x00000008,
PFF_NATIVEENDIAN = 0x00000010,
PFF_LUMINANCE = 0x00000020,
PFF_INTEGER = 0x00000040
};
// 对应 PixelComponentType(OgrePixelFormat.h 331-340)
enum PixelComponentType : uint8_t {
PCT_BYTE = 0,
PCT_SHORT = 1,
PCT_FLOAT16 = 2,
PCT_FLOAT32 = 3,
PCT_SINT = 4,
PCT_UINT = 5
};
// 对应 PixelFormatDescription(OgrePixelFormatDescriptions.h 36-58)
struct PixelFormatDescription {
String name;
uint8_t elemBytes;
uint32_t flags;
PixelComponentType componentType;
uint8_t componentCount;
uint8_t rbits, gbits, bbits, abits;
uint64_t rmask, gmask, bmask, amask;
uint8_t rshift, gshift, bshift, ashift;
};
// 对应 _pixelFormats 静态表(61-1542)的关键子集
static const PixelFormatDescription kPixelFormats[PF_COUNT] = {
{"PF_UNKNOWN", 0, 0, PCT_BYTE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"PF_L8", 1, PFF_LUMINANCE | PFF_NATIVEENDIAN, PCT_BYTE, 1, 8, 0, 0, 0, 0xFF, 0, 0, 0, 0, 0, 0, 0},
{"PF_R5G6B5", 2, PFF_NATIVEENDIAN, PCT_BYTE, 3, 5, 6, 5, 0, 0xF800, 0x07E0, 0x001F, 0, 11, 5, 0, 0},
{"PF_A8R8G8B8", 4, PFF_HASALPHA | PFF_NATIVEENDIAN, PCT_BYTE, 4, 8, 8, 8, 8, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 16, 8, 0, 24},
{"PF_FLOAT32_RGBA", 16, PFF_FLOAT | PFF_HASALPHA, PCT_FLOAT32, 4, 32, 32, 32, 32, 0, 0, 0, 0, 0, 0, 0, 0},
{"PF_DXT1", 0, PFF_COMPRESSED, PCT_BYTE, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"PF_DXT5", 0, PFF_COMPRESSED | PFF_HASALPHA, PCT_BYTE, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{"PF_DEPTH24_STENCIL8", 4, PFF_LUMINANCE | PFF_DEPTH | PFF_NATIVEENDIAN, PCT_UINT, 1, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
};
// 对应 PixelUtil(OgrePixelFormat.h 464-657)的关键子集
struct PixelUtil {
static const PixelFormatDescription& getDescriptionFor(PixelFormat format) {
return kPixelFormats[format];
}
static uint8_t getNumElemBytes(PixelFormat format) { return getDescriptionFor(format).elemBytes; }
static uint8_t getNumElemBits(PixelFormat format) { return getDescriptionFor(format).elemBytes * 8; }
static uint32_t getFlags(PixelFormat format) { return getDescriptionFor(format).flags; }
static bool hasAlpha(PixelFormat f) { return (getFlags(f) & PFF_HASALPHA) > 0; }
static bool isFloatingPoint(PixelFormat f) { return (getFlags(f) & PFF_FLOAT) > 0; }
static bool isCompressed(PixelFormat f) { return (getFlags(f) & PFF_COMPRESSED) > 0; }
static bool isDepth(PixelFormat f) { return (getFlags(f) & PFF_DEPTH) > 0; }
static bool isNativeEndian(PixelFormat f) { return (getFlags(f) & PFF_NATIVEENDIAN) > 0; }
static bool isLuminance(PixelFormat f) { return (getFlags(f) & PFF_LUMINANCE) > 0; }
static void getBitDepths(PixelFormat f, uint8_t rgba[4]) {
const auto& d = getDescriptionFor(f);
rgba[0] = d.rbits; rgba[1] = d.gbits; rgba[2] = d.bbits; rgba[3] = d.abits;
}
static void getBitMasks(PixelFormat f, uint64_t rgba[4]) {
const auto& d = getDescriptionFor(f);
rgba[0] = d.rmask; rgba[1] = d.gmask; rgba[2] = d.bmask; rgba[3] = d.amask;
}
static void getBitShifts(PixelFormat f, uint8_t rgba[4]) {
const auto& d = getDescriptionFor(f);
rgba[0] = d.rshift; rgba[1] = d.gshift; rgba[2] = d.bshift; rgba[3] = d.ashift;
}
static const String& getFormatName(PixelFormat f) { return getDescriptionFor(f).name; }
static bool isAccessible(PixelFormat f) { return f != PF_UNKNOWN && !isCompressed(f); }
static PixelComponentType getComponentType(PixelFormat f) { return getDescriptionFor(f).componentType; }
static uint8_t getComponentCount(PixelFormat f) { return getDescriptionFor(f).componentCount; }
// 对应 getMemorySize(OgrePixelFormat.cpp 105-190)
static size_t getMemorySize(uint32_t width, uint32_t height, uint32_t depth, PixelFormat format) {
if (isCompressed(format)) {
switch (format) {
case PF_DXT1:
return ((width + 3) / 4) * ((height + 3) / 4) * 8 * depth;
case PF_DXT5:
return ((width + 3) / 4) * ((height + 3) / 4) * 16 * depth;
default:
return 0;
}
}
return size_t(width) * height * depth * getNumElemBytes(format);
}
};
// 对应 PixelBox(OgrePixelFormat.h 349-458)的关键子集
struct PixelBox {
uint32_t width, height, depth;
PixelFormat format;
size_t rowPitch, slicePitch;
PixelBox(uint32_t w, uint32_t h, uint32_t d, PixelFormat f)
: width(w), height(h), depth(d), format(f) {
setConsecutive();
}
void setConsecutive() {
rowPitch = width;
slicePitch = width * height;
}
size_t getRowSkip() const { return rowPitch - width; }
size_t getSliceSkip() const { return slicePitch - (height * rowPitch); }
bool isConsecutive() const { return rowPitch == width && slicePitch == width * height; }
size_t getConsecutiveSize() const { return PixelUtil::getMemorySize(width, height, depth, format); }
};
} // namespace ogre_repro
int main() {
using namespace ogre_repro;
// 元素字节数 / 位深:直接查描述表
CHECK(PixelUtil::getNumElemBytes(PF_L8) == 1);
CHECK(PixelUtil::getNumElemBits(PF_L8) == 8);
CHECK(PixelUtil::getNumElemBytes(PF_R5G6B5) == 2);
CHECK(PixelUtil::getNumElemBytes(PF_A8R8G8B8) == 4);
CHECK(PixelUtil::getNumElemBytes(PF_FLOAT32_RGBA) == 16);
CHECK(PixelUtil::getNumElemBits(PF_A8R8G8B8) == 32);
// flags 位域判断
CHECK(PixelUtil::hasAlpha(PF_A8R8G8B8));
CHECK(!PixelUtil::hasAlpha(PF_R5G6B5));
CHECK(PixelUtil::isFloatingPoint(PF_FLOAT32_RGBA));
CHECK(PixelUtil::isCompressed(PF_DXT1));
CHECK(PixelUtil::isCompressed(PF_DXT5));
CHECK(PixelUtil::isDepth(PF_DEPTH24_STENCIL8));
CHECK(PixelUtil::isNativeEndian(PF_A8R8G8B8));
CHECK(PixelUtil::isLuminance(PF_L8));
CHECK(!PixelUtil::isLuminance(PF_R5G6B5));
// 位深 / 掩码 / 位移
uint8_t depths[4];
PixelUtil::getBitDepths(PF_A8R8G8B8, depths);
CHECK(depths[0] == 8 && depths[1] == 8 && depths[2] == 8 && depths[3] == 8);
PixelUtil::getBitDepths(PF_R5G6B5, depths);
CHECK(depths[0] == 5 && depths[1] == 6 && depths[2] == 5 && depths[3] == 0);
uint64_t masks[4];
PixelUtil::getBitMasks(PF_A8R8G8B8, masks);
CHECK(masks[0] == 0x00FF0000); // R 掩码
CHECK(masks[3] == 0xFF000000); // A 掩码
uint8_t shifts[4];
PixelUtil::getBitShifts(PF_A8R8G8B8, shifts);
CHECK(shifts[0] == 16 && shifts[1] == 8 && shifts[2] == 0 && shifts[3] == 24);
// 用掩码 / 位移打包:RGBA(0x40,0x80,0xC0,0xFF) -> 0xFF4080C0(A8R8G8B8)
uint32_t packed = (uint32_t)((0x40u << 16) | (0x80u << 8) | 0xC0u | (0xFFu << 24));
CHECK(packed == 0xFF4080C0u);
// 名称 / 可访问性 / 分量
CHECK(PixelUtil::getFormatName(PF_A8R8G8B8) == "PF_A8R8G8B8");
CHECK(PixelUtil::getFormatName(PF_DXT1) == "PF_DXT1");
CHECK(PixelUtil::isAccessible(PF_R5G6B5));
CHECK(!PixelUtil::isAccessible(PF_DXT1));
CHECK(PixelUtil::getComponentCount(PF_A8R8G8B8) == 4);
CHECK(PixelUtil::getComponentType(PF_FLOAT32_RGBA) == PCT_FLOAT32);
// getMemorySize:非压缩 = w*h*d*elemBytes
CHECK(PixelUtil::getMemorySize(64, 64, 1, PF_A8R8G8B8) == 64 * 64 * 4);
// 压缩:DXT1 每 4x4 块 8 字节,DXT5 每 4x4 块 16 字节
CHECK(PixelUtil::getMemorySize(64, 64, 1, PF_DXT1) == 16 * 16 * 8); // 16x16 块
CHECK(PixelUtil::getMemorySize(64, 64, 1, PF_DXT5) == 16 * 16 * 16);
// 非 4 的倍数向上取整块
CHECK(PixelUtil::getMemorySize(65, 65, 1, PF_DXT1) == ((65 + 3) / 4) * ((65 + 3) / 4) * 8);
// PixelBox:连续布局与行 / 切片跳过
PixelBox box(64, 32, 1, PF_A8R8G8B8);
CHECK(box.rowPitch == 64);
CHECK(box.slicePitch == 64 * 32);
CHECK(box.isConsecutive());
CHECK(box.getConsecutiveSize() == 64 * 32 * 4);
// 不连续布局:rowPitch 更大(每行带对齐填充)
PixelBox padded(64, 32, 1, PF_A8R8G8B8);
padded.rowPitch = 66; // 每行 2 个元素填充
padded.slicePitch = 66 * 32;
CHECK(!padded.isConsecutive());
CHECK(padded.getRowSkip() == 2);
CHECK(padded.getSliceSkip() == 0);
return lab::report("11-3 像素格式");
}
本机实测(Apple clang 16,clang++ -std=c++20 -Wall -I.):编译零警告,断言 38/38 通过。
小结
PixelFormat枚举 +PixelFormatFlags位标志描述「一个像素的存储格式」,PF_COUNT同时是描述表长度。PixelFormatDescription每条记录元素字节数、flags、分量类型/个数、RGBA 位深与掩码/位移,_pixelFormats[PF_COUNT]按枚举下标排列。PixelUtil全部查询是一行查表:getNumElemBytes、getFlags、hasAlpha/isCompressed/isFloatingPoint/isDepth等。getMemorySize对非压缩格式用w*h*d*elemBytes,对压缩格式按块计算(DXT1 8B/块、DXT2-5 16B/块,(w+3)/4向上取整块数)。PixelBox用rowPitch/slicePitch表达行/切片间距,getRowSkip/getSliceSkip反映对齐填充。
阅读导航:上一节:11.2 交换链 · 下一节:12.1 渲染纹理 。
继续阅读
探索更多技术文章
浏览归档,发现更多关于系统设计、工具链和工程实践的内容。