getCameraToViewportRay method is thread safe?

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
Gdlk
Halfling
Posts: 53
Joined: Mon Dec 05, 2011 9:43 pm
x 1

getCameraToViewportRay method is thread safe?

Post by Gdlk »

Hi!

I want to know if the method getCameraToViewportRay in the ogre camera is thread safe or not.

Thanks!!

Regards!!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: getCameraToViewportRay method is thread safe?

Post by dark_sylinc »

Hi!

I just took a quick look, and no, unfortunately it's not thread safe :roll:

The routine calls getViewMatrix which ends up calling Frustum::isViewOutOfDate; and this in turn performs:

Code: Select all

bool Frustum::isViewOutOfDate(void) const
{
    // Attached to node?
    if( mParentNode )
    {
        const Quaternion derivedOrient( mParentNode->_getDerivedOrientationUpdated() ); //----> Problematic
        const Vector3 derivedPos( mParentNode->_getDerivedPosition() );
It's a shame, because a version that only uses cached values (cached view & projection matrices) if you guarantee the Camera is up to date and not touched while in another thread; it could be "safe".

If you really need this functionality the best I can recommend is to copy the code inside Camera::getCameraToViewportRay into your own routine; and use a cached view & projection matrix (that was grabbed from the main thread) and then your routine would be thread safe.
With the exception of getProjectionMatrix & getViewMatrix, everything else inside getCameraToViewportRay is pure math and local variables.

Cheers
Gdlk
Halfling
Posts: 53
Joined: Mon Dec 05, 2011 9:43 pm
x 1

Re: getCameraToViewportRay method is thread safe?

Post by Gdlk »

Ok! I will copy the code then and cache the matrix, thanks!! =)

Regards!!
Post Reply