Hey guys
I have been using SFML to write some custom CG software and I'm hoping someone may be able to help me with a performance issue. Each frame of my render loop must be captured into a BGRA bitmap which is then sent across the network. My issue is, the act of copying the image from the render texture is so slow that my frames drop from almost one million(when unlimited) to around 20. I realise that transferring large amounts of data from the GPU memory to RAM is a slow process and I'm likely stuck, but I thought I would try and get some outside perspective before I return to the drawing board.
Here is my main render loop.
while (true)
{
//Re/Start watch
watch.Restart();
//Lock render texture for thread safety
lock (m_RenderTexture)
{
// clear the render texture with full transparency
m_RenderTexture.Clear(SFML.Graphics.Color.Transparent);
//Lock layers collection for thread safety
lock (m_Layers)
{
//Update layers
foreach (ILayer layer in m_Layers)
{
layer.Update(m_FrameTime);
}
//Draw layers
foreach (ILayer layer in m_Layers)
{
m_RenderTexture.Draw(layer);
}
}
//Display what has been drawn
m_RenderTexture.Display();
//Get frame from graphics card
Image frame = m_RenderTexture.Texture.CopyToImage();
//Send frame to tricaster
m_TriCaster.SendFrame(frame);
//Dispose frame
frame.Dispose();
}
//Limit loop to specified max framerate
while (watch.ElapsedMilliseconds < ((1.0 / m_MaxFrameRate) * 1000.0))
{
//Sleep thread for required time to match requested framerate
waittime = (int)(((1.0 / m_MaxFrameRate) * 1000.0) - watch.ElapsedMilliseconds);
Thread.Sleep(Math.Max(waittime, 0));
}
//Stop watch and store frame time
watch.Stop();
m_FrameTime = watch.Elapsed;
}
Any assistance would be greatly appreciated.
Thanks