Added new osg::TextureBase, osg::Texture1D, osg::Texture2D, and osg::Texture3D

classes, and changed osg::Texture and osg::TextureCubeMap so that they now derive
from osg::TextureBase.
This commit is contained in:
Robert Osfield
2002-08-24 19:39:39 +00:00
parent 0c383901a7
commit 239068f223
35 changed files with 2801 additions and 1140 deletions

View File

@@ -134,13 +134,13 @@ class MyCopyOp : public osg::CopyOp
return ret_attr;
}
virtual Texture* operator() (const Texture* text) const
virtual TextureBase* operator() (const TextureBase* text) const
{
writeIndent(); std::cout << "copying Texture "<<text;
if (text) std::cout<<" "<<text->className();
std::cout<<std::endl;
moveIn();
osg::Texture* ret_text = CopyOp::operator()(text);
osg::TextureBase* ret_text = CopyOp::operator()(text);
moveOut();
return ret_text;
}

View File

@@ -47,7 +47,7 @@ class MyCullCallback : public osg::NodeCallback
{
public:
MyCullCallback(osg::Node* subgraph,osg::Texture* texture):
MyCullCallback(osg::Node* subgraph,osg::Texture2D* texture):
_subgraph(subgraph),
_texture(texture) {}
@@ -76,9 +76,9 @@ class MyCullCallback : public osg::NodeCallback
void doPreRender(osg::Node& node, osgUtil::CullVisitor& cv);
osg::ref_ptr<osg::Node> _subgraph;
osg::ref_ptr<osg::Texture> _texture;
osg::ref_ptr<osg::Image> _image;
osg::ref_ptr<osg::Node> _subgraph;
osg::ref_ptr<osg::Texture2D> _texture;
osg::ref_ptr<osg::Image> _image;
};
@@ -286,69 +286,140 @@ class MyGeometryCallback :
// Custom Texture subload callback, just acts the the standard subload modes in osg::Texture right now
// but code be used to define your own style callbacks.
class MyTextureSubloadCallback : public osg::Texture::SubloadCallback
class MyTextureSubloadCallback : public osg::Texture2D::SubloadCallback
{
public:
virtual void load(GLenum target, const osg::Texture& texture,osg::State&) const
MyTextureSubloadCallback():
_subloadMode(AUTO),
_subloadTextureOffsetX(0),
_subloadTextureOffsetY(0),
_subloadImageOffsetX(0),
_subloadImageOffsetY(0),
_subloadImageWidth(0),
_subloadImageHeight(0)
{
}
enum SubloadMode {
OFF,
AUTO,
IF_DIRTY
};
/** 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)
{
_textureWidth = width;
_textureHeight = height;
}
/** Get the texture subload width. */
inline void getSubloadTextureSize(int& width, int& height) const
{
width = _textureWidth;
height = _textureHeight;
}
/** Set the subload image offsets. */
inline void setSubloadImageOffset(const int x, const int y)
{
_subloadImageOffsetX = x;
_subloadImageOffsetY = y;
}
/** Get the subload image offsets. */
inline void getSubloadImageOffset(int& x, int& y) const
{
x = _subloadImageOffsetX;
y = _subloadImageOffsetY;
}
/** Set the image subload width. If width or height are zero then
* the repsective size value is calculated from the source image sizes. */
inline void setSubloadImageSize(const int width, const int height)
{
_subloadImageWidth = width;
_subloadImageHeight = height;
}
/** Get the image subload width. */
inline void getSubloadImageSize(int& width, int& height) const
{
width = _subloadImageWidth;
height = _subloadImageHeight;
}
virtual void load(const osg::Texture2D& texture,osg::State&) const
{
osg::notify(osg::INFO)<<"doing load"<<std::endl;
static bool s_SGIS_GenMipmap = osg::isGLExtensionSupported("GL_SGIS_generate_mipmap");
if (s_SGIS_GenMipmap && (texture.getFilter(osg::Texture::MIN_FILTER) != osg::Texture::LINEAR && texture.getFilter(osg::Texture::MIN_FILTER) != osg::Texture::NEAREST))
if (s_SGIS_GenMipmap && (texture.getFilter(osg::Texture2D::MIN_FILTER) != osg::Texture2D::LINEAR && texture.getFilter(osg::Texture2D::MIN_FILTER) != osg::Texture2D::NEAREST))
{
texture.setNumMipmapLevels(1); // will leave this at one, since the mipmap will be created internally by OpenGL.
glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
}
else
{
texture.setNumMipmapLevels(1);
}
int subloadImageOffsetX;
int subloadImageOffsetY;
texture.getSubloadImageOffset(subloadImageOffsetX,subloadImageOffsetY);
int subloadImageWidth;
int subloadImageHeight;
texture.getSubloadImageSize(subloadImageWidth,subloadImageHeight);
GLsizei width = (subloadImageWidth>0)?subloadImageWidth:texture.getImage()->s();
GLsizei height = (subloadImageHeight>0)?subloadImageHeight:texture.getImage()->t();
GLsizei width = (_subloadImageWidth>0)?_subloadImageWidth:texture.getImage()->s();
GLsizei height = (_subloadImageHeight>0)?_subloadImageHeight:texture.getImage()->t();
int subloadTextureOffsetX;
int subloadTextureOffsetY;
texture.getSubloadTextureOffset(subloadTextureOffsetX,subloadTextureOffsetY);
int textureWidth;
int textureHeight;
texture.getSubloadTextureSize(textureWidth, textureHeight);
bool sizeChanged = false;
if (textureWidth==0)
if (_textureWidth==0)
{
// need to calculate texture dimension
sizeChanged = true;
textureWidth = 1;
for (; textureWidth < (static_cast<GLsizei>(subloadTextureOffsetX) + width); textureWidth <<= 1) {}
_textureWidth = 1;
for (; _textureWidth < (static_cast<GLsizei>(_subloadTextureOffsetX) + width); _textureWidth <<= 1) {}
}
if (textureHeight==0)
if (_textureHeight==0)
{
// need to calculate texture dimension
sizeChanged = true;
textureHeight = 1;
for (; textureHeight < (static_cast<GLsizei>(subloadTextureOffsetY) + height); textureHeight <<= 1) {}
_textureHeight = 1;
for (; _textureHeight < (static_cast<GLsizei>(_subloadTextureOffsetY) + height); _textureHeight <<= 1) {}
}
if (sizeChanged)
{
texture.setSubloadTextureSize(textureWidth, textureHeight);
texture.setTextureSize(_textureWidth, _textureHeight);
}
// reserve appropriate texture memory
glTexImage2D(target, 0, texture.getInternalFormatValue(),
textureWidth, textureHeight, 0,
glTexImage2D(GL_TEXTURE_2D, 0, texture.getInternalFormat(),
_textureWidth, _textureHeight, 0,
(GLenum) texture.getImage()->getPixelFormat(), (GLenum) texture.getImage()->getDataType(),
NULL);
@@ -356,42 +427,37 @@ class MyTextureSubloadCallback : public osg::Texture::SubloadCallback
glPixelStorei(GL_UNPACK_ROW_LENGTH,texture.getImage()->s());
glTexSubImage2D(target, 0,
subloadTextureOffsetX, subloadTextureOffsetY,
glTexSubImage2D(GL_TEXTURE_2D, 0,
_subloadTextureOffsetX, _subloadTextureOffsetY,
width, height,
(GLenum) texture.getImage()->getPixelFormat(), (GLenum) texture.getImage()->getDataType(),
texture.getImage()->data(subloadImageOffsetX,subloadImageOffsetY));
texture.getImage()->data(_subloadImageOffsetX,_subloadImageOffsetY));
glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
}
virtual void subload(GLenum target, const osg::Texture& texture,osg::State&) const
virtual void subload(const osg::Texture2D& texture,osg::State&) const
{
osg::notify(osg::INFO)<<"doing subload"<<std::endl;
glPixelStorei(GL_UNPACK_ROW_LENGTH,texture.getImage()->s());
int subloadTextureOffsetX;
int subloadTextureOffsetY;
texture.getSubloadTextureOffset(subloadTextureOffsetX,subloadTextureOffsetY);
int subloadImageOffsetX;
int subloadImageOffsetY;
texture.getSubloadImageOffset(subloadImageOffsetX,subloadImageOffsetY);
int subloadImageWidth;
int subloadImageHeight;
texture.getSubloadImageSize(subloadImageWidth,subloadImageHeight);
glTexSubImage2D(target, 0,
subloadTextureOffsetX, subloadTextureOffsetY,
(subloadImageWidth>0)?subloadImageWidth:texture.getImage()->s(), (subloadImageHeight>0)?subloadImageHeight:texture.getImage()->t(),
glTexSubImage2D(GL_TEXTURE_2D, 0,
_subloadTextureOffsetX, _subloadTextureOffsetY,
(_subloadImageWidth>0)?_subloadImageWidth:texture.getImage()->s(), (_subloadImageHeight>0)?_subloadImageHeight:texture.getImage()->t(),
(GLenum) texture.getImage()->getPixelFormat(), (GLenum) texture.getImage()->getDataType(),
texture.getImage()->data(subloadImageOffsetX,subloadImageOffsetY));
texture.getImage()->data(_subloadImageOffsetX,_subloadImageOffsetY));
glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
}
SubloadMode _subloadMode;
mutable GLsizei _textureWidth, _textureHeight;
GLint _subloadTextureOffsetX, _subloadTextureOffsetY;
GLint _subloadImageOffsetX, _subloadImageOffsetY;
GLsizei _subloadImageWidth, _subloadImageHeight;
};
@@ -460,12 +526,12 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph)
osg::Image* image = new osg::Image;
image->setInternalTextureFormat(GL_RGBA);
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
//texture->setSubloadMode(osg::Texture::IF_DIRTY);
texture->setSubloadCallback(new MyTextureSubloadCallback());
texture->setImage(image);
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
polyGeom->setStateSet(stateset);

