-
Notifications
You must be signed in to change notification settings - Fork 3
/
spec-cache.hpp
39 lines (35 loc) · 1012 Bytes
/
spec-cache.hpp
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
#pragma once
#include "spec.hpp"
#include "texture.hpp"
#include <functional>
#include <imgui/imgui.h>
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <SDL_opengles2.h>
#else
#include <SDL_opengl.h>
#endif
class SpecCache
{
public:
SpecCache(Spec &, float k, int screenWidth, double rangeTime, std::function<int(double)> time2Sample);
auto getTex(double time) -> GLuint;
auto clear() -> void;
private:
std::reference_wrapper<Spec> spec;
float k;
int width;
double rangeTime;
std::function<int(double)> time2Sample;
struct Tex
{
explicit Tex(std::list<int>::iterator age) : age(std::move(age)) {}
explicit Tex(Texture &&texture, std::list<int>::iterator age) : texture(std::move(texture)), age(std::move(age)) {}
Texture texture;
std::list<int>::iterator age;
bool isDirty = true;
};
std::unordered_map<int, Tex> range2Tex;
std::list<int> age;
std::vector<std::array<unsigned char, 3>> data;
auto populateTex(GLuint texture, bool &isDirty, int key) -> GLuint;
};