-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscm-cache.hpp
83 lines (61 loc) · 2.41 KB
/
scm-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
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
// Copyright (C) 2011-2012 Robert Kooima
//
// LIBSCM is free software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITH-
// OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
#ifndef SCM_CACHE_HPP
#define SCM_CACHE_HPP
#include <vector>
#include <string>
#include <GL/glew.h>
#include "scm-queue.hpp"
#include "scm-fifo.hpp"
#include "scm-task.hpp"
#include "scm-set.hpp"
//------------------------------------------------------------------------------
class scm_system;
//------------------------------------------------------------------------------
/// An scm_cache is a virtual texture, demand-paged with threaded data access,
/// represented as a single large OpenGL texture atlas.
class scm_cache
{
public:
static int cache_size;
static int cache_threads;
static int need_queue_size;
static int load_queue_size;
static int loads_per_cycle;
scm_cache(scm_system *, int, int, int);
~scm_cache();
void add_load(scm_task&);
int get_grid_size() const { return s; }
int get_page_size() const { return n; }
GLuint get_texture() const;
int get_page(int, long long, int, int&);
void update(int, bool);
void render(int, int);
void flush ();
private:
scm_system *sys;
scm_set pages; // Page set currently active
scm_set waits; // Page set currently being loaded
scm_queue<scm_task> loads; // Page loader queue
scm_fifo <GLuint> pbos; // Asynchronous upload ring
GLuint texture; // Atlas texture object
int s; // Atlas width and height in pages
int l; // Atlas current page
int n; // Page width and height in pixels
int c; // Channels per pixel
int b; // Bits per channel
int get_slot(int, long long);
};
typedef std::vector<scm_cache *> scm_cache_v;
typedef std::vector<scm_cache *>::iterator scm_cache_i;
//------------------------------------------------------------------------------
#endif