Add load origin hint to options

This is to allow the DDS cache to handle the image load differently depending on the origin.
This commit is contained in:
Richard Harrison
2019-01-20 18:28:37 +01:00
parent 4f6c8f7784
commit 07036ac48f
3 changed files with 62 additions and 15 deletions
+25 -3
View File
@@ -76,7 +76,7 @@ osg::Texture* TextureBuilder::buildFromType(Effect* effect, Pass* pass, const st
typedef boost::tuple<string, Texture::FilterMode, Texture::FilterMode,
Texture::WrapMode, Texture::WrapMode, Texture::WrapMode,
string, MipMapTuple> TexTuple;
string, MipMapTuple, ImageInternalFormat> TexTuple;
EffectNameValue<TexEnv::Mode> texEnvModesInit[] =
{
@@ -239,6 +239,17 @@ TexTuple makeTexTuple(Effect* effect, const SGPropertyNode* props,
}
}
const SGPropertyNode* pInternalFormat = getEffectPropertyChild(effect, props, "internal-format");
pInternalFormat = props->getChild("internal-format");
ImageInternalFormat iformat = ImageInternalFormat::Unspecified;
if (pInternalFormat) {
std::string internalFormat = pInternalFormat->getStringValue();
if (internalFormat == "normalized") {
iformat = ImageInternalFormat::Normalized;
SG_LOG(SG_INPUT, SG_ALERT, "internal-format normalized '" << imageName << "'");
}
}
const SGPropertyNode* pMipmapControl
= getEffectPropertyChild(effect, props, "mipmap-control");
MipMapTuple mipmapFunctions( AUTOMATIC, AUTOMATIC, AUTOMATIC, AUTOMATIC );
@@ -246,7 +257,7 @@ TexTuple makeTexTuple(Effect* effect, const SGPropertyNode* props,
mipmapFunctions = makeMipMapTuple(effect, pMipmapControl, options);
return TexTuple(absFileName, minFilter, magFilter, sWrap, tWrap, rWrap,
texType, mipmapFunctions);
texType, mipmapFunctions, iformat);
}
bool setAttrs(const TexTuple& attrs, Texture* tex,
@@ -258,7 +269,14 @@ bool setAttrs(const TexTuple& attrs, Texture* tex,
osgDB::ReaderWriter::ReadResult result;
// load texture for effect
SGReaderWriterOptions::LoadOriginHint origLOH = options->getLoadOriginHint();
if(attrs.get<8>() == ImageInternalFormat::Normalized)
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS_NORMALIZED);
else
options->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS);
result = osgDB::readRefImageFile(imageName, options);
options->setLoadOriginHint(origLOH);
osg::ref_ptr<osg::Image> image;
if (result.success())
image = result.getImage();
@@ -586,7 +604,10 @@ Texture* CubeMapBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*
cubeTexture->setWrap(osg::Texture3D::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
osgDB::ReaderWriter::ReadResult result;
result = osgDB::readImageFile(_tuple.get<0>(), options);
SGReaderWriterOptions* wOpts = (SGReaderWriterOptions*)options;
SGReaderWriterOptions::LoadOriginHint origLOH = wOpts->getLoadOriginHint();
wOpts->setLoadOriginHint(SGReaderWriterOptions::LoadOriginHint::ORIGIN_EFFECTS);
result = osgDB::readRefImageFile(_tuple.get<0>(), options);
if(result.success()) {
osg::Image* image = result.getImage();
cubeTexture->setImage(TextureCubeMap::POSITIVE_X, image);
@@ -616,6 +637,7 @@ Texture* CubeMapBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode*
osg::Image* image = result.getImage();
cubeTexture->setImage(TextureCubeMap::NEGATIVE_Z, image);
}
wOpts->setLoadOriginHint(origLOH);
if (itr == _cubemaps.end())
_cubemaps[_tuple] = cubeTexture;
+12 -8
View File
@@ -31,14 +31,18 @@ class Effect;
class SGReaderWriterOptions;
namespace effect {
enum MipMapFunction {
AUTOMATIC,
AVERAGE,
SUM,
PRODUCT,
MIN,
MAX
};
enum MipMapFunction {
AUTOMATIC,
AVERAGE,
SUM,
PRODUCT,
MIN,
MAX
};
enum ImageInternalFormat {
Unspecified,
Normalized,
};
typedef boost::tuple<MipMapFunction, MipMapFunction, MipMapFunction, MipMapFunction> MipMapTuple;
+25 -4
View File
@@ -38,12 +38,22 @@ namespace simgear
class SGReaderWriterOptions : public osgDB::Options {
public:
enum LoadOriginHint
{
ORIGIN_MODEL,
ORIGIN_EFFECTS,
ORIGIN_EFFECTS_NORMALIZED,
};
//SGReaderWriterOptions* cloneOptions(const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) const { return static_cast<SGReaderWriterOptions*>(clone(copyop)); }
SGReaderWriterOptions() :
_materialLib(0),
_load_panel(0),
_model_data(0),
_instantiateEffects(false),
_instantiateMaterialEffects(false)
_instantiateMaterialEffects(false),
_LoadOriginHint(ORIGIN_MODEL)
{ }
SGReaderWriterOptions(const std::string& str) :
osgDB::Options(str),
@@ -51,7 +61,8 @@ public:
_load_panel(0),
_model_data(0),
_instantiateEffects(false),
_instantiateMaterialEffects(false)
_instantiateMaterialEffects(false),
_LoadOriginHint(ORIGIN_MODEL)
{ }
SGReaderWriterOptions(const osgDB::Options& options,
const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) :
@@ -60,7 +71,8 @@ public:
_load_panel(0),
_model_data(0),
_instantiateEffects(false),
_instantiateMaterialEffects(false)
_instantiateMaterialEffects(false),
_LoadOriginHint(ORIGIN_MODEL)
{ }
SGReaderWriterOptions(const SGReaderWriterOptions& options,
const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) :
@@ -75,7 +87,8 @@ public:
_instantiateEffects(options._instantiateEffects),
_instantiateMaterialEffects(options._instantiateMaterialEffects),
_materialName(options._materialName),
_sceneryPathSuffixes(options._sceneryPathSuffixes)
_sceneryPathSuffixes(options._sceneryPathSuffixes),
_LoadOriginHint(ORIGIN_MODEL)
{ }
META_Object(simgear, SGReaderWriterOptions);
@@ -139,6 +152,13 @@ public:
const SGGeod& getLocation() const
{ return _geod; }
// the load origin defines where the load request has come from.
// example usage; to allow the DDS Texture Cache (DTC) to ignore
// any texture that is used in a shader, as these often have special values
// encoded into the channels that aren't suitable for conversion.
void setLoadOriginHint(LoadOriginHint _v) const { _LoadOriginHint = _v; }
LoadOriginHint getLoadOriginHint() const { return _LoadOriginHint; }
protected:
virtual ~SGReaderWriterOptions();
@@ -157,6 +177,7 @@ private:
string _materialName;
string_list _sceneryPathSuffixes;
SGGeod _geod;
mutable LoadOriginHint _LoadOriginHint;
};
}