File: TextureUtils.cpp

package info (click to toggle)
dolphin-emu 2512%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 76,328 kB
  • sloc: cpp: 499,023; ansic: 119,674; python: 6,547; sh: 2,338; makefile: 1,093; asm: 726; pascal: 257; javascript: 183; perl: 97; objc: 75; xml: 30
file content (80 lines) | stat: -rw-r--r-- 2,345 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoCommon/TextureUtils.h"

#include <fmt/format.h>

#include "Common/FileSearch.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"

#include "Core/Config/GraphicsSettings.h"
#include "Core/ConfigManager.h"

#include "VideoCommon/AbstractTexture.h"

namespace
{
std::string BuildDumpTextureFilename(std::string basename, u32 level, bool is_arbitrary)
{
  if (is_arbitrary)
    basename += "_arb";

  if (level > 0)
    basename += fmt::format("_mip{}", level);

  return basename;
}
}  // namespace
namespace VideoCommon::TextureUtils
{
void DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
                 bool is_arbitrary)
{
  const std::string dump_dir =
      File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().GetGameID();

  if (!File::IsDirectory(dump_dir))
    File::CreateDir(dump_dir);

  const std::string name = BuildDumpTextureFilename(std::move(basename), level, is_arbitrary);
  const std::string filename = fmt::format("{}/{}.png", dump_dir, name);

  if (File::Exists(filename))
    return;

  texture.Save(filename, level, Config::Get(Config::GFX_TEXTURE_PNG_COMPRESSION_LEVEL));
}

void TextureDumper::DumpTexture(const ::AbstractTexture& texture, std::string basename, u32 level,
                                bool is_arbitrary)
{
  const std::string dump_dir =
      File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().GetGameID();

  if (m_dumped_textures.empty())
  {
    if (!File::IsDirectory(dump_dir))
      File::CreateDir(dump_dir);

    for (auto& filename : Common::DoFileSearch({dump_dir}, {".png"}, true))
    {
      std::string name;
      SplitPath(filename, nullptr, &name, nullptr);
      m_dumped_textures.insert(name);
    }

    NOTICE_LOG_FMT(VIDEO, "Found {} dumped textures that will not be re-dumped.",
                   m_dumped_textures.size());
  }

  const std::string name = BuildDumpTextureFilename(std::move(basename), level, is_arbitrary);
  const bool file_existed = !m_dumped_textures.insert(name).second;
  if (file_existed)
    return;

  texture.Save(fmt::format("{}/{}.png", dump_dir, name), level,
               Config::Get(Config::GFX_TEXTURE_PNG_COMPRESSION_LEVEL));
}
}  // namespace VideoCommon::TextureUtils