【发布时间】:2013-08-29 23:50:02
【问题描述】:
在我的 OpenGL 程序中,我正在加载一个宽度为 501 的 24BPP 图像。 GL_UNPACK_ALINGMENT 参数设置为4。他们写it shouldn't work,因为正在上传的每一行的大小(501*3 = 1503)不能被4除。但是,我可以在显示时看到没有伪影的正常纹理。
所以我的代码有效。我正在考虑为什么要充分理解这一点并防止整个项目被窃听。
也许(?)它有效,因为我不只是打电话给glTexImage2D。相反,首先我正在创建一个适当的(尺寸是 2 的幂)空白纹理,然后使用 glTexSubImage2D 上传像素。
编辑:
但是你认为写一些这样的代码有意义吗?
// w - the width of the image
// depth - the depth of the image
bool change_alignment = false;
if (depth != 4 && !is_divisible(w*depth)) // *
{
change_alignment = true;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
// ... now use glTexImage2D
if (change_alingment) glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // set to default
// * - of course we don't even need such a function
// but I wanted to make the code as clear as possible
希望它能防止应用程序崩溃或故障?
【问题讨论】:
标签: c++ opengl textures data-transfer 24-bit