如何检查 OpenGL 中 mip-map 的可用性?

发布于 2024-09-05 23:58:22 字数 1009 浏览 6 评论 0原文

最近,我遇到了一个问题,即我的 OpenGL 程序无法在配备 nVidia Quadro 140 卡的 2 年旧联想笔记本电脑上正确渲染纹理。它运行 OpenGL 2.1.2 和 GLSL 1.20,但是当我打开 mip-mapping 时,整个屏幕是黑色的,没有警告或错误。

这是我的纹理过滤器代码:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

经过 40 分钟的摆弄,我发现 mip 映射是问题所在。将其关闭修复了它:

// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

我得到了很多别名,但至少程序是可见的并且运行良好。

最后,有两个问题:

  1. 除了检查 OpenGL 版本之外,检查机器上是否可用 mip 映射的最佳或标准方法是什么?
  2. 如果 mip 映射不可用,避免锯齿的最佳解决方法是什么?

编辑:

这是我真正想要的问题:

如何以编程方式检查 mip 映射在平台上是否可用?

Recently I bumped into a problem where my OpenGL program would not render textures correctly on a 2-year-old Lenovo laptop with an nVidia Quadro 140 card. It runs OpenGL 2.1.2, and GLSL 1.20, but when I turned on mip-mapping, the whole screen is black, with no warnings or errors.

This is my texture filter code:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

After 40 minutes of fiddling around, I found out mip-mapping was the problem. Turning it off fixed it:

// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

I get a lot of aliasing, but at least the program is visible and runs fine.

Finally, two questions:

  1. What's the best or standard way to check if mip-mapping is available on a machine, aside from checking OpenGL versions?
  2. If mip-mapping is not available, what's the best work-around to avoid aliasing?

Edit:

Here's the question I'm really after:

How do you programmactically check if mip-mapping is available on a platform?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北恋 2024-09-12 23:58:22

OpenGL 1.4 需要支持自动 mipmap生成(使用 GL_GENERATE_MIPMAP),使用 mipmap 的纹理应该在几乎所有显卡上都可用。
我想问题可能不是
缺少 mipmap 功能
但也许这一代人
mip 贴图。仅用于调试
目的,你可以尝试生成
使用 gluBuild2DMipmaps 绘制 mipmap?

如果此问题特定于此显卡/配置,检查更新的驱动程序也可能是一个好主意。

消除混叠的一个好方法是多重采样

OpenGL 1.4 is required for support for automatic mipmap generation (using GL_GENERATE_MIPMAP), texturing using mipmaps should be available on virtually every graphic card out there.
I guess the problem might not be
missing mipmapping functionality
but maybe the generation of the
mipmaps. Just for debugging
purposes, can you try generating the
mipmaps using gluBuild2DMipmaps?

If this problem is specific to this graphic card/configuration, checking for updated drivers might be a good idea, too.

A good method to get rid of aliasing is multisampling.

小…红帽 2024-09-12 23:58:22

如果没有可用的 mip 映射,您可能不想避免锯齿。没有 mip 映射的平台通常不值得这么麻烦。

但是,如果您确实想要避免锯齿,则可以通过按基元 mip 映射来近似按片段 mip 映射。首先,您必须手动生成所有 mip-map 级别并将其上传到单独的纹理中。在渲染三角形之前,在 cpu 上计算适当的 mip-map 级别并使用与此 mip-map 级别对应的纹理。为了避免大型基元上出现伪影,请将它们细分。

If no mip-mapping is available, your probably don't want to avoid the aliasing. A platform without mip-mapping is usually not worth the trouble.

However, if you really really want to avoid aliasing, you could approximate per-fragment mip-mapping by per-primitive mip-mapping. First you have to generate and upload all mip-map-levels by hand into separate textures. Before rendering a triangle, compute the appropriate mip-map level on the cpu and use the texture corresponding to this mip-map level. To avoid artifacts on large primitives, subdivide them.

甜心小果奶 2024-09-12 23:58:22

OpenGL 要求 Core 中的所有纹理格式都支持 mip-mapping。因此,没有特定的方法来询问纹理格式是否支持 mip 映射。

一些扩展在首次引入时放宽了对新格式的限制(最值得注意的是,两个纹理的非幂和浮动纹理)。扩展本身明确表示根本不支持 mip 映射。但在将它们集成到核心之前,恢复了对 mip 映射支持的要求。

OpenGL requires that all texture formats that are part of the Core support mip-mapping. As such there is no specific way to ask whether a texture format supports mip-mapping.

Some extensions, when first introduced, were relaxing this constraint for new formats (most notably, non-power of two textures, and float textures). The extension itself made it clear that the mip-mapping was not supported at all. But before those got integrated into the core, the requirement for mip-mapping support was reinstated.

娇俏 2024-09-12 23:58:22

如果您的实现确实不支持 mipmap,我会感到非常惊讶。您更有可能错过一个或多个级别,这是很容易意外发生的事情。

如果您只错过一个 mip 级别并启用 mipmap,您就会得到您所拥有的黑色。确保定义低至 1x1 的所有级别,或者相应地设置 GL_TEXTURE_MAX_LEVEL TexParameter。

I would be very surprised if your implementation really didn't support mipmaps. More likely you are missing one or more levels, this is something that can easily happen by accident.

If you only miss as much as a single mip level and enable mipmapping, you get just what you have, black. Be sure that either all levels down to 1x1 are defined, or set the GL_TEXTURE_MAX_LEVEL TexParameter accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文