Sign in to follow this  
h3ro

ResolveBackBuffer very slow?

Recommended Posts

Hallo, I am very new to graphics programming using directX/XNA and I have a question. Is ResolveBackBuffer very very slow? Resolving the backbuffer and drawing it to the screen again costs me more then 100fps! Is is that slow, or am I doing something wrong?
public void Render(Vector2 cameraPosition)
{
    m_graphics.GraphicsDevice.Clear(BackgroundColour);

    // Render all the items that should be effected by the bloom filter
    // -----------------------------------------------------------------
        int renderIndex = (int)RenderBatch.Pre_bloom;
        m_spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);  
        for(int i = 0; i < m_renderList[renderIndex].Count; i++)
        {
            BaseSprite sprite = m_renderList[renderIndex][i].Sprite;
            sprite.render(m_spriteBatch, cameraPosition);
        }
        m_spriteBatch.End();

        // Get the backbuffer
        Graphics.ResolveBackBuffer(m_screenTexture);

        // Apply bloom to the screen
        if (m_settings.UseBloom)
        {
            m_bloom.Render(m_screenTexture, ref m_renderTarget);

            m_spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
                m_spriteBatch.Draw(m_renderTarget.GetTexture(), new Rectangle(0, 0, m_screenTexture.Width, m_screenTexture.Height), Color.White);
            m_spriteBatch.End();
        }
        else
        {
            m_spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
                m_spriteBatch.Draw(m_screenTexture, new Rectangle(0, 0, m_screenTexture.Width, m_screenTexture.Height), Color.White);
            m_spriteBatch.End();
        }
    // Render the text, this is only used for debug 
    // -----------------------------------------------------------------
        m_spriteBatch.Begin();
        foreach (TextInfo info in m_textRendeList)
            m_spriteBatch.DrawString(info.Font, info.Data, info.Position, info.FontColor);
        m_spriteBatch.End();
}

Share this post


Link to post
Share on other sites
Well first things first: measuring a difference in FPS is a bad way to profile. This is because FPS is non-linear: going from 1000 to 900 FPS is very different than going from 150 to 50. Instead measure your frame time in milliseconds, and compare that value.

As for resolving the backbuffer, I suspect that XNA just copies the back buffer data to another surface. While I don't see how this could be too slow, it's never going to be faster than just rendering to a RenderTarget instead. You should do that if you plan on doing post-processing.

Share this post


Link to post
Share on other sites
Thank you, I will change my code tomorrow to show me how long it takes to render a frame in ms. Going to have a look at your PIX tutorial tomorrow :)

I game you some wrong information, its not the ResolveBackbBuffer that is very slow, it is the part where I am drawing it to the screen again that is causing a massive drop in fps. Any idea?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this