SCM Library
Spherical Cube Map rendering library
|
An scm_cache is a virtual texture, demand-paged with threaded data access, represented as a single large OpenGL texture atlas. More...
#include <scm-cache.hpp>
Public Member Functions | |
scm_cache (scm_system *, int, int, int) | |
Create a new page cache with a queue for making page requests. More... | |
~scm_cache () | |
Destroy a page cache and finalize all OpenGL state. | |
void | add_load (scm_task &) |
Add a page request to the load queue. | |
int | get_grid_size () const |
int | get_page_size () const |
GLuint | get_texture () const |
Return the OpenGL texture object representing the cache. | |
int | get_page (int, long long, int, int &) |
Return the cache line of a loaded page. More... | |
void | update (int, bool) |
Handle incoming textures on the loads queue, copying them to the atlas. More... | |
void | render (int, int) |
Render a 2D overlay of the contents of all caches. More... | |
void | flush () |
Eject all pages. More... | |
Static Public Attributes | |
static int | cache_size = 16 |
The cache grid size. The texture atlas will have size N x N where N = grid_size * page_size. Too large a value may exceed the maximum texture size or available VRAM, resulting in peer performance. Too small a value may result in poor image quality and unnecessary data traffic. | |
static int | cache_threads = 2 |
The number of loader threads servicing page load requests for each cache. | |
static int | need_queue_size = 32 |
The maximum number of page load requests allowed at any moment. (Requests from the render thread to the loader threads.) If this limit is exceeded the render thread will abandon the request and repeat it later. | |
static int | load_queue_size = 8 |
The maximum number of page load results allowed at any moment. (Results from the loader threads to the render thread.) If this limit is exceeded the loader thread will block on load queue. | |
static int | loads_per_cycle = 2 |
The maximum number of page load results that may be uploaded to the atlas by the render thread each frame. A large value may impact frame rate. A small value may increase frame latency and/or block the loader threads. | |
An scm_cache is a virtual texture, demand-paged with threaded data access, represented as a single large OpenGL texture atlas.
scm_cache::scm_cache | ( | scm_system * | sys, |
int | n, | ||
int | c, | ||
int | b | ||
) |
Create a new page cache with a queue for making page requests.
Initialize all OpenGL state including the texture atlas and a ring of pixel buffer objects for use in asynchronous upload of page data.
sys | SCM system |
n | Page size in pixels |
c | Channels per pixel |
b | Bits per channel |
int scm_cache::get_page | ( | int | f, |
long long | i, | ||
int | t, | ||
int & | u | ||
) |
Return the cache line of a loaded page.
Cache lines are indexed from left to right and top to bottom. Request the page if necessary. Return 0 if the page is not available (line 0 is always transparent blank and will thus appear invisible).
f | File index |
i | Page index |
t | Current time |
u | Time at which the page was loaded. |
void scm_cache::update | ( | int | t, |
bool | b | ||
) |
Handle incoming textures on the loads queue, copying them to the atlas.
This should be called by the render thread every frame. If invoked with the synchronous flag, loop until all page requests in the load queue are handled.
t | Current time |
b | Synchronous? |
void scm_cache::render | ( | int | ii, |
int | nn | ||
) |
Render a 2D overlay of the contents of all caches.
The parameters are used to format an optimal on-screen array of caches.
ii | Cache index |
nn | Cache count |
void scm_cache::flush | ( | ) |
Eject all pages.
All page requests in the load queue remain, so a flush is unlikely to be 100% effective unless performed directly after a synchronous update.