Removed deprecated code from the distribution.

Added .osg support for Texture1D and Texture3D.
This commit is contained in:
Robert Osfield 2002-08-28 15:28:11 +00:00
parent 951b6e9f3f
commit 8353fc0ed6
41 changed files with 911 additions and 1823 deletions

View File

@ -381,10 +381,6 @@ SOURCE=..\..\src\osg\Texture.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\TextureBase.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\Texture1D.cpp
# End Source File
# Begin Source File
@ -533,10 +529,6 @@ SOURCE=..\..\include\osg\ClearNode
# End Source File
# Begin Source File
SOURCE=..\..\include\osg\EarthSky
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Export
# End Source File
# Begin Source File
@ -777,10 +769,6 @@ SOURCE=..\..\Include\Osg\Texture
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\TextureBase
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Texture1D
# End Source File
# Begin Source File

View File

@ -278,7 +278,7 @@ SOURCE=..\..\..\src\osgPlugins\osg\Texture.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\TextureBase.cpp
SOURCE=..\..\..\src\osgPlugins\osg\Texture1D.cpp
# End Source File
# Begin Source File
@ -286,6 +286,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\Texture2D.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\Texture3D.cpp
# End Source File
# Begin Source File
SOURCE=..\..\..\src\osgPlugins\osg\TextureCubeMap.cpp
# End Source File
# Begin Source File

View File

@ -30,7 +30,7 @@
<ul>
<li>Open scene graph .osg demo data set can downloaded here:</li>
<i><a href="http://www.openscenegraph.org/downloads/osg_data-0.8-45.tar.gz">http://www.openscenegraph.org/downloads/osg_data-0.8-45.tar.gz</a></i>
<i><a href="http://www.openscenegraph.org/download/data/OpenSceneGraphData-0.9.1.tar.gz">http://www.openscenegraph.org/download/data/OpenSceneGraphData-0.9.1.tar.gz</a></i>
<br>
<br>

View File

@ -49,12 +49,7 @@ class SG_EXPORT BoundingBox
_min.set(FLT_MAX,FLT_MAX,FLT_MAX);
_max.set(-FLT_MAX,-FLT_MAX,-FLT_MAX);
}
#ifdef USE_DEPRECATED_API
/** deprecated, use valid() instead.*/
inline const bool isValid() const { return _max.x()>=_min.x(); }
#endif
inline const bool valid() const
{
return _max.x()>=_min.x();

View File

@ -38,10 +38,6 @@ class SG_EXPORT BoundingSphere
_radius = -1.0f;
}
#ifdef USE_DEPRECATED_API
/** deprecated, use valid() instead.*/
inline const bool isValid() const { return _radius>=0.0f; }
#endif
/** return true if the bounding sphere contains valid values,
false if the bounding sphere is effectively unset.*/
inline const bool valid() const { return _radius>=0.0f; }

View File

@ -13,7 +13,7 @@ class Referenced;
class Object;
class Image;
//class Texture;
class TextureBase;
class Texture;
class StateSet;
class StateAttribute;
class Node;
@ -54,8 +54,7 @@ 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 TextureBase* operator() (const TextureBase* text) const;
virtual Texture* operator() (const Texture* text) const;
virtual Image* operator() (const Image* image) const;
virtual Array* operator() (const Array* image) const;
virtual Primitive* operator() (const Primitive* image) const;

View File

@ -1,18 +0,0 @@
//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_EARTHSKY
#define OSG_EARTHSKY 1
#include <osg/ClearNode>
namespace osg {
#ifdef USE_DEPRECATED_API
typedef ClearNode EarthSky;
#endif
}
#endif

View File

@ -167,17 +167,6 @@ class SG_EXPORT Matrix : public Object
inline static Matrix lookAt(const Vec3& eye,const Vec3& center,const Vec3& up);
#ifdef USE_DEPRECATED_API
/** make a rotation Matrix from euler angles.
* assume Z up, Y north, X east and euler convention
* as per Open Flight & Performer.
* Applies a positive rotation about Y axis for roll,
* then applies a positive roation about X for pitch,
* and finally a negative rotation about the Z axis.*/
void makeRotate( float heading, float pitch, float roll); //Euler angles
inline static Matrix rotate( float heading, float pitch, float roll);
#endif
inline Vec3 preMult( const Vec3& v ) const;
@ -299,14 +288,6 @@ inline Matrix Matrix::rotate(float angle, const Vec3& axis )
m.makeRotate(angle,axis);
return m;
}
#ifdef USE_DEPRECATED_API
inline Matrix Matrix::rotate(float heading, float pitch, float roll)
{
Matrix m;
m.makeRotate(heading,pitch,roll);
return m;
}
#endif
inline Matrix Matrix::rotate( float angle1, const Vec3& axis1,
float angle2, const Vec3& axis2,
float angle3, const Vec3& axis3)

View File

@ -225,18 +225,8 @@ class SG_EXPORT Quat
Watch out for the two special cases of when the vectors
are co-incident or opposite in direction.*/
void makeRotate( const Vec3& vec1, const Vec3& vec2 );
#ifdef USE_DEPRECATED_API
/** make a rotation Quat from euler angles.
* assume Z up, Y north, X east and euler convention
* as per Open Flight & Performer.
* Applies a positive rotation about Y axis for roll,
* then applies a positive roation about X for pitch,
* and finally a negative rotation about the Z axis.*/
void makeRotate( float heading, float pitch, float roll);
#endif
/** Return the angle and vector components represented by the quaternion.*/
/** Return the angle and vector components represented by the quaternion.*/
void getRotate ( float& angle, float& x, float& y, float& z ) const;
/** Return the angle and vector represented by the quaternion.*/
void getRotate ( float& angle, Vec3& vec ) const;

View File

@ -82,12 +82,6 @@ class SG_EXPORT StateAttribute : public Object
OVERRIDE = 0x2,
/** Protecting of GLMode's os StateAttributes is enabled, so that state from above connot override this and below state.*/
PROTECTED = 0x4,
#ifdef USE_DEPRECATED_API
/** Equivilant to OFF | OVERRIDE.*/
OVERRIDE_OFF = 0x2,
/** Equivilant to ON | OVERRIDE.*/
OVERRIDE_ON = 0x3,
#endif
/** means that GLMode or StateAttribute should in inherited from above.*/
INHERIT = 0x8
};

View File

@ -2,216 +2,282 @@
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
// -*-c++-*-
//#define TEXTURE_USE_DEPRECATED_API
#ifdef TEXTURE_USE_DEPRECATED_API
#ifndef OSG_TEXTURE
#define OSG_TEXTURE 1
#include <osg/TextureBase>
#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 state class which encapsulates OpenGl texture functionality.*/
class SG_EXPORT Texture : public TextureBase
/** Texture base class which encapsulates OpenGl texture functionality which common betweent the various types of OpenGL textures.*/
class SG_EXPORT Texture : public osg::StateAttribute
{
public :
Texture();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Texture(const Texture& 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 Texture *>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "Texture"; }
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; _texParametersDirty = true; }
const Vec4& borderColor(void) const { return _borderColor; }
META_StateAttribute(osg, Texture,TEXTURE);
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
virtual int compare(const StateAttribute& rhs) const;
enum FilterParameter {
MIN_FILTER,
MAG_FILTER
};
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
{
modes.push_back(GL_TEXTURE_2D);
}
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 image. */
void setImage(Image* image);
/** Get the texture image. */
Image* getImage() { return _image.get(); }
/** Set the texture filter mode.*/
void setFilter(const FilterParameter which, const FilterMode filter);
/** Get the const texture image. */
inline const Image* getImage() const { return _image.get(); }
/** Get the texture filter mode.*/
const FilterMode getFilter(const FilterParameter which) const;
/** 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.
/** 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.
*/
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 );
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 setInternalFormatValue(const int internalFormat)
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 getInternalFormatValue() const { return _internalFormat; }
inline const int getInternalFormat() const { if (_internalFormat==0) computeInternalFormat(); return _internalFormat; }
bool isCompressedInternalFormat() const;
enum SubloadMode {
OFF,
AUTO,
IF_DIRTY,
USE_CALLBACK
};
/** 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; }
/** Set the texture subload texture offsets. */
inline void setSubloadTextureOffset(const int x, const int y)
{
_subloadTextureOffsetX = x;
_subloadTextureOffsetY = y;
}
/** Get the texture subload texture offsets. */
inline void getSubloadTextureOffset(int& x, int& y) const
{
x = _subloadTextureOffsetX;
y = _subloadTextureOffsetY;
}
/** Set the texture subload width. If width or height are zero then
* the repsective size value is calculated from the source image sizes. */
inline void setSubloadTextureSize(const int width, const int height) 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
{
_textureWidth = width;
_textureHeight = height;
// 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];
}
/** Get the texture subload width. */
inline void getSubloadTextureSize(int& width, int& height) const
inline uint& getModifiedTag(const uint contextID) const
{
width = _textureWidth;
height = _textureHeight;
// 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();
/** 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;
}
/** 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);
/** Get the image subload width. */
inline void getSubloadImageSize(int& width, int& height) const
{
width = _subloadImageWidth;
height = _subloadImageHeight;
}
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;
};
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
static void flushDeletedTextureObjects(uint contextID);
void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb; _subloadMode = cb ? USE_CALLBACK:OFF; }
/** 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();
SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
/** Texture is pure virtual base class, apply must be overriden. */
virtual void apply(State& state) const = 0;
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;
/** Calls apply(state) to compile the texture. */
virtual void compile(State& state) const;
protected :
virtual ~Texture();
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;
virtual void computeInternalFormat() const = 0;
// number of mip map levels the the texture has been created with,
mutable GLsizei _numMimpmapLevels;
void computeInternalFormatWithImage(osg::Image& image) const;
SubloadMode _subloadMode;
GLint _subloadTextureOffsetX, _subloadTextureOffsetY;
GLint _subloadImageOffsetX, _subloadImageOffsetY;
GLsizei _subloadImageWidth, _subloadImageHeight;
bool isCompressedInternalFormat(GLint internalFormat) const;
ref_ptr<SubloadCallback> _subloadCallback;
/** 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 compareTexture(const Texture& 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 _texParametersDirty;
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
#else // USE_DEPRECATED_API
#ifdef USE_DEPRECATED_API
#include <osg/Texture2D>
namespace osg {
typedef Texture2D Texture;
}
#endif
#endif // USE_DEPRECATED_API

View File

@ -7,12 +7,12 @@
#ifndef OSG_TEXTURE1D
#define OSG_TEXTURE1D 1
#include <osg/TextureBase>
#include <osg/Texture>
namespace osg {
/** Texture state class which encapsulates OpenGl 1D texture functionality.*/
class SG_EXPORT Texture1D : public TextureBase
class SG_EXPORT Texture1D : public Texture
{
public :

View File

@ -7,12 +7,12 @@
#ifndef OSG_TEXTURE2D
#define OSG_TEXTURE2D 1
#include <osg/TextureBase>
#include <osg/Texture>
namespace osg {
/** Texture state class which encapsulates OpenGl texture functionality.*/
class SG_EXPORT Texture2D : public TextureBase
class SG_EXPORT Texture2D : public Texture
{
public :

View File

@ -7,12 +7,12 @@
#ifndef OSG_TEXTURE3D
#define OSG_TEXTURE3D 1
#include <osg/TextureBase>
#include <osg/Texture>
namespace osg {
/** Texture state class which encapsulates OpenGl 3D texture functionality.*/
class SG_EXPORT Texture3D : public TextureBase
class SG_EXPORT Texture3D : public Texture
{
public :

View File

@ -1,283 +0,0 @@
//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; _texParametersDirty = 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 _texParametersDirty;
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

View File

@ -7,7 +7,7 @@
#ifndef OSG_TEXTURECUBEMAP
#define OSG_TEXTURECUBEMAP 1
#include <osg/TextureBase>
#include <osg/Texture>
#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 TextureBase
class SG_EXPORT TextureCubeMap : public Texture
{
public :

View File

@ -43,9 +43,6 @@ class SG_EXPORT Transform : public Group
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Transform(const Transform&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
#ifdef USE_DEPRECATED_API
Transform(const Matrix& matix);
#endif
META_Node(osg, Transform);
enum ReferenceFrame
@ -118,8 +115,6 @@ class SG_EXPORT Transform : public Group
return computeWorldToLocalMatrix(matrix,nv);
}
#ifndef USE_DEPRECATED_API
virtual const bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_TO_PARENTS)
@ -146,47 +141,6 @@ class SG_EXPORT Transform : public Group
}
}
#else
/** Set the transform's matrix.*/
void setMatrix(const Matrix& mat) { (*_deprecated_matrix) = mat; _deprecated_inverseDirty=true; computeInverse(); dirtyBound(); }
/** Get the transform's matrix. */
inline const Matrix& getMatrix() const { return *_deprecated_matrix; }
/** preMult transform. */
void preMult(const Matrix& mat) { _deprecated_matrix->preMult(mat); _deprecated_inverseDirty=true; computeInverse(); dirtyBound(); }
/** postMult transform. */
void postMult(const Matrix& mat) { _deprecated_matrix->postMult(mat); _deprecated_inverseDirty=true; computeInverse(); dirtyBound(); }
virtual const bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_TO_PARENTS)
{
matrix.preMult(*_deprecated_matrix);
}
else // absolute
{
matrix = *_deprecated_matrix;
}
return true;
}
virtual const bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_TO_PARENTS)
{
matrix.postMult(*_deprecated_inverse);
}
else // absolute
{
matrix = *_deprecated_inverse;
}
return true;
}
#endif
protected :
virtual ~Transform();
@ -202,21 +156,6 @@ class SG_EXPORT Transform : public Group
ReferenceFrame _referenceFrame;
#ifdef USE_DEPRECATED_API
inline void computeInverse() const
{
if (_deprecated_inverseDirty)
{
_deprecated_inverse->invert(*_deprecated_matrix);
_deprecated_inverseDirty = false;
}
}
ref_ptr<Matrix> _deprecated_matrix;
mutable ref_ptr<Matrix> _deprecated_inverse;
mutable bool _deprecated_inverseDirty;
#endif
};
}

