2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2002-03-19 07:10:33 +08:00
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
#ifndef OSG_TEXTURECUBEMAP
|
|
|
|
#define OSG_TEXTURECUBEMAP 1
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
#include <osg/Texture>
|
2002-03-19 07:10:33 +08:00
|
|
|
|
2002-03-21 06:39:51 +08:00
|
|
|
#ifndef GL_TEXTURE_CUBE_MAP
|
|
|
|
#define GL_TEXTURE_CUBE_MAP 0x8513
|
|
|
|
#endif
|
2002-03-19 07:10:33 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/** TextureCubeMap state class which encapsulates OpenGl texture cubemap functionality.*/
|
2002-08-28 23:28:11 +08:00
|
|
|
class SG_EXPORT TextureCubeMap : public Texture
|
2002-03-19 07:10:33 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public :
|
|
|
|
|
|
|
|
TextureCubeMap();
|
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
2002-08-25 03:39:39 +08:00
|
|
|
TextureCubeMap(const TextureCubeMap& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
2002-03-19 07:10:33 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
META_StateAttribute(osg, TextureCubeMap,TEXTURE);
|
2002-03-19 07:10:33 +08:00
|
|
|
|
|
|
|
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
|
|
|
virtual int compare(const StateAttribute& rhs) const;
|
|
|
|
|
|
|
|
enum Face {
|
|
|
|
POSITIVE_X=0,
|
|
|
|
NEGATIVE_X=1,
|
|
|
|
POSITIVE_Y=2,
|
|
|
|
NEGATIVE_Y=3,
|
|
|
|
POSITIVE_Z=4,
|
|
|
|
NEGATIVE_Z=5
|
|
|
|
};
|
|
|
|
|
2002-03-21 06:39:51 +08:00
|
|
|
/** Set the texture image for specified face. */
|
|
|
|
void setImage(const Face, Image* image);
|
|
|
|
|
|
|
|
/** Get the texture image for specified face. */
|
|
|
|
Image* getImage(const Face);
|
|
|
|
|
|
|
|
/** Get the const texture image for specified face. */
|
|
|
|
const Image* getImage(const Face) const;
|
2002-03-19 07:10:33 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
|
|
|
|
/** Set the texture width and height. If width or height are zero then
|
|
|
|
* the repsective size value is calculated from the source image sizes. */
|
|
|
|
inline void setTextureSize(const int width, const int height) const
|
|
|
|
{
|
|
|
|
_textureWidth = width;
|
|
|
|
_textureHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the texture subload width. */
|
|
|
|
inline void getTextureSize(int& width, int& height) const
|
|
|
|
{
|
|
|
|
width = _textureWidth;
|
|
|
|
height = _textureHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SubloadCallback : public Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void load(const TextureCubeMap& texture,State& state) const = 0;
|
|
|
|
virtual void subload(const TextureCubeMap& texture,State& state) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
|
|
|
|
|
|
|
|
SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
|
|
|
|
|
|
|
|
const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the number of mip map levels the the texture has been created with,
|
|
|
|
should only be called within an osg::Texuture::apply() and custom OpenGL texture load.*/
|
|
|
|
void setNumMipmapLevels(unsigned int num) const { _numMimpmapLevels=num; }
|
|
|
|
|
|
|
|
/** Get the number of mip map levels the the texture has been created with.*/
|
|
|
|
unsigned int getNumMipmapLevels() const { return _numMimpmapLevels; }
|
|
|
|
|
2002-03-19 07:10:33 +08:00
|
|
|
/** On first apply (unless already compiled), create the minmapped
|
|
|
|
* texture and bind it, subsequent apply will simple bind to texture.*/
|
|
|
|
virtual void apply(State& state) const;
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2002-03-19 07:10:33 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~TextureCubeMap();
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2002-03-19 07:10:33 +08:00
|
|
|
bool imagesValid() const;
|
2002-08-25 03:39:39 +08:00
|
|
|
|
|
|
|
virtual void computeInternalFormat() const;
|
2002-03-19 07:10:33 +08:00
|
|
|
|
|
|
|
mutable ref_ptr<Image> _images[6];
|
2002-08-25 03:39:39 +08:00
|
|
|
|
|
|
|
// subloaded images can have different texture and image sizes.
|
|
|
|
mutable GLsizei _textureWidth, _textureHeight;
|
|
|
|
|
|
|
|
// number of mip map levels the the texture has been created with,
|
|
|
|
mutable GLsizei _numMimpmapLevels;
|
|
|
|
|
|
|
|
ref_ptr<SubloadCallback> _subloadCallback;
|
2002-03-19 07:10:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|