summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/SamplerCache.h
blob: a7c6ae988f4b8ea410d42342dcc5cc73d7cd0acd (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
// Copyright 2013 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <array>
#include <map>
#include <memory>

#include "Common/CommonTypes.h"
#include "Common/GL/GLExtensions/GLExtensions.h"
#include "VideoCommon/Constants.h"
#include "VideoCommon/RenderState.h"

namespace OGL
{
class SamplerCache
{
public:
  SamplerCache();
  ~SamplerCache();

  SamplerCache(const SamplerCache&) = delete;
  SamplerCache& operator=(const SamplerCache&) = delete;
  SamplerCache(SamplerCache&&) = delete;
  SamplerCache& operator=(SamplerCache&&) = delete;

  void SetSamplerState(u32 stage, const SamplerState& state);
  void InvalidateBinding(u32 stage);

  void Clear();
  void BindNearestSampler(int stage);
  void BindLinearSampler(int stage);

private:
  static void SetParameters(GLuint sampler_id, const SamplerState& params);

  std::map<SamplerState, GLuint> m_cache;
  std::array<std::pair<SamplerState, GLuint>, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS>
      m_active_samplers{};

  GLuint m_point_sampler;
  GLuint m_linear_sampler;
};

extern std::unique_ptr<SamplerCache> g_sampler_cache;
}  // namespace OGL