Windows应用商店应用 - SwapChainPanel DrawLine性能

时间:2013-10-12 10:55:38

标签: windows-runtime windows-store-apps direct2d

我正在使用XAML / C#开发Windows应用商店应用。该应用程序还有一个Windows运行时组件,用于显示使用DirectX的图表输出。

我使用SwapChainPanel方法绘制线条(x轴,y轴和波形)。

我从下面的MSDN示例中选择了这种方法(参见场景3 - D2DPanel) http://code.msdn.microsoft.com/windowsapps/XAML-SwapChainPanel-00cb688b

这是我的问题, 我的波形包含大量数据(范围从1,000到20,000点)。在每次渲染函数调用期间,我会连续为所有这些点调用DrawLine。

该控件还提供平移和缩放功能,但无论缩放级别如何,都会使StrokeWidth保持不变,因此可见区域(渲染目标)可能远小于我绘制的线条。

在屏幕外调用DrawLine会导致性能问题吗?

我尝试过PathGeometry& GeometryRealization但我无法在各种缩放级别控制StrokeWidth。

我的渲染方法通常类似于下面的代码段。无论缩放级别如何,lineThickness都被控制为相同。

m_d2dContext->SetTransform(m_worldMatrix);

float lineThickness = 2.0f / m_zoom;

for (unsigned int i = 0; i < points->Size; i += 2)
{
    double wavex1 = points->GetAt(i);
    double wavey1 = points->GetAt(i + 1);

    if (i != 0)
    {
        m_d2dContext->DrawLine(Point2F(prevX, prevY), Point2F(wavex1, wavey1), brush, lineThickness);
    }

    prevX = wavex1;
    prevY = wavey1;
}

我是DirectX的新手,但不是C ++的新手。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

简短回答:它可能会。在绘图之前推送剪辑是一种很好的做法。例如,在您的情况下,您将使用绘图表面的边界调用ID2D1DeviceContext::PushAxisAlignedClip。这将确保没有绘图调用试图在表面边界之外绘制。

答案很长:实际上,它取决于一些因素,包括但不限于设备上下文所针对的目标,显示硬件和显示驱动程序。例如,如果你正在绘制一个支持CPU的ID2D1Bitmap,那么假设没有太大差别可能是公平的。

但是,如果您直接绘制到某个硬件支持的表面(GPU位图或从IDXGISurface创建的位图),它可能会有点毛茸茸。例如,请考虑excellently documented MSDN sample中的此评论。在这里,代码的位置ClearID2D1Bitmap创建IDXGISurface

// The Clear call must follow and not precede the PushAxisAlignedClip call. 
// Placing the Clear call before the clip is set violates the contract of the 
// virtual surface image source in that the application draws outside the 
// designated portion of the surface the image source hands over to it. This 
// violation won't actually cause the content to spill outside the designated 
// area because the image source will safeguard it. But this extra protection 
// has a runtime cost associated with it, and in some drivers this cost can be 
// very expensive. So the best performance strategy here is to never create a 
// situation where this protection is required. Not drawing outside the appropriate 
// clip does that the right way.