mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-16 02:09:42 +00:00
Modernize NiSourceTexture and BSShaderTextureSet
This commit is contained in:
parent
fb8ead2bd4
commit
2e847a12c4
3 changed files with 90 additions and 84 deletions
components
|
@ -7,50 +7,41 @@ namespace Nif
|
|||
|
||||
void NiSourceTexture::read(NIFStream* nif)
|
||||
{
|
||||
Named::read(nif);
|
||||
NiTexture::read(nif);
|
||||
|
||||
external = nif->getChar() != 0;
|
||||
bool internal = false;
|
||||
if (external)
|
||||
filename = nif->getString();
|
||||
else
|
||||
{
|
||||
if (nif->getVersion() <= NIFStream::generateVersion(10, 0, 1, 3))
|
||||
internal = nif->getChar();
|
||||
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0))
|
||||
filename = nif->getString(); // Original file path of the internal texture
|
||||
}
|
||||
if (nif->getVersion() <= NIFStream::generateVersion(10, 0, 1, 3))
|
||||
{
|
||||
if (!external && internal)
|
||||
data.read(nif);
|
||||
}
|
||||
else
|
||||
{
|
||||
data.read(nif);
|
||||
}
|
||||
nif->read(mExternal);
|
||||
if (mExternal || nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 0))
|
||||
nif->read(mFile);
|
||||
|
||||
pixel = nif->getUInt();
|
||||
mipmap = nif->getUInt();
|
||||
alpha = nif->getUInt();
|
||||
bool hasData = nif->getVersion() >= NIFStream::generateVersion(10, 0, 1, 4);
|
||||
if (!hasData && !mExternal)
|
||||
nif->read(hasData);
|
||||
|
||||
// Renderer hints, typically of no use for us
|
||||
/* bool mIsStatic = */ nif->getChar();
|
||||
if (hasData)
|
||||
mData.read(nif);
|
||||
|
||||
mPrefs.mPixelLayout = static_cast<PixelLayout>(nif->get<uint32_t>());
|
||||
mPrefs.mUseMipMaps = static_cast<MipMapFormat>(nif->get<uint32_t>());
|
||||
mPrefs.mAlphaFormat = static_cast<AlphaFormat>(nif->get<uint32_t>());
|
||||
|
||||
nif->read(mIsStatic);
|
||||
if (nif->getVersion() >= NIFStream::generateVersion(10, 1, 0, 103))
|
||||
/* bool mDirectRendering = */ nif->getBoolean();
|
||||
if (nif->getVersion() >= NIFStream::generateVersion(20, 2, 0, 4))
|
||||
/* bool mPersistRenderData = */ nif->getBoolean();
|
||||
{
|
||||
nif->read(mDirectRendering);
|
||||
if (nif->getVersion() >= NIFStream::generateVersion(20, 2, 0, 4))
|
||||
nif->read(mPersistRenderData);
|
||||
}
|
||||
}
|
||||
|
||||
void NiSourceTexture::post(Reader& nif)
|
||||
{
|
||||
Named::post(nif);
|
||||
data.post(nif);
|
||||
NiTexture::post(nif);
|
||||
mData.post(nif);
|
||||
}
|
||||
|
||||
void BSShaderTextureSet::read(NIFStream* nif)
|
||||
{
|
||||
nif->getSizedStrings(textures, nif->getUInt());
|
||||
nif->getSizedStrings(mTextures, nif->get<uint32_t>());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,35 +12,48 @@ namespace Nif
|
|||
|
||||
struct NiSourceTexture : public NiTexture
|
||||
{
|
||||
// Is this an external (references a separate texture file) or
|
||||
// internal (data is inside the nif itself) texture?
|
||||
bool external;
|
||||
enum class PixelLayout : uint32_t
|
||||
{
|
||||
Palette = 0,
|
||||
HighColor = 1,
|
||||
TrueColor = 2,
|
||||
Compressed = 3,
|
||||
BumpMap = 4,
|
||||
Default = 5,
|
||||
};
|
||||
|
||||
std::string filename; // In case of external textures
|
||||
NiPixelDataPtr data; // In case of internal textures
|
||||
enum class MipMapFormat : uint32_t
|
||||
{
|
||||
No = 0,
|
||||
Yes = 1,
|
||||
Default = 2,
|
||||
};
|
||||
|
||||
/* Pixel layout
|
||||
0 - Palettised
|
||||
1 - High color 16
|
||||
2 - True color 32
|
||||
3 - Compressed
|
||||
4 - Bumpmap
|
||||
5 - Default */
|
||||
unsigned int pixel;
|
||||
enum class AlphaFormat : uint32_t
|
||||
{
|
||||
None = 0,
|
||||
Binary = 1,
|
||||
Smooth = 2,
|
||||
Default = 3,
|
||||
};
|
||||
|
||||
/* Mipmap format
|
||||
0 - no
|
||||
1 - yes
|
||||
2 - default */
|
||||
unsigned int mipmap;
|
||||
struct FormatPrefs
|
||||
{
|
||||
PixelLayout mPixelLayout;
|
||||
MipMapFormat mUseMipMaps;
|
||||
AlphaFormat mAlphaFormat;
|
||||
};
|
||||
|
||||
/* Alpha
|
||||
0 - none
|
||||
1 - binary
|
||||
2 - smooth
|
||||
3 - default (use material alpha, or multiply material with texture if present)
|
||||
*/
|
||||
unsigned int alpha;
|
||||
char mExternal; // References external file
|
||||
|
||||
std::string mFile;
|
||||
NiPixelDataPtr mData;
|
||||
|
||||
FormatPrefs mPrefs;
|
||||
|
||||
char mIsStatic{ 1 };
|
||||
bool mDirectRendering{ true };
|
||||
bool mPersistRenderData{ false };
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
void post(Reader& nif) override;
|
||||
|
@ -48,18 +61,18 @@ namespace Nif
|
|||
|
||||
struct BSShaderTextureSet : public Record
|
||||
{
|
||||
enum TextureType
|
||||
enum class TextureType : uint32_t
|
||||
{
|
||||
TextureType_Base = 0,
|
||||
TextureType_Normal = 1,
|
||||
TextureType_Glow = 2,
|
||||
TextureType_Parallax = 3,
|
||||
TextureType_Env = 4,
|
||||
TextureType_EnvMask = 5,
|
||||
TextureType_Subsurface = 6,
|
||||
TextureType_BackLighting = 7
|
||||
Base = 0,
|
||||
Normal = 1,
|
||||
Glow = 2,
|
||||
Parallax = 3,
|
||||
Environment = 4,
|
||||
EnvironmentMask = 5,
|
||||
Subsurface = 6,
|
||||
BackLighting = 7,
|
||||
};
|
||||
std::vector<std::string> textures;
|
||||
std::vector<std::string> mTextures;
|
||||
|
||||
void read(NIFStream* nif) override;
|
||||
};
|
||||
|
|
|
@ -510,15 +510,15 @@ namespace NifOsg
|
|||
return nullptr;
|
||||
|
||||
osg::ref_ptr<osg::Image> image;
|
||||
if (!st->external && !st->data.empty())
|
||||
if (st->mExternal)
|
||||
{
|
||||
image = handleInternalTexture(st->data.getPtr());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string filename = Misc::ResourceHelpers::correctTexturePath(st->filename, imageManager->getVFS());
|
||||
std::string filename = Misc::ResourceHelpers::correctTexturePath(st->mFile, imageManager->getVFS());
|
||||
image = imageManager->getImage(filename);
|
||||
}
|
||||
else if (!st->mData.empty())
|
||||
{
|
||||
image = handleInternalTexture(st->mData.getPtr());
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
|
@ -2009,15 +2009,15 @@ namespace NifOsg
|
|||
|
||||
const unsigned int uvSet = 0;
|
||||
|
||||
for (size_t i = 0; i < textureSet->textures.size(); ++i)
|
||||
for (size_t i = 0; i < textureSet->mTextures.size(); ++i)
|
||||
{
|
||||
if (textureSet->textures[i].empty())
|
||||
if (textureSet->mTextures[i].empty())
|
||||
continue;
|
||||
switch (i)
|
||||
switch (static_cast<Nif::BSShaderTextureSet::TextureType>(i))
|
||||
{
|
||||
case Nif::BSShaderTextureSet::TextureType_Base:
|
||||
case Nif::BSShaderTextureSet::TextureType_Normal:
|
||||
case Nif::BSShaderTextureSet::TextureType_Glow:
|
||||
case Nif::BSShaderTextureSet::TextureType::Base:
|
||||
case Nif::BSShaderTextureSet::TextureType::Normal:
|
||||
case Nif::BSShaderTextureSet::TextureType::Glow:
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
@ -2027,7 +2027,7 @@ namespace NifOsg
|
|||
}
|
||||
}
|
||||
std::string filename
|
||||
= Misc::ResourceHelpers::correctTexturePath(textureSet->textures[i], imageManager->getVFS());
|
||||
= Misc::ResourceHelpers::correctTexturePath(textureSet->mTextures[i], imageManager->getVFS());
|
||||
osg::ref_ptr<osg::Image> image = imageManager->getImage(filename);
|
||||
osg::ref_ptr<osg::Texture2D> texture2d = new osg::Texture2D(image);
|
||||
if (image)
|
||||
|
@ -2036,17 +2036,19 @@ namespace NifOsg
|
|||
unsigned int texUnit = boundTextures.size();
|
||||
stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON);
|
||||
// BSShaderTextureSet presence means there's no need for FFP support for the affected node
|
||||
switch (i)
|
||||
switch (static_cast<Nif::BSShaderTextureSet::TextureType>(i))
|
||||
{
|
||||
case Nif::BSShaderTextureSet::TextureType_Base:
|
||||
case Nif::BSShaderTextureSet::TextureType::Base:
|
||||
texture2d->setName("diffuseMap");
|
||||
break;
|
||||
case Nif::BSShaderTextureSet::TextureType_Normal:
|
||||
case Nif::BSShaderTextureSet::TextureType::Normal:
|
||||
texture2d->setName("normalMap");
|
||||
break;
|
||||
case Nif::BSShaderTextureSet::TextureType_Glow:
|
||||
case Nif::BSShaderTextureSet::TextureType::Glow:
|
||||
texture2d->setName("emissiveMap");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
boundTextures.emplace_back(uvSet);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue