Skip to content

Commit

Permalink
Fixed bugs in the embed texture spell
Browse files Browse the repository at this point in the history
  • Loading branch information
fo76utils committed Jan 25, 2025
1 parent f31dc6d commit d592d18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/gl/gltex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,23 +568,28 @@ bool TexCache::Tex::ImageInfo::savePixelData( TexCache & t, NifModel * nif, QMod
{
// gltexloaders function goes here
//qDebug() << "TexCache::Tex:savePixelData: Packing" << iSource << "from file" << filepath << "to" << iData;
return t.texSaveNIF( nif, filepath, iData );
try {
return t.texSaveNIF( nif, filepath, iData );
} catch ( QString & e ) {
qCWarning( nsIo ) << e;
}
return false;
}

bool TexCache::loadSettings( QSettings & settings )
{
int tmp = settings.value( "Settings/Render/General/Ibl Cube Map Resolution", 2 ).toInt();
tmp = 128 << std::min< int >( std::max< int >( tmp, 0 ), 4 );
tmp = 128 << std::clamp< int >( tmp, 0, 4 );
bool r = ( tmp != pbrCubeMapResolution );
pbrCubeMapResolution = tmp;

tmp = settings.value( "Settings/Render/General/Ibl Importance Sample Cnt", 2 ).toInt();
tmp = 64 << std::min< int >( std::max< int >( tmp, 0 ), 6 );
tmp = 64 << std::clamp< int >( tmp, 0, 6 );
r = r | ( tmp != pbrImportanceSamples );
pbrImportanceSamples = tmp;

tmp = settings.value( "Settings/Render/General/Hdr Tone Map", 8 ).toInt();
tmp = std::min< int >( std::max< int >( tmp, 0 ), 16 );
tmp = std::clamp< int >( tmp, 0, 16 );
r = r | ( tmp != hdrToneMapLevel );
hdrToneMapLevel = tmp;

Expand Down
10 changes: 6 additions & 4 deletions src/gl/gltexloaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "message.h"
#include "model/nifmodel.h"

#include "dds.h"
#include "libfo76utils/src/filebuf.hpp"
#include "libfo76utils/src/pbr_lut.hpp"
#include "libfo76utils/src/sfcube2.hpp"
Expand All @@ -52,6 +51,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QString>
#include <QtEndian>

#include "dds.h"

/*! @file gltexloaders.cpp
* @brief Texture loading functions.
Expand Down Expand Up @@ -1726,11 +1726,13 @@ bool TexCache::texSaveNIF( NifModel * nif, const QString & filepath, QModelIndex
// If DDS raw, DXT1 or DXT5, copy directly from texture
//qDebug() << "texSaveNIF: saving" << filepath << "to" << iData;

QFile f( filepath );

if ( !f.open( QIODevice::ReadOnly ) )
QByteArray fileData;
if ( !nif->getResourceFile( fileData, filepath, "textures/", nullptr ) )
throw QString( "could not open file" );

QBuffer f( &fileData );
f.open( QIODevice::ReadOnly );

if ( filepath.endsWith( ".nif", Qt::CaseInsensitive ) || filepath.endsWith( ".texcache", Qt::CaseInsensitive ) ) {
// NIF-to-NIF copy
NifModel pix;
Expand Down

0 comments on commit d592d18

Please sign in to comment.