Trigger
This commit is contained in:
parent
be92b1fd23
commit
dab569fc53
|
@ -32,6 +32,15 @@ NexusMt::~NexusMt() {
|
|||
preload.waitfor();
|
||||
}
|
||||
|
||||
void NexusMt::SetPreload(bool on) {
|
||||
if(on == (preload.get_running() && !preload.get_finished())) return;
|
||||
if(on) preload.start();
|
||||
else {
|
||||
preload.signal();
|
||||
// preload.waitfor();
|
||||
}
|
||||
}
|
||||
|
||||
bool NexusMt::Load(const string &filename) {
|
||||
if(!Nexus::Load(filename, true)) return false;
|
||||
if(!history.IsQuick() && !history.UpdatesToQuick())
|
||||
|
@ -39,12 +48,6 @@ bool NexusMt::Load(const string &filename) {
|
|||
return true;
|
||||
}
|
||||
|
||||
//void NexusMt::Close() {
|
||||
// prefetch.signal();
|
||||
// prefetch.waitfor();
|
||||
// patches.Close();
|
||||
//}
|
||||
|
||||
bool NexusMt::InitGL(bool vbo) {
|
||||
use_vbo = vbo;
|
||||
|
||||
|
@ -97,6 +100,7 @@ void NexusMt::Render(Extraction &extraction, DrawContest &contest,
|
|||
}
|
||||
|
||||
preload.lock.enter();
|
||||
if(skipped.size()) cerr << "Skipped: " << skipped.size() << endl;
|
||||
for(vector<unsigned int>::iterator i = skipped.begin();
|
||||
i != skipped.end(); i++) {
|
||||
GetPatch(*i);
|
||||
|
@ -156,10 +160,15 @@ void NexusMt::Draw(unsigned int cell, DrawContest &contest) {
|
|||
GL_UNSIGNED_SHORT, fstart);
|
||||
break;
|
||||
case DrawContest::FLAT:
|
||||
if(use_vbo) {
|
||||
cerr << "Mode incompatible with VBO\n";
|
||||
exit(0);
|
||||
}
|
||||
if(signature & NXS_FACES) {
|
||||
glBegin(GL_TRIANGLES);
|
||||
unsigned short *f = patch.Face(0);
|
||||
for(int i = 0; i < patch.nf; i++) {
|
||||
unsigned short *f = patch.Face(i);
|
||||
|
||||
Point3f &p0 = patch.Vert(f[0]);
|
||||
Point3f &p1 = patch.Vert(f[1]);
|
||||
Point3f &p2 = patch.Vert(f[2]);
|
||||
|
@ -168,6 +177,7 @@ void NexusMt::Draw(unsigned int cell, DrawContest &contest) {
|
|||
glVertex3f(p0[0], p0[1], p0[2]);
|
||||
glVertex3f(p1[0], p1[1], p1[2]);
|
||||
glVertex3f(p2[0], p2[1], p2[2]);
|
||||
f += 3;
|
||||
}
|
||||
glEnd();
|
||||
} else if(signature & NXS_STRIP) {
|
||||
|
@ -195,15 +205,16 @@ void NexusMt::FlushPatch(unsigned int id) {
|
|||
}
|
||||
|
||||
void NexusMt::LoadVbo(Entry &entry) {
|
||||
if(entry.vbo_element) return;
|
||||
glGenBuffersARB(1, &entry.vbo_element);
|
||||
assert(entry.vbo_element);
|
||||
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, entry.vbo_element);
|
||||
assert(entry.vbo_element == 0);
|
||||
// if(entry.vbo_element) return;
|
||||
|
||||
Patch &patch = *entry.patch;
|
||||
unsigned int size = patch.nf * sizeof(unsigned short);
|
||||
if((signature & NXS_FACES) != 0) size *= 3;
|
||||
|
||||
glGenBuffersARB(1, &entry.vbo_element);
|
||||
assert(entry.vbo_element);
|
||||
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, entry.vbo_element);
|
||||
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, size, patch.FaceBegin(),
|
||||
GL_STATIC_DRAW_ARB);
|
||||
vbo_used += size;
|
||||
|
@ -214,7 +225,6 @@ void NexusMt::LoadVbo(Entry &entry) {
|
|||
glGenBuffersARB(1, &entry.vbo_array);
|
||||
assert(entry.vbo_array);
|
||||
glBindBufferARB(GL_ARRAY_BUFFER_ARB, entry.vbo_array);
|
||||
|
||||
glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, patch.VertBegin(),
|
||||
GL_STATIC_DRAW_ARB);
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ namespace nxs {
|
|||
void Render(Extraction &extraction,
|
||||
DrawContest &contest,
|
||||
Stats *stats = NULL);
|
||||
// void Draw(std::vector<unsigned int> &selected);
|
||||
// void Extract(std::vector<unsigned int> &selected);
|
||||
|
||||
void SetPreload(bool on);
|
||||
|
||||
protected:
|
||||
void FlushPatch(unsigned int id);
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.30 2005/01/21 17:09:13 ponchio
|
||||
Porting and debug.
|
||||
|
||||
Revision 1.29 2005/01/17 17:35:47 ponchio
|
||||
Small changes and adding realtime extr.
|
||||
|
||||
|
@ -203,10 +206,10 @@ int main(int argc, char *argv[]) {
|
|||
float error = 4;
|
||||
|
||||
Trackball track;
|
||||
// int option;
|
||||
|
||||
if(argc != 2) {
|
||||
cerr << "Usage: " << argv[0] << " <nexus file>\n"; return -1;
|
||||
cerr << "Usage: " << argv[0] << " <nexus file>\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
NexusMt nexus;
|
||||
|
@ -257,7 +260,7 @@ int main(int argc, char *argv[]) {
|
|||
bool show_statistics = true;
|
||||
bool extract = true;
|
||||
bool realtime = true;
|
||||
bool stepping = true;
|
||||
bool preload = true;
|
||||
bool step = true;
|
||||
|
||||
if(!nexus.InitGL()) {
|
||||
|
@ -274,7 +277,6 @@ int main(int argc, char *argv[]) {
|
|||
SDL_Event event;
|
||||
int x, y;
|
||||
float alpha = 0;
|
||||
bool redraw = false;
|
||||
float fps = 0;
|
||||
unsigned int nave = 5;
|
||||
unsigned int offset = 0;
|
||||
|
@ -319,8 +321,8 @@ int main(int argc, char *argv[]) {
|
|||
case SDLK_m: contest.mode = DrawContest::SMOOTH; break;
|
||||
|
||||
case SDLK_o: realtime = !realtime; break;
|
||||
case SDLK_s: step = true; break;
|
||||
|
||||
case SDLK_s: preload = !preload; nexus.SetPreload(preload); break;
|
||||
case SDLK_t: show_statistics = !show_statistics; break;
|
||||
case SDLK_r:
|
||||
case SDLK_SPACE: rotate = !rotate; break;
|
||||
|
||||
|
@ -376,11 +378,8 @@ int main(int argc, char *argv[]) {
|
|||
default: break;
|
||||
}
|
||||
}
|
||||
redraw = true;
|
||||
|
||||
|
||||
//if(!redraw && !keepdrawing) continue;
|
||||
redraw = false;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
@ -443,7 +442,6 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}*/
|
||||
|
||||
//cerr Do some reporting:
|
||||
if(show_statistics) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
@ -461,36 +459,29 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
double ftime = (tframe[(offset+4)%5] - tframe[(offset)%5])/5.0f;
|
||||
|
||||
sprintf(buffer, "Ram size : %.3fMb (max) %.3fMb (cur)",
|
||||
nexus.ram_max * nexus.chunk_size/(float)(1<<20),
|
||||
nexus.ram_used * nexus.chunk_size/(float)(1<<20));
|
||||
sprintf(buffer, "Ram size : %.2f / %.2f Mb",
|
||||
nexus.ram_used * nexus.chunk_size/(float)(1<<20),
|
||||
nexus.ram_max * nexus.chunk_size/(float)(1<<20));
|
||||
gl_print(0.03, 0.15, buffer);
|
||||
|
||||
sprintf(buffer, "Extr size: %.3fMb(max) %.3fMb(cur)",
|
||||
extraction.extr_max * nexus.chunk_size/(float)(1<<20),
|
||||
extraction.extr_used * nexus.chunk_size/(float)(1<<20));
|
||||
sprintf(buffer, "Extr size: %.2f / %.2f Mb",
|
||||
extraction.extr_used * nexus.chunk_size/(float)(1<<20),
|
||||
extraction.extr_max * nexus.chunk_size/(float)(1<<20));
|
||||
gl_print(0.03, 0.12, buffer);
|
||||
|
||||
sprintf(buffer, "Draw size: %.3fMb(max) %.3fMb(cur)",
|
||||
extraction.draw_max * nexus.chunk_size/(float)(1<<20),
|
||||
extraction.draw_used * nexus.chunk_size/(float)(1<<20));
|
||||
sprintf(buffer, "Draw size: %.2f / %.2f Mb",
|
||||
extraction.draw_used * nexus.chunk_size/(float)(1<<20),
|
||||
extraction.draw_max * nexus.chunk_size/(float)(1<<20));
|
||||
gl_print(0.03, 0.09, buffer);
|
||||
|
||||
sprintf(buffer, "Disk size: %.3fMb(max) %.3fMb(cur)",
|
||||
sprintf(buffer, "Disk size: %.2f / %.2f Mb",
|
||||
extraction.disk_max * nexus.chunk_size/(float)(1<<20),
|
||||
extraction.disk_used * nexus.chunk_size/(float)(1<<20));
|
||||
gl_print(0.03, 0.06, buffer);
|
||||
|
||||
// sprintf(buffer, "Vbo size : %.3fMb(cur) Load: %.4fK Pref: %.4fK",
|
||||
// nexus.patches.vbo_used * nexus.chunk_size/(float)(1<<20),
|
||||
// nexus.prefetch.loading, nexus.prefetch.prefetching);
|
||||
// gl_print(0.03, 0.06, buffer);
|
||||
|
||||
sprintf(buffer, "Triangles: %.2fK (tot) %.2fK (vis) "
|
||||
" %.2f FPS",
|
||||
sprintf(buffer, "%.2f KTri %.2f FPS %.0f M/s",
|
||||
stats.ktri/(float)(1<<10),
|
||||
stats.ktri/(float)(1<<10),
|
||||
stats.fps);
|
||||
stats.fps, stats.fps * stats.ktri/(float)(1<<20));
|
||||
gl_print(0.03, 0.03, buffer);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "preload.h"
|
||||
#include "nexusmt.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace nxs;
|
||||
|
@ -9,9 +10,8 @@ using namespace nxs;
|
|||
while(!get_signaled()) {
|
||||
lock.enter();
|
||||
while(!queue.size()) {
|
||||
//cerr << "Acc nothing to preload!\n";
|
||||
lock.leave();
|
||||
pt::psleep(10);
|
||||
trigger.wait();
|
||||
lock.enter();
|
||||
}
|
||||
//TODO check we are not loading too much memory!
|
||||
|
|
|
@ -17,10 +17,11 @@ class Preload: public pt::thread{
|
|||
NexusMt *mt;
|
||||
|
||||
pt::mutex lock;
|
||||
pt::trigger trigger;
|
||||
|
||||
std::vector<unsigned int> queue;
|
||||
|
||||
Preload(): thread(false) {}
|
||||
Preload(): thread(false), trigger(true, false) {}
|
||||
~Preload() {
|
||||
waitfor();
|
||||
}
|
||||
|
@ -29,6 +30,7 @@ class Preload: public pt::thread{
|
|||
|
||||
void post(std::vector<unsigned int> &patches) {
|
||||
lock.enter();
|
||||
trigger.post();
|
||||
queue = patches;
|
||||
lock.leave();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue