summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Assets/TextureAsset.h
blob: e0929a79f09c56eecd18b959968aee8fc8da84d6 (plain)
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
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <fmt/format.h>
#include <picojson.h>

#include "Common/EnumFormatter.h"
#include "VideoCommon/Assets/CustomAsset.h"
#include "VideoCommon/Assets/CustomTextureData.h"
#include "VideoCommon/RenderState.h"

namespace VideoCommon
{
struct TextureData
{
  static bool FromJson(const CustomAssetLibrary::AssetID& asset_id, const picojson::object& json,
                       TextureData* data);
  static void ToJson(picojson::object* obj, const TextureData& data);
  enum class Type
  {
    Type_Undefined,
    Type_Texture2D,
    Type_TextureCube,
    Type_Max = Type_TextureCube
  };
  Type m_type;
  CustomTextureData m_texture;
  SamplerState m_sampler;
};

class GameTextureAsset final : public CustomLoadableAsset<TextureData>
{
public:
  using CustomLoadableAsset::CustomLoadableAsset;

  // Validates that the game texture matches the native dimensions provided
  // Callees are expected to call this once the data is loaded
  bool Validate(u32 native_width, u32 native_height) const;

private:
  CustomAssetLibrary::LoadInfo LoadImpl(const CustomAssetLibrary::AssetID& asset_id) override;
};
}  // namespace VideoCommon

template <>
struct fmt::formatter<VideoCommon::TextureData::Type>
    : EnumFormatter<VideoCommon::TextureData::Type::Type_Max>
{
  constexpr formatter() : EnumFormatter({"Undefined", "Texture2D", "TextureCube"}) {}
};