View File

@ -1,18 +0,0 @@
//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_TRANSPARENCY
#define OSG_TRANSPARENCY 1
#include <osg/BlendFunc>
namespace osg {
#ifdef USE_DEPRECATED_API
typedef BlendFunc Transparency;
#endif
}
#endif

View File

@ -3,7 +3,7 @@
#include <osg/Geode>
#include <osg/Group>
#include <osg/Notify>
#include <osg/TextureBase>
#include <osg/Texture>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
@ -134,13 +134,13 @@ class MyCopyOp : public osg::CopyOp
return ret_attr;
}
virtual TextureBase* operator() (const TextureBase* text) const
virtual Texture* operator() (const Texture* text) const
{
writeIndent(); std::cout << "copying Texture "<<text;
if (text) std::cout<<" "<<text->className();
std::cout<<std::endl;
moveIn();
osg::TextureBase* ret_text = CopyOp::operator()(text);
osg::Texture* ret_text = CopyOp::operator()(text);
moveOut();
return ret_text;
}

View File

@ -1,7 +1,7 @@
#include <osg/CopyOp>
#include <osg/Node>
#include <osg/StateSet>
#include <osg/TextureBase>
#include <osg/Texture>
#include <osg/Drawable>
#include <osg/Array>
#include <osg/Primitive>
@ -48,42 +48,28 @@ StateAttribute* CopyOp::operator() (const StateAttribute* attr) const
{
if (attr && _flags&DEEP_COPY_STATEATTRIBUTES)
{
const TextureBase* textbase = dynamic_cast<const TextureBase*>(attr);
const Texture* textbase = dynamic_cast<const Texture*>(attr);
if (textbase)
{
return operator()(textbase);
}
else
{
// const Texture* text = dynamic_cast<const Texture*>(attr);
// if (text)
// {
// return operator()(text);
// }
// else
return dynamic_cast<StateAttribute*>(attr->clone(*this));
return dynamic_cast<StateAttribute*>(attr->clone(*this));
}
}
else
return const_cast<StateAttribute*>(attr);
}
TextureBase* CopyOp::operator() (const TextureBase* text) const
Texture* CopyOp::operator() (const Texture* text) const
{
if (text && _flags&DEEP_COPY_TEXTURES)
return dynamic_cast<TextureBase*>(text->clone(*this));
return dynamic_cast<Texture*>(text->clone(*this));
else
return const_cast<TextureBase*>(text);
return const_cast<Texture*>(text);
}
// Texture* CopyOp::operator() (const Texture* text) const
// {
// if (text && _flags&DEEP_COPY_TEXTURES)
// return dynamic_cast<Texture*>(text->clone(*this));
// else
// return const_cast<Texture*>(text);
// }
Image* CopyOp::operator() (const Image* image) const
{
if (image && _flags&DEEP_COPY_IMAGES)

View File

@ -458,7 +458,7 @@ void Image::ensureValidSizeForTexturing()
int new_s = computeNearestPowerOfTwo(_s);
int new_t = computeNearestPowerOfTwo(_t);
static GLint max_size=TextureBase::getMaxTextureSize();
static GLint max_size=Texture::getMaxTextureSize();
if (new_s>max_size) new_s = max_size;
if (new_t>max_size) new_t = max_size;

View File

@ -75,7 +75,6 @@ CXXFILES =\
TexGen.cpp\
TexMat.cpp\
Texture.cpp\
TextureBase.cpp\
Texture1D.cpp\
Texture2D.cpp\
Texture3D.cpp\

View File

@ -136,15 +136,6 @@ void Matrix::makeRotate( const Quat& q )
q.get(*this);
}
#ifdef USE_DEPRECATED_API
void Matrix::makeRotate( float heading, float pitch, float roll)
{
Quat quat;
quat.makeRotate(heading,pitch,roll);
quat.get(*this);
}
#endif
void Matrix::makeRotate( float angle1, const Vec3& axis1,
float angle2, const Vec3& axis2,
float angle3, const Vec3& axis3)

View File

