为什么没有ValidateRect会导致Directx应用程序极大地减慢速度?(C ++) [英] why does not having ValidateRect cause a directx application to slow down tremendously??(c++)

查看:56
本文介绍了为什么没有ValidateRect会导致Directx应用程序极大地减慢速度?(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚问了一个问题发现缺陷c ++代码并意识到在我的应用程序中的消息处理程序中使用ValidateRect会导致极大的速度下降,这是为什么?,这怎么会以这种方式影响Directx应用程序?

I just asked a question Spot the flaw c++ code earlier and realised that not having ValidateRect in my application at the message handler causes tremendous slow downs 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应用程序极大地减慢速度?(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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