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.
This commit is contained in:
@@ -12,7 +12,8 @@ namespace osg {
|
||||
class Referenced;
|
||||
class Object;
|
||||
class Image;
|
||||
class Texture;
|
||||
//class Texture;
|
||||
class TextureBase;
|
||||
class StateSet;
|
||||
class StateAttribute;
|
||||
class Node;
|
||||
@@ -53,7 +54,8 @@ class SG_EXPORT CopyOp
|
||||
virtual Drawable* operator() (const Drawable* drawable) const;
|
||||
virtual StateSet* operator() (const StateSet* stateset) const;
|
||||
virtual StateAttribute* operator() (const StateAttribute* attr) const;
|
||||
virtual Texture* operator() (const Texture* text) const;
|
||||
// virtual Texture* operator() (const Texture* text) const;
|
||||
virtual TextureBase* operator() (const TextureBase* text) const;
|
||||
virtual Image* operator() (const Image* image) const;
|
||||
virtual Array* operator() (const Array* image) const;
|
||||
virtual Primitive* operator() (const Primitive* image) const;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
class Texture;
|
||||
class Texture2D;
|
||||
class Impostor;
|
||||
class ImpostorSpriteManager;
|
||||
|
||||
@@ -106,10 +106,10 @@ class SG_EXPORT ImpostorSprite : public Drawable
|
||||
* which transform local coords into screen space.*/
|
||||
const float calcPixelError(const Matrix& MVPW) const;
|
||||
|
||||
void setTexture(Texture* tex,int s,int t);
|
||||
void setTexture(Texture2D* tex,int s,int t);
|
||||
|
||||
Texture* getTexture() { return _texture; }
|
||||
const Texture* getTexture() const { return _texture; }
|
||||
Texture2D* getTexture() { return _texture; }
|
||||
const Texture2D* getTexture() const { return _texture; }
|
||||
const int s() const { return _s; }
|
||||
const int t() const { return _t; }
|
||||
|
||||
@@ -149,7 +149,7 @@ class SG_EXPORT ImpostorSprite : public Drawable
|
||||
Vec2 _texcoords[4];
|
||||
Vec3 _controlcoords[4];
|
||||
|
||||
Texture* _texture;
|
||||
Texture2D* _texture;
|
||||
int _s;
|
||||
int _t;
|
||||
|
||||
|
||||
@@ -4,72 +4,17 @@
|
||||
|
||||
// -*-c++-*-
|
||||
|
||||
#define TEXTURE_USE_DEPRECATED_API
|
||||
#ifdef TEXTURE_USE_DEPRECATED_API
|
||||
|
||||
#ifndef OSG_TEXTURE
|
||||
#define OSG_TEXTURE 1
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/Types>
|
||||
#include <osg/Image>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Vec4>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
// if not defined by gl.h use the definition found in:
|
||||
// http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_filter_anisotropic.txt
|
||||
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
|
||||
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARB_texture_compression
|
||||
#define GL_COMPRESSED_ALPHA_ARB 0x84E9
|
||||
#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA
|
||||
#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB
|
||||
#define GL_COMPRESSED_INTENSITY_ARB 0x84EC
|
||||
#define GL_COMPRESSED_RGB_ARB 0x84ED
|
||||
#define GL_COMPRESSED_RGBA_ARB 0x84EE
|
||||
#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF
|
||||
#define GL_TEXTURE_IMAGE_SIZE_ARB 0x86A0
|
||||
#define GL_TEXTURE_COMPRESSED_ARB 0x86A1
|
||||
#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2
|
||||
#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3
|
||||
#endif
|
||||
|
||||
#ifndef GL_EXT_texture_compression_s3tc
|
||||
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
||||
#endif
|
||||
|
||||
#ifndef GL_MIRRORED_REPEAT_IBM
|
||||
#define GL_MIRRORED_REPEAT_IBM 0x8370
|
||||
#endif
|
||||
|
||||
#ifndef GL_CLAMP_TO_EDGE
|
||||
#define GL_CLAMP_TO_EDGE 0x812F
|
||||
#endif
|
||||
|
||||
#ifndef GL_CLAMP_TO_BORDER_ARB
|
||||
#define GL_CLAMP_TO_BORDER_ARB 0x812D
|
||||
#endif
|
||||
|
||||
#ifndef GL_GENERATE_MIPMAP_SGIS
|
||||
#define GL_GENERATE_MIPMAP_SGIS 0x8191
|
||||
#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192
|
||||
#endif
|
||||
|
||||
#ifndef GL_TEXTURE_3D
|
||||
#define GL_TEXTURE_3D 0x806F
|
||||
#endif
|
||||
|
||||
#include <osg/TextureBase>
|
||||
namespace osg {
|
||||
|
||||
/** Texture state class which encapsulates OpenGl texture functionality.*/
|
||||
class SG_EXPORT Texture : public StateAttribute
|
||||
class SG_EXPORT Texture : public TextureBase
|
||||
{
|
||||
|
||||
public :
|
||||
@@ -80,15 +25,13 @@ class SG_EXPORT Texture : public StateAttribute
|
||||
Texture(const Texture& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, Texture,TEXTURE);
|
||||
|
||||
virtual bool isTextureAttribute() const { return true; }
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& rhs) const;
|
||||
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
modes.push_back(_target);
|
||||
modes.push_back(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
/** Set the texture image. */
|
||||
@@ -100,17 +43,6 @@ class SG_EXPORT Texture : public StateAttribute
|
||||
/** Get the const texture image. */
|
||||
inline const Image* getImage() const { return _image.get(); }
|
||||
|
||||
/** Set the unreference image after apply flag, default value is false.
|
||||
* If set to true the attached image is unreferenced via a _image = 0;
|
||||
* if the image has no other references to it, it will be automatically
|
||||
* deleted. Note, this should only by used in case where only a single
|
||||
* graphics context is being used, otherwise only the first context will
|
||||
* be set, with the rest left with no image to apply.*/
|
||||
void setUnrefImageAfterApply(bool unrefImage) { _unrefImageAfterApply = unrefImage; }
|
||||
|
||||
/** Get the unreference image after apply flag.*/
|
||||
bool getUnrefImageAfterApply() const { return _unrefImageAfterApply; }
|
||||
|
||||
/** 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
|
||||
@@ -126,82 +58,7 @@ class SG_EXPORT Texture : public StateAttribute
|
||||
*/
|
||||
void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height );
|
||||
|
||||
enum WrapParameter {
|
||||
WRAP_S,
|
||||
WRAP_T,
|
||||
WRAP_R
|
||||
};
|
||||
|
||||
enum WrapMode {
|
||||
CLAMP = GL_CLAMP,
|
||||
CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
|
||||
CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER_ARB,
|
||||
REPEAT = GL_REPEAT,
|
||||
MIRROR = GL_MIRRORED_REPEAT_IBM
|
||||
};
|
||||
|
||||
/** Set the texture wrap mode.*/
|
||||
void setWrap(const WrapParameter which, const WrapMode wrap);
|
||||
/** Get the texture wrap mode.*/
|
||||
const WrapMode getWrap(const WrapParameter which) const;
|
||||
|
||||
|
||||
/** Sets the border color for this texture. Makes difference only if
|
||||
* wrap mode is CLAMP_TO_BORDER */
|
||||
void setBorderColor(const Vec4& color) { _borderColor = color; _texParamtersDirty = true; }
|
||||
|
||||
const Vec4& borderColor(void) const { return _borderColor; }
|
||||
|
||||
|
||||
enum FilterParameter {
|
||||
MIN_FILTER,
|
||||
MAG_FILTER
|
||||
};
|
||||
|
||||
enum FilterMode {
|
||||
LINEAR = GL_LINEAR,
|
||||
LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR,
|
||||
LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
|
||||
NEAREST = GL_NEAREST,
|
||||
NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
|
||||
NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
|
||||
};
|
||||
|
||||
|
||||
/** Set the texture filter mode.*/
|
||||
void setFilter(const FilterParameter which, const FilterMode filter);
|
||||
|
||||
/** Get the texture filter mode.*/
|
||||
const FilterMode getFilter(const FilterParameter which) const;
|
||||
|
||||
/** Set the maximum anisotropy value, default value is 1.0 for
|
||||
* no anisotropic filtering. If hardware does not support anisotropic
|
||||
* filtering then normal filtering is used, equivilant to a max anisotropy value of 1.0.
|
||||
* valid range is 1.0f upwards. The maximum value depends on the graphics
|
||||
* system being used.*/
|
||||
void setMaxAnisotropy(float anis);
|
||||
|
||||
/** Get the maximum anisotropy value.*/
|
||||
inline float getMaxAnisotropy() const { return _maxAnisotropy; }
|
||||
|
||||
enum InternalFormatMode {
|
||||
USE_IMAGE_DATA_FORMAT,
|
||||
USE_USER_DEFINED_FORMAT,
|
||||
USE_ARB_COMPRESSION,
|
||||
USE_S3TC_DXT1_COMPRESSION,
|
||||
USE_S3TC_DXT3_COMPRESSION,
|
||||
USE_S3TC_DXT5_COMPRESSION
|
||||
};
|
||||
|
||||
/** Set the internal format mode.
|
||||
* Note, If the mode is set USE_IMAGE_DATA_FORMAT, USE_ARB_COMPRESSION,
|
||||
* USE_S3TC_COMPRESSION the internalFormat is automatically selected,
|
||||
* and will overwrite the previous _internalFormatValue.
|
||||
*/
|
||||
inline void setInternalFormatMode(const InternalFormatMode mode) { _internalFormatMode = mode; }
|
||||
|
||||
/** Get the internal format mode.*/
|
||||
inline const InternalFormatMode getInternalFormatMode() const { return _internalFormatMode; }
|
||||
|
||||
/** Set the internal format to use when creating OpenGL textures.
|
||||
* Also sets the internalFormatMode to USE_USER_DEFINED_FORMAT.
|
||||
@@ -209,11 +66,11 @@ class SG_EXPORT Texture : public StateAttribute
|
||||
inline void setInternalFormatValue(const int internalFormat)
|
||||
{
|
||||
_internalFormatMode = USE_USER_DEFINED_FORMAT;
|
||||
_internalFormatValue = internalFormat;
|
||||
_internalFormat = internalFormat;
|
||||
}
|
||||
|
||||
/** Get the internal format to use when creating OpenGL textures.*/
|
||||
inline const int getInternalFormatValue() const { return _internalFormatValue; }
|
||||
inline const int getInternalFormatValue() const { return _internalFormat; }
|
||||
|
||||
|
||||
enum SubloadMode {
|
||||
@@ -301,41 +158,6 @@ class SG_EXPORT Texture : public StateAttribute
|
||||
|
||||
const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
|
||||
|
||||
|
||||
|
||||
/** Get the handle to the texture object for the current context.*/
|
||||
/** return the OpenGL texture object for specified context.*/
|
||||
inline GLuint& getTextureObject(const uint contextID) const
|
||||
{
|
||||
// pad out handle list if required.
|
||||
if (_handleList.size()<=contextID)
|
||||
_handleList.resize(contextID+1,0);
|
||||
|
||||
// get the globj for the current contextID.
|
||||
return _handleList[contextID];
|
||||
}
|
||||
|
||||
inline uint& getModifiedTag(const uint contextID) const
|
||||
{
|
||||
// pad out handle list if required.
|
||||
if (_modifiedTag.size()<=contextID)
|
||||
_modifiedTag.resize(contextID+1,0);
|
||||
|
||||
// get the modified tag for the current contextID.
|
||||
return _modifiedTag[contextID];
|
||||
}
|
||||
|
||||
/** Force a recompile on next apply() of associated OpenGL texture objects.*/
|
||||
void dirtyTextureObject();
|
||||
|
||||
/** 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;
|
||||
|
||||
/** Compile the texture mip maps. Implemented by simply calling apply().*/
|
||||
virtual void compile(State& state) const;
|
||||
|
||||
|
||||
/** 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; }
|
||||
@@ -343,41 +165,15 @@ class SG_EXPORT Texture : public StateAttribute
|
||||
/** Get the number of mip map levels the the texture has been created with.*/
|
||||
unsigned int getNumMipmapLevels() const { return _numMimpmapLevels; }
|
||||
|
||||
|
||||
|
||||
/** use deleteTextureObject instead of glDeleteTextures to allow
|
||||
* OpenGL texture objects to cached until they can be deleted
|
||||
* by the OpenGL context in which they were created, specified
|
||||
* by contextID.*/
|
||||
static void deleteTextureObject(uint contextID,GLuint handle);
|
||||
|
||||
/** flush all the cached display list which need to be deleted
|
||||
* in the OpenGL context related to contextID.*/
|
||||
static void flushDeletedTextureObjects(uint contextID);
|
||||
|
||||
/** Get the maximum texture size supported, this is the
|
||||
normally define by GL_MAX_TEXTURE_SIZE, but can be overridden
|
||||
by the OSG_MAX_TEXTURE_SIZE environmental variable.*/
|
||||
static GLint getMaxTextureSize();
|
||||
/** 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 ~Texture();
|
||||
|
||||
|
||||
/** Method which does setting of texture paramters. */
|
||||
void applyTexParameters(GLenum target, State& state) const;
|
||||
|
||||
/** Method which does the creation of the texture itself, and
|
||||
* does not set or use texture binding. */
|
||||
virtual void applyTexImage(GLenum target, Image* image, State& state) const;
|
||||
|
||||
typedef std::vector<GLuint> TextureNameList;
|
||||
mutable TextureNameList _handleList;
|
||||
|
||||
typedef std::vector<uint> ImageModifiedTag;
|
||||
mutable ImageModifiedTag _modifiedTag;
|
||||
|
||||
virtual void computeInternalFormat() const;
|
||||
|
||||
// not ideal that _image is mutable, but its required since
|
||||
// Image::ensureDimensionsArePowerOfTwo() can only be called
|
||||
@@ -385,32 +181,11 @@ class SG_EXPORT Texture : public StateAttribute
|
||||
// which is const...
|
||||
mutable ref_ptr<Image> _image;
|
||||
|
||||
bool _unrefImageAfterApply;
|
||||
|
||||
GLenum _target; // defaults to GL_TEXTURE_2D
|
||||
|
||||
WrapMode _wrap_s;
|
||||
WrapMode _wrap_t;
|
||||
WrapMode _wrap_r;
|
||||
|
||||
FilterMode _min_filter;
|
||||
FilterMode _mag_filter;
|
||||
float _maxAnisotropy;
|
||||
|
||||
// true if apply tex parameters required.
|
||||
mutable bool _texParamtersDirty;
|
||||
|
||||
|
||||
InternalFormatMode _internalFormatMode;
|
||||
mutable GLint _internalFormatValue;
|
||||
|
||||
Vec4 _borderColor;
|
||||
|
||||
// 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 unsigned int _numMimpmapLevels;
|
||||
mutable GLsizei _numMimpmapLevels;
|
||||
|
||||
SubloadMode _subloadMode;
|
||||
GLint _subloadTextureOffsetX, _subloadTextureOffsetY;
|
||||
@@ -418,14 +193,21 @@ class SG_EXPORT Texture : public StateAttribute
|
||||
GLsizei _subloadImageWidth, _subloadImageHeight;
|
||||
|
||||
ref_ptr<SubloadCallback> _subloadCallback;
|
||||
|
||||
// static cache of deleted display lists which can only
|
||||
// by completely deleted once the appropriate OpenGL context
|
||||
// is set.
|
||||
typedef std::map<uint,std::set<uint> > DeletedTextureObjectCache;
|
||||
static DeletedTextureObjectCache s_deletedTextureObjectCache;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#else // USE_DEPRECATED_API
|
||||
|
||||
#include <osg/Texture2D>
|
||||
|
||||
namespace osg {
|
||||
|
||||
typedef Texture2D Texture;
|
||||
|
||||
}
|
||||
|
||||
#endif // USE_DEPRECATED_API
|
||||
|
||||
126
include/osg/Texture1D
Normal file
126
include/osg/Texture1D
Normal file
@@ -0,0 +1,126 @@
|
||||
//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_TEXTURE1D
|
||||
#define OSG_TEXTURE1D 1
|
||||
|
||||
#include <osg/TextureBase>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Texture state class which encapsulates OpenGl 1D texture functionality.*/
|
||||
class SG_EXPORT Texture1D : public TextureBase
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
Texture1D();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Texture1D(const Texture1D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, Texture1D,TEXTURE);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& rhs) const;
|
||||
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
modes.push_back(GL_TEXTURE_1D);
|
||||
}
|
||||
|
||||
/** Set the texture image. */
|
||||
void setImage(Image* image);
|
||||
|
||||
/** Get the texture image. */
|
||||
Image* getImage() { return _image.get(); }
|
||||
|
||||
/** Get the const texture image. */
|
||||
inline const Image* getImage() const { return _image.get(); }
|
||||
|
||||
|
||||
/** 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
|
||||
{
|
||||
_textureWidth = width;
|
||||
}
|
||||
|
||||
/** Get the texture subload width. */
|
||||
inline void getTextureSize(int& width) const
|
||||
{
|
||||
width = _textureWidth;
|
||||
}
|
||||
|
||||
|
||||
class SubloadCallback : public Referenced
|
||||
{
|
||||
public:
|
||||
virtual void load(const Texture1D& texture,State& state) const = 0;
|
||||
virtual void subload(const Texture1D& 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; }
|
||||
|
||||
|
||||
/** Copy pixels into a 1D texture image.As per glCopyTexImage1D.
|
||||
* Creates an OpenGL texture object from the current OpenGL background
|
||||
* framebuffer contents at pos \a x, \a y with width \a width. \a width must be a power of two.
|
||||
*/
|
||||
void copyTexImage1D(State& state, int x, int y, int width);
|
||||
|
||||
/** Copy a one-dimensional texture subimage. As per glCopyTexSubImage1D.
|
||||
* Updates portion of an existing OpenGL texture object from the current OpenGL background
|
||||
* framebuffer contents at pos \a x, \a y with width \a width.
|
||||
*/
|
||||
void copyTexSubImage1D(State& state, int xoffset, int x, int y, int width);
|
||||
|
||||
|
||||
/** 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 ~Texture1D();
|
||||
|
||||
virtual void computeInternalFormat() const;
|
||||
|
||||
/** Helper method which does the creation of the texture itself, and
|
||||
* does not set or use texture binding. */
|
||||
void applyTexImage1D(GLenum target, Image* image, State& state, GLsizei& width, GLsizei& numMimpmapLevels) const;
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
// subloaded images can have different texture and image sizes.
|
||||
mutable GLsizei _textureWidth;
|
||||
|
||||
// number of mip map levels the the texture has been created with,
|
||||
mutable GLsizei _numMimpmapLevels;
|
||||
|
||||
ref_ptr<SubloadCallback> _subloadCallback;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
127
include/osg/Texture2D
Normal file
127
include/osg/Texture2D
Normal file
@@ -0,0 +1,127 @@
|
||||
//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_TEXTURE2D
|
||||
#define OSG_TEXTURE2D 1
|
||||
|
||||
#include <osg/TextureBase>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Texture state class which encapsulates OpenGl texture functionality.*/
|
||||
class SG_EXPORT Texture2D : public TextureBase
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
Texture2D();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Texture2D(const Texture2D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, Texture2D,TEXTURE);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& rhs) const;
|
||||
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
modes.push_back(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
/** Set the texture image. */
|
||||
void setImage(Image* image);
|
||||
|
||||
/** Get the texture image. */
|
||||
Image* getImage() { return _image.get(); }
|
||||
|
||||
/** Get the const texture image. */
|
||||
inline const Image* getImage() const { return _image.get(); }
|
||||
|
||||
|
||||
/** 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 Texture2D& texture,State& state) const = 0;
|
||||
virtual void subload(const Texture2D& 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; }
|
||||
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
void copyTexImage2D(State& state, int x, int y, int width, int height );
|
||||
|
||||
/** Copy a two-dimensional texture subimage. As per glCopyTexSubImage2D.
|
||||
* Updates portion of an existing 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,
|
||||
* and writing into the texture with offset \a xoffset and \a yoffset.
|
||||
*/
|
||||
void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height );
|
||||
|
||||
|
||||
/** 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 ~Texture2D();
|
||||
|
||||
virtual void computeInternalFormat() const;
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
// 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
|
||||
121
include/osg/Texture3D
Normal file
121
include/osg/Texture3D
Normal file
@@ -0,0 +1,121 @@
|
||||
//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_TEXTURE3D
|
||||
#define OSG_TEXTURE3D 1
|
||||
|
||||
#include <osg/TextureBase>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Texture state class which encapsulates OpenGl 3D texture functionality.*/
|
||||
class SG_EXPORT Texture3D : public TextureBase
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
Texture3D();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Texture3D(const Texture3D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, Texture3D,TEXTURE);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& rhs) const;
|
||||
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
modes.push_back(GL_TEXTURE_3D);
|
||||
}
|
||||
|
||||
/** Set the texture image. */
|
||||
void setImage(Image* image);
|
||||
|
||||
/** Get the texture image. */
|
||||
Image* getImage() { return _image.get(); }
|
||||
|
||||
/** Get the const texture image. */
|
||||
inline const Image* getImage() const { return _image.get(); }
|
||||
|
||||
|
||||
/** 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 int depth) const
|
||||
{
|
||||
_textureWidth = width;
|
||||
_textureHeight = height;
|
||||
_textureDepth = depth;
|
||||
}
|
||||
|
||||
/** Get the texture subload width. */
|
||||
inline void getTextureSize(int& width, int& height, int& depth) const
|
||||
{
|
||||
width = _textureWidth;
|
||||
height = _textureHeight;
|
||||
depth = _textureDepth;
|
||||
}
|
||||
|
||||
|
||||
class SubloadCallback : public Referenced
|
||||
{
|
||||
public:
|
||||
virtual void load(const Texture3D& texture,State& state) const = 0;
|
||||
virtual void subload(const Texture3D& 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; }
|
||||
|
||||
|
||||
/** Copy a two-dimensional texture subimage. As per glCopyTexSubImage2D.
|
||||
* Updates portion of an existing OpenGL texture object from the current OpenGL background
|
||||
* framebuffer contents at pos \a x, \a y with width \a width and
|
||||
* height \a height. */
|
||||
void copyTexSubImage3D(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height);
|
||||
|
||||
|
||||
/** 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 ~Texture3D();
|
||||
|
||||
virtual void computeInternalFormat() const;
|
||||
|
||||
void applyTexImage3D(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLsizei& indepth, GLsizei& numMimpmapLevels) const;
|
||||
|
||||
// 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;
|
||||
|
||||
// subloaded images can have different texture and image sizes.
|
||||
mutable GLsizei _textureWidth, _textureHeight, _textureDepth;
|
||||
|
||||
// number of mip map levels the the texture has been created with,
|
||||
mutable GLsizei _numMimpmapLevels;
|
||||
|
||||
ref_ptr<SubloadCallback> _subloadCallback;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
283
include/osg/TextureBase
Normal file
283
include/osg/TextureBase
Normal file
@@ -0,0 +1,283 @@
|
||||
//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.
|
||||
|
||||
#ifndef OSG_TEXTUREBASE
|
||||
#define OSG_TEXTUREBASE 1
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/Types>
|
||||
#include <osg/Image>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Vec4>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
// if not defined by gl.h use the definition found in:
|
||||
// http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_filter_anisotropic.txt
|
||||
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
|
||||
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARB_texture_compression
|
||||
#define GL_COMPRESSED_ALPHA_ARB 0x84E9
|
||||
#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA
|
||||
#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB
|
||||
#define GL_COMPRESSED_INTENSITY_ARB 0x84EC
|
||||
#define GL_COMPRESSED_RGB_ARB 0x84ED
|
||||
#define GL_COMPRESSED_RGBA_ARB 0x84EE
|
||||
#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF
|
||||
#define GL_TEXTURE_IMAGE_SIZE_ARB 0x86A0
|
||||
#define GL_TEXTURE_COMPRESSED_ARB 0x86A1
|
||||
#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2
|
||||
#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3
|
||||
#endif
|
||||
|
||||
#ifndef GL_EXT_texture_compression_s3tc
|
||||
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
||||
#endif
|
||||
|
||||
#ifndef GL_MIRRORED_REPEAT_IBM
|
||||
#define GL_MIRRORED_REPEAT_IBM 0x8370
|
||||
#endif
|
||||
|
||||
#ifndef GL_CLAMP_TO_EDGE
|
||||
#define GL_CLAMP_TO_EDGE 0x812F
|
||||
#endif
|
||||
|
||||
#ifndef GL_CLAMP_TO_BORDER_ARB
|
||||
#define GL_CLAMP_TO_BORDER_ARB 0x812D
|
||||
#endif
|
||||
|
||||
#ifndef GL_GENERATE_MIPMAP_SGIS
|
||||
#define GL_GENERATE_MIPMAP_SGIS 0x8191
|
||||
#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192
|
||||
#endif
|
||||
|
||||
#ifndef GL_TEXTURE_3D
|
||||
#define GL_TEXTURE_3D 0x806F
|
||||
#endif
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Texture base class which encapsulates OpenGl texture functionality which common betweent the various types of OpenGL textures.*/
|
||||
class SG_EXPORT TextureBase : public osg::StateAttribute
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
|
||||
TextureBase();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
TextureBase(const TextureBase& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual osg::Object* cloneType() const = 0;
|
||||
virtual osg::Object* clone(const CopyOp& copyop) const = 0;
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const TextureBase *>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "TextureBase"; }
|
||||
virtual const Type getType() const { return TEXTURE; }
|
||||
|
||||
virtual bool isTextureAttribute() const { return true; }
|
||||
|
||||
enum WrapParameter {
|
||||
WRAP_S,
|
||||
WRAP_T,
|
||||
WRAP_R
|
||||
};
|
||||
|
||||
enum WrapMode {
|
||||
CLAMP = GL_CLAMP,
|
||||
CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
|
||||
CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER_ARB,
|
||||
REPEAT = GL_REPEAT,
|
||||
MIRROR = GL_MIRRORED_REPEAT_IBM
|
||||
};
|
||||
|
||||
/** Set the texture wrap mode.*/
|
||||
void setWrap(const WrapParameter which, const WrapMode wrap);
|
||||
/** Get the texture wrap mode.*/
|
||||
const WrapMode getWrap(const WrapParameter which) const;
|
||||
|
||||
|
||||
/** Sets the border color for this texture. Makes difference only if
|
||||
* wrap mode is CLAMP_TO_BORDER */
|
||||
void setBorderColor(const Vec4& color) { _borderColor = color; _texParamtersDirty = true; }
|
||||
|
||||
const Vec4& borderColor(void) const { return _borderColor; }
|
||||
|
||||
|
||||
enum FilterParameter {
|
||||
MIN_FILTER,
|
||||
MAG_FILTER
|
||||
};
|
||||
|
||||
enum FilterMode {
|
||||
LINEAR = GL_LINEAR,
|
||||
LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR,
|
||||
LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
|
||||
NEAREST = GL_NEAREST,
|
||||
NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
|
||||
NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST
|
||||
};
|
||||
|
||||
|
||||
/** Set the texture filter mode.*/
|
||||
void setFilter(const FilterParameter which, const FilterMode filter);
|
||||
|
||||
/** Get the texture filter mode.*/
|
||||
const FilterMode getFilter(const FilterParameter which) const;
|
||||
|
||||
/** Set the maximum anisotropy value, default value is 1.0 for
|
||||
* no anisotropic filtering. If hardware does not support anisotropic
|
||||
* filtering then normal filtering is used, equivilant to a max anisotropy value of 1.0.
|
||||
* valid range is 1.0f upwards. The maximum value depends on the graphics
|
||||
* system being used.*/
|
||||
void setMaxAnisotropy(float anis);
|
||||
|
||||
/** Get the maximum anisotropy value.*/
|
||||
inline float getMaxAnisotropy() const { return _maxAnisotropy; }
|
||||
|
||||
enum InternalFormatMode {
|
||||
USE_IMAGE_DATA_FORMAT,
|
||||
USE_USER_DEFINED_FORMAT,
|
||||
USE_ARB_COMPRESSION,
|
||||
USE_S3TC_DXT1_COMPRESSION,
|
||||
USE_S3TC_DXT3_COMPRESSION,
|
||||
USE_S3TC_DXT5_COMPRESSION
|
||||
};
|
||||
|
||||
/** Set the internal format mode.
|
||||
* Note, If the mode is set USE_IMAGE_DATA_FORMAT, USE_ARB_COMPRESSION,
|
||||
* USE_S3TC_COMPRESSION the internalFormat is automatically selected,
|
||||
* and will overwrite the previous _internalFormat.
|
||||
*/
|
||||
inline void setInternalFormatMode(const InternalFormatMode mode) { _internalFormatMode = mode; }
|
||||
|
||||
/** Get the internal format mode.*/
|
||||
inline const InternalFormatMode getInternalFormatMode() const { return _internalFormatMode; }
|
||||
|
||||
/** Set the internal format to use when creating OpenGL textures.
|
||||
* Also sets the internalFormatMode to USE_USER_DEFINED_FORMAT.
|
||||
*/
|
||||
inline void setInternalFormat(const int internalFormat)
|
||||
{
|
||||
_internalFormatMode = USE_USER_DEFINED_FORMAT;
|
||||
_internalFormat = internalFormat;
|
||||
}
|
||||
|
||||
/** Get the internal format to use when creating OpenGL textures.*/
|
||||
inline const int getInternalFormat() const { if (_internalFormat==0) computeInternalFormat(); return _internalFormat; }
|
||||
|
||||
bool isCompressedInternalFormat() const;
|
||||
|
||||
|
||||
/** Get the handle to the texture object for the current context.*/
|
||||
/** return the OpenGL texture object for specified context.*/
|
||||
inline GLuint& getTextureObject(const uint contextID) const
|
||||
{
|
||||
// pad out handle list if required.
|
||||
if (_handleList.size()<=contextID)
|
||||
_handleList.resize(contextID+1,0);
|
||||
|
||||
// get the globj for the current contextID.
|
||||
return _handleList[contextID];
|
||||
}
|
||||
|
||||
inline uint& getModifiedTag(const uint contextID) const
|
||||
{
|
||||
// pad out handle list if required.
|
||||
if (_modifiedTag.size()<=contextID)
|
||||
_modifiedTag.resize(contextID+1,0);
|
||||
|
||||
// get the modified tag for the current contextID.
|
||||
return _modifiedTag[contextID];
|
||||
}
|
||||
|
||||
/** Force a recompile on next apply() of associated OpenGL texture objects.*/
|
||||
void dirtyTextureObject();
|
||||
|
||||
|
||||
|
||||
/** use deleteTextureObject instead of glDeleteTextures to allow
|
||||
* OpenGL texture objects to cached until they can be deleted
|
||||
* by the OpenGL context in which they were created, specified
|
||||
* by contextID.*/
|
||||
static void deleteTextureObject(uint contextID,GLuint handle);
|
||||
|
||||
/** flush all the cached display list which need to be deleted
|
||||
* in the OpenGL context related to contextID.*/
|
||||
static void flushDeletedTextureObjects(uint contextID);
|
||||
|
||||
/** Get the maximum texture size supported, this is the
|
||||
normally define by GL_MAX_TEXTURE_SIZE, but can be overridden
|
||||
by the OSG_MAX_TEXTURE_SIZE environmental variable.*/
|
||||
static GLint getMaxTextureSize();
|
||||
|
||||
/** TextureBase is pure virtual base class, apply must be overriden. */
|
||||
virtual void apply(State& state) const = 0;
|
||||
|
||||
/** Calls apply(state) to compile the texture. */
|
||||
virtual void compile(State& state) const;
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~TextureBase();
|
||||
|
||||
virtual void computeInternalFormat() const = 0;
|
||||
|
||||
void computeInternalFormatWithImage(osg::Image& image) const;
|
||||
|
||||
bool isCompressedInternalFormat(GLint internalFormat) const;
|
||||
|
||||
/** Helper method which does setting of texture paramters. */
|
||||
void applyTexParameters(GLenum target, State& state) const;
|
||||
|
||||
/** Helper method which does the creation of the texture itself, and
|
||||
* does not set or use texture binding. */
|
||||
void applyTexImage2D(GLenum target, Image* image, State& state, GLsizei& width, GLsizei& height,GLsizei& numMimpmapLevels) const;
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
int compareTextureBase(const TextureBase& rhs) const;
|
||||
|
||||
typedef std::vector<GLuint> TextureNameList;
|
||||
mutable TextureNameList _handleList;
|
||||
|
||||
typedef std::vector<uint> ImageModifiedTag;
|
||||
mutable ImageModifiedTag _modifiedTag;
|
||||
|
||||
|
||||
WrapMode _wrap_s;
|
||||
WrapMode _wrap_t;
|
||||
WrapMode _wrap_r;
|
||||
|
||||
FilterMode _min_filter;
|
||||
FilterMode _mag_filter;
|
||||
float _maxAnisotropy;
|
||||
|
||||
Vec4 _borderColor;
|
||||
|
||||
// true if apply tex parameters required.
|
||||
mutable bool _texParamtersDirty;
|
||||
|
||||
|
||||
InternalFormatMode _internalFormatMode;
|
||||
mutable GLint _internalFormat;
|
||||
|
||||
// static cache of deleted display lists which can only
|
||||
// by completely deleted once the appropriate OpenGL context
|
||||
// is set.
|
||||
typedef std::map<uint,std::set<uint> > DeletedTextureObjectCache;
|
||||
static DeletedTextureObjectCache s_deletedTextureObjectCache;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -7,7 +7,7 @@
|
||||
#ifndef OSG_TEXTURECUBEMAP
|
||||
#define OSG_TEXTURECUBEMAP 1
|
||||
|
||||
#include <osg/Texture>
|
||||
#include <osg/TextureBase>
|
||||
|
||||
#ifndef GL_TEXTURE_CUBE_MAP
|
||||
#define GL_TEXTURE_CUBE_MAP 0x8513
|
||||
@@ -16,7 +16,7 @@
|
||||
namespace osg {
|
||||
|
||||
/** TextureCubeMap state class which encapsulates OpenGl texture cubemap functionality.*/
|
||||
class SG_EXPORT TextureCubeMap : public Texture
|
||||
class SG_EXPORT TextureCubeMap : public TextureBase
|
||||
{
|
||||
|
||||
public :
|
||||
@@ -24,8 +24,7 @@ class SG_EXPORT TextureCubeMap : public Texture
|
||||
TextureCubeMap();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
TextureCubeMap(const TextureCubeMap& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Texture(cm,copyop) {}
|
||||
TextureCubeMap(const TextureCubeMap& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, TextureCubeMap,TEXTURE);
|
||||
|
||||
@@ -50,19 +49,65 @@ class SG_EXPORT TextureCubeMap : public Texture
|
||||
/** 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;
|
||||
void setImage(Image*) {} // prevent call to Texture::setImage(Image* image)
|
||||
Image* getImage() { return _image.get(); } // prevent call to Texture::setImage(Image* image)
|
||||
const Image* getImage() const { return _image.get(); } // prevent call to Texture::setImage(Image* image)
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#ifndef OSGUTIL_RENDERTOTEXTURESTAGE
|
||||
#define OSGUTIL_RENDERTOTEXTURESTAGE 1
|
||||
|
||||
#include <osg/Texture>
|
||||
#include <osg/Texture2D>
|
||||
|
||||
#include <osgUtil/RenderStage>
|
||||
|
||||
@@ -31,8 +31,8 @@ class OSGUTIL_EXPORT RenderToTextureStage : public RenderStage
|
||||
|
||||
virtual void reset();
|
||||
|
||||
void setTexture(osg::Texture* texture) { _texture = texture; }
|
||||
osg::Texture* getTexture() { return _texture.get(); }
|
||||
void setTexture(osg::Texture2D* texture) { _texture = texture; }
|
||||
osg::Texture2D* getTexture() { return _texture.get(); }
|
||||
|
||||
void setImage(osg::Image* image) { _image = image; }
|
||||
osg::Image* getImage() { return _image.get(); }
|
||||
@@ -46,7 +46,7 @@ class OSGUTIL_EXPORT RenderToTextureStage : public RenderStage
|
||||
|
||||
virtual ~RenderToTextureStage();
|
||||
|
||||
osg::ref_ptr<osg::Texture> _texture;
|
||||
osg::ref_ptr<osg::Texture2D> _texture;
|
||||
osg::ref_ptr<osg::Image> _image;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user