summaryrefslogtreecommitdiffstats
path: root/src/video_core/texture_cache/format_lookup_table.h
blob: aa77e0a5aacbff3464b3c99cf989a818a5368aa7 (plain) (blame)
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
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <array>
#include <limits>
#include "video_core/surface.h"
#include "video_core/textures/texture.h"

namespace VideoCommon {

class FormatLookupTable {
public:
    explicit FormatLookupTable();

    VideoCore::Surface::PixelFormat GetPixelFormat(
        Tegra::Texture::TextureFormat format, bool is_srgb,
        Tegra::Texture::ComponentType red_component, Tegra::Texture::ComponentType green_component,
        Tegra::Texture::ComponentType blue_component,
        Tegra::Texture::ComponentType alpha_component) const noexcept;

private:
    static_assert(VideoCore::Surface::MaxPixelFormat <= std::numeric_limits<u8>::max());

    static constexpr std::size_t NumTextureFormats = 128;

    static constexpr std::size_t PerComponent = 8;
    static constexpr std::size_t PerComponents2 = PerComponent * PerComponent;
    static constexpr std::size_t PerComponents3 = PerComponents2 * PerComponent;
    static constexpr std::size_t PerComponents4 = PerComponents3 * PerComponent;
    static constexpr std::size_t PerFormat = PerComponents4 * 2;

    static std::size_t CalculateIndex(Tegra::Texture::TextureFormat format, bool is_srgb,
                                      Tegra::Texture::ComponentType red_component,
                                      Tegra::Texture::ComponentType green_component,
                                      Tegra::Texture::ComponentType blue_component,
                                      Tegra::Texture::ComponentType alpha_component) noexcept;

    void Set(Tegra::Texture::TextureFormat format, bool is_srgb,
             Tegra::Texture::ComponentType red_component,
             Tegra::Texture::ComponentType green_component,
             Tegra::Texture::ComponentType blue_component,
             Tegra::Texture::ComponentType alpha_component,
             VideoCore::Surface::PixelFormat pixel_format);

    std::array<u8, NumTextureFormats * PerFormat> table;
};

} // namespace VideoCommon