是否可以将 NPOT 图像 glTexImage2d 转换到 Pow-2 纹理上而无需额外分配?
我发现仍然有相当多的驱动程序不支持 NPOT 纹理,因此我正在尝试改造我的 2D 引擎(基于 OpenTK,而 OpenTK 又基于 OpenGL),改为支持 Texture2D依赖GL_ARB_texture_rectangle。作为其中的一部分,我强制所有 NPOTS 纹理位图分配额外的空间,直到下一个 2 的幂大小,这样它们就不会在这些驱动程序上引起错误。我的问题是,我真的必须调整真实位图和纹理的大小并分配所有额外的内存,还是有办法告诉 OpenGL 我想要一个 2 的幂大小的纹理,但我只会使用它的一部分在左上角?
现在我的调用看起来像这样:
GL.TexImage2D(texTarget, 0, PixelInternalFormat.Rgba8, bmpUse.Width, bmpUse.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, bits.Scan0);
这是在我将 bmpUse 设为我的真实纹理位图的副本之后,在右侧和底部有额外的空间。
I have discovered that there are still a fair number of drivers out there that don't support NPOT textures so I'm trying to retro-fit my 2D engine (based on OpenTK, which is in turn based on OpenGL) with Texture2D support instead of relying on GL_ARB_texture_rectangle. As part of this I am forcing all NPOTS texture bitmaps to allocate extra space up to the next power-of-2 size so they won't cause errors on these drivers. My question is, do I really have to resize the real bitmap and texture and allocate all that extra memory, or is there a way to tell OpenGL that I want a power-of-2 size texture, but I'm only going to use a portion of it in the upper left?
Right now my call looks like this:
GL.TexImage2D(texTarget, 0, PixelInternalFormat.Rgba8, bmpUse.Width, bmpUse.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, bits.Scan0);
This is after I have made bmpUse be a copy of my real texture bitmap with extra space on the right and bottom.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用带有空数据的
glTexImage2D
来初始化纹理,并使用glTexSubImage2D
用数据填充其中的一部分。从技术上讲,OpenGL允许给glTexImage{1,2,3}D
的数据参数为空指针,表示纹理对象刚刚被初始化。这取决于语言绑定,目标语言是否仍然支持该功能 - 只需测试传递空指针时会发生什么。Use
glTexImage2D
with empty data to initialize the texture andglTexSubImage2D
to fill a portion of it with data. Technically OpenGL allows the data parameter given toglTexImage{1,2,3}D
to be a null pointer, indicating that the texture object is just to be initializd. It depends on the language binding, if that feature remains supported in the target language – just test what happens if you pass a null pointer.datenwolf 关于如何仅使用部分图像初始化纹理的说法是正确的,但是您需要注意两个问题:
[0-orig_width/pagged_width]
datenwolf is right on how to initialize the texture with just a partial image, but there are 2 issues with this you need to be aware of:
[0-orig_width/padded_width]