View File

@@ -2,7 +2,7 @@
#include <osg/Geometry>
#include <osg/Notify>
#include <osg/MatrixTransform>
#include <osg/Texture>
#include <osg/Texture2D>
#include <osg/DrawPixels>
#include <osgGA/TrackballManipulator>
@@ -24,22 +24,22 @@
typedef std::vector< osg::ref_ptr<osg::Image> > ImageList;
class TextureCallback : public osg::NodeCallback
class Texture2DCallback : public osg::NodeCallback
{
public:
TextureCallback(osg::Texture* texture):_texture(texture)
Texture2DCallback(osg::Texture2D* texture):_texture(texture)
{
_filterRange.push_back(osg::Texture::LINEAR);
_filterRange.push_back(osg::Texture::LINEAR_MIPMAP_LINEAR);
_filterRange.push_back(osg::Texture::LINEAR_MIPMAP_NEAREST);
_filterRange.push_back(osg::Texture::NEAREST);
_filterRange.push_back(osg::Texture::NEAREST_MIPMAP_LINEAR);
_filterRange.push_back(osg::Texture::NEAREST_MIPMAP_NEAREST);
_filterRange.push_back(osg::Texture2D::LINEAR);
_filterRange.push_back(osg::Texture2D::LINEAR_MIPMAP_LINEAR);
_filterRange.push_back(osg::Texture2D::LINEAR_MIPMAP_NEAREST);
_filterRange.push_back(osg::Texture2D::NEAREST);
_filterRange.push_back(osg::Texture2D::NEAREST_MIPMAP_LINEAR);
_filterRange.push_back(osg::Texture2D::NEAREST_MIPMAP_NEAREST);
_currPos = 0;
_prevTime = 0.0;
}
virtual ~TextureCallback() {}
virtual ~Texture2DCallback() {}
virtual void operator()(osg::Node*, osg::NodeVisitor* nv)
{
@@ -49,7 +49,7 @@ class TextureCallback : public osg::NodeCallback
if (currTime-_prevTime>1.0)
{
std::cout<<"Updating texturing filter to "<<std::hex<<_filterRange[_currPos]<<std::dec<<std::endl;
_texture->setFilter(osg::Texture::MAG_FILTER,_filterRange[_currPos]);
_texture->setFilter(osg::Texture2D::MAG_FILTER,_filterRange[_currPos]);
_currPos++;
if (_currPos>=_filterRange.size()) _currPos=0;
_prevTime = currTime;
@@ -57,8 +57,8 @@ class TextureCallback : public osg::NodeCallback
}
}
osg::ref_ptr<osg::Texture> _texture;
std::vector<osg::Texture::FilterMode> _filterRange;
osg::ref_ptr<osg::Texture2D> _texture;
std::vector<osg::Texture2D::FilterMode> _filterRange;
osg::uint _currPos;
double _prevTime;
};
@@ -127,7 +127,7 @@ osg::Drawable* createSquare(float textureCoordMax=1.0f)
return geom;
}
osg::Node* createTexturedItem(const osg::Vec3& offset,osg::Texture* texture,osg::Node* geometry)
osg::Node* createTexturedItem(const osg::Vec3& offset,osg::Texture2D* texture,osg::Node* geometry)
{
// create a tranform node to position each square in appropriate
// place and also to add individual texture set to it, so that
@@ -183,7 +183,7 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
// defaults mipmapped texturing.
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
// add the transform node to root group node.
@@ -199,12 +199,12 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
// bilinear
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
// set up bilinear filtering.
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_NEAREST);
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR_MIPMAP_NEAREST);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
// add the transform node to root group node.
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
@@ -216,12 +216,12 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
// trilinear
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
// set up trilinear filtering.
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR_MIPMAP_LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
// add the transform node to root group node.
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
@@ -234,12 +234,12 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
// anisotropic
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
// set up anistropic filtering.
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR);
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR_MIPMAP_LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
texture->setMaxAnisotropy(2.0f);
// add the transform node to root group node.
@@ -252,10 +252,10 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
// arb compression
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
texture->setInternalFormatMode(osg::Texture::USE_ARB_COMPRESSION);
texture->setInternalFormatMode(osg::Texture2D::USE_ARB_COMPRESSION);
// add the transform node to root group node.
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
@@ -267,10 +267,10 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
// s3tc_dxt1 compression
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT1_COMPRESSION);
texture->setInternalFormatMode(osg::Texture2D::USE_S3TC_DXT1_COMPRESSION);
// add the transform node to root group node.
top_transform->addChild(createTexturedItem(local_offset,texture,geometry));
@@ -279,10 +279,10 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
}
// default wrap mode. (osg::Texture::CLAMP)
// default wrap mode. (osg::Texture2D::CLAMP)
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
// add the transform node to root group node.
@@ -295,11 +295,11 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
// clamp-to-edge mode.
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_EDGE);
// add the transform node to root group node.
top_transform->addChild(createTexturedItem(local_offset,texture,geometryRep));
@@ -311,11 +311,11 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
// repeat wrap mode.
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT);
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT);
texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::REPEAT);
texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::REPEAT);
// add the transform node to root group node.
top_transform->addChild(createTexturedItem(local_offset,texture,geometryRep));
@@ -327,11 +327,11 @@ osg::Node* createLayer(const osg::Vec3& offset,osg::Image* image,osg::Node* geom
// mirror wrap mode.
{
// create the texture attribute
osg::Texture* texture = new osg::Texture;
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::MIRROR);
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::MIRROR);
texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::MIRROR);
texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::MIRROR);
// add the transform node to root group node.
top_transform->addChild(createTexturedItem(local_offset,texture,geometryRep));