@ -36,22 +36,6 @@ void Quat::makeRotate( const float angle, const Vec3& vec )
makeRotate( angle, vec[0], vec[1], vec[2] );
}
#ifdef USE_DEPRECATED_API
// assume Z up, Y north, X east and euler convention
// as per Open Flight & Performer.
// applies a positive rotation about Y axis for roll,
// then applies a positive roation about X for pitch,
// and finally a negative rotation about the Z axis.
void Quat::makeRotate( float heading, float pitch, float roll)
{
Quat q_roll; q_roll.makeRotate(roll,0.0,1.0,0.0);
Quat q_pitch; q_pitch.makeRotate(pitch,1.0,0.0,0.0);
Quat q_heading; q_heading.makeRotate(-heading,0.0,0.0,1.0);
*this = q_roll*q_pitch*q_heading;
}
#endif
void Quat::makeRotate ( float angle1, const Vec3& axis1,
float angle2, const Vec3& axis2,

View File

@ -12,7 +12,6 @@
#include <osg/BlendFunc>
#include <osg/Depth>
#include <osg/TextureBase>
#include <osg/TextureCubeMap>
#include <set>

View File

@ -1,272 +1,493 @@
#include <osg/GLExtensions>
#include <osg/Texture>
#ifdef TEXTURE_USE_DEPRECATED_API
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#endif
#include <osg/ref_ptr>
#include <osg/Image>
#include <osg/Texture>
#include <osg/State>
#include <osg/Notify>
#include <osg/GLU>
typedef void (APIENTRY * MyCompressedTexImage2DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data);
using namespace osg;
Texture::DeletedTextureObjectCache Texture::s_deletedTextureObjectCache;
Texture::Texture():
_textureWidth(0),
_textureHeight(0),
_numMimpmapLevels(0),
_subloadMode(OFF),
_subloadTextureOffsetX(0),
_subloadTextureOffsetY(0),
_subloadImageOffsetX(0),
_subloadImageOffsetY(0),
_subloadImageWidth(0),
_subloadImageHeight(0)
_wrap_s(CLAMP),
_wrap_t(CLAMP),
_wrap_r(CLAMP),
_min_filter(LINEAR_MIPMAP_LINEAR), // trilinear
_mag_filter(LINEAR),
_maxAnisotropy(1.0f),
_borderColor(0.0, 0.0, 0.0, 0.0),
_texParametersDirty(true),
_internalFormatMode(USE_IMAGE_DATA_FORMAT),
_internalFormat(0)
{
_handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
_modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
}
Texture::Texture(const Texture& text,const CopyOp& copyop):
TextureBase(text,copyop),
_image(copyop(text._image.get())),
_textureWidth(text._textureWidth),
_textureHeight(text._textureHeight),
_numMimpmapLevels(text._numMimpmapLevels),
_subloadMode(text._subloadMode),
_subloadTextureOffsetX(text._subloadTextureOffsetX),
_subloadTextureOffsetY(text._subloadTextureOffsetY),
_subloadImageOffsetX(text._subloadImageOffsetX),
_subloadImageOffsetY(text._subloadImageOffsetY),
_subloadImageWidth(text._subloadImageWidth),
_subloadImageHeight(text._subloadImageHeight),
_subloadCallback(text._subloadCallback)
{}
StateAttribute(text,copyop),
_wrap_s(text._wrap_s),
_wrap_t(text._wrap_t),
_wrap_r(text._wrap_r),
_min_filter(text._min_filter),
_mag_filter(text._mag_filter),
_maxAnisotropy(text._maxAnisotropy),
_borderColor(text._borderColor),
_texParametersDirty(false),
_internalFormatMode(text._internalFormatMode),
_internalFormat(text._internalFormat)
{
_handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
_modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
}
Texture::~Texture()
{
}
int Texture::compare(const StateAttribute& sa) const
{
// check the types are equal and then create the rhs variable
// used by the COMPARE_StateAttribute_Paramter macro's below.
COMPARE_StateAttribute_Types(Texture,sa)
if (_image!=rhs._image) // smart pointer comparison.
{
if (_image.valid())
{
if (rhs._image.valid())
{
if (_image->getFileName()<rhs._image->getFileName()) return -1;
else if (_image->getFileName()>rhs._image->getFileName()) return 1;;
}
else
{
return 1; // valid lhs._image is greater than null.
}
}
else if (rhs._image.valid())
{
return -1; // valid rhs._image is greater than null.
}
}
int result = compareTextureBase(rhs);
if (result!=0) return result;
// compare each paramter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_textureWidth)
COMPARE_StateAttribute_Parameter(_textureHeight)
COMPARE_StateAttribute_Parameter(_subloadMode)
COMPARE_StateAttribute_Parameter(_subloadTextureOffsetX)
COMPARE_StateAttribute_Parameter(_subloadTextureOffsetY)
COMPARE_StateAttribute_Parameter(_subloadImageOffsetX)
COMPARE_StateAttribute_Parameter(_subloadImageOffsetY)
COMPARE_StateAttribute_Parameter(_subloadImageWidth)
COMPARE_StateAttribute_Parameter(_subloadImageHeight)
return 0; // passed all the above comparison macro's, must be equal.
}
void Texture::setImage(Image* image)
{
// delete old texture objects.
for(TextureNameList::iterator itr=_handleList.begin();
itr!=_handleList.end();
++itr)
dirtyTextureObject();
}
int Texture::compareTexture(const Texture& rhs) const
{
COMPARE_StateAttribute_Parameter(_wrap_s)
COMPARE_StateAttribute_Parameter(_wrap_t)
COMPARE_StateAttribute_Parameter(_wrap_r)
COMPARE_StateAttribute_Parameter(_min_filter)
COMPARE_StateAttribute_Parameter(_mag_filter)
COMPARE_StateAttribute_Parameter(_maxAnisotropy)
COMPARE_StateAttribute_Parameter(_internalFormatMode)
COMPARE_StateAttribute_Parameter(_internalFormat)
return 0;
}
void Texture::setWrap(const WrapParameter which, const WrapMode wrap)
{
switch( which )
{
if (*itr != 0)
case WRAP_S : _wrap_s = wrap; _texParametersDirty = true; break;
case WRAP_T : _wrap_t = wrap; _texParametersDirty = true; break;
case WRAP_R : _wrap_r = wrap; _texParametersDirty = true; break;
default : notify(WARN)<<"Error: invalid 'which' passed Texture::setWrap("<<(unsigned int)which<<","<<(unsigned int)wrap<<")"<<std::endl; break;
}
}
const Texture::WrapMode Texture::getWrap(const WrapParameter which) const
{
switch( which )
{
case WRAP_S : return _wrap_s;
case WRAP_T : return _wrap_t;
case WRAP_R : return _wrap_r;
default : notify(WARN)<<"Error: invalid 'which' passed Texture::getWrap(which)"<<std::endl; return _wrap_s;
}
}
void Texture::setFilter(const FilterParameter which, const FilterMode filter)
{
switch( which )
{
case MIN_FILTER : _min_filter = filter; _texParametersDirty = true; break;
case MAG_FILTER : _mag_filter = filter; _texParametersDirty = true; break;
default : notify(WARN)<<"Error: invalid 'which' passed Texture::setFilter("<<(unsigned int)which<<","<<(unsigned int)filter<<")"<<std::endl; break;
}
}
const Texture::FilterMode Texture::getFilter(const FilterParameter which) const
{
switch( which )
{
case MIN_FILTER : return _min_filter;
case MAG_FILTER : return _mag_filter;
default : notify(WARN)<<"Error: invalid 'which' passed Texture::getFilter(which)"<< std::endl; return _min_filter;
}
}
void Texture::setMaxAnisotropy(float anis)
{
if (_maxAnisotropy!=anis)
{
_maxAnisotropy = anis;
_texParametersDirty = true;
}
}
/** Force a recompile on next apply() of associated OpenGL texture objects.*/
void Texture::dirtyTextureObject()
{
for(uint i=0;i<_handleList.size();++i)
{
if (_handleList[i] != 0)
{
// contact global texture object handler to delete texture objects
// in appropriate context.
// glDeleteTextures( 1L, (const GLuint *)itr );
*itr = 0;
Texture::deleteTextureObject(i,_handleList[i]);
_handleList[i] = 0;
}
}
}
void Texture::computeInternalFormatWithImage(osg::Image& image) const
{
static bool s_ARB_Compression = isGLExtensionSupported("GL_ARB_texture_compression");
static bool s_S3TC_Compression = isGLExtensionSupported("GL_EXT_texture_compression_s3tc");
GLint internalFormat = image.getInternalTextureFormat();
switch(_internalFormatMode)
{
case(USE_IMAGE_DATA_FORMAT):
internalFormat = image.getInternalTextureFormat();
break;
case(USE_ARB_COMPRESSION):
if (s_ARB_Compression)
{
switch(image.getPixelFormat())
{
case(1): internalFormat = GL_COMPRESSED_ALPHA_ARB; break;
case(2): internalFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB; break;
case(3): internalFormat = GL_COMPRESSED_RGB_ARB; break;
case(4): internalFormat = GL_COMPRESSED_RGBA_ARB; break;
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_ARB; break;
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_ARB; break;
case(GL_ALPHA): internalFormat = GL_COMPRESSED_ALPHA_ARB; break;
case(GL_LUMINANCE): internalFormat = GL_COMPRESSED_LUMINANCE_ARB; break;
case(GL_LUMINANCE_ALPHA): internalFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB; break;
case(GL_INTENSITY): internalFormat = GL_COMPRESSED_INTENSITY_ARB; break;
}
}
else internalFormat = image.getInternalTextureFormat();
break;
case(USE_S3TC_DXT1_COMPRESSION):
if (s_S3TC_Compression)
{
switch(image.getPixelFormat())
{
case(3): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(4): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
default: internalFormat = image.getInternalTextureFormat(); break;
}
}
else internalFormat = image.getInternalTextureFormat();
break;
case(USE_S3TC_DXT3_COMPRESSION):
if (s_S3TC_Compression)
{
switch(image.getPixelFormat())
{
case(3):
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(4):
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
default: internalFormat = image.getInternalTextureFormat(); break;
}
}
else internalFormat = image.getInternalTextureFormat();
break;
case(USE_S3TC_DXT5_COMPRESSION):
if (s_S3TC_Compression)
{
switch(image.getPixelFormat())
{
case(3):
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(4):
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
default: internalFormat = image.getInternalTextureFormat(); break;
}
}
else internalFormat = image.getInternalTextureFormat();
break;
case(USE_USER_DEFINED_FORMAT):
internalFormat = _internalFormat;
break;
}
_internalFormat = internalFormat;
}
bool Texture::isCompressedInternalFormat(GLint internalFormat) const
{
switch(internalFormat)
{
case(GL_COMPRESSED_ALPHA_ARB):
case(GL_COMPRESSED_INTENSITY_ARB):
case(GL_COMPRESSED_LUMINANCE_ALPHA_ARB):
case(GL_COMPRESSED_LUMINANCE_ARB):
case(GL_COMPRESSED_RGBA_ARB):
case(GL_COMPRESSED_RGB_ARB):
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
return true;
default:
return false;
}
}
void Texture::applyTexParameters(GLenum target, State&) const
{
WrapMode ws = _wrap_s, wt = _wrap_t;
// GL_IBM_texture_mirrored_repeat, fall-back REPEAT
static bool s_mirroredSupported = isGLExtensionSupported("GL_IBM_texture_mirrored_repeat");
if (!s_mirroredSupported)
{
if (ws == MIRROR)
ws = REPEAT;
if (wt == MIRROR)
wt = REPEAT;
}
// GL_EXT_texture_edge_clamp, fall-back CLAMP
static bool s_edgeClampSupported = isGLExtensionSupported("GL_EXT_texture_edge_clamp");
if (!s_edgeClampSupported)
{
if (ws == CLAMP_TO_EDGE)
ws = CLAMP;
if (wt == CLAMP_TO_EDGE)
wt = CLAMP;
}
static bool s_borderClampSupported = isGLExtensionSupported("GL_ARB_texture_border_clamp");
if(!s_borderClampSupported)
{
if(ws == CLAMP_TO_BORDER)
ws = CLAMP;
if(wt == CLAMP_TO_BORDER)
wt = CLAMP;
}
glTexParameteri( target, GL_TEXTURE_WRAP_S, ws );
glTexParameteri( target, GL_TEXTURE_WRAP_T, wt );
glTexParameteri( target, GL_TEXTURE_MIN_FILTER, _min_filter);
glTexParameteri( target, GL_TEXTURE_MAG_FILTER, _mag_filter);
if (_maxAnisotropy>1.0f)
{
// check for support for anisotropic filter,
// note since this is static varible it is intialised
// only on the first time entering this code block,
// is then never reevaluated on subsequent calls.
static bool s_anisotropicSupported =
isGLExtensionSupported("GL_EXT_texture_filter_anisotropic");
if (s_anisotropicSupported)
{
// note, GL_TEXTURE_MAX_ANISOTROPY_EXT will either be defined
// by gl.h (or via glext.h) or by include/osg/Texture.
glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, _maxAnisotropy);
}
}
_image = image;
if (s_borderClampSupported)
{
glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, _borderColor.ptr());
}
_texParametersDirty=false;
}
void Texture::apply(State& state) const
void Texture::applyTexImage2D(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight,GLsizei& numMimpmapLevels) const
{
// if we don't have a valid image we can't create a texture!
if (!image || !image->data())
return;
// get the contextID (user defined ID of 0 upwards) for the
// current OpenGL context.
const uint contextID = state.getContextID();
// get the globj for the current contextID.
GLuint& handle = getTextureObject(contextID);
// update the modified tag to show that it is upto date.
getModifiedTag(contextID) = image->getModifiedTag();
if (handle != 0)
// compute the internal texture format, this set the _internalFormat to an appropriate value.
computeInternalFormat();
// select the internalFormat required for the texture.
bool compressed = isCompressedInternalFormat(_internalFormat);
image->ensureValidSizeForTexturing();
glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking());
static MyCompressedTexImage2DArbProc glCompressedTexImage2D_ptr =
(MyCompressedTexImage2DArbProc)getGLExtensionFuncPtr("glCompressedTexImage2DARB");
if( _min_filter == LINEAR || _min_filter == NEAREST )
{
if (_subloadMode == OFF)
if ( !compressed )
{
glBindTexture( GL_TEXTURE_2D, handle );
if (_texParametersDirty) applyTexParameters(GL_TEXTURE_2D,state);
numMimpmapLevels = 1;
glTexImage2D( target, 0, _internalFormat,
image->s(), image->t(), 0,
(GLenum)image->getPixelFormat(),
(GLenum)image->getDataType(),
image->data() );
}
else if (_image.valid() && _image->data())
else if(glCompressedTexImage2D_ptr)
{
glBindTexture( GL_TEXTURE_2D, handle );
if (_texParametersDirty) applyTexParameters(GL_TEXTURE_2D,state);
numMimpmapLevels = 1;
GLint blockSize = ( _internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? 8 : 16 );
GLint size = ((image->s()+3)/4)*((image->t()+3)/4)*blockSize;
glCompressedTexImage2D_ptr(target, 0, _internalFormat,
image->s(), image->t(),0,
size,
image->data());
uint& modifiedTag = getModifiedTag(contextID);
if (_subloadMode == AUTO ||
(_subloadMode == IF_DIRTY && modifiedTag != _image->getModifiedTag()))
}
}
else
{
if(!image->isMipmap())
{
numMimpmapLevels = 1;
gluBuild2DMipmaps( target, _internalFormat,
image->s(),image->t(),
(GLenum)image->getPixelFormat(), (GLenum)image->getDataType(),
image->data() );
}
else
{
numMimpmapLevels = image->getNumMipmapLevels();
int width = image->s();
int height = image->t();
if( !compressed )
{
glPixelStorei(GL_UNPACK_ROW_LENGTH,_image->s());
for( GLsizei k = 0 ; k < numMimpmapLevels && (width || height) ;k++)
{
glTexSubImage2D(GL_TEXTURE_2D, 0,
_subloadTextureOffsetX, _subloadTextureOffsetY,
(_subloadImageWidth>0)?_subloadImageWidth:_image->s(), (_subloadImageHeight>0)?_subloadImageHeight:_image->t(),
(GLenum) _image->getPixelFormat(), (GLenum) _image->getDataType(),
_image->data(_subloadImageOffsetX,_subloadImageOffsetY));
if (width == 0)
width = 1;
if (height == 0)
height = 1;
glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
glTexImage2D( target, k, _internalFormat,
width, height, 0,
(GLenum)image->getPixelFormat(),
(GLenum)image->getDataType(),
image->getMipmapData(k));
// update the modified flag to show that the image has been loaded.
modifiedTag = _image->getModifiedTag();
width >>= 1;
height >>= 1;
}
}
else if (_subloadMode == USE_CALLBACK)
else if(glCompressedTexImage2D_ptr)
{
_subloadCallback->subload(GL_TEXTURE_2D,*this,state);
GLint blockSize = ( _internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? 8 : 16 );
GLint size = 0;
for( GLsizei k = 0 ; k < numMimpmapLevels && (width || height) ;k++)
{
if (width == 0)
width = 1;
if (height == 0)
height = 1;
size = ((width+3)/4)*((height+3)/4)*blockSize;
glCompressedTexImage2D_ptr(target, k, _internalFormat,
width, height, 0, size, image->getMipmapData(k));
width >>= 1;
height >>= 1;
}
}
}
}
inwidth = image->s();
inheight = image->t();
}
/** 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.*/
void Texture::deleteTextureObject(uint contextID,GLuint handle)
{
if (handle!=0)
{
// insert the handle into the cache for the appropriate context.
s_deletedTextureObjectCache[contextID].insert(handle);
}
}
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
void Texture::flushDeletedTextureObjects(uint contextID)
{
DeletedTextureObjectCache::iterator citr = s_deletedTextureObjectCache.find(contextID);
if (citr!=s_deletedTextureObjectCache.end())
{
std::set<uint>& textureObjectSet = citr->second;
for(std::set<uint>::iterator titr=textureObjectSet.begin();
titr!=textureObjectSet.end();
++titr)
{
glDeleteTextures( 1L, (const GLuint *)&(*titr ));
}
s_deletedTextureObjectCache.erase(citr);
}
}
GLint Texture::getMaxTextureSize()
{
static GLint s_maxTextureSize = 0;
if (s_maxTextureSize == 0)
{
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&s_maxTextureSize);
notify(INFO) << "GL_MAX_TEXTURE_SIZE "<<s_maxTextureSize<<std::endl;
char *ptr;
if( (ptr = getenv("OSG_MAX_TEXTURE_SIZE")) != 0)
{
GLint osg_max_size = atoi(ptr);
notify(INFO) << "OSG_MAX_TEXTURE_SIZE "<<osg_max_size<<std::endl;
if (osg_max_size<s_maxTextureSize)
{
s_maxTextureSize = osg_max_size;
}
}
}
else if (_image.valid() && _image->data())
{
glGenTextures( 1L, (GLuint *)&handle );
glBindTexture( GL_TEXTURE_2D, handle );
applyTexParameters(GL_TEXTURE_2D,state);
applyTexImage2D(GL_TEXTURE_2D,_image.get(),state, _textureWidth, _textureHeight, _numMimpmapLevels);
// in theory the following line is redundent, but in practice
// have found that the first frame drawn doesn't apply the textures
// unless a second bind is called?!!
// perhaps it is the first glBind which is not required...
glBindTexture( GL_TEXTURE_2D, handle );
}
else
{
glBindTexture( GL_TEXTURE_2D, 0 );
}
notify(INFO) << "Selected max texture size "<<s_maxTextureSize<<std::endl;
}
return s_maxTextureSize;
}
void Texture::computeInternalFormat() const
void Texture::compile(State& state) const
{
if (_image.valid()) computeInternalFormatWithImage(*_image);
apply(state);
}
void Texture::copyTexImage2D(State& state, int x, int y, int width, int height )
{
const uint contextID = state.getContextID();
// get the globj for the current contextID.
GLuint& handle = getTextureObject(contextID);
if (handle)
{
if (width==(int)_textureWidth && height==(int)_textureHeight)
{
// we have a valid texture object which is the right size
// so lets play clever and use copyTexSubImage2D instead.
// this allows use to reuse the texture object and avoid
// expensive memory allocations.
copyTexSubImage2D(state,0 ,0, x, y, width, height);
return;
}
// the relevent texture object is not of the right size so
// needs to been deleted
// remove previously bound textures.
dirtyTextureObject();
// note, dirtyTextureObject() dirties all the texture objects for
// this texture, is this right? Perhaps we should dirty just the
// one for this context. Note sure yet will leave till later.
// RO July 2001.
}
// remove any previously assigned images as these are nolonger valid.
_image = NULL;
// switch off mip-mapping.
_min_filter = LINEAR;
_mag_filter = LINEAR;
// Get a new 2d texture handle.
glGenTextures( 1, &handle );
glBindTexture( GL_TEXTURE_2D, handle );
applyTexParameters(GL_TEXTURE_2D,state);
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, x, y, width, height, 0 );
_textureWidth = width;
_textureHeight = height;
// inform state that this texture is the current one bound.
state.haveAppliedAttribute(this);
}
void Texture::copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height )
{
const uint contextID = state.getContextID();
// get the globj for the current contextID.
GLuint& handle = getTextureObject(contextID);
if (handle)
{
// we have a valid image
glBindTexture( GL_TEXTURE_2D, handle );
applyTexParameters(GL_TEXTURE_2D,state);
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, xoffset,yoffset, x, y, width, height);
/* Redundant, delete later */
glBindTexture( GL_TEXTURE_2D, handle );
// inform state that this texture is the current one bound.
state.haveAppliedAttribute(this);
}
else
{
// no texture object already exsits for this context so need to
// create it upfront - simply call copyTexImage2D.
copyTexImage2D(state,x,y,width,height);
}
}
#endif // USE_DEPRECATED_API

