SFML community forums

Help => General => Topic started by: kullerhamPster on December 08, 2009, 10:33:36 pm

Title: Performance within VirtualBox
Post by: kullerhamPster on December 08, 2009, 10:33:36 pm
I tried to run a simple SFML-app I've written inside a Linux virtual machine, hosted by VirtualBox on a Win 7 x64 host.

VirtualBox supports OpenGL for guest operating systems since quite a while now, and the performance is surprisingly good when using some Compiz desktop effects inside the VM (like wobbly windows or transparency). My SFML-app however (which does not much more than drawing a few sprites) runs really, really slow and stuttering, and I'm not quite sure whether this is a problem of VirtualBox, my app, or SFML.

Has anyone else here ever tried to use SFML inside a virual machine?

EDIT: Just found out that the problem seems to be created by drawing a pseudo-3D-starfield in the background which consisted of 500 stars. Perhaps there's something wrong with the way I update the position of these stars. I'll see if I can figure it out.

EDIT2: Ok, it seems to be related to some graphic/OpenGL-stuff. If I calculate the position for each star but don't draw it (by commenting out the call to the draw-method of the render-window), it runs at quite normal speed.
Title: Performance within VirtualBox
Post by: Laurent on December 08, 2009, 11:26:05 pm
Can you show your code?
Title: Performance within VirtualBox
Post by: kullerhamPster on December 09, 2009, 10:33:40 pm
The code for drawing the stars looks like this:
Code: [Select]

void Starfield::draw()
{
    for ( int i = 0; i < this->nStars; ++i )
    {        
        int screenX = this->starList[i].x / this->starList[i].z + this->centerX;
        int screenY = this->starList[i].y / this->starList[i].z + this->centerY;
        sf::Shape rect = sf::Shape::Rectangle( screenX, screenY, screenX + 3, screenY + 3,
                                               sf::Color(255 - starList[i].z * 2,
                                                         255 - starList[i].z * 2,
                                                         255 - starList[i].z * 2,
                                                         255) );
        this->window->Draw( rect );

        this->starList[i].z -= this->speedList[i] * this->window->GetFrameTime();

        if ( this->starList[i].z < 1 )
            this->starList[i].z = rand() % 50 + 1;
    }
}


This method is called in every iteration of the main loop. If I comment out the this->window->Draw( rect ); line, the app is running at relatively normal speed.

Perhaps its just too many OpenGL calls which lead to world switches between the guest and the host?!
Title: Performance within VirtualBox
Post by: kullerhamPster on December 09, 2009, 10:58:39 pm
I just had a look at the activity inside the VM when my app is running: It's not the app itself that causes high CPU loads, but Xorg.
Title: Performance within VirtualBox
Post by: Laurent on December 09, 2009, 10:59:55 pm
Quote
Perhaps its just too many OpenGL calls

Probably. This kind of stuff is much faster in SFML 2.
Title: Performance within VirtualBox
Post by: Dominator on December 10, 2009, 02:37:14 pm
Can you confirm that OpenGL is working correctly in the VM, kullerhamPster?

Because with Win7 x64 as host, I don't get hardware accelerated OpenGL in the Ubuntu guest.

SFML apps run really slow in software rendering mode.
I for example get only about 10 fps when simply drawing a square each frame.

For me it works fine with WinXP as host though.
Title: Performance within VirtualBox
Post by: panithadrum on December 10, 2009, 06:45:37 pm
Quote from: "Dominator"
Can you confirm that OpenGL is working correctly in the VM, kullerhamPster?

Because with Win7 x64 as host, I don't get hardware accelerated OpenGL in the Ubuntu guest.

SFML apps run really slow in software rendering mode.
I for example get only about 10 fps when simply drawing a square each frame.

For me it works fine with WinXP as host though.


Same here, I use W7x64 and I can't get hardware accelerated OpenGL in Ubuntu.
Title: Performance within VirtualBox
Post by: kullerhamPster on December 10, 2009, 10:56:26 pm
I didn't really check it, I just saw that the desktop-effects I enabled (wobbly windows and a transparent terminal) ran pretty smooth, so I assumed that it must be HW-accelerated.

I'm not sure how to find out if HW-acceleration is actually active. What should glxinfo print out if it is?

glxgears claims to render around 12800 frames in 5 seconds.
Title: Performance within VirtualBox
Post by: kullerhamPster on December 10, 2009, 10:58:33 pm
I'm running Linux Mint 8 in the 32 bit version inside the VM, but Linux Mint is afaik more or less the same as Ubuntu, so that shouldn't make a difference.

Edit: Ooops, didn't want to create a new post for that, I accidentally pressed "quote" instead of "edit".
Title: Performance within VirtualBox
Post by: Dominator on December 10, 2009, 11:58:45 pm
Quote from: "kullerhamPster"
glxgears claims to render around 12800 frames in 5 seconds.

Looks like OpenGL is hardware accelerated for you.
You should try SFML2, it may fix your issue.
Title: Performance within VirtualBox
Post by: kullerhamPster on December 20, 2009, 09:28:04 pm
How/when/where can I get SFML2? I just downloaded and built the trunk tarball, but that seems to be 1.6.
Title: Performance within VirtualBox
Post by: Laurent on December 20, 2009, 09:36:39 pm
You must use a SVN client, then checkout branches/sfml2. I think there's a tutorial on the wiki.
Title: Performance within VirtualBox
Post by: kullerhamPster on December 20, 2009, 09:55:34 pm
Quote from: "Laurent"
You must use a SVN client, then checkout branches/sfml2. I think there's a tutorial on the wiki.


Thanks for the quick reply. I just checked it out, now I'll see if it builds.

Didn't find a tutorial related to SFML 2, though.
Title: Performance within VirtualBox
Post by: Nexus on December 20, 2009, 10:11:56 pm
Quote from: "kullerhamPster"
Didn't find a tutorial related to SFML 2, though.
There is none.

Many things in the interface have remained the same, but there have been some key name alterations, for example at sf::String. Check out the general discussions (http://www.sfml-dev.org/forum/viewforum.php?f=1) forum, where Laurent announces important changes. For smaller things, you can orientate yourself by the documentation in the SFML headers.
Title: Performance within VirtualBox
Post by: kullerhamPster on December 20, 2009, 10:15:59 pm
I was able to build SFML 2, but now my project doesn't build anymore, I get tons of undefine reference errors.

I guess part of my problem is that I didn't want to install SFML 2 globally, but instead placed it in my home directory, and still have SFML 1.4 installed system-wide. As I've no idea how to specify header search dirs with scons, I guess I'm currently using the 1.4 includes, but trying to link against 2.0.

I'll see if I can fix this...
Title: Performance within VirtualBox
Post by: kullerhamPster on December 24, 2009, 12:02:58 am
Yeah, it works :D

Took me quite a while to figure out the reason for all those "undefined references", but it was a very small error in the end: I had forgotten to add libsfml-window to the list of libraries to which I link. Seems that it wasn't necessary with SFML 1.4, perhaps some functions were moved from graphics to window?!

Afterwards, I had to find out how to add another search path for dynamic libraries - LD_LIBRARY_PATH didn't work. ld's "-rpath" option is the answer ;)

The performance with SFML2 seems indeed to be much better than with SFML 1.4 - though I can't make a direct comparison at the moment, as I uninstalled SFML 1.4 during my bug-search ;)

Thanks again for all the help, and Merry Christmas :)