C# 在XNA fast中绘制多个2D纹理

C# 在XNA fast中绘制多个2D纹理,c#,xna,texture2d,C#,Xna,Texture2d,在XNA中尝试同时绘制两种2D纹理时,我遇到了性能问题(请参见下面的代码) 我只画了一个覆盖着遮罩的网络摄像头捕捉到的画面,就得到了30帧的稳定画面 只画高斯点(即使是大量的点),我也会得到很高的FPS 但将捕获的图像、帧、掩模和高斯点放在一起,FPS下降到15。然而,我的应用程序需要更高的FPS 我的问题是,在这种情况下,如何实现更高的帧速率(如稳定的30 FPS)。我需要改变什么 我对一件事感到困惑:我以为随着2D绘制纹理数量的增加,性能会下降。然而,即使我只是画了一帧,遮罩并添加了一个高斯

在XNA中尝试同时绘制两种2D纹理时,我遇到了性能问题(请参见下面的代码)

我只画了一个覆盖着遮罩的网络摄像头捕捉到的画面,就得到了30帧的稳定画面

只画高斯点(即使是大量的点),我也会得到很高的FPS

但将捕获的图像、帧、掩模和高斯点放在一起,FPS下降到15。然而,我的应用程序需要更高的FPS

我的问题是,在这种情况下,如何实现更高的帧速率(如稳定的30 FPS)。我需要改变什么

我对一件事感到困惑:我以为随着2D绘制纹理数量的增加,性能会下降。然而,即使我只是画了一帧,遮罩并添加了一个高斯点,它也会直接下降到15 FPS-取消高斯点2d纹理的数量(即绘制的纹理总数)似乎不再有什么区别。所以问题一定在于把这两种不同的东西结合在一起

有人能帮忙吗

非常感谢

// if residual is enabled, blend the video with the mask
if (configPanel.GetResidualEnabled())
{
    // Turn alpha blending on
    GraphicsDevice.BlendState = BlendState.Additive;

    Texture2D frame = configPanel.GetFrame();

    // Set the channels to write to the R, G, B channels 
    // and draw the first texture using a sprite batch
    spriteBatch.Draw(frame, new Rectangle(
                           0, 0, graphics.PreferredBackBufferWidth, 
                           graphics.PreferredBackBufferHeight),
                           new Rectangle(0, 0, frame.Width, frame.Height), 
                           Color.White, 0.0f, 
                           new Vector2(0, 0), myEffect, 0.0f);

    // Set channels to alpha only, and draw the alpha mask
    spriteBatch.Draw(configPanel.GetMask(), new Vector2(0, 0), Color.White);



    GraphicsDevice.BlendState = BlendState.Opaque;
}
// render the gaussian dots
if (configPanel.GetgaussianDotsEnabled())
{
    Texture2D gaussianDotTexture = configPanel.GetgaussianDot();

    foreach (GaussianDot gaussianDot in configPanel.GetGaussianDotList())
    {
        // Draw the gaussianDot with the correct amount of transparency 
        // and shift them by 1/2 of gaussianDot's size
        if (!configPanel.GetHorizontalFlip())
            spriteBatch.Draw(gaussianDotTexture, 
                        new Vector2(gaussianDot.centreX - 
                        gaussianDotTexture.Width / 2, 
                        gaussianDot.centreY - 
                        gaussianDotTexture.Height / 2), 
                        Color.White * gaussianDot.alpha);
        // if the box is checked, flip the horizontal by shifting the centres
        else
            spriteBatch.Draw(configPanel.GetgaussianDot(), 
                        new Vector2(graphics.PreferredBackBufferWidth - 
                        (gaussianDot.centreX + gaussianDotTexture.Width / 2), 
                        gaussianDot.centreY - gaussianDotTexture.Height / 2), 
                        Color.White * gaussianDot.alpha);
    }
}

无法真正说出代码中的原因。您应该使用VisualStudio中的“分析”菜单评测应用程序,让它运行一段时间,然后停止它并查看样例评测报告

然后查找代码中标记为热的位置,如下面的示例