View File

@ -14,7 +14,7 @@ Texture1D::Texture1D():
}
Texture1D::Texture1D(const Texture1D& text,const CopyOp& copyop):
TextureBase(text,copyop),
Texture(text,copyop),
_image(copyop(text._image.get())),
_textureWidth(text._textureWidth),
_numMimpmapLevels(text._numMimpmapLevels),
@ -52,7 +52,7 @@ int Texture1D::compare(const StateAttribute& sa) const
}
}
int result = compareTextureBase(rhs);
int result = compareTexture(rhs);
if (result!=0) return result;
// compare each paramter in turn against the rhs.

View File

@ -15,7 +15,7 @@ Texture2D::Texture2D():
}
Texture2D::Texture2D(const Texture2D& text,const CopyOp& copyop):
TextureBase(text,copyop),
Texture(text,copyop),
_image(copyop(text._image.get())),
_textureWidth(text._textureWidth),
_textureHeight(text._textureHeight),
@ -54,7 +54,7 @@ int Texture2D::compare(const StateAttribute& sa) const
}
}
int result = compareTextureBase(rhs);
int result = compareTexture(rhs);
if (result!=0) return result;
// compare each paramter in turn against the rhs.

View File

@ -23,7 +23,7 @@ Texture3D::Texture3D():
}
Texture3D::Texture3D(const Texture3D& text,const CopyOp& copyop):
TextureBase(text,copyop),
Texture(text,copyop),
_image(copyop(text._image.get())),
_textureWidth(text._textureWidth),
_textureHeight(text._textureHeight),
@ -63,7 +63,7 @@ int Texture3D::compare(const StateAttribute& sa) const
}
}
int result = compareTextureBase(rhs);
int result = compareTexture(rhs);
if (result!=0) return result;
// compare each paramter in turn against the rhs.

View File

