From Brede Johansen, "added a new reader option to replace the texture

wrap mode CLAMP with CLAMP_TO_EDGE."
This commit is contained in:
Robert Osfield
2006-12-05 14:28:07 +00:00
parent cf41b3128c
commit 289331569d
6 changed files with 26 additions and 34 deletions

View File

@@ -58,7 +58,8 @@ class AttrData : public osg::Object
enum WrapMode {
WRAP_REPEAT = 0,
WRAP_CLAMP = 1,
WRAP_MIRRORED_REPEAT = 2
WRAP_NONE = 2,
WRAP_MIRRORED_REPEAT = 3
};
enum TexEnvMode {

View File

@@ -10,6 +10,7 @@ using namespace flt;
Document::Document() :
_replaceClampWithClampToEdge(false),
_preserveFace(false),
_preserveObject(false),
_defaultDOFAnimationState(false),

View File

@@ -142,6 +142,8 @@ class Document
// Options
void setReplaceClampWithClampToEdge(bool flag) { _replaceClampWithClampToEdge = flag; }
bool getReplaceClampWithClampToEdge() const { return _replaceClampWithClampToEdge; }
void setPreserveFace(bool flag) { _preserveFace = flag; }
bool getPreserveFace() const { return _preserveFace; }
void setPreserveObject(bool flag) { _preserveObject = flag; }
@@ -164,6 +166,7 @@ class Document
// Options
osg::ref_ptr<const osgDB::ReaderWriter::Options> _options;
bool _replaceClampWithClampToEdge;
bool _preserveFace;
bool _preserveObject;
bool _defaultDOFAnimationState;

View File

@@ -246,22 +246,26 @@ protected:
virtual ~TexturePalette() {}
osg::Texture2D::WrapMode convertWrapMode( int32 wrap )
osg::Texture2D::WrapMode convertWrapMode(int32 attrWrapMode, const Document& document)
{
switch( wrap )
osg::Texture2D::WrapMode osgWrapMode = osg::Texture2D::REPEAT;
switch (attrWrapMode)
{
case AttrData::WRAP_CLAMP:
return osg::Texture2D::CLAMP;
if (document.getReplaceClampWithClampToEdge())
osgWrapMode = osg::Texture2D::CLAMP_TO_EDGE;
else
osgWrapMode = osg::Texture2D::CLAMP;
break;
case AttrData::WRAP_MIRRORED_REPEAT:
return osg::Texture2D::MIRROR;
osgWrapMode = osg::Texture2D::MIRROR;
break;
default:
case AttrData::WRAP_REPEAT:
return osg::Texture2D::REPEAT;
osgWrapMode = osg::Texture2D::REPEAT;
break;
}
return osg::Texture2D::REPEAT;
return osgWrapMode;
}
virtual void readRecord(RecordInputStream& in, Document& document)
@@ -299,10 +303,10 @@ protected:
if (attr.valid())
{
// Wrap mode
osg::Texture2D::WrapMode wrap_s = convertWrapMode( attr->wrapMode_u );
osg::Texture2D::WrapMode wrap_s = convertWrapMode(attr->wrapMode_u,document);
texture->setWrap(osg::Texture2D::WRAP_S,wrap_s);
osg::Texture2D::WrapMode wrap_t = convertWrapMode( attr->wrapMode_v );
osg::Texture2D::WrapMode wrap_t = convertWrapMode(attr->wrapMode_v,document);
texture->setWrap(osg::Texture2D::WRAP_T,wrap_t);
// Min filter

View File

@@ -69,14 +69,14 @@ ReaderWriter::ReadResult ReaderWriterATTR::readObject(const std::string& file, c
attr->fileFormat = in.readInt32();
attr->minFilterMode = in.readInt32();
attr->magFilterMode = in.readInt32();
attr->wrapMode = in.readInt32();
attr->wrapMode = in.readInt32(AttrData::WRAP_REPEAT);
attr->wrapMode_u = in.readInt32();
if ((attr->wrapMode_u != AttrData::WRAP_CLAMP) && ((attr->wrapMode_u != AttrData::WRAP_REPEAT)))
if (attr->wrapMode_u == AttrData::WRAP_NONE)
attr->wrapMode_u = attr->wrapMode;
attr->wrapMode_v = in.readInt32();
if ((attr->wrapMode_v != AttrData::WRAP_CLAMP) && ((attr->wrapMode_v != AttrData::WRAP_REPEAT)))
if (attr->wrapMode_v == AttrData::WRAP_NONE)
attr->wrapMode_v = attr->wrapMode;
attr->modifyFlag = in.readInt32();
@@ -86,7 +86,7 @@ ReaderWriter::ReadResult ReaderWriterATTR::readObject(const std::string& file, c
// v11 ends here
// if (in.eof() || (_flt_version <= 11)) return true;
#if 1
attr->texEnvMode = in.readInt32();
attr->texEnvMode = in.readInt32(AttrData::TEXENV_MODULATE);
attr->intensityAsAlpha = in.readInt32();
in.forward(4*8);
attr->size_u = in.readFloat64();

View File

@@ -159,6 +159,9 @@ class FLTReaderWriter : public ReaderWriter
{
const char readerMsg[] = "flt reader option: ";
document.setReplaceClampWithClampToEdge((options->getOptionString().find("clampToEdge")!=std::string::npos));
osg::notify(osg::DEBUG_INFO) << readerMsg << "clampToEdge=" << document.getReplaceClampWithClampToEdge() << std::endl;
document.setKeepExternalReferences((options->getOptionString().find("keepExternalReferences")!=std::string::npos));
osg::notify(osg::DEBUG_INFO) << readerMsg << "keepExternalReferences=" << document.getKeepExternalReferences() << std::endl;
@@ -243,26 +246,6 @@ class FLTReaderWriter : public ReaderWriter
virtual WriteResult writeNode(const Node& /*node*/,const std::string& /*fileName*/, const osgDB::ReaderWriter::Options* /*options*/) const
{
return WriteResult::FILE_NOT_HANDLED;
#if 0
// following code creates a blank file even though file write isn't supported, so have #if'd out implementation.
// can only presume the author implementated the following is with a final write flt support in mind.
// Robert Osfield, Novemeber 2006.
std::string ext = getFileExtension(fileName);
if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED;
// code for setting up the database path so that internally referenced file are searched for on relative paths.
osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
if(local_opt->getDatabasePathList().empty())
local_opt->setDatabasePath(osgDB::getFilePath(fileName));
std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary);
WriteResult result = writeNode(node, fout, local_opt.get());
fout.close();
return result;
#endif
}
virtual WriteResult writeObject(const Object& object,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const