/*****************************************************************************
 * $LastChangedDate: 2011-04-09 21:58:06 -0400 (Sat, 09 Apr 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Hardware light for 3D models incompatible with shaders.
 *//*
 * LEGAL:   COPYRIGHT (C) 2009 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#if COMPILE_HW_LIGHT
#ifndef SHADER_LIGHT_HW_HH
#define SHADER_LIGHT_HW_HH 1

#define GET_HW_LIGHT() (HwLight::GetInstance())

#include "base/singleton.hh"
namespace view { class View; }
using namespace view;
#include "shader/light_base.hh"

#include <osg/Light>
#include <osg/LightSource>
#include <osg/Fog>

namespace shader {

class HwLight_PreDrawViewListener;  // to transform light position

////////////////////////////////////////////////////////////////////////////////
/// @brief The hardware light for 3D models incompatible with shaders.
///
/// Most clients should use the interface of Light class (shader/light.hh).
///
/// By design, this has only one light source (the main light).
/// Also includes hw fog.
///
class HwLight : public BaseLight
{
PREVENT_COPYING(HwLight)
friend class HwLight_PreDrawViewListener;
private:
    HwLight( void );
    ~HwLight();

public:
    DEFINE_GetInstance( HwLight )  // Singleton
    RefPtr<osg::LightSource> MakeHwLightGroup( void );

// -- Light interface --

// Individual lights:
    void        SetLightType( const uint lightNum, const shader::defs::eLightType type );
    void        SetLightPosition( const uint lightNum, const WorldVertex& pos );
    WorldVertex GetLightPosition( const uint lightNum );
    void        SetLightColor( const uint lightNum, const RGBA color );

// Brightness:
    void        SetLightBrightness( const fp brightness, const shader::defs::eBrightness setting );
    fp          GetLightBrightness( void );
    void        SetLightBaseAmbient( const RGBA color );

// Fog:
    void        SetFogDensity( const fpx fogDensity, const osg::Fog::Mode fogMode );
    void        SetFogColor( const RGBA fogColor );
    void        SetFogMin( const fp fogMin );

private:
    void        PreDraw( shptr<View> view );

private:
    CLASS_CONST uint            HW_LIGHT_NUM = 0;   ///< GL_LIGHT0 is wrong in OSG
    CLASS_VAR HwLight*          msInstance;
    shptr<HwLight_PreDrawViewListener> mPreDrawViewListener;    ///< reflected to event listeners in app
    RefPtr<osg::Light>          mHwLight;           ///< hw light
    RefPtr<osg::Fog>            mHwFog;             ///< hw fog
    shader::defs::eLightType    mLightType;
    WorldVertex                 mLightPosition;     ///< position in world space
    osg::Vec4                   mLightAmbient;
    osg::Vec4                   mLightDiffuse;
    osg::Vec4                   mLightSpecular;
    fp                          mLightBrightness;
    osg::Vec4                   mFogColor;
};

} // namespace shader

#endif // SHADER_LIGHT_HW_HH
#endif // COMPILE_HW_LIGHT
