vcglib/apps/nexus/patchserver.h

86 lines
1.9 KiB
C
Raw Normal View History

2004-10-09 13:09:13 +02:00
#ifndef NXS_PATCH_SERVER_H
#define NXS_PATCH_SERVER_H
#include "patch.h"
2004-10-21 14:19:52 +02:00
#include "mfile.h"
2004-10-09 13:09:13 +02:00
#include <vector>
namespace nxs {
struct PatchEntry {
unsigned int patch_start; //granularita' Chunk
2004-10-10 19:19:42 +02:00
unsigned short ram_size; //in chunks
unsigned short disk_size; // in chunks (used when compressed)
2004-10-09 13:09:13 +02:00
unsigned int lru_pos;
};
2004-10-21 14:19:52 +02:00
class PatchServer: public MFile {
2004-10-09 13:09:13 +02:00
public:
2004-10-19 03:23:02 +02:00
2004-10-09 13:09:13 +02:00
struct PTime {
2004-10-19 03:23:02 +02:00
unsigned int npatch;
2004-10-09 13:09:13 +02:00
unsigned int frame;
2004-10-19 03:23:02 +02:00
Patch *patch;
unsigned int vbo_array;
unsigned int vbo_element;
bool locked;
2004-10-09 13:09:13 +02:00
PTime(unsigned int p = 0xffffffff, unsigned int f = 0xffffffff):
2004-10-19 03:23:02 +02:00
npatch(p), frame(f), patch(NULL),
vbo_array(0), vbo_element(0) {}
2004-10-09 13:09:13 +02:00
2004-10-10 19:19:42 +02:00
bool operator<(const PTime &p) const { return frame > p.frame; }
2004-10-09 13:09:13 +02:00
};
Signature signature;
unsigned int chunk_size;
2004-10-14 15:46:34 +02:00
2004-10-09 13:09:13 +02:00
unsigned int ram_size;
unsigned int ram_used;
2004-10-15 18:45:27 +02:00
unsigned int vbo_size;
unsigned int vbo_used;
2004-10-09 13:09:13 +02:00
unsigned int frame;
2004-10-14 15:46:34 +02:00
//statistics:
unsigned int ram_readed;
unsigned int ram_flushed;
2004-10-09 13:09:13 +02:00
2004-10-20 17:07:02 +02:00
PatchServer(): chunk_size(1024), ram_size(128000000), vbo_size(32000000) {}
2004-10-09 13:09:13 +02:00
bool Create(const std::string &filename, Signature signature,
2004-10-21 14:19:52 +02:00
unsigned int chunk_size, unsigned int ram_size = 128000000);
2004-10-09 13:09:13 +02:00
bool Load(const std::string &filename, Signature sig,
unsigned int chunk_size, bool readonly,
2004-10-21 14:19:52 +02:00
unsigned int ram_size = 128000000);
2004-10-09 13:09:13 +02:00
void Close();
bool ReadEntries(FILE *fp);
bool WriteEntries(FILE *fp);
void AddPatch(unsigned short nvert, unsigned short nface);
2004-10-15 18:45:27 +02:00
Patch &GetPatch(unsigned int patch,
unsigned short nvert, unsigned short nface,
2004-10-09 13:09:13 +02:00
bool flush = true);
2004-10-19 03:23:02 +02:00
void GetVbo(unsigned int patch, unsigned int &element, unsigned int &array);
2004-10-15 18:45:27 +02:00
2004-10-19 18:52:01 +02:00
void Flush(PTime &ptime);
2004-10-15 18:45:27 +02:00
//return false if was not allocated.
2004-10-19 18:52:01 +02:00
bool FlushVbo(PTime &ptime);
2004-10-09 13:09:13 +02:00
void Flush();
void FlushAll();
2004-10-15 18:45:27 +02:00
2004-10-10 19:19:42 +02:00
void SetRamBufferSize(unsigned int ram_buffer);
2004-10-09 13:09:13 +02:00
std::vector<PatchEntry> patches;
std::vector<PTime> lru;
};
}
#endif