SCM Library
Spherical Cube Map rendering library
 All Classes Files Functions Variables Friends Pages
scm-cache.hpp
1 // Copyright (C) 2011-2012 Robert Kooima
2 //
3 // LIBSCM is free software; you can redistribute it and/or modify it under the
4 // terms of the GNU General Public License as published by the Free Software
5 // Foundation; either version 2 of the License, or (at your option) any later
6 // version.
7 //
8 // This program is distributed in the hope that it will be useful, but WITH-
9 // OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 // more details.
12 
13 #ifndef SCM_CACHE_HPP
14 #define SCM_CACHE_HPP
15 
16 #include <vector>
17 #include <string>
18 
19 #include <GL/glew.h>
20 
21 #include "scm-queue.hpp"
22 #include "scm-fifo.hpp"
23 #include "scm-task.hpp"
24 #include "scm-set.hpp"
25 
26 //------------------------------------------------------------------------------
27 
28 class scm_system;
29 
30 //------------------------------------------------------------------------------
31 
34 
35 class scm_cache
36 {
37 public:
38 
39  static int cache_size;
40  static int cache_threads;
41  static int need_queue_size;
42  static int load_queue_size;
43  static int loads_per_cycle;
44 
45  scm_cache(scm_system *, int, int, int);
46  ~scm_cache();
47 
48  void add_load(scm_task&);
49 
50  int get_grid_size() const { return s; }
51  int get_page_size() const { return n; }
52 
53  GLuint get_texture() const;
54  int get_page(int, long long, int, int&);
55 
56  void update(int, bool);
57  void render(int, int);
58  void flush ();
59 
60 private:
61 
62  scm_system *sys;
63  scm_set pages; // Page set currently active
64  scm_set waits; // Page set currently being loaded
65  scm_queue<scm_task> loads; // Page loader queue
66  scm_fifo <GLuint> pbos; // Asynchronous upload ring
67 
68  GLuint texture; // Atlas texture object
69  int s; // Atlas width and height in pages
70  int l; // Atlas current page
71  int n; // Page width and height in pixels
72  int c; // Channels per pixel
73  int b; // Bits per channel
74 
75  int get_slot(int, long long);
76 };
77 
78 typedef std::vector<scm_cache *> scm_cache_v;
79 typedef std::vector<scm_cache *>::iterator scm_cache_i;
80 
81 //------------------------------------------------------------------------------
82 
83 #endif
static int need_queue_size
The maximum number of page load requests allowed at any moment. (Requests from the render thread to t...
Definition: scm-cache.hpp:41
static int load_queue_size
The maximum number of page load results allowed at any moment. (Results from the loader threads to th...
Definition: scm-cache.hpp:42
int get_page(int, long long, int, int &)
Return the cache line of a loaded page.
Definition: scm-cache.cpp:166
An scm_task represents a page load task, as executed by a loader thread.
Definition: scm-task.hpp:34
void add_load(scm_task &)
Add a page request to the load queue.
Definition: scm-cache.cpp:141
void update(int, bool)
Handle incoming textures on the loads queue, copying them to the atlas.
Definition: scm-cache.cpp:254
static int loads_per_cycle
The maximum number of page load results that may be uploaded to the atlas by the render thread each f...
Definition: scm-cache.hpp:43
GLuint get_texture() const
Return the OpenGL texture object representing the cache.
Definition: scm-cache.cpp:150
void flush()
Eject all pages.
Definition: scm-cache.cpp:346
~scm_cache()
Destroy a page cache and finalize all OpenGL state.
Definition: scm-cache.cpp:118
scm_cache(scm_system *, int, int, int)
Create a new page cache with a queue for making page requests.
Definition: scm-cache.cpp:67
void render(int, int)
Render a 2D overlay of the contents of all caches.
Definition: scm-cache.cpp:293
static int cache_threads
The number of loader threads servicing page load requests for each cache.
Definition: scm-cache.hpp:40
static int cache_size
The cache grid size. The texture atlas will have size N x N where N = grid_size * page_size...
Definition: scm-cache.hpp:39
An scm_set represents an a set of active pages, either currently in a cache or awaiting loading...
Definition: scm-set.hpp:41
An scm_system encapsulates all of the state of an SCM renderer. Its interface is the primary API of t...
Definition: scm-system.hpp:175
An scm_cache is a virtual texture, demand-paged with threaded data access, represented as a single la...
Definition: scm-cache.hpp:35