@ -1,493 +0,0 @@
#include <osg/GLExtensions>
#include <osg/Image>
#include <osg/TextureBase>
#include <osg/State>
#include <osg/Notify>
#include <osg/GLU>
typedef void (APIENTRY * MyCompressedTexImage2DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data);
using namespace osg;
TextureBase::DeletedTextureObjectCache TextureBase::s_deletedTextureObjectCache;
TextureBase::TextureBase():
_wrap_s(CLAMP),
_wrap_t(CLAMP),
_wrap_r(CLAMP),
_min_filter(LINEAR_MIPMAP_LINEAR), // trilinear
_mag_filter(LINEAR),
_maxAnisotropy(1.0f),
_borderColor(0.0, 0.0, 0.0, 0.0),
_texParametersDirty(true),
_internalFormatMode(USE_IMAGE_DATA_FORMAT),
_internalFormat(0)
{
_handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
_modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
}
TextureBase::TextureBase(const TextureBase& text,const CopyOp& copyop):
StateAttribute(text,copyop),
_wrap_s(text._wrap_s),
_wrap_t(text._wrap_t),
_wrap_r(text._wrap_r),
_min_filter(text._min_filter),
_mag_filter(text._mag_filter),
_maxAnisotropy(text._maxAnisotropy),
_borderColor(text._borderColor),
_texParametersDirty(false),
_internalFormatMode(text._internalFormatMode),
_internalFormat(text._internalFormat)
{
_handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
_modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
}
TextureBase::~TextureBase()
{
// delete old texture objects.
dirtyTextureObject();
}
int TextureBase::compareTextureBase(const TextureBase& rhs) const
{
COMPARE_StateAttribute_Parameter(_wrap_s)
COMPARE_StateAttribute_Parameter(_wrap_t)
COMPARE_StateAttribute_Parameter(_wrap_r)
COMPARE_StateAttribute_Parameter(_min_filter)
COMPARE_StateAttribute_Parameter(_mag_filter)
COMPARE_StateAttribute_Parameter(_maxAnisotropy)
COMPARE_StateAttribute_Parameter(_internalFormatMode)
COMPARE_StateAttribute_Parameter(_internalFormat)
return 0;
}
void TextureBase::setWrap(const WrapParameter which, const WrapMode wrap)
{
switch( which )
{
case WRAP_S : _wrap_s = wrap; _texParametersDirty = true; break;
case WRAP_T : _wrap_t = wrap; _texParametersDirty = true; break;
case WRAP_R : _wrap_r = wrap; _texParametersDirty = true; break;
default : notify(WARN)<<"Error: invalid 'which' passed TextureBase::setWrap("<<(unsigned int)which<<","<<(unsigned int)wrap<<")"<<std::endl; break;
}
}
const TextureBase::WrapMode TextureBase::getWrap(const WrapParameter which) const
{
switch( which )
{
case WRAP_S : return _wrap_s;
case WRAP_T : return _wrap_t;
case WRAP_R : return _wrap_r;
default : notify(WARN)<<"Error: invalid 'which' passed TextureBase::getWrap(which)"<<std::endl; return _wrap_s;
}
}
void TextureBase::setFilter(const FilterParameter which, const FilterMode filter)
{
switch( which )
{
case MIN_FILTER : _min_filter = filter; _texParametersDirty = true; break;
case MAG_FILTER : _mag_filter = filter; _texParametersDirty = true; break;
default : notify(WARN)<<"Error: invalid 'which' passed TextureBase::setFilter("<<(unsigned int)which<<","<<(unsigned int)filter<<")"<<std::endl; break;
}
}
const TextureBase::FilterMode TextureBase::getFilter(const FilterParameter which) const
{
switch( which )
{
case MIN_FILTER : return _min_filter;
case MAG_FILTER : return _mag_filter;
default : notify(WARN)<<"Error: invalid 'which' passed TextureBase::getFilter(which)"<< std::endl; return _min_filter;
}
}
void TextureBase::setMaxAnisotropy(float anis)
{
if (_maxAnisotropy!=anis)
{
_maxAnisotropy = anis;
_texParametersDirty = true;
}
}
/** Force a recompile on next apply() of associated OpenGL texture objects.*/
void TextureBase::dirtyTextureObject()
{
for(uint i=0;i<_handleList.size();++i)
{
if (_handleList[i] != 0)
{
TextureBase::deleteTextureObject(i,_handleList[i]);
_handleList[i] = 0;
}
}
}
void TextureBase::computeInternalFormatWithImage(osg::Image& image) const
{
static bool s_ARB_Compression = isGLExtensionSupported("GL_ARB_texture_compression");
static bool s_S3TC_Compression = isGLExtensionSupported("GL_EXT_texture_compression_s3tc");
GLint internalFormat = image.getInternalTextureFormat();
switch(_internalFormatMode)
{
case(USE_IMAGE_DATA_FORMAT):
internalFormat = image.getInternalTextureFormat();
break;
case(USE_ARB_COMPRESSION):
if (s_ARB_Compression)
{
switch(image.getPixelFormat())
{
case(1): internalFormat = GL_COMPRESSED_ALPHA_ARB; break;
case(2): internalFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB; break;
case(3): internalFormat = GL_COMPRESSED_RGB_ARB; break;
case(4): internalFormat = GL_COMPRESSED_RGBA_ARB; break;
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_ARB; break;
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_ARB; break;
case(GL_ALPHA): internalFormat = GL_COMPRESSED_ALPHA_ARB; break;
case(GL_LUMINANCE): internalFormat = GL_COMPRESSED_LUMINANCE_ARB; break;
case(GL_LUMINANCE_ALPHA): internalFormat = GL_COMPRESSED_LUMINANCE_ALPHA_ARB; break;
case(GL_INTENSITY): internalFormat = GL_COMPRESSED_INTENSITY_ARB; break;
}
}
else internalFormat = image.getInternalTextureFormat();
break;
case(USE_S3TC_DXT1_COMPRESSION):
if (s_S3TC_Compression)
{
switch(image.getPixelFormat())
{
case(3): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(4): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
default: internalFormat = image.getInternalTextureFormat(); break;
}
}
else internalFormat = image.getInternalTextureFormat();
break;
case(USE_S3TC_DXT3_COMPRESSION):
if (s_S3TC_Compression)
{
switch(image.getPixelFormat())
{
case(3):
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(4):
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
default: internalFormat = image.getInternalTextureFormat(); break;
}
}
else internalFormat = image.getInternalTextureFormat();
break;
case(USE_S3TC_DXT5_COMPRESSION):
if (s_S3TC_Compression)
{
switch(image.getPixelFormat())
{
case(3):
case(GL_RGB): internalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
case(4):
case(GL_RGBA): internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
default: internalFormat = image.getInternalTextureFormat(); break;
}
}
else internalFormat = image.getInternalTextureFormat();
break;
case(USE_USER_DEFINED_FORMAT):
internalFormat = _internalFormat;
break;
}
_internalFormat = internalFormat;
}
bool TextureBase::isCompressedInternalFormat(GLint internalFormat) const
{
switch(internalFormat)
{
case(GL_COMPRESSED_ALPHA_ARB):
case(GL_COMPRESSED_INTENSITY_ARB):
case(GL_COMPRESSED_LUMINANCE_ALPHA_ARB):
case(GL_COMPRESSED_LUMINANCE_ARB):
case(GL_COMPRESSED_RGBA_ARB):
case(GL_COMPRESSED_RGB_ARB):
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
return true;
default:
return false;
}
}
void TextureBase::applyTexParameters(GLenum target, State&) const
{
WrapMode ws = _wrap_s, wt = _wrap_t;
// GL_IBM_texture_mirrored_repeat, fall-back REPEAT
static bool s_mirroredSupported = isGLExtensionSupported("GL_IBM_texture_mirrored_repeat");
if (!s_mirroredSupported)
{
if (ws == MIRROR)
ws = REPEAT;
if (wt == MIRROR)
wt = REPEAT;
}
// GL_EXT_texture_edge_clamp, fall-back CLAMP
static bool s_edgeClampSupported = isGLExtensionSupported("GL_EXT_texture_edge_clamp");
if (!s_edgeClampSupported)
{
if (ws == CLAMP_TO_EDGE)
ws = CLAMP;
if (wt == CLAMP_TO_EDGE)
wt = CLAMP;
}
static bool s_borderClampSupported = isGLExtensionSupported("GL_ARB_texture_border_clamp");
if(!s_borderClampSupported)
{
if(ws == CLAMP_TO_BORDER)
ws = CLAMP;
if(wt == CLAMP_TO_BORDER)
wt = CLAMP;
}
glTexParameteri( target, GL_TEXTURE_WRAP_S, ws );
glTexParameteri( target, GL_TEXTURE_WRAP_T, wt );
glTexParameteri( target, GL_TEXTURE_MIN_FILTER, _min_filter);
glTexParameteri( target, GL_TEXTURE_MAG_FILTER, _mag_filter);
if (_maxAnisotropy>1.0f)
{
// check for support for anisotropic filter,
// note since this is static varible it is intialised
// only on the first time entering this code block,
// is then never reevaluated on subsequent calls.
static bool s_anisotropicSupported =
isGLExtensionSupported("GL_EXT_texture_filter_anisotropic");
if (s_anisotropicSupported)
{
// note, GL_TEXTURE_MAX_ANISOTROPY_EXT will either be defined
// by gl.h (or via glext.h) or by include/osg/Texture.
glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, _maxAnisotropy);
}
}
if (s_borderClampSupported)
{
glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, _borderColor.ptr());
}
_texParametersDirty=false;
}
void TextureBase::applyTexImage2D(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight,GLsizei& numMimpmapLevels) const
{
// if we don't have a valid image we can't create a texture!
if (!image || !image->data())
return;
// get the contextID (user defined ID of 0 upwards) for the
// current OpenGL context.
const uint contextID = state.getContextID();
// update the modified tag to show that it is upto date.
getModifiedTag(contextID) = image->getModifiedTag();
// compute the internal texture format, this set the _internalFormat to an appropriate value.
computeInternalFormat();
// select the internalFormat required for the texture.
bool compressed = isCompressedInternalFormat(_internalFormat);
image->ensureValidSizeForTexturing();
glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking());
static MyCompressedTexImage2DArbProc glCompressedTexImage2D_ptr =
(MyCompressedTexImage2DArbProc)getGLExtensionFuncPtr("glCompressedTexImage2DARB");
if( _min_filter == LINEAR || _min_filter == NEAREST )
{
if ( !compressed )
{
numMimpmapLevels = 1;
glTexImage2D( target, 0, _internalFormat,
image->s(), image->t(), 0,
(GLenum)image->getPixelFormat(),
(GLenum)image->getDataType(),
image->data() );
}
else if(glCompressedTexImage2D_ptr)
{
numMimpmapLevels = 1;
GLint blockSize = ( _internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? 8 : 16 );
GLint size = ((image->s()+3)/4)*((image->t()+3)/4)*blockSize;
glCompressedTexImage2D_ptr(target, 0, _internalFormat,
image->s(), image->t(),0,
size,
image->data());
}
}
else
{
if(!image->isMipmap())
{
numMimpmapLevels = 1;
gluBuild2DMipmaps( target, _internalFormat,
image->s(),image->t(),
(GLenum)image->getPixelFormat(), (GLenum)image->getDataType(),
image->data() );
}
else
{
numMimpmapLevels = image->getNumMipmapLevels();
int width = image->s();
int height = image->t();
if( !compressed )
{
for( GLsizei k = 0 ; k < numMimpmapLevels && (width || height) ;k++)
{
if (width == 0)
width = 1;
if (height == 0)
height = 1;
glTexImage2D( target, k, _internalFormat,
width, height, 0,
(GLenum)image->getPixelFormat(),
(GLenum)image->getDataType(),
image->getMipmapData(k));
width >>= 1;
height >>= 1;
}
}
else if(glCompressedTexImage2D_ptr)
{
GLint blockSize = ( _internalFormat == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ? 8 : 16 );
GLint size = 0;
for( GLsizei k = 0 ; k < numMimpmapLevels && (width || height) ;k++)
{
if (width == 0)
width = 1;
if (height == 0)
height = 1;
size = ((width+3)/4)*((height+3)/4)*blockSize;
glCompressedTexImage2D_ptr(target, k, _internalFormat,
width, height, 0, size, image->getMipmapData(k));
width >>= 1;
height >>= 1;
}
}
}
}
inwidth = image->s();
inheight = image->t();
}
/** 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.*/
void TextureBase::deleteTextureObject(uint contextID,GLuint handle)
{
if (handle!=0)
{
// insert the handle into the cache for the appropriate context.
s_deletedTextureObjectCache[contextID].insert(handle);
}
}
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
void TextureBase::flushDeletedTextureObjects(uint contextID)
{
DeletedTextureObjectCache::iterator citr = s_deletedTextureObjectCache.find(contextID);
if (citr!=s_deletedTextureObjectCache.end())
{
std::set<uint>& textureObjectSet = citr->second;
for(std::set<uint>::iterator titr=textureObjectSet.begin();
titr!=textureObjectSet.end();
++titr)
{
glDeleteTextures( 1L, (const GLuint *)&(*titr ));
}
s_deletedTextureObjectCache.erase(citr);
}
}
GLint TextureBase::getMaxTextureSize()
{
static GLint s_maxTextureSize = 0;
if (s_maxTextureSize == 0)
{
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&s_maxTextureSize);
notify(INFO) << "GL_MAX_TEXTURE_SIZE "<<s_maxTextureSize<<std::endl;
char *ptr;
if( (ptr = getenv("OSG_MAX_TEXTURE_SIZE")) != 0)
{
GLint osg_max_size = atoi(ptr);
notify(INFO) << "OSG_MAX_TEXTURE_SIZE "<<osg_max_size<<std::endl;
if (osg_max_size<s_maxTextureSize)
{
s_maxTextureSize = osg_max_size;
}
}
notify(INFO) << "Selected max texture size "<<s_maxTextureSize<<std::endl;
}
return s_maxTextureSize;
}
void TextureBase::compile(State& state) const
{
apply(state);
}

