/*****************************************************************************
 * $LastChangedDate: 2011-04-09 21:58:06 -0400 (Sat, 09 Apr 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Texture class.
 *//*
 * 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_TEXTURE_HH
#define FX_TEXTURE_HH 1

#include <osg/Image>
#include <osg/Texture2D>

namespace fx {

//------------------------------------------------------------------------------
namespace defs {
// Texture unit assignments:
const int TEXTURE_UNIT_0      = 0;  ///< should be int for GLSL uniforms
const int TEXTURE_UNIT_SHADOW = 3;
}  // namespace defs
//------------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////
/// @brief Texture class abstracts a texture object.
///
/// Texture class facilitates constructing textures in various ways.
/// Textures constructed from files use ImageCache.
///
class Texture : public Shared
{
PREVENT_COPYING(Texture)
public:
            Texture( uint8* buf, const uint width, const osg::Image::AllocationMode allocationMode );
            Texture( RefPtr<osg::Image> image );
            Texture( const string& filename );
            ~Texture();
    void    Bind( osg::StateSet& stateset );  // difficult to abstract osg::StateSet
    bool    SaveToFile( const string& filename );
    CLASS_METHOD RefPtr<osg::StateSet> NewTextureAsStateSet( const string& filename );

private:
    void Configure( void )
    {
        // GL_CLAMP_TO_EDGE should prevent texture creasing problems.
        mTextureObject->setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE );  // tx
        mTextureObject->setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE );  // ty
    }

private:
    RefPtr<osg::Texture2D>  mTextureObject;
public:
    DECLARE_TYPESIG(TYPESIG_TEXTURE)
};

} // namespace fx

#endif // FX_TEXTURE_HH
