具有奇特宽度的16位纹理正在震撼 [英] 16bit Texture with odd sized width is sheering

查看:49
本文介绍了具有奇特宽度的16位纹理正在震撼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下OpenGL命令上传35 x 100 16bpp纹理:

I am uploading a 35 x 100 16bpp texture with the following OpenGL command:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, 35, 100, 0, GL_RG, GL_UNSIGNED_BYTE, pixelData);

但是随着y的增加(在绘制时以及在gpu内存中进行检查时),最终生成的纹理向左倾斜了一个像素:

But the resulting texture is sheered by one pixel toward the left as y increases (both when drawn and when inspected in gpu memory):

o o x o o               o o o x o
o o x o o               o o o o x
o o x o o               x o o o o
o o x o o               o x o o o
o o x o o  becomes->    o o x o o

如果给定的宽度与 pixelData 的宽度相差一个像素,则可能会发生这种类型的调整,但是缓冲区和给定的尺寸是准确的.将我的纹理更改为36 x 100,并且没有其他更改也可以解决该问题.仅当宽度为奇数的纹理时才会发生这种情况.

This type of sheering could occur if the width given differed from pixelData by one pixel, but the buffer and given dimensions are accurate. Changing my texture to be 36 x 100 with no other changes fixes the issue as well. This ONLY occurs for textures with an odd number as it's width.

我的问题是,这是驱动程序错误吗?据我了解,现代硬件允许使用非POT纹理,但这表明仍然存在一些未公布的对齐要求,也许特定于16bpp纹理.至少在我能找到的任何地方都没有提及这种行为或要求.

My question is, is this a driver bug? It was my understanding that non-POT textures were allowed on modern hardware, but this would suggest there's still some sort of unadvertised alignment requirement, perhaps specific to 16bpp textures; there's no mention of this behavior or requirement anywhere I could find at least.

推荐答案

纹理具有必须在每条扫描线(水平行)末尾遇到的对齐方式,通常默认为4个字节.如果不满足此对齐要求,则纹理将需要在您自己必须在上传的像素数据中提供的这些位置进行填充.除非您将非pow2纹理大小与每像素纹理数据少于32位混合在一起,否则通常不必担心.

Textures have an alignment they must meet at the end of each scanline (horizontal row), usually a default of 4 bytes. If this alignment isn't met, the texture will need padding at these locations that you yourself must provide in the uploaded pixel data. This isn't usually a concern until you mix non-pow2 texture sizes with less than 32bit per pixel texture data.

使用 glPixelStorei()可以根据需要将该要求调整为2或1的对齐方式,或者在处理16位纹理时可以简单地确保纹理大小与4的倍数对齐.

Using glPixelStorei() can adjust this requirement to an alignment of 2 or 1 as necessary, or you can simply ensure texture sizes align to a multiple of 4 when dealing with 16bit textures.

这篇关于具有奇特宽度的16位纹理正在震撼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