Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - samsonch

Pages: [1]
1
Graphics / [SOLVED] Is sf::Drawable::draw thread safe?
« on: March 21, 2013, 04:39:16 pm »
 I had not thought of using the mutable keyword...
Thanks, this answers my question perfectly!  :D

2
Graphics / Re: Is sf::Drawable::draw thread safe?
« on: March 20, 2013, 09:15:47 pm »
Sorry for the confusion. I'll try to be more specific.

The computation thread call an user defined method to change the texture of a sprite. (It's not my real code but it's in the spirit)
void MyClass::SetFrame(sf::Texture& texture)
{
        m_Sprite.setTexture(texture);
}

The rendering thread call the declaration of the draw method.
void MyClass::draw (sf::RenderTarget &target, sf::RenderStates states) const
{
        target.draw(m_Sprite, states);
}

So, maybe it may occur a collision when the first thread update the texture and the other display the sprite at the same time. This collision can it occur? And if so, how can I avoid it?

Thanks

3
Graphics / [SOLVED] Is sf::Drawable::draw thread safe?
« on: March 20, 2013, 06:57:12 pm »
Hi,  :D
As mentionned in the title, I wonder if sf::Drawable::draw thread safe.

I created a class derived from sf::Drawable for rendering. It is designed to be executed in parallel with computation. The reason is that computation take to mush time to be executed and I don't want that rendering be frozen during this time. The class has a method called "SetFrame(...)" to pass data from the computation thread to the rendering thread, including textures for some sprites.

To be thread safe, I used some mutex. But, for the sprites, I can't use mutex because the draw method doesn't permit changes (const keyword). :-\

So, is sf::Drawable::draw already thread safe, or I must find an other way?

Thanks  :D

Pages: [1]
anything