为什么不调用 `ValidateRect` 会导致 DirectX 应用程序显着变慢? [英] Why does not calling `ValidateRect` cause a DirectX application to slow down tremendously?

查看:23
本文介绍了为什么不调用 `ValidateRect` 会导致 DirectX 应用程序显着变慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前问过一个相关问题,并意识到不调用 ValidateRect 在应用程序中作为对 WM_PAINT 的响应会导致极大的减速.

I asked a related question earlier and realised that not calling ValidateRect in the application as response to WM_PAINT causes tremendous slowdown.

这是为什么?这如何以这种方式影响 DirectX 应用程序?

Why is this? How could this affect a DirectX application in such a manner?

// ----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
    switch(msg) {
        case WM_DESTROY:
            Cleanup();
            PostQuitMessage( 0 );
            return 0;
        case WM_PAINT:
            Render();
            ValidateRect( hWnd, NULL );
            return 0;
    }
    return DefWindowProc( hWnd, msg, wParam, lParam );
}

推荐答案

您的应用程序正在变慢,因为它的渲染速度远远超出了需要.它正在接收 WM_PAINT 消息的狂暴流.

Your application is slowing down because it is rendering far more than necessary. It is receiving a furious stream of WM_PAINT messages.

当 Windows 认为应该绘制窗口时,它会向窗口发送 WM_PAINT 消息.它根据窗口是否已失效来进行此确定.一旦你完全渲染了窗口,你必须通过验证窗口的客户区来告诉 Windows 这是这种情况.只要有一些无效区域,Windows 就会继续向您的窗口发送 WM_PAINT 消息.

Windows sends a WM_PAINT message to a window when it thinks the window should be painted. It makes this determination based on whether a window has been invalidated. Once you have rendered the window completely, you must tell Windows that this is the case by validating the window’s client area. As long as there is some invalidated area, Windows will continue to send your window WM_PAINT messages.

在 DirectX 之前,应用程序窗口在调用 EndPaint 时进行验证.您仍然可以调用 BeginPaint 和 EndPaint,包装您正在执行的任何 DirectX 渲染,或者您可以在完成渲染后简单地调用 ValidateRect.

Before DirectX, application windows were validated when they called EndPaint. You can still call BeginPaint and EndPaint, wrapping whatever DirectX rendering you’re doing, or you can simply call ValidateRect when you’re done rendering.

这篇关于为什么不调用 `ValidateRect` 会导致 DirectX 应用程序显着变慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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