2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2001-10-04 23:12:57 +08:00
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
// -*-c++-*-
|
|
|
|
|
2002-08-28 05:01:22 +08:00
|
|
|
//#define TEXTURE_USE_DEPRECATED_API
|
2002-08-25 03:39:39 +08:00
|
|
|
#ifdef TEXTURE_USE_DEPRECATED_API
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_TEXTURE
|
|
|
|
#define OSG_TEXTURE 1
|
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
#include <osg/TextureBase>
|
2002-08-25 23:31:44 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
namespace osg {
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Texture state class which encapsulates OpenGl texture functionality.*/
|
2002-08-25 03:39:39 +08:00
|
|
|
class SG_EXPORT Texture : public TextureBase
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public :
|
|
|
|
|
|
|
|
Texture();
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
2002-07-29 07:28:27 +08:00
|
|
|
Texture(const Texture& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
META_StateAttribute(osg, Texture,TEXTURE);
|
2002-07-09 17:35:42 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
|
|
|
virtual int compare(const StateAttribute& rhs) const;
|
|
|
|
|
2002-07-09 17:35:42 +08:00
|
|
|
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2002-08-25 03:39:39 +08:00
|
|
|
modes.push_back(GL_TEXTURE_2D);
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Set the texture image. */
|
|
|
|
void setImage(Image* image);
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
/** Get the texture image. */
|
2001-09-20 05:08:56 +08:00
|
|
|
Image* getImage() { return _image.get(); }
|
|
|
|
|
|
|
|
/** Get the const texture image. */
|
|
|
|
inline const Image* getImage() const { return _image.get(); }
|
2002-07-29 07:28:27 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Copy pixels into a 2D texture image.As per glCopyTexImage2D.
|
|
|
|
* Creates an OpenGL texture object from the current OpenGL background
|
|
|
|
* framebuffer contents at pos \a x, \a y with width \a width and
|
|
|
|
* height \a height. \a width and \a height must be a power of two.
|
|
|
|
*/
|
2002-03-20 19:24:47 +08:00
|
|
|
void copyTexImage2D(State& state, int x, int y, int width, int height );
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
/** Copy a two-dimensional texture subimage. As per glCopyTexSubImage2D.
|
2001-10-01 19:15:55 +08:00
|
|
|
* Updates portion of an existing OpenGL texture object from the current OpenGL background
|
2001-09-20 05:08:56 +08:00
|
|
|
* framebuffer contents at pos \a x, \a y with width \a width and
|
|
|
|
* height \a height. \a width and \a height must be a power of two,
|
|
|
|
* and writing into the texture with offset \a xoffset and \a yoffset.
|
|
|
|
*/
|
2002-03-20 19:24:47 +08:00
|
|
|
void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height );
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-03-14 08:07:29 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Set the internal format to use when creating OpenGL textures.
|
|
|
|
* Also sets the internalFormatMode to USE_USER_DEFINED_FORMAT.
|
|
|
|
*/
|
|
|
|
inline void setInternalFormatValue(const int internalFormat)
|
|
|
|
{
|
|
|
|
_internalFormatMode = USE_USER_DEFINED_FORMAT;
|
2002-08-25 03:39:39 +08:00
|
|
|
_internalFormat = internalFormat;
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the internal format to use when creating OpenGL textures.*/
|
2002-08-25 03:39:39 +08:00
|
|
|
inline const int getInternalFormatValue() const { return _internalFormat; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum SubloadMode {
|
|
|
|
OFF,
|
|
|
|
AUTO,
|
2002-08-16 21:33:32 +08:00
|
|
|
IF_DIRTY,
|
|
|
|
USE_CALLBACK
|
2001-09-20 05:08:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Set the texture subload mode. */
|
|
|
|
inline void setSubloadMode(const SubloadMode mode) { _subloadMode = mode; }
|
|
|
|
|
|
|
|
/** Get the texture subload mode. */
|
|
|
|
inline const SubloadMode getSubloadMode() const { return _subloadMode; }
|
|
|
|
|
2002-07-29 07:28:27 +08:00
|
|
|
/** Set the texture subload texture offsets. */
|
|
|
|
inline void setSubloadTextureOffset(const int x, const int y)
|
|
|
|
{
|
|
|
|
_subloadTextureOffsetX = x;
|
|
|
|
_subloadTextureOffsetY = y;
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
2002-07-29 07:28:27 +08:00
|
|
|
/** Get the texture subload texture offsets. */
|
|
|
|
inline void getSubloadTextureOffset(int& x, int& y) const
|
|
|
|
{
|
|
|
|
x = _subloadTextureOffsetX;
|
|
|
|
y = _subloadTextureOffsetY;
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
2002-03-28 06:51:58 +08:00
|
|
|
/** Set the texture subload width. If width or height are zero then
|
|
|
|
* the repsective size value is calculated from the source image sizes. */
|
2002-08-16 23:14:43 +08:00
|
|
|
inline void setSubloadTextureSize(const int width, const int height) const
|
2002-07-29 07:28:27 +08:00
|
|
|
{
|
|
|
|
_textureWidth = width;
|
|
|
|
_textureHeight = height;
|
2002-03-28 06:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the texture subload width. */
|
2002-07-29 07:28:27 +08:00
|
|
|
inline void getSubloadTextureSize(int& width, int& height) const
|
|
|
|
{
|
|
|
|
width = _textureWidth;
|
|
|
|
height = _textureHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the subload image offsets. */
|
|
|
|
inline void setSubloadImageOffset(const int x, const int y)
|
|
|
|
{
|
|
|
|
_subloadImageOffsetX = x;
|
|
|
|
_subloadImageOffsetY = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the subload image offsets. */
|
|
|
|
inline void getSubloadImageOffset(int& x, int& y) const
|
|
|
|
{
|
|
|
|
x = _subloadImageOffsetX;
|
|
|
|
y = _subloadImageOffsetY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the image subload width. If width or height are zero then
|
|
|
|
* the repsective size value is calculated from the source image sizes. */
|
|
|
|
inline void setSubloadImageSize(const int width, const int height)
|
|
|
|
{
|
|
|
|
_subloadImageWidth = width;
|
|
|
|
_subloadImageHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the image subload width. */
|
|
|
|
inline void getSubloadImageSize(int& width, int& height) const
|
|
|
|
{
|
|
|
|
width = _subloadImageWidth;
|
|
|
|
height = _subloadImageHeight;
|
2002-03-28 06:51:58 +08:00
|
|
|
}
|
|
|
|
|
2002-08-16 23:14:43 +08:00
|
|
|
class SubloadCallback : public Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void load(GLenum target, const Texture& texture,State& state) const = 0;
|
|
|
|
virtual void subload(GLenum target, const Texture& texture,State& state) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb; _subloadMode = cb ? USE_CALLBACK:OFF; }
|
|
|
|
|
|
|
|
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; }
|
2002-08-16 21:33:32 +08:00
|
|
|
|
2002-08-16 23:14:43 +08:00
|
|
|
/** Get the number of mip map levels the the texture has been created with.*/
|
|
|
|
unsigned int getNumMipmapLevels() const { return _numMimpmapLevels; }
|
2002-08-16 21:33:32 +08:00
|
|
|
|
2002-08-25 03:39:39 +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;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~Texture();
|
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
virtual void computeInternalFormat() const;
|
2002-03-15 00:01:21 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
// not ideal that _image is mutable, but its required since
|
|
|
|
// Image::ensureDimensionsArePowerOfTwo() can only be called
|
|
|
|
// in a valid OpenGL context, a therefore within an Texture::apply
|
|
|
|
// which is const...
|
|
|
|
mutable ref_ptr<Image> _image;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
// subloaded images can have different texture and image sizes.
|
2002-03-30 01:26:40 +08:00
|
|
|
mutable GLsizei _textureWidth, _textureHeight;
|
2002-08-16 21:33:32 +08:00
|
|
|
|
|
|
|
// number of mip map levels the the texture has been created with,
|
2002-08-25 03:39:39 +08:00
|
|
|
mutable GLsizei _numMimpmapLevels;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
SubloadMode _subloadMode;
|
2002-07-29 07:28:27 +08:00
|
|
|
GLint _subloadTextureOffsetX, _subloadTextureOffsetY;
|
|
|
|
GLint _subloadImageOffsetX, _subloadImageOffsetY;
|
|
|
|
GLsizei _subloadImageWidth, _subloadImageHeight;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-08-16 21:33:32 +08:00
|
|
|
ref_ptr<SubloadCallback> _subloadCallback;
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#endif
|
2002-08-25 03:39:39 +08:00
|
|
|
|
|
|
|
#else // USE_DEPRECATED_API
|
|
|
|
|
2002-08-25 23:31:44 +08:00
|
|
|
#ifdef USE_DEPRECATED_API
|
2002-08-25 03:39:39 +08:00
|
|
|
#include <osg/Texture2D>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
typedef Texture2D Texture;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-25 23:31:44 +08:00
|
|
|
#endif
|
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
#endif // USE_DEPRECATED_API
|