View File

@ -82,7 +82,7 @@ TextureCubeMap::TextureCubeMap():
}
TextureCubeMap::TextureCubeMap(const TextureCubeMap& text,const CopyOp& copyop):
TextureBase(text,copyop),
Texture(text,copyop),
_textureWidth(text._textureWidth),
_textureHeight(text._textureHeight),
_numMimpmapLevels(text._numMimpmapLevels),
@ -132,7 +132,7 @@ int TextureCubeMap::compare(const StateAttribute& sa) const
}
}
int result = compareTextureBase(rhs);
int result = compareTexture(rhs);
if (result!=0) return result;
// compare each paramter in turn against the rhs.

View File

@ -3,42 +3,17 @@
using namespace osg;
Transform::Transform()
#ifdef USE_DEPRECATED_API
:_deprecated_inverseDirty(false)
#endif
{
_referenceFrame = RELATIVE_TO_PARENTS;
#ifdef USE_DEPRECATED_API
_deprecated_matrix = osgNew Matrix;
_deprecated_inverse = osgNew Matrix;
#endif
}
Transform::Transform(const Transform& transform,const CopyOp& copyop):
Group(transform,copyop),
_computeTransformCallback(transform._computeTransformCallback),
_referenceFrame(transform._referenceFrame)
#ifdef USE_DEPRECATED_API
,
_deprecated_matrix(osgNew Matrix(*transform._deprecated_matrix)),
_deprecated_inverse(osgNew Matrix(*transform._deprecated_inverse)),
_deprecated_inverseDirty(transform._deprecated_inverseDirty)
#endif
{
}
#ifdef USE_DEPRECATED_API
Transform::Transform(const Matrix& mat )
{
_referenceFrame = RELATIVE_TO_PARENTS;
_deprecated_matrix = osgNew Matrix(mat);
_deprecated_inverse = osgNew Matrix();
_deprecated_inverseDirty = false;
}
#endif
Transform::~Transform()
{
}

View File

@ -12,7 +12,7 @@
#include <osg/Object>
#include <osg/LOD>
#include <osg/Transparency>
#include <osg/BlendFunc>
#include <osg/Geode>
#include <osg/StateSet>
#include <osg/Material>

View File

@ -49,8 +49,9 @@ CXXFILES =\
TexGen.cpp\
TexMat.cpp\
Texture.cpp\
TextureBase.cpp\
Texture1D.cpp\
Texture2D.cpp\
Texture3D.cpp\
TextureCubeMap.cpp\
Transform.cpp\

View File

