2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-03-19 07:10:33 +08:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** TextureCubeMap state class which encapsulates OpenGL texture cubemap functionality. */
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT TextureCubeMap : public Texture
|
2002-03-19 07:10:33 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public :
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-03-19 07:10:33 +08:00
|
|
|
TextureCubeMap();
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** 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);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
2002-03-19 07:10:33 +08:00
|
|
|
virtual int compare(const StateAttribute& rhs) const;
|
|
|
|
|
2005-07-27 19:27:44 +08:00
|
|
|
virtual GLenum getTextureTarget() const { return GL_TEXTURE_CUBE_MAP; }
|
2002-10-07 19:06:37 +08:00
|
|
|
|
2002-03-19 07:10:33 +08:00
|
|
|
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. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual void setImage(unsigned int face, Image* image);
|
2002-03-21 06:39:51 +08:00
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
template<class T> void setImage(unsigned int face, const ref_ptr<T>& image) { setImage(face, image.get()); }
|
|
|
|
|
2002-03-21 06:39:51 +08:00
|
|
|
/** Get the texture image for specified face. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual Image* getImage(unsigned int face);
|
2002-03-21 06:39:51 +08:00
|
|
|
|
|
|
|
/** Get the const texture image for specified face. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual const Image* getImage(unsigned int face) const;
|
2002-03-19 07:10:33 +08:00
|
|
|
|
2004-07-27 18:11:45 +08:00
|
|
|
/** Get the number of images that can be assigned to the Texture. */
|
|
|
|
virtual unsigned int getNumImages() const { return 6; }
|
|
|
|
|
2018-02-13 20:01:57 +08:00
|
|
|
|
|
|
|
/** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/
|
|
|
|
virtual bool isDirty(unsigned int contextID) const
|
|
|
|
{
|
|
|
|
return (_images[0].valid() && _images[0]->getModifiedCount()!=_modifiedCount[0][contextID]) ||
|
|
|
|
(_images[1].valid() && _images[1]->getModifiedCount()!=_modifiedCount[1][contextID]) ||
|
|
|
|
(_images[2].valid() && _images[2]->getModifiedCount()!=_modifiedCount[2][contextID]) ||
|
|
|
|
(_images[3].valid() && _images[3]->getModifiedCount()!=_modifiedCount[3][contextID]) ||
|
|
|
|
(_images[4].valid() && _images[4]->getModifiedCount()!=_modifiedCount[4][contextID]) ||
|
|
|
|
(_images[5].valid() && _images[5]->getModifiedCount()!=_modifiedCount[5][contextID]);
|
|
|
|
}
|
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
inline unsigned int& getModifiedCount(unsigned int face,unsigned int contextID) const
|
2003-04-07 17:46:06 +08:00
|
|
|
{
|
2005-02-09 18:39:45 +08:00
|
|
|
// get the modified count for the current contextID.
|
|
|
|
return _modifiedCount[face][contextID];
|
2003-04-07 17:46:06 +08:00
|
|
|
}
|
2002-08-25 03:39:39 +08:00
|
|
|
|
|
|
|
/** Set the texture width and height. If width or height are zero then
|
2010-09-24 22:53:10 +08:00
|
|
|
* the respective size value is calculated from the source image sizes.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setTextureSize(int width, int height) const
|
2002-08-25 03:39:39 +08:00
|
|
|
{
|
|
|
|
_textureWidth = width;
|
|
|
|
_textureHeight = height;
|
|
|
|
}
|
|
|
|
|
2005-11-04 20:08:16 +08:00
|
|
|
void setTextureWidth(int width) { _textureWidth=width; }
|
|
|
|
void setTextureHeight(int height) { _textureHeight=height; }
|
2006-08-03 23:57:39 +08:00
|
|
|
|
|
|
|
virtual int getTextureWidth() const { return _textureWidth; }
|
|
|
|
virtual int getTextureHeight() const { return _textureHeight; }
|
|
|
|
virtual int getTextureDepth() const { return 1; }
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT SubloadCallback : public Referenced
|
2002-08-25 03:39:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void load(const TextureCubeMap& texture,State& state) const = 0;
|
|
|
|
virtual void subload(const TextureCubeMap& texture,State& state) const = 0;
|
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
|
|
|
|
|
|
|
|
const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
|
|
|
|
|
|
|
|
|
2015-06-01 21:11:49 +08:00
|
|
|
/** Set the number of mip map levels the texture has been created with.
|
2004-09-13 23:14:11 +08:00
|
|
|
* Should only be called within an osg::Texuture::apply() and custom OpenGL texture load.
|
|
|
|
*/
|
2003-04-30 19:40:17 +08:00
|
|
|
void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2015-06-01 21:11:49 +08:00
|
|
|
/** Get the number of mip map levels the texture has been created with. */
|
2012-03-22 01:36:20 +08:00
|
|
|
unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2005-07-25 21:05:57 +08:00
|
|
|
/** Copies a two-dimensional texture subimage, as per
|
|
|
|
* glCopyTexSubImage2D. Updates a portion of an existing OpenGL
|
|
|
|
* texture object from the current OpenGL background framebuffer
|
|
|
|
* contents at position \a x, \a y with width \a width and height
|
|
|
|
* \a height. Loads framebuffer data into the texture using offsets
|
|
|
|
* \a xoffset and \a yoffset. \a width and \a height must be powers
|
|
|
|
* of two. */
|
|
|
|
void copyTexSubImageCubeMap(State& state, int face, int xoffset, int yoffset, int x, int y, int width, int height );
|
|
|
|
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** On first apply (unless already compiled), create the mipmapped
|
|
|
|
* texture and bind it. Subsequent apply will simple bind to texture.
|
|
|
|
*/
|
2002-03-19 07:10:33 +08:00
|
|
|
virtual void apply(State& state) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-03-19 07:10:33 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~TextureCubeMap();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-03-19 07:10:33 +08:00
|
|
|
bool imagesValid() const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
virtual void computeInternalFormat() const;
|
2007-09-11 20:04:58 +08:00
|
|
|
void allocateMipmap(State& state) const;
|
2002-03-19 07:10:33 +08:00
|
|
|
|
2003-04-07 20:51:00 +08:00
|
|
|
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;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2015-06-01 21:11:49 +08:00
|
|
|
// number of mip map levels the texture has been created with,
|
2003-04-30 19:40:17 +08:00
|
|
|
mutable GLsizei _numMipmapLevels;
|
2002-08-25 03:39:39 +08:00
|
|
|
|
|
|
|
ref_ptr<SubloadCallback> _subloadCallback;
|
2003-04-07 17:46:06 +08:00
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
typedef buffered_value<unsigned int> ImageModifiedCount;
|
|
|
|
mutable ImageModifiedCount _modifiedCount[6];
|
2002-03-19 07:10:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|