OpenSceneGraph/include/osg/TextureCubeMap
Robert Osfield 239068f223 Added new osg::TextureBase, osg::Texture1D, osg::Texture2D, and osg::Texture3D
classes, and changed osg::Texture and osg::TextureCubeMap so that they now derive
from osg::TextureBase.
2002-08-24 19:39:39 +00:00

116 lines
3.6 KiB
C++

//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
// -*-c++-*-
#ifndef OSG_TEXTURECUBEMAP
#define OSG_TEXTURECUBEMAP 1
#include <osg/TextureBase>
#ifndef GL_TEXTURE_CUBE_MAP
#define GL_TEXTURE_CUBE_MAP 0x8513
#endif
namespace osg {
/** TextureCubeMap state class which encapsulates OpenGl texture cubemap functionality.*/
class SG_EXPORT TextureCubeMap : public TextureBase
{
public :
TextureCubeMap();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TextureCubeMap(const TextureCubeMap& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_StateAttribute(osg, TextureCubeMap,TEXTURE);
/** 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
};
/** 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;
/** 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; }
/** 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;
protected :
virtual ~TextureCubeMap();
bool imagesValid() const;
virtual void computeInternalFormat() const;
mutable ref_ptr<Image> _images[6];
// 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;
};
}
#endif