This commit is contained in:
Federico Ponchio 2005-02-01 16:42:30 +00:00
parent be92b1fd23
commit dab569fc53
5 changed files with 65 additions and 62 deletions

View File

@ -32,6 +32,15 @@ NexusMt::~NexusMt() {
preload.waitfor(); 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) { bool NexusMt::Load(const string &filename) {
if(!Nexus::Load(filename, true)) return false; if(!Nexus::Load(filename, true)) return false;
if(!history.IsQuick() && !history.UpdatesToQuick()) if(!history.IsQuick() && !history.UpdatesToQuick())
@ -39,12 +48,6 @@ bool NexusMt::Load(const string &filename) {
return true; return true;
} }
//void NexusMt::Close() {
// prefetch.signal();
// prefetch.waitfor();
// patches.Close();
//}
bool NexusMt::InitGL(bool vbo) { bool NexusMt::InitGL(bool vbo) {
use_vbo = vbo; use_vbo = vbo;
@ -97,6 +100,7 @@ void NexusMt::Render(Extraction &extraction, DrawContest &contest,
} }
preload.lock.enter(); preload.lock.enter();
if(skipped.size()) cerr << "Skipped: " << skipped.size() << endl;
for(vector<unsigned int>::iterator i = skipped.begin(); for(vector<unsigned int>::iterator i = skipped.begin();
i != skipped.end(); i++) { i != skipped.end(); i++) {
GetPatch(*i); GetPatch(*i);
@ -156,10 +160,15 @@ void NexusMt::Draw(unsigned int cell, DrawContest &contest) {
GL_UNSIGNED_SHORT, fstart); GL_UNSIGNED_SHORT, fstart);
break; break;
case DrawContest::FLAT: case DrawContest::FLAT:
if(use_vbo) {
cerr << "Mode incompatible with VBO\n";
exit(0);
}
if(signature & NXS_FACES) { if(signature & NXS_FACES) {
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
unsigned short *f = patch.Face(0);
for(int i = 0; i < patch.nf; i++) { for(int i = 0; i < patch.nf; i++) {
unsigned short *f = patch.Face(i);
Point3f &p0 = patch.Vert(f[0]); Point3f &p0 = patch.Vert(f[0]);
Point3f &p1 = patch.Vert(f[1]); Point3f &p1 = patch.Vert(f[1]);
Point3f &p2 = patch.Vert(f[2]); 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(p0[0], p0[1], p0[2]);
glVertex3f(p1[0], p1[1], p1[2]); glVertex3f(p1[0], p1[1], p1[2]);
glVertex3f(p2[0], p2[1], p2[2]); glVertex3f(p2[0], p2[1], p2[2]);
f += 3;
} }
glEnd(); glEnd();
} else if(signature & NXS_STRIP) { } else if(signature & NXS_STRIP) {
@ -195,15 +205,16 @@ void NexusMt::FlushPatch(unsigned int id) {
} }
void NexusMt::LoadVbo(Entry &entry) { void NexusMt::LoadVbo(Entry &entry) {
if(entry.vbo_element) return; assert(entry.vbo_element == 0);
glGenBuffersARB(1, &entry.vbo_element); // if(entry.vbo_element) return;
assert(entry.vbo_element);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, entry.vbo_element);
Patch &patch = *entry.patch; Patch &patch = *entry.patch;
unsigned int size = patch.nf * sizeof(unsigned short); unsigned int size = patch.nf * sizeof(unsigned short);
if((signature & NXS_FACES) != 0) size *= 3; 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(), glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, size, patch.FaceBegin(),
GL_STATIC_DRAW_ARB); GL_STATIC_DRAW_ARB);
vbo_used += size; vbo_used += size;
@ -214,7 +225,6 @@ void NexusMt::LoadVbo(Entry &entry) {
glGenBuffersARB(1, &entry.vbo_array); glGenBuffersARB(1, &entry.vbo_array);
assert(entry.vbo_array); assert(entry.vbo_array);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, entry.vbo_array); glBindBufferARB(GL_ARRAY_BUFFER_ARB, entry.vbo_array);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, patch.VertBegin(), glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, patch.VertBegin(),
GL_STATIC_DRAW_ARB); GL_STATIC_DRAW_ARB);

View File

@ -64,8 +64,8 @@ namespace nxs {
void Render(Extraction &extraction, void Render(Extraction &extraction,
DrawContest &contest, DrawContest &contest,
Stats *stats = NULL); Stats *stats = NULL);
// void Draw(std::vector<unsigned int> &selected);
// void Extract(std::vector<unsigned int> &selected); void SetPreload(bool on);
protected: protected:
void FlushPatch(unsigned int id); void FlushPatch(unsigned int id);

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.29 2005/01/17 17:35:47 ponchio
Small changes and adding realtime extr. Small changes and adding realtime extr.
@ -203,10 +206,10 @@ int main(int argc, char *argv[]) {
float error = 4; float error = 4;
Trackball track; Trackball track;
// int option;
if(argc != 2) { if(argc != 2) {
cerr << "Usage: " << argv[0] << " <nexus file>\n"; return -1; cerr << "Usage: " << argv[0] << " <nexus file>\n";
return -1;
} }
NexusMt nexus; NexusMt nexus;
@ -257,7 +260,7 @@ int main(int argc, char *argv[]) {
bool show_statistics = true; bool show_statistics = true;
bool extract = true; bool extract = true;
bool realtime = true; bool realtime = true;
bool stepping = true; bool preload = true;
bool step = true; bool step = true;
if(!nexus.InitGL()) { if(!nexus.InitGL()) {
@ -274,7 +277,6 @@ int main(int argc, char *argv[]) {
SDL_Event event; SDL_Event event;
int x, y; int x, y;
float alpha = 0; float alpha = 0;
bool redraw = false;
float fps = 0; float fps = 0;
unsigned int nave = 5; unsigned int nave = 5;
unsigned int offset = 0; unsigned int offset = 0;
@ -319,8 +321,8 @@ int main(int argc, char *argv[]) {
case SDLK_m: contest.mode = DrawContest::SMOOTH; break; case SDLK_m: contest.mode = DrawContest::SMOOTH; break;
case SDLK_o: realtime = !realtime; 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_r:
case SDLK_SPACE: rotate = !rotate; break; case SDLK_SPACE: rotate = !rotate; break;
@ -376,11 +378,8 @@ int main(int argc, char *argv[]) {
default: break; default: break;
} }
} }
redraw = true;
//if(!redraw && !keepdrawing) continue;
redraw = false;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@ -421,7 +420,7 @@ int main(int argc, char *argv[]) {
if(!realtime) { if(!realtime) {
extraction.Extract(&nexus); extraction.Extract(&nexus);
} else { } else {
extraction.Update(&nexus); extraction.Update(&nexus);
} }
} }
nexus.Render(extraction, contest, &stats); nexus.Render(extraction, contest, &stats);
@ -443,7 +442,6 @@ int main(int argc, char *argv[]) {
} }
}*/ }*/
//cerr Do some reporting:
if(show_statistics) { if(show_statistics) {
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
@ -461,36 +459,29 @@ int main(int argc, char *argv[]) {
double ftime = (tframe[(offset+4)%5] - tframe[(offset)%5])/5.0f; double ftime = (tframe[(offset+4)%5] - tframe[(offset)%5])/5.0f;
sprintf(buffer, "Ram size : %.3fMb (max) %.3fMb (cur)", sprintf(buffer, "Ram size : %.2f / %.2f Mb",
nexus.ram_max * nexus.chunk_size/(float)(1<<20), nexus.ram_used * nexus.chunk_size/(float)(1<<20),
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); gl_print(0.03, 0.15, buffer);
sprintf(buffer, "Extr size: %.3fMb(max) %.3fMb(cur)", sprintf(buffer, "Extr size: %.2f / %.2f Mb",
extraction.extr_max * nexus.chunk_size/(float)(1<<20), extraction.extr_used * nexus.chunk_size/(float)(1<<20),
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); gl_print(0.03, 0.12, buffer);
sprintf(buffer, "Draw size: %.3fMb(max) %.3fMb(cur)", sprintf(buffer, "Draw size: %.2f / %.2f Mb",
extraction.draw_max * nexus.chunk_size/(float)(1<<20), extraction.draw_used * nexus.chunk_size/(float)(1<<20),
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); 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_max * nexus.chunk_size/(float)(1<<20),
extraction.disk_used * nexus.chunk_size/(float)(1<<20)); extraction.disk_used * nexus.chunk_size/(float)(1<<20));
gl_print(0.03, 0.06, buffer); gl_print(0.03, 0.06, buffer);
// sprintf(buffer, "Vbo size : %.3fMb(cur) Load: %.4fK Pref: %.4fK", sprintf(buffer, "%.2f KTri %.2f FPS %.0f M/s",
// 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",
stats.ktri/(float)(1<<10), stats.ktri/(float)(1<<10),
stats.ktri/(float)(1<<10), stats.fps, stats.fps * stats.ktri/(float)(1<<20));
stats.fps);
gl_print(0.03, 0.03, buffer); gl_print(0.03, 0.03, buffer);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);

View File

@ -1,25 +1,25 @@
#include "preload.h" #include "preload.h"
#include "nexusmt.h" #include "nexusmt.h"
#include <iostream>
using namespace std; using namespace std;
using namespace nxs; using namespace nxs;
void Preload::execute() { void Preload::execute() {
assert(mt); assert(mt);
while(!get_signaled()) { while(!get_signaled()) {
lock.enter(); lock.enter();
while(!queue.size()) { while(!queue.size()) {
//cerr << "Acc nothing to preload!\n"; lock.leave();
lock.leave(); trigger.wait();
pt::psleep(10); lock.enter();
lock.enter(); }
} //TODO check we are not loading too much memory!
//TODO check we are not loading too much memory! assert(queue.size());
assert(queue.size()); unsigned int patch = queue.back();
unsigned int patch = queue.back(); mt->GetPatch(patch, false);
mt->GetPatch(patch, false); queue.pop_back();
queue.pop_back(); lock.leave();
lock.leave(); }
} }
}

View File

@ -17,10 +17,11 @@ class Preload: public pt::thread{
NexusMt *mt; NexusMt *mt;
pt::mutex lock; pt::mutex lock;
pt::trigger trigger;
std::vector<unsigned int> queue; std::vector<unsigned int> queue;
Preload(): thread(false) {} Preload(): thread(false), trigger(true, false) {}
~Preload() { ~Preload() {
waitfor(); waitfor();
} }
@ -29,6 +30,7 @@ class Preload: public pt::thread{
void post(std::vector<unsigned int> &patches) { void post(std::vector<unsigned int> &patches) {
lock.enter(); lock.enter();
trigger.post();
queue = patches; queue = patches;
lock.leave(); lock.leave();
} }