@ -1,11 +1,8 @@
#include "osg/Texture"
#include <osg/Texture>
#ifdef TEXTURE_USE_DEPRECATED_API
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
using namespace osg;
using namespace osgDB;
@ -20,17 +17,15 @@ bool Texture_matchFilterStr(const char* str,Texture::FilterMode& filter);
const char* Texture_getFilterStr(Texture::FilterMode filter);
bool Texture_matchInternalFormatModeStr(const char* str,Texture::InternalFormatMode& mode);
const char* Texture_getInternalFormatModeStr(Texture::InternalFormatMode mode);
bool Texture_matchInternalFormatValueStr(const char* str,int& value);
const char* Texture_getInternalFormatValueStr(int value);
bool Texture_matchSubloadModeStr(const char* str, Texture::SubloadMode& value);
const char* Texture_getSubloadModeStr(Texture::SubloadMode value);
bool Texture_matchInternalFormatStr(const char* str,int& value);
const char* Texture_getInternalFormatStr(int value);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_TextureProxy
(
osgNew osg::Texture,
"Texture",
"Object StateAttribute Texture TextureBase",
0,
"TextureBase",
"Object StateAttribute TextureBase",
&Texture_readLocalData,
&Texture_writeLocalData
);
@ -42,87 +37,67 @@ bool Texture_readLocalData(Object& obj, Input& fr)
Texture& texture = static_cast<Texture&>(obj);
if (fr[0].matchWord("file") && fr[1].isString())
Texture::WrapMode wrap;
if (fr[0].matchWord("wrap_s") && Texture_matchWrapStr(fr[1].getStr(),wrap))
{
std::string filename = fr[1].getStr();
Image* image = fr.readImage(filename.c_str());
if (image)
{
// name will have already been set by the image plugin,
// but it will have absolute path, so will override it
// here to keep the original name intact.
//image->setFileName(filename);
texture.setImage(image);
}
fr += 2;
texture.setWrap(Texture::WRAP_S,wrap);
fr+=2;
iteratorAdvanced = true;
}
Texture::SubloadMode submode;
if (fr[0].matchWord("subloadMode") && Texture_matchSubloadModeStr(fr[1].getStr(),submode))
if (fr[0].matchWord("wrap_t") && Texture_matchWrapStr(fr[1].getStr(),wrap))
{
texture.setSubloadMode(submode);
fr += 2;
texture.setWrap(Texture::WRAP_T,wrap);
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("subloadOffset"))
if (fr[0].matchWord("wrap_r") && Texture_matchWrapStr(fr[1].getStr(),wrap))
{
int x, y;
if (fr[1].getInt(x) && fr[2].getInt(y))
{
texture.setSubloadTextureOffset(x, y);
fr += 3;
iteratorAdvanced = true;
}
texture.setWrap(Texture::WRAP_R,wrap);
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("subloadSize"))
Texture::FilterMode filter;
if (fr[0].matchWord("min_filter") && Texture_matchFilterStr(fr[1].getStr(),filter))
{
int width, height;
if (fr[1].getInt(width) && fr[2].getInt(height))
{
texture.setSubloadImageSize(width, height);
fr += 3;
iteratorAdvanced = true;
}
texture.setFilter(Texture::MIN_FILTER,filter);
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("subloadTextureOffset"))
if (fr[0].matchWord("mag_filter") && Texture_matchFilterStr(fr[1].getStr(),filter))
{
int x, y;
if (fr[1].getInt(x) && fr[2].getInt(y))
{
texture.setSubloadTextureOffset(x, y);
fr += 3;
iteratorAdvanced = true;
}
texture.setFilter(Texture::MAG_FILTER,filter);
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("subloadTextureSize"))
if (fr.matchSequence("maxAnisotropy %f"))
{
int width, height;
if (fr[1].getInt(width) && fr[2].getInt(height))
{
texture.setSubloadTextureSize(width, height);
fr += 3;
iteratorAdvanced = true;
}
float anis=1.0f;
fr[1].getFloat(anis);
texture.setMaxAnisotropy(anis);
fr +=2 ;
iteratorAdvanced = true;
}
if (fr[0].matchWord("subloadImageOffset"))
Texture::InternalFormatMode mode;
if (fr[0].matchWord("internalFormatMode") && Texture_matchInternalFormatModeStr(fr[1].getStr(),mode))
{
int x, y;
if (fr[1].getInt(x) && fr[2].getInt(y))
{
texture.setSubloadImageOffset(x, y);
fr += 3;
iteratorAdvanced = true;
}
texture.setInternalFormatMode(mode);
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("subloadImageSize"))
if (fr[0].matchWord("internalFormatValue"))
{
int width, height;
if (fr[1].getInt(width) && fr[2].getInt(height))
int value;
if (Texture_matchInternalFormatStr(fr[1].getStr(),value) || fr[1].getInt(value))
{
texture.setSubloadImageSize(width, height);
fr += 3;
texture.setInternalFormat(value);
fr+=2;
iteratorAdvanced = true;
}
}
@ -135,28 +110,21 @@ bool Texture_writeLocalData(const Object& obj, Output& fw)
{
const Texture& texture = static_cast<const Texture&>(obj);
if (texture.getImage() && !(texture.getImage()->getFileName().empty()))
fw.indent() << "wrap_s " << Texture_getWrapStr(texture.getWrap(Texture::WRAP_S)) << std::endl;
fw.indent() << "wrap_t " << Texture_getWrapStr(texture.getWrap(Texture::WRAP_T)) << std::endl;
fw.indent() << "wrap_r " << Texture_getWrapStr(texture.getWrap(Texture::WRAP_R)) << std::endl;
fw.indent() << "min_filter " << Texture_getFilterStr(texture.getFilter(Texture::MIN_FILTER)) << std::endl;
fw.indent() << "mag_filter " << Texture_getFilterStr(texture.getFilter(Texture::MAG_FILTER)) << std::endl;
fw.indent() << "maxAnisotropy " << texture.getMaxAnisotropy() << std::endl;
fw.indent() << "internalFormatMode " << Texture_getInternalFormatModeStr(texture.getInternalFormatMode()) << std::endl;
if (texture.getInternalFormatMode()==Texture::USE_USER_DEFINED_FORMAT)
{
fw.indent() << "file \""<<fw.getFileNameForOutput(texture.getImage()->getFileName())<<"\""<< std::endl;
}
fw.indent() << "subloadMode " << Texture_getSubloadModeStr(texture.getSubloadMode()) << std::endl;
if (texture.getSubloadMode()!=Texture::OFF)
{
int x, y;
texture.getSubloadTextureOffset(x, y);
fw.indent() << "subloadTextureOffset " << x << " " << y << std::endl;
int width, height;
texture.getSubloadTextureSize(width, height);
fw.indent() << "subloadTextureSize " << width << " " << height << std::endl;
texture.getSubloadImageOffset(x, y);
fw.indent() << "subloadImageOffset " << x << " " << y << std::endl;
texture.getSubloadImageSize(width, height);
fw.indent() << "subloadImageSize " << width << " " << height << std::endl;
const char* str = Texture_getInternalFormatStr(texture.getInternalFormat());
if (str) fw.indent() << "internalFormat " << str << std::endl;
else fw.indent() << "internalFormat " << texture.getInternalFormat() << std::endl;
}
return true;
@ -245,7 +213,7 @@ const char* Texture_getInternalFormatModeStr(Texture::InternalFormatMode mode)
}
bool Texture_matchInternalFormatValueStr(const char* str,int& value)
bool Texture_matchInternalFormatStr(const char* str,int& value)
{
if ( strcmp(str,"GL_INTENSITY")==0) value = GL_INTENSITY;
@ -269,7 +237,7 @@ bool Texture_matchInternalFormatValueStr(const char* str,int& value)
}
const char* Texture_getInternalFormatValueStr(int value)
const char* Texture_getInternalFormatStr(int value)
{
switch(value)
{
@ -293,29 +261,3 @@ const char* Texture_getInternalFormatValueStr(int value)
return NULL;
}
bool Texture_matchSubloadModeStr(const char* str,Texture::SubloadMode& value)
{
if (strcmp(str, "OFF") == 0)
value = Texture::OFF;
else if (strcmp(str, "AUTO") == 0)
value = Texture::AUTO;
else if (strcmp(str, "IF_DIRTY") == 0)
value = Texture::IF_DIRTY;
else
return false;
return true;
}
const char* Texture_getSubloadModeStr(Texture::SubloadMode value)
{
switch (value)
{
case Texture::OFF: return "OFF";
case Texture::AUTO: return "AUTO";
case Texture::IF_DIRTY: return "IF_DIRTY";
}
return NULL;
}
#endif

View File

@ -0,0 +1,70 @@
#include "osg/Texture1D"
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool Texture1D_readLocalData(Object& obj, Input& fr);
bool Texture1D_writeLocalData(const Object& obj, Output& fw);
bool Texture1D_matchWrapStr(const char* str,Texture1D::WrapMode& wrap);
const char* Texture1D_getWrapStr(Texture1D::WrapMode wrap);
bool Texture1D_matchFilterStr(const char* str,Texture1D::FilterMode& filter);
const char* Texture1D_getFilterStr(Texture1D::FilterMode filter);
bool Texture1D_matchInternalFormatModeStr(const char* str,Texture1D::InternalFormatMode& mode);
const char* Texture1D_getInternalFormatModeStr(Texture1D::InternalFormatMode mode);
bool Texture1D_matchInternalFormatStr(const char* str,int& value);
const char* Texture1D_getInternalFormatStr(int value);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_Texture1DProxy
(
osgNew osg::Texture1D,
"Texture1D",
"Object StateAttribute Texture1D TextureBase",
&Texture1D_readLocalData,
&Texture1D_writeLocalData
);
bool Texture1D_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
Texture1D& texture = static_cast<Texture1D&>(obj);
if (fr[0].matchWord("file") && fr[1].isString())
{
std::string filename = fr[1].getStr();
Image* image = fr.readImage(filename.c_str());
if (image)
{
// name will have already been set by the image plugin,
// but it will have absolute path, so will override it
// here to keep the original name intact.
//image->setFileName(filename);
texture.setImage(image);
}
fr += 2;
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
bool Texture1D_writeLocalData(const Object& obj, Output& fw)
{
const Texture1D& texture = static_cast<const Texture1D&>(obj);
if (texture.getImage() && !(texture.getImage()->getFileName().empty()))
{
fw.indent() << "file \""<<fw.getFileNameForOutput(texture.getImage()->getFileName())<<"\""<< std::endl;
}
return true;
}

View File

@ -20,11 +20,7 @@ const char* Texture2D_getInternalFormatModeStr(Texture2D::InternalFormatMode mod
bool Texture2D_matchInternalFormatStr(const char* str,int& value);
const char* Texture2D_getInternalFormatStr(int value);
#include "osg/Texture"
#ifndef TEXTURE_USE_DEPRECATED_API
RegisterDotOsgWrapperProxy g_TextureProxy
RegisterDotOsgWrapperProxy g_OldTextureProxy
(
osgNew osg::Texture2D,
"Texture",
@ -32,7 +28,6 @@ RegisterDotOsgWrapperProxy g_TextureProxy
0,
0
);
#endif
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_Texture2DProxy

View File

@ -0,0 +1,70 @@
#include "osg/Texture3D"
#include "osgDB/Registry"
#include "osgDB/Input"
#include "osgDB/Output"
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool Texture3D_readLocalData(Object& obj, Input& fr);
bool Texture3D_writeLocalData(const Object& obj, Output& fw);
bool Texture3D_matchWrapStr(const char* str,Texture3D::WrapMode& wrap);
const char* Texture3D_getWrapStr(Texture3D::WrapMode wrap);
bool Texture3D_matchFilterStr(const char* str,Texture3D::FilterMode& filter);
const char* Texture3D_getFilterStr(Texture3D::FilterMode filter);
bool Texture3D_matchInternalFormatModeStr(const char* str,Texture3D::InternalFormatMode& mode);
const char* Texture3D_getInternalFormatModeStr(Texture3D::InternalFormatMode mode);
bool Texture3D_matchInternalFormatStr(const char* str,int& value);
const char* Texture3D_getInternalFormatStr(int value);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_Texture3DProxy
(
osgNew osg::Texture3D,
"Texture3D",
"Object StateAttribute Texture3D TextureBase",
&Texture3D_readLocalData,
&Texture3D_writeLocalData
);
bool Texture3D_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
Texture3D& texture = static_cast<Texture3D&>(obj);
if (fr[0].matchWord("file") && fr[1].isString())
{
std::string filename = fr[1].getStr();
Image* image = fr.readImage(filename.c_str());
if (image)
{
// name will have already been set by the image plugin,
// but it will have absolute path, so will override it
// here to keep the original name intact.
//image->setFileName(filename);
texture.setImage(image);
}
fr += 2;
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
bool Texture3D_writeLocalData(const Object& obj, Output& fw)
{
const Texture3D& texture = static_cast<const Texture3D&>(obj);
if (texture.getImage() && !(texture.getImage()->getFileName().empty()))
{
fw.indent() << "file \""<<fw.getFileNameForOutput(texture.getImage()->getFileName())<<"\""<< std::endl;
}
return true;
}

View File

@ -1,263 +0,0 @@
#include <osg/TextureBase>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
using namespace osg;
using namespace osgDB;
// forward declare functions to use later.
bool TextureBase_readLocalData(Object& obj, Input& fr);
bool TextureBase_writeLocalData(const Object& obj, Output& fw);
bool TextureBase_matchWrapStr(const char* str,TextureBase::WrapMode& wrap);
const char* TextureBase_getWrapStr(TextureBase::WrapMode wrap);
bool TextureBase_matchFilterStr(const char* str,TextureBase::FilterMode& filter);
const char* TextureBase_getFilterStr(TextureBase::FilterMode filter);
bool TextureBase_matchInternalFormatModeStr(const char* str,TextureBase::InternalFormatMode& mode);
const char* TextureBase_getInternalFormatModeStr(TextureBase::InternalFormatMode mode);
bool TextureBase_matchInternalFormatStr(const char* str,int& value);
const char* TextureBase_getInternalFormatStr(int value);
// register the read and write functions with the osgDB::Registry.
RegisterDotOsgWrapperProxy g_TextureBaseProxy
(
0,
"TextureBase",
"Object StateAttribute TextureBase",
&TextureBase_readLocalData,
&TextureBase_writeLocalData
);
bool TextureBase_readLocalData(Object& obj, Input& fr)
{
bool iteratorAdvanced = false;
TextureBase& texture = static_cast<TextureBase&>(obj);
TextureBase::WrapMode wrap;
if (fr[0].matchWord("wrap_s") && TextureBase_matchWrapStr(fr[1].getStr(),wrap))
{
texture.setWrap(TextureBase::WRAP_S,wrap);
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("wrap_t") && TextureBase_matchWrapStr(fr[1].getStr(),wrap))
{
texture.setWrap(TextureBase::WRAP_T,wrap);
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("wrap_r") && TextureBase_matchWrapStr(fr[1].getStr(),wrap))
{
texture.setWrap(TextureBase::WRAP_R,wrap);
fr+=2;
iteratorAdvanced = true;
}
TextureBase::FilterMode filter;
if (fr[0].matchWord("min_filter") && TextureBase_matchFilterStr(fr[1].getStr(),filter))
{
texture.setFilter(TextureBase::MIN_FILTER,filter);
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("mag_filter") && TextureBase_matchFilterStr(fr[1].getStr(),filter))
{
texture.setFilter(TextureBase::MAG_FILTER,filter);
fr+=2;
iteratorAdvanced = true;
}
if (fr.matchSequence("maxAnisotropy %f"))
{
float anis=1.0f;
fr[1].getFloat(anis);
texture.setMaxAnisotropy(anis);
fr +=2 ;
iteratorAdvanced = true;
}
TextureBase::InternalFormatMode mode;
if (fr[0].matchWord("internalFormatMode") && TextureBase_matchInternalFormatModeStr(fr[1].getStr(),mode))
{
texture.setInternalFormatMode(mode);
fr+=2;
iteratorAdvanced = true;
}
if (fr[0].matchWord("internalFormatValue"))
{
int value;
if (TextureBase_matchInternalFormatStr(fr[1].getStr(),value) || fr[1].getInt(value))
{
texture.setInternalFormat(value);
fr+=2;
iteratorAdvanced = true;
}
}
return iteratorAdvanced;
}
bool TextureBase_writeLocalData(const Object& obj, Output& fw)
{
const TextureBase& texture = static_cast<const TextureBase&>(obj);
fw.indent() << "wrap_s " << TextureBase_getWrapStr(texture.getWrap(TextureBase::WRAP_S)) << std::endl;
fw.indent() << "wrap_t " << TextureBase_getWrapStr(texture.getWrap(TextureBase::WRAP_T)) << std::endl;
fw.indent() << "wrap_r " << TextureBase_getWrapStr(texture.getWrap(TextureBase::WRAP_R)) << std::endl;
fw.indent() << "min_filter " << TextureBase_getFilterStr(texture.getFilter(TextureBase::MIN_FILTER)) << std::endl;
fw.indent() << "mag_filter " << TextureBase_getFilterStr(texture.getFilter(TextureBase::MAG_FILTER)) << std::endl;
fw.indent() << "maxAnisotropy " << texture.getMaxAnisotropy() << std::endl;
fw.indent() << "internalFormatMode " << TextureBase_getInternalFormatModeStr(texture.getInternalFormatMode()) << std::endl;
if (texture.getInternalFormatMode()==TextureBase::USE_USER_DEFINED_FORMAT)
{
const char* str = TextureBase_getInternalFormatStr(texture.getInternalFormat());
if (str) fw.indent() << "internalFormat " << str << std::endl;
else fw.indent() << "internalFormat " << texture.getInternalFormat() << std::endl;
}
return true;
}
bool TextureBase_matchWrapStr(const char* str,TextureBase::WrapMode& wrap)
{
if (strcmp(str,"CLAMP")==0) wrap = TextureBase::CLAMP;
else if (strcmp(str,"CLAMP_TO_EDGE")==0) wrap = TextureBase::CLAMP_TO_EDGE;
else if (strcmp(str,"CLAMP_TO_BORDER")==0) wrap = TextureBase::CLAMP_TO_BORDER;
else if (strcmp(str,"REPEAT")==0) wrap = TextureBase::REPEAT;
else if (strcmp(str,"MIRROR")==0) wrap = TextureBase::MIRROR;
else return false;
return true;
}
const char* TextureBase_getWrapStr(TextureBase::WrapMode wrap)
{
switch(wrap)
{
case(TextureBase::CLAMP): return "CLAMP";
case(TextureBase::CLAMP_TO_EDGE): return "CLAMP_TO_EDGE";
case(TextureBase::CLAMP_TO_BORDER): return "CLAMP_TO_BORDER";
case(TextureBase::REPEAT): return "REPEAT";
case(TextureBase::MIRROR): return "MIRROR";
}
return "";
}
bool TextureBase_matchFilterStr(const char* str,TextureBase::FilterMode& filter)
{
if (strcmp(str,"NEAREST")==0) filter = TextureBase::NEAREST;
else if (strcmp(str,"LINEAR")==0) filter = TextureBase::LINEAR;
else if (strcmp(str,"NEAREST_MIPMAP_NEAREST")==0) filter = TextureBase::NEAREST_MIPMAP_NEAREST;
else if (strcmp(str,"LINEAR_MIPMAP_NEAREST")==0) filter = TextureBase::LINEAR_MIPMAP_NEAREST;
else if (strcmp(str,"NEAREST_MIPMAP_LINEAR")==0) filter = TextureBase::NEAREST_MIPMAP_LINEAR;
else if (strcmp(str,"LINEAR_MIPMAP_LINEAR")==0) filter = TextureBase::LINEAR_MIPMAP_LINEAR;
else if (strcmp(str,"ANISOTROPIC")==0) filter = TextureBase::LINEAR;
else return false;
return true;
}
const char* TextureBase_getFilterStr(TextureBase::FilterMode filter)
{
switch(filter)
{
case(TextureBase::NEAREST): return "NEAREST";
case(TextureBase::LINEAR): return "LINEAR";
case(TextureBase::NEAREST_MIPMAP_NEAREST): return "NEAREST_MIPMAP_NEAREST";
case(TextureBase::LINEAR_MIPMAP_NEAREST): return "LINEAR_MIPMAP_NEAREST";
case(TextureBase::NEAREST_MIPMAP_LINEAR): return "NEAREST_MIPMAP_LINEAR";
case(TextureBase::LINEAR_MIPMAP_LINEAR): return "LINEAR_MIPMAP_LINEAR";
}
return "";
}
bool TextureBase_matchInternalFormatModeStr(const char* str,TextureBase::InternalFormatMode& mode)
{
if (strcmp(str,"USE_IMAGE_DATA_FORMAT")==0) mode = TextureBase::USE_IMAGE_DATA_FORMAT;
else if (strcmp(str,"USE_USER_DEFINED_FORMAT")==0) mode = TextureBase::USE_USER_DEFINED_FORMAT;
else if (strcmp(str,"USE_ARB_COMPRESSION")==0) mode = TextureBase::USE_ARB_COMPRESSION;
else if (strcmp(str,"USE_S3TC_DXT1_COMPRESSION")==0) mode = TextureBase::USE_S3TC_DXT1_COMPRESSION;
else if (strcmp(str,"USE_S3TC_DXT3_COMPRESSION")==0) mode = TextureBase::USE_S3TC_DXT3_COMPRESSION;
else if (strcmp(str,"USE_S3TC_DXT5_COMPRESSION")==0) mode = TextureBase::USE_S3TC_DXT5_COMPRESSION;
else return false;
return true;
}
const char* TextureBase_getInternalFormatModeStr(TextureBase::InternalFormatMode mode)
{
switch(mode)
{
case(TextureBase::USE_IMAGE_DATA_FORMAT): return "USE_IMAGE_DATA_FORMAT";
case(TextureBase::USE_USER_DEFINED_FORMAT): return "USE_USER_DEFINED_FORMAT";
case(TextureBase::USE_ARB_COMPRESSION): return "USE_ARB_COMPRESSION";
case(TextureBase::USE_S3TC_DXT1_COMPRESSION): return "USE_S3TC_DXT1_COMPRESSION";
case(TextureBase::USE_S3TC_DXT3_COMPRESSION): return "USE_S3TC_DXT3_COMPRESSION";
case(TextureBase::USE_S3TC_DXT5_COMPRESSION): return "USE_S3TC_DXT5_COMPRESSION";
}
return "";
}
bool TextureBase_matchInternalFormatStr(const char* str,int& value)
{
if ( strcmp(str,"GL_INTENSITY")==0) value = GL_INTENSITY;
else if (strcmp(str,"GL_LUMINANCE")==0) value = GL_LUMINANCE;
else if (strcmp(str,"GL_ALPHA")==0) value = GL_ALPHA;
else if (strcmp(str,"GL_LUMINANCE_ALPHA")==0) value = GL_LUMINANCE_ALPHA;
else if (strcmp(str,"GL_RGB")==0) value = GL_RGB;
else if (strcmp(str,"GL_RGBA")==0) value = GL_RGBA;
else if (strcmp(str,"GL_COMPRESSED_ALPHA_ARB")==0) value = GL_COMPRESSED_ALPHA_ARB;
else if (strcmp(str,"GL_COMPRESSED_LUMINANCE_ARB")==0) value = GL_COMPRESSED_LUMINANCE_ARB;
else if (strcmp(str,"GL_COMPRESSED_INTENSITY_ARB")==0) value = GL_COMPRESSED_INTENSITY_ARB;
else if (strcmp(str,"GL_COMPRESSED_LUMINANCE_ALPHA_ARB")==0) value = GL_COMPRESSED_LUMINANCE_ALPHA_ARB;
else if (strcmp(str,"GL_COMPRESSED_RGB_ARB")==0) value = GL_COMPRESSED_RGB_ARB;
else if (strcmp(str,"GL_COMPRESSED_RGBA_ARB")==0) value = GL_COMPRESSED_RGBA_ARB;
else if (strcmp(str,"GL_COMPRESSED_RGB_S3TC_DXT1_EXT")==0) value = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
else if (strcmp(str,"GL_COMPRESSED_RGBA_S3TC_DXT1_EXT")==0) value = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
else if (strcmp(str,"GL_COMPRESSED_RGBA_S3TC_DXT3_EXT")==0) value = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
else if (strcmp(str,"GL_COMPRESSED_RGBA_S3TC_DXT5_EXT")==0) value = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
else return false;
return true;
}
const char* TextureBase_getInternalFormatStr(int value)
{
switch(value)
{
case(GL_INTENSITY): return "GL_INTENSITY";
case(GL_LUMINANCE): return "GL_LUMINANCE";
case(GL_ALPHA): return "GL_ALPHA";
case(GL_LUMINANCE_ALPHA): return "GL_LUMINANCE_ALPHA";
case(GL_RGB): return "GL_RGB";
case(GL_RGBA): return "GL_RGBA";
case(GL_COMPRESSED_ALPHA_ARB): return "GL_COMPRESSED_ALPHA_ARB";
case(GL_COMPRESSED_LUMINANCE_ARB): return "GL_COMPRESSED_LUMINANCE_ARB";
case(GL_COMPRESSED_INTENSITY_ARB): return "GL_COMPRESSED_INTENSITY_ARB";
case(GL_COMPRESSED_LUMINANCE_ALPHA_ARB): return "GL_COMPRESSED_LUMINANCE_ALPHA_ARB";
case(GL_COMPRESSED_RGB_ARB): return "GL_COMPRESSED_RGB_ARB";
case(GL_COMPRESSED_RGBA_ARB): return "GL_COMPRESSED_RGBA_ARB";
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): return "GL_COMPRESSED_RGB_S3TC_DXT1_EXT";
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): return "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT";
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): return "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT";
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): return "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT";
}
return NULL;
}

