/*****************************************************************************
 * $LastChangedDate: 2010-04-13 13:14:34 -0400 (Tue, 13 Apr 2010) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Motion blur.
 *//*
 * LEGAL:   COPYRIGHT (C) 2008 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef FX_MOTION_BLUR_HH
#define FX_MOTION_BLUR_HH 1

#include <osg/OperationThread>

namespace fx {

#define GET_MOTION_BLUR() (fx::MotionBlur::GetInstance())

////////////////////////////////////////////////////////////////////////////////
/// @brief Motion blur.
///
/// Adapted from examples/osgmotionblur.
///
class MotionBlur
{
PREVENT_COPYING(MotionBlur)
private:
    MotionBlur( void );
    ~MotionBlur();
public:
    CLASS_METHOD MotionBlur& GetInstance( void );  // Singleton
    void Enable( const fp persistence );
    void Disable( void );

private:
    class Operation : public osg::Operation
    {
    public:
        Operation( void );
        virtual ~Operation();
        void SetPersistence( const fp persistence );
        virtual void operator ()( osg::Object* object );
    private:
        fp      mPersistence;
        bool    mCleared;
        fp      mT0;
        bool    mForceDisable;
    };

private:
    CLASS_VAR MotionBlur*   msInstance;
    bool                    mEnabled;
    const RefPtr<Operation> mOperation;
};

} // namespace fx

#endif // FX_MOTION_BLUR_HH
