Skip to content

Commit

Permalink
return back mips to sky textures
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Oct 3, 2024
1 parent 4cc296d commit c695afa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion game/graphics/sky/sky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ const Texture2d* Sky::implSkyTexture(std::string_view name, bool day, size_t id)
for(auto& i:tex)
i = char(std::toupper(i));

auto r = Resources::loadTexture(tex);
auto r = Resources::loadTexture(tex, true);
if(r==&Resources::fallbackTexture())
return &Resources::fallbackBlack(); //format error
return r;
Expand Down
38 changes: 19 additions & 19 deletions game/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,21 +325,21 @@ int64_t Resources::vdfTimestamp(const std::u16string& name) {
}
}

Tempest::Texture2d* Resources::implLoadTexture(TextureCache& cache, std::string_view cname) {
Tempest::Texture2d* Resources::implLoadTexture(std::string_view cname, bool forceMips) {
if(cname.empty())
return nullptr;

std::string name = std::string(cname);
auto it=cache.find(name);
if(it!=cache.end())
auto it=texCache.find(name);
if(it!=texCache.end())
return it->second.get();

if(FileExt::hasExt(name,"TGA")) {
name.resize(name.size() + 2);
std::memcpy(&name[0]+name.size()-6,"-C.TEX",6);

it=cache.find(name);
if(it!=cache.end())
it=texCache.find(name);
if(it!=texCache.end())
return it->second.get();

if(const auto* entry = Resources::vdfsIndex().find(name)) {
Expand All @@ -348,15 +348,15 @@ Tempest::Texture2d* Resources::implLoadTexture(TextureCache& cache, std::string_
auto reader = entry->open_read();
tex.load(reader.get());

if (tex.format() == zenkit::TextureFormat::DXT1 ||
tex.format() == zenkit::TextureFormat::DXT2 ||
tex.format() == zenkit::TextureFormat::DXT3 ||
tex.format() == zenkit::TextureFormat::DXT4 ||
tex.format() == zenkit::TextureFormat::DXT5) {
if(tex.format() == zenkit::TextureFormat::DXT1 ||
tex.format() == zenkit::TextureFormat::DXT2 ||
tex.format() == zenkit::TextureFormat::DXT3 ||
tex.format() == zenkit::TextureFormat::DXT4 ||
tex.format() == zenkit::TextureFormat::DXT5) {
auto dds = zenkit::to_dds(tex);
auto ddsRead = zenkit::Read::from(dds);

auto t = implLoadTexture(cache, std::string(cname), *ddsRead);
auto t = implLoadTexture(std::string(cname), *ddsRead, forceMips);
if(t!=nullptr)
return t;
} else {
Expand All @@ -368,7 +368,7 @@ Tempest::Texture2d* Resources::implLoadTexture(TextureCache& cache, std::string_

std::unique_ptr<Texture2d> t{new Texture2d(dev.texture(pm))};
Texture2d* ret=t.get();
cache[std::move(name)] = std::move(t);
texCache[std::move(name)] = std::move(t);
return ret;
}
catch (...) {
Expand All @@ -379,14 +379,14 @@ Tempest::Texture2d* Resources::implLoadTexture(TextureCache& cache, std::string_

if(auto* entry = Resources::vdfsIndex().find(cname)) {
auto reader = entry->open_read();
return implLoadTexture(cache,std::string(cname),*reader);
return implLoadTexture(std::string(cname), *reader, forceMips);
}

cache[name]=nullptr;
texCache[name]=nullptr;
return nullptr;
}

Texture2d *Resources::implLoadTexture(TextureCache& cache, std::string&& name, zenkit::Read& data) {
Texture2d *Resources::implLoadTexture(std::string&& name, zenkit::Read& data, bool forceMips) {
try {
std::vector<uint8_t> raw;
data.seek(0, zenkit::Whence::END);
Expand All @@ -397,10 +397,10 @@ Texture2d *Resources::implLoadTexture(TextureCache& cache, std::string&& name, z
Tempest::MemReader rd((uint8_t*)raw.data(), raw.size());
Tempest::Pixmap pm(rd);

const bool useMipmap = pm.mipCount()>1; // do not generate mips, if original texture has has none
const bool useMipmap = forceMips || (pm.mipCount()>1); // do not generate mips, if original texture has has none
std::unique_ptr<Texture2d> t{new Texture2d(dev.texture(pm, useMipmap))};
Texture2d* ret=t.get();
cache[std::move(name)] = std::move(t);
texCache[std::move(name)] = std::move(t);
return ret;
}
catch(...){
Expand Down Expand Up @@ -749,9 +749,9 @@ GthFont &Resources::implLoadFont(std::string_view name, FontType type) {
return *f;
}

const Texture2d *Resources::loadTexture(std::string_view name) {
const Texture2d *Resources::loadTexture(std::string_view name, bool forceMips) {
std::lock_guard<std::recursive_mutex> g(inst->sync);
return inst->implLoadTexture(inst->texCache,name);
return inst->implLoadTexture(name,forceMips);
}

const Texture2d* Resources::loadTexture(Tempest::Color color) {
Expand Down
6 changes: 3 additions & 3 deletions game/resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Resources final {
static const Tempest::Texture2d& fallbackBlack();
static auto fallbackImage() -> const Tempest::StorageImage&;
static auto fallbackImage3d() -> const Tempest::StorageImage&;
static const Tempest::Texture2d* loadTexture(std::string_view name);
static const Tempest::Texture2d* loadTexture(std::string_view name, bool forceMips = false);
static const Tempest::Texture2d* loadTexture(Tempest::Color color);
static const Tempest::Texture2d* loadTexture(std::string_view name, int32_t v, int32_t c);
static Tempest::Texture2d loadTexturePm(const Tempest::Pixmap& pm);
Expand Down Expand Up @@ -176,8 +176,8 @@ class Resources final {
int64_t vdfTimestamp(const std::u16string& name);
void detectVdf(std::vector<Archive>& ret, const std::u16string& root);

Tempest::Texture2d* implLoadTexture(TextureCache& cache, std::string_view cname);
Tempest::Texture2d* implLoadTexture(TextureCache& cache, std::string &&name, zenkit::Read& data);
Tempest::Texture2d* implLoadTexture(std::string_view cname, bool forceMips);
Tempest::Texture2d* implLoadTexture(std::string &&name, zenkit::Read& data, bool forceMips);
ProtoMesh* implLoadMesh(std::string_view name);
std::unique_ptr<ProtoMesh> implLoadMeshMain(std::string name);
std::unique_ptr<Animation> implLoadAnimation(std::string name);
Expand Down

0 comments on commit c695afa

Please sign in to comment.