View File

@ -49,21 +49,6 @@ bool Transform_readLocalData(Object& obj, Input& fr)
}
#ifdef USE_DEPRECATED_API
if (!dynamic_cast<MatrixTransform*>(&obj))
{
static Matrix s_matrix;
if (Matrix* tmpMatrix = static_cast<Matrix*>(fr.readObjectOfType(s_matrix)))
{
transform.setMatrix(*tmpMatrix);
osgDelete tmpMatrix;
iteratorAdvanced = true;
}
}
#endif
if (fr[0].matchWord("referenceFrame")) {
if (fr[1].matchWord("RELATIVE_TO_ABSOLUTE")) {
transform.setReferenceFrame(Transform::RELATIVE_TO_ABSOLUTE);
@ -85,13 +70,6 @@ bool Transform_writeLocalData(const Object& obj, Output& fw)
{
const Transform& transform = static_cast<const Transform&>(obj);
#ifdef USE_DEPRECATED_API
if (!dynamic_cast<const MatrixTransform*>(&obj))
{
fw.writeObject(transform.getMatrix());
}
#endif
fw.indent() << "referenceFrame ";
switch (transform.getReferenceFrame()) {
case Transform::RELATIVE_TO_ABSOLUTE:

View File

@ -3,7 +3,7 @@
#include <osgUtil/DisplayListVisitor>
#include <osg/Notify>
#include <osg/TextureBase>
#include <osg/Texture>
#include <osg/AlphaFunc>
#include <osg/TexEnv>
#include <osg/ColorMatrix>
@ -615,7 +615,7 @@ void SceneView::drawStage(osgUtil::RenderStage* renderStage)
// context for when the object were originally created. Here we know what
// context we are in so can flush the appropriate caches.
osg::Drawable::flushDeletedDisplayLists(_state->getContextID());
osg::TextureBase::flushDeletedTextureObjects(_state->getContextID());
osg::Texture::flushDeletedTextureObjects(_state->getContextID());
RenderLeaf* previous = NULL;