简体   繁体   English

改善窗口大小调整行为,可能通过手动设置更大的帧缓冲区大小

[英]Improving window resize behaviour, possibly by manually setting bigger framebuffer size

I was considering using glfw in my application, while developing on mac 我正在考虑在我的应用程序中使用glfw,同时在mac上进行开发

After successfully writing a very simple program to render a triangle on a colored backround, I noticed that when resizing the window, it takes quite some time to rerender the scene, as I suspect due to framebuffer resize. 在成功编写一个非常简单的程序以在彩色背景上渲染三角形之后,我注意到在调整窗口大小时,重新渲染场景需要相当长的时间,因为我怀疑是由于帧缓冲区调整大小。

This is not the case when I am repeating the experiment with NSOpenGLView. 当我用NSOpenGLView重复实验时,情况并非如此。 Is there a way to hint glfw to use bigger framebuffer size on start, to avoid expensive resizes? 有没有办法暗示glfw在启动时使用更大的帧缓冲区大小,以避免昂贵的调整大小?

I am using GLFW 3. 我正在使用GLFW 3。

Could you also help me with enabling High DPI for retina display. 你能帮助我为视网膜显示启用高DPI吗? Couldn't find something in docs on that, but it supported in version 3. 无法在文档中找到某些内容,但在版本3中支持。

Obtaining a larger framebuffer 获得更大的帧缓冲区

Try to obtain a large initial frame-buffer by calling glfwCreateWindow() with large values for width & height and immediately switching to displaying a smaller window using glfwSetWindowSize() with the actual initial window size desired. 尝试通过调用widthheight值较大的glfwCreateWindow()并立即切换到使用glfwSetWindowSize()显示较小的窗口glfwSetWindowSize()所需的实际初始窗口大小来获取大的初始帧缓冲区。

Alternately, register your own framebuffer size callback function using glfwSetFramebufferSizeCallback() and set the framebuffer to a large size according to your requirement as follows : 或者,使用glfwSetFramebufferSizeCallback()注册您自己的帧缓冲区大小回调函数,并根据您的要求将帧缓冲区设置为大尺寸,如下所示:

void custom_fbsize_callback(GLFWwindow* window, int width, int height)
{
    /* use system width,height */
    /* glViewport(0, 0, width, height); */

    /* use custom width,height */
    glViewport(0, 0, <CUSTOM_WIDTH>, <CUSTOM_HEIGHT>);
}

UPDATE : 更新
The render pipeline stall seen during the window re-size(and window drag) operation is due to the blocking behavior implemented in the window manager. 在窗口重新调整大小(和窗口拖动)操作期间看到渲染管道停顿是由于在窗口管理器中实现的阻塞行为。

To mitigate this in one's app, one needs to install handler functions for the window messages and run the render pipeline in a separate thread independent from the main app(GUI) thread. 为了在一个应用程序中缓解这种情况,需要为窗口消息安装处理函数,并在独立于主应用程序(GUI)线程的单独线程中运行渲染管道。


High DPI support 高DPI支持

The GLFW documentation says : GLFW文件说:

GLFW now supports high-DPI monitors on both Windows and OS X, giving windows full resolution framebuffers where other UI elements are scaled up. GLFW现在支持Windows和OS X上的高DPI监视器,提供窗口全分辨率帧缓冲区,其他UI元素按比例放大。 To achieve this, glfwGetFramebufferSize() and glfwSetFramebufferSizeCallback() have been added. 为此,添加了glfwGetFramebufferSize()glfwSetFramebufferSizeCallback() These work with pixels, while the rest of the GLFW API work with screen coordinates. 这些使用像素,而GLFW API的其余部分使用屏幕坐标。

AFAIK, that seems to be pretty much everything about high-DPI in the documentation. AFAIK,在文档中似乎几乎所有关于高DPI的内容。

Going through the code we can see that on Windows, glfw hooks into the SetProcessDPIAware() and calls it during platformInit . 通过代码,我们可以看到在Windows上, glfw挂钩到 SetProcessDPIAware()在platformInit期间调用它 Currently i am not able to find any similar code for high-DPI support on mac. 目前我无法在mac上找到任何类似的高DPI支持代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM