summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/SamplerCache.h
blob: 920835ef0323a9b5da493aab9e5c8a3bd6df6ed7 (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
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
81
82
83
84
85
86
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <map>
#include <memory>

#include "Common/CommonTypes.h"
#include "Common/NonCopyable.h"
#include "Common/GL/GLUtil.h"
#include "VideoBackends/OGL/Render.h"

namespace OGL
{

class SamplerCache : NonCopyable
{
public:
	SamplerCache();
	~SamplerCache();

	void SetSamplerState(int stage, const TexMode0& tm0, const TexMode1& tm1, bool custom_tex);
	void Clear();
	void BindNearestSampler(int stage);
	void BindLinearSampler(int stage);

private:
	struct Params
	{
		union
		{
			struct
			{
				TexMode0 tm0;
				TexMode1 tm1;
			};

			u64 hex;
		};

		Params()
			: hex()
		{}

		Params(const TexMode0& _tm0, const TexMode1& _tm1)
			: tm0(_tm0)
			, tm1(_tm1)
		{
			static_assert(sizeof(Params) == 8, "Assuming I can treat this as a 64bit int.");
		}

		bool operator<(const Params& other) const
		{
			return hex < other.hex;
		}

		bool operator!=(const Params& other) const
		{
			return hex != other.hex;
		}
	};

	struct Value
	{
		Value()
			: sampler_id()
		{}

		GLuint sampler_id;
	};

	void SetParameters(GLuint sampler_id, const Params& params);
	Value& GetEntry(const Params& params);

	std::map<Params, Value> m_cache;
	std::pair<Params, Value> m_active_samplers[8];

	int m_last_max_anisotropy;
	u32 m_sampler_id[2];
};

extern std::unique_ptr<SamplerCache> g_sampler_cache;

}