OpenGL 如何创建并渲染到大于窗口的帧缓冲区? [英] OpenGL how to create, and render to, a framebuffer that's larger than the window?

查看:144
本文介绍了OpenGL 如何创建并渲染到大于窗口的帧缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我可以创建一个带有渲染缓冲区和纹理附件的帧缓冲区,大小不限(卡支持).但是,当 glViewportGL_MAX_VIEWPORT_DIMS 限制时,我如何才能真正绘制整个内容,GL_MAX_VIEWPORT_DIMS 需要至少与窗口,就我而言,并不大.https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml

I gather that I can create a Framebuffer with Renderbuffer and Texture attachments in whatever size I want (that's supported by the card). However, how can I actually draw to the whole thing when glViewport is limited by the GL_MAX_VIEWPORT_DIMS, which needs to be at least as large as the window, and in my case, is no larger. https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGet.xml

在我的用例中,我希望为点光源创建一个阴影立方体贴图,这是一个很好的大性感尺寸.我的窗口是 1600x900.由于一些后处理会影响渲染到四边形,这是下采样,我之前调用了 glViewport 将大小设置为各种东西.

In my use case I'm looking to create a shadow cubemap for a point light that's a nice big sexy size. My window is 1600x900. Due to some post-processing affects that render to quads, which are downsampled, I have previous calls to glViewport that's setting the size to various things.

但我不能让它比窗口大,所以我永远无法绘制到帧缓冲区的外部区域?

But I can't make it any larger than the window, so I can't ever draw to the outside areas of my Framebuffer?

或者在创建帧缓冲区时游戏永远不会超过窗口的大小?

Or do games never exceed the size of the window when creating framebuffers?

推荐答案

规范中讨论屏幕尺寸的语言只是实现需要支持的保证最小值的一部分.规范说:

The language in the spec talking about the screen size is only part of the guaranteed minimum that needs to be supported by an implementation. The spec says:

最大视口尺寸必须大于或等于正在渲染的显示器的可见尺寸(如果显示器存在),以及可以成功创建并附加到帧缓冲对象的最大渲染缓冲图像 [..]

The maximum viewport dimensions must be greater than or equal to the larger of the visible dimensions of the display being rendered to (if a display exists), and the largest renderbuffer image which can be successfully created and attached to a framebuffer object [..]

这意味着 GL_MAX_VIEWPORT_DIMS 也将至少与 GL_MAX_RENDERBUFFER_SIZE 一样大.该限制的保证最小值取决于版本.例如,在 OpenGL 3.3 中为 1024,在 OpenGL 4.5 中为 16,384.

This means that GL_MAX_VIEWPORT_DIMS will also be at least as large as GL_MAX_RENDERBUFFER_SIZE. The guaranteed minimum for that limit is version dependent. It's for example 1024 in OpenGL 3.3, and 16,384 in OpenGL 4.5.

如果您查询GL_MAX_VIEWPORT_DIMS,您通常会发现它比屏幕尺寸大很多.它与最大纹理大小相同是很常见的.因此,它通常不会阻止您渲染到您可以创建的任何纹理/渲染缓冲区.

If you query GL_MAX_VIEWPORT_DIMS, you will mostly find it to be considerably larger than the screen size. It's common for it to be the same as the maximum texture size. So it shouldn't normally stop you from rendering to any texture/renderbuffer you can create.

在渲染到 FBO 之前,您需要确保使用 FBO 中渲染目标的大小调用 glViewport().请注意,视口大小不是 FBO 状态的一部分,因此在开始渲染到不同的帧缓冲区(FBO 或默认帧缓冲区)之前,您必须每次执行此操作.

Before rendering to the FBO, you need to make sure that you call glViewport() with the size of the render targets in your FBO. Note that the viewport size is not part of the FBO state, so you have to do this each time before starting to render to a different framebuffer (FBO or default framebuffer).

如果您启用了剪刀测试,您还需要确保在切换到大于默认帧缓冲区的 FBO 时禁用它或更新剪刀矩形.

If you have the scissor test enabled, you will also need to make sure that you either disable it, or update the scissor rectangle, when switching to a FBO that is larger than your default framebuffer.

这篇关于OpenGL 如何创建并渲染到大于窗口的帧缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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