可移植并正确地在OpenGL中获得最大1D/2D/3D/立方体纹理分辨率 [英] Portably and Correctly Getting Maximum 1D/2D/3D/Cube Texture Resolution in OpenGL

查看:126
本文介绍了可移植并正确地在OpenGL中获得最大1D/2D/3D/立方体纹理分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣获得硬件支持的最大纹理分辨率.

I am interested in getting the maximum hardware-supported resolution for textures.

据我发现,有两种机制可以执行与此相关的操作:

There are, as far as I have found, two mechanisms for doing something related to this:

  1. glGetIntegerv(GL_MAX_TEXTURE_SIZE,&dim)用于2D(和立方体?)纹理的效果很好.对于3D纹理,我发现(困难的方式)需要使用GL_MAX_3D_TEXTURE_SIZE代替.据我所知,它们沿一侧返回最大分辨率,而另一侧假定相同.

  1. glGetIntegerv(GL_MAX_TEXTURE_SIZE,&dim) for 2D (and cube?) textures has served me well. For 3D textures, I discovered (the hard way) that you need to use GL_MAX_3D_TEXTURE_SIZE instead. As far as I can tell, these return the maximum resolution along one side, with the other sides assumed to be the same.

目前尚不清楚这些值实际代表什么.根据文档,glGetIntegerv(...)返回的值被认为是粗略估计",但尚不清楚它们是保守的低估,最佳猜测还是最佳情况.此外,根据可用的图形内存量,这些是硬件限制还是当前限制还不清楚.

It is unclear what these values actually represent. The values returned by glGetIntegerv(...) are to be considered "rough estimate"s, according to the documentation, but it's unclear whether they are conservative underestimates, best guesses, or best-cases. Furthermore, it's unclear whether these are hardware limitations or current limitations based on the amount of available graphics memory.

该文档建议使用. . .

The documentation instead suggests using . . .

GL_PROXY_TEXTURE_(1|2|3)D/GL_PROXY_TEXTURE_CUBE_MAP.这里的想法是在创建真实纹理之前先创建代理纹理.然后,通过检查其实际尺寸来检查代理纹理是否还可以.对于3D纹理,它看起来像:

GL_PROXY_TEXTURE_(1|2|3)D/GL_PROXY_TEXTURE_CUBE_MAP. The idea here is you make a proxy texture before you make your real one. Then, you check to see whether the proxy texture was okay by checking the actual dimensions it got. For 3D textures, that would look like:

glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0,  GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_HEIGHT, &height);
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0,  GL_TEXTURE_DEPTH, &depth);

如果一切顺利,则返回的尺寸将为非零(并且可能与您要求的尺寸相同).然后删除代理,使纹理变为真实.

If all goes well, then the dimensions returned will be nonzero (and presumably the same as what you requested). Then you delete the proxy and make the texture for real.

某些

Some older sources state that proxy textures give outright wrong answers, but that may not be true today.

因此,对于现代OpenGL(GL 4. *很好),什么是获得1D-,2D-,3D-和立方纹理的最大硬件支持分辨率的最佳方法?

So, for modern OpenGL (GL 4.* is fine), what is the best way to get the maximum hardware-supported resolution for 1D-, 2D-, 3D-, and cube-textures?

推荐答案

多维数据集映射有一个单独的值,可通过GL_MAX_CUBE_MAP_TEXTURE_SIZE查询.因此限制为:

There is a separate value for cube maps, which is queried with GL_MAX_CUBE_MAP_TEXTURE_SIZE. So the limits are:

  • GL_MAX_TEXTURE_SIZE:GL_TEXTURE_1DGL_TEXTURE_2D的最大大小.
  • GL_MAX_RECTANGLE_TEXTURE_SIZE:GL_TEXTURE_RECTANGLE的最大大小.
  • GL_MAX_CUBE_MAP_TEXTURE_SIZE:GL_TEXTURE_CUBE_MAP的最大大小.
  • GL_MAX_3D_TEXTURE_SIZE:GL_TEXTURE_3D的最大大小.
  • GL_MAX_TEXTURE_SIZE: Maximum size for GL_TEXTURE_1D and GL_TEXTURE_2D.
  • GL_MAX_RECTANGLE_TEXTURE_SIZE: Maximum size for GL_TEXTURE_RECTANGLE.
  • GL_MAX_CUBE_MAP_TEXTURE_SIZE: Maximum size for GL_TEXTURE_CUBE_MAP.
  • GL_MAX_3D_TEXTURE_SIZE: Maximum size for GL_TEXTURE_3D.

您在手册页上找到的粗略估计"语言似乎很不幸.如果您看的是更相关的规格文档,它会谈到最大允许宽度和高度",或者只是说使用大于这些限制的尺寸是错误的.

The "rough estimate" language you found on the man pages seems unfortunate. If you look at the much more relevant spec document instead, it talks about the "maximum allowable width and height", or simply says that it's an error to use a size larger than these limits.

这些限制代表硬件支持的最大大小.或更准确地说,是所宣传的硬件限制.只要持续应用广告限制,将硬件限制限制在硬件实际支持的范围内当然是合法的.图片显示硬件只能管理/采样给定大小的纹理,这是这些限制所报告的大小.

These limits represent the maximum sizes supported by the hardware. Or more precisely, the advertised hardware limit. It's of course legal for hardware to restrict the limit below what the hardware could actually support, as long as the advertised limit is consistently applied. Picture that the hardware can only manage/sample textures up to a given size, and this is the size reported by these limits.

这些限制与可用内存量无关,因此绝对不能保证可以成功分配大小的纹理.

These limits have nothing to do with the amount of memory available, so staying within these limits is absolutely no guarantee that a texture of the size can successfully be allocated.

我相信代理纹理的目的是让您检查可以实际分配的大小.我不知道这在任何平台上是否都能正常运行.该机制确实不适合现代GPU如何管理内存.但是我从来没有使用过代理纹理,也没有处理过实现它们的问题.我绝对希望平台/供应商对它们的运行方式有很大的依赖性.因此,您可能应该尝试在他们关心的平台上,如果它们能够为您提供理想的结果.

I believe the intention of proxy textures is to let you check what size can actually be allocated. I don't know if that works reliably on any platforms. The mechanism really is not a good fit for how modern GPUs manage memory. But I have never used proxy textures, or dealt with implementing them. I would definitely expect significant platform/vendor dependencies in how exactly they operate. So you should probably try if they give you the desired results on the platforms you care about.

这篇关于可移植并正确地在OpenGL中获得最大1D/2D/3D/立方体纹理分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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