是否可以将NPOT图像glTexImage2d转换为Pow-2纹理而无需额外分配? [英] Possible to glTexImage2d an NPOT image onto a Pow-2 texture without extra allocation?

查看:459
本文介绍了是否可以将NPOT图像glTexImage2d转换为Pow-2纹理而无需额外分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现那里仍然有很多不支持NPOT纹理的驱动程序,因此我试图对我的2D引擎(基于OpenTK,后者又基于OpenGL)进行改装.支持Texture2D,而不是依赖GL_ARB_texture_rectangle.作为此过程的一部分,我将强制所有NPOTS纹理位图分配额外的空间,直到下一个2的幂,以便它们不会在这些驱动程序上引起错误.我的问题是,我真的必须调整实际位图和纹理的大小并分配所有额外的内存,还是有办法告诉OpenGL我想要2幂次方的纹理,但是我只打算使用一部分在左上角?

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);

这是在我使bmpUse成为我的真实纹理位图的副本之后,在右侧和底部有额外的空间.

This is after I have made bmpUse be a copy of my real texture bitmap with extra space on the right and bottom.

推荐答案

对空数据使用glTexImage2D初始化纹理,并使用glTexSubImage2D用数据填充纹理的一部分.从技术上讲,OpenGL允许赋予glTexImage{1,2,3}D的数据参数为空指针,指示纹理对象将被初始化.如果目标语言仍支持该功能,则取决于语言绑定.只需测试传递空指针后会发生什么.

Use glTexImage2D with empty data to initialize the texture and glTexSubImage2D to fill a portion of it with data. Technically OpenGL allows the data parameter given to glTexImage{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.

这篇关于是否可以将NPOT图像glTexImage2d转换为Pow-2纹理而无需额外分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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