# HG changeset patch # User John Tsiombikas # Date 1402204325 -10800 # Node ID d15ee526daa6490f75d3cac9fda5f4f9c43f568a # Parent 2c768a49e86e15bb4c6f18c413d4a511b83f71f1 - changed the UI font, made it a bit smaller - fixed the text positioning in the status bar - added ThreadPool::clear to remove all pending jobs - fixed the TargetCamera matrix calculation to avoid singularities when the camera looks straight up or down. - fixed ommited normalization in TargetCamera's matrix calculation - added paths/sec display in the status bar diff -r 2c768a49e86e -r d15ee526daa6 Makefile --- a/Makefile Sat Jun 07 14:21:56 2014 +0300 +++ b/Makefile Sun Jun 08 08:12:05 2014 +0300 @@ -3,9 +3,9 @@ obj = $(csrc:.c=.o) $(ccsrc:.cc=.o) bin = erebus -opt = -O3 -ffast-math -dbg = -g -warn = -Wall +export opt = -O3 -ffast-math +export dbg = -g +export warn = -Wall CFLAGS = -pedantic $(warn) $(opt) $(dbg) -Iliberebus/src CXXFLAGS = -std=c++11 $(CFLAGS) @@ -22,10 +22,17 @@ liberebus: $(MAKE) -C liberebus +.PHONY: liberebus-clean +liberebus-clean: + $(MAKE) -C liberebus clean + .PHONY: clean clean: rm -f $(obj) $(bin) +.PHONY: cleanall +cleanall: clean liberebus-clean + uname = $(shell uname -s) ifeq ($(uname), Darwin) sys = mac diff -r 2c768a49e86e -r d15ee526daa6 data/serif.glyphmap Binary file data/serif.glyphmap has changed diff -r 2c768a49e86e -r d15ee526daa6 liberebus/Makefile --- a/liberebus/Makefile Sat Jun 07 14:21:56 2014 +0300 +++ b/liberebus/Makefile Sun Jun 08 08:12:05 2014 +0300 @@ -8,8 +8,8 @@ api_major = 0 api_minor = 1 -CXXFLAGS = -std=c++11 -pedantic -Wall -g $(pic) -LDFLAGS = -lvmath -limago -lm +CXXFLAGS = -std=c++11 -pthread -pedantic $(warn) $(dbg) $(opt) $(pic) +LDFLAGS = -pthread -lvmath -limago -lm ifeq ($(shell uname -s), Darwin) shared = -dynamiclib diff -r 2c768a49e86e -r d15ee526daa6 liberebus/src/brdf.cc --- a/liberebus/src/brdf.cc Sat Jun 07 14:21:56 2014 +0300 +++ b/liberebus/src/brdf.cc Sun Jun 08 08:12:05 2014 +0300 @@ -18,7 +18,7 @@ } tangent = Vector3(1.0f, 0.0f, 0.0f); - if(fabs(fabs(dot_product(normal, tangent)) - 1.0f) < 1e-4f) { + if(1.0 - fabs(dot_product(normal, tangent)) < 1e-4f) { tangent = Vector3(0.0f, 0.0f, 1.0f); } Vector3 bitan = cross_product(normal, tangent); diff -r 2c768a49e86e -r d15ee526daa6 liberebus/src/camera.cc --- a/liberebus/src/camera.cc Sat Jun 07 14:21:56 2014 +0300 +++ b/liberebus/src/camera.cc Sun Jun 08 08:12:05 2014 +0300 @@ -108,9 +108,14 @@ void TargetCamera::calc_matrix(Matrix4x4 *mat) const { - Vector3 up(0, 1, 0); + Vector3 up{0, 1, 0}; Vector3 dir = (target - pos).normalized(); - Vector3 right = cross_product(up, dir); + + if(1.0 - fabs(dot_product(dir, up)) < 1e-4) { + up = Vector3(0, 0, 1); + } + + Vector3 right = cross_product(up, dir).normalized(); up = cross_product(dir, right); *mat = Matrix4x4( diff -r 2c768a49e86e -r d15ee526daa6 liberebus/src/erebus.cc --- a/liberebus/src/erebus.cc Sat Jun 07 14:21:56 2014 +0300 +++ b/liberebus/src/erebus.cc Sun Jun 08 08:12:05 2014 +0300 @@ -133,6 +133,7 @@ int num_threads = erb_getopti(ctx, ERB_OPT_NUM_THREADS); ctx->tpool = new ThreadPool(num_threads); } + ctx->tpool->clear_work(); // remove any previously pending jobs ++ctx->cur_frame; ctx->cur_sample = 0; @@ -214,9 +215,7 @@ int erb_get_status(struct erebus *ctx, struct erb_render_status *stat) { long pending = ctx->tpool->pending(); - if(!pending) { - return -1; - } + int xsz = ctx->fbimg.get_width(); int ysz = ctx->fbimg.get_height(); int xblocks = (xsz + BLKSZ - 1) / BLKSZ; @@ -232,9 +231,17 @@ if((stat->max_samples = erb_getopti(ctx, ERB_OPT_MAX_SAMPLES)) == INF_SAMPLES) { stat->max_samples = stat->samples; - stat->progress_percent = 100 * stat->blocks / stat->max_blocks; + if(stat->max_blocks) { + stat->progress_percent = 100 * stat->blocks / stat->max_blocks; + } else { + stat->progress_percent = 0; + } } else { - stat->progress_percent = 100 * stat->samples / stat->max_samples; + if(stat->max_samples) { + stat->progress_percent = 100 * stat->samples / stat->max_samples; + } else { + stat->progress_percent = 0; + } } return 0; } diff -r 2c768a49e86e -r d15ee526daa6 liberebus/src/threadpool.cc --- a/liberebus/src/threadpool.cc Sat Jun 07 14:21:56 2014 +0300 +++ b/liberebus/src/threadpool.cc Sun Jun 08 08:12:05 2014 +0300 @@ -33,10 +33,7 @@ ThreadPool::~ThreadPool() { #ifdef _MSC_VER - workq_mutex.lock(); - workq.clear(); - qsize = 0; - workq_mutex.unlock(); + clear_work(); #endif quit = true; @@ -79,6 +76,13 @@ workq_condvar.notify_all(); } +void ThreadPool::clear_work() +{ + std::unique_lock lock(workq_mutex); + workq.clear(); + qsize = 0; +} + int ThreadPool::queued() const { std::unique_lock lock(workq_mutex); diff -r 2c768a49e86e -r d15ee526daa6 liberebus/src/threadpool.h --- a/liberebus/src/threadpool.h Sat Jun 07 14:21:56 2014 +0300 +++ b/liberebus/src/threadpool.h Sun Jun 08 08:12:05 2014 +0300 @@ -32,11 +32,13 @@ void thread_func(); public: - ThreadPool(int num_threads = -1); + // passing num_threads == -1 auto-detects based on number of processors + explicit ThreadPool(int num_threads = -1); ~ThreadPool(); void add_work(std::function func); void add_work(std::function work_func, std::function done_func); + void clear_work(); // returns the number of queued work items int queued() const; diff -r 2c768a49e86e -r d15ee526daa6 src/main.cc --- a/src/main.cc Sat Jun 07 14:21:56 2014 +0300 +++ b/src/main.cc Sun Jun 08 08:12:05 2014 +0300 @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -88,10 +89,10 @@ width = glutGet(GLUT_WINDOW_WIDTH) / opt_imgscale; height = glutGet(GLUT_WINDOW_HEIGHT) / opt_imgscale; + //if(!(font = dtx_open_font("/usr/share/fonts/opentype/linux-libertine/LinLibertine_R.otf", 22))) { if(!(font = dtx_open_font_glyphmap("data/serif.glyphmap"))) { fprintf(stderr, "warning: failed to load font!\n"); } - dtx_use_font(font, 24); if(!(erb = erb_init())) { return false; @@ -244,6 +245,9 @@ float maxu = (float)width / (float)rtex_width; float maxv = (float)height / (float)rtex_height; + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, rtex); + glBegin(GL_QUADS); glColor4f(1, 1, 1, 1); glTexCoord2f(0, maxv); glVertex2f(-1, -1); @@ -267,7 +271,6 @@ bool show_progress = opt_samples > 0; - glPushAttrib(GL_ENABLE_BIT); glDisable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); @@ -279,40 +282,68 @@ glPushMatrix(); glLoadIdentity(); - int font_height = dtx_glyph_height('Q'); + dtx_box bbox; + dtx_glyph_box('Q', &bbox); + + // draw progress/status bar + int bar_height = bbox.height + 4; int prog_width = show_progress ? status.progress_percent * win_width / 100 : 0; glBegin(GL_QUADS); glColor4f(0, 0, 0, 1); glVertex2f(prog_width, 0); glVertex2f(win_width, 0); - glVertex2f(win_width, font_height); - glVertex2f(prog_width, font_height); + glVertex2f(win_width, bar_height); + glVertex2f(prog_width, bar_height); glColor4f(0.25, 0, 0, 1); glVertex2f(0, 0); glVertex2f(prog_width, 0); - glVertex2f(prog_width, font_height); - glVertex2f(0, font_height); + glVertex2f(prog_width, bar_height); + glVertex2f(0, bar_height); glEnd(); - glTranslatef(5, 5, 0); + // draw the text + glTranslatef(bbox.x + 2, bbox.y + 2, 0); glColor4f(1, 1, 1, 1); if(opt_samples > 0) { - dtx_printf("samples: %d / %d\n", status.samples, status.max_samples); + dtx_printf("samples: %ld / %ld", status.samples, status.max_samples); - glTranslatef(win_width - dtx_string_width("progress: 100%") - 5, 0, 0); - dtx_printf("progress: %d%%\n", status.progress_percent); + glLoadIdentity(); + glTranslatef(win_width - dtx_string_width("progress: 100%") - 2, bbox.y + 2, 0); + dtx_printf("progress: %ld%%", status.progress_percent); } else { - dtx_printf("samples: %d\n", status.samples); + dtx_printf("samples: %ld", status.samples); } + + // samples/sec display + static long paths_per_sec, prev_msec, prev_paths; + + long msec = duration_cast(steady_clock::now() - start_time).count(); + long dt = msec - prev_msec; + + if(dt >= 1500) { // average over 1.5 seconds + long paths = status.samples * width * height; + if(prev_msec > 0 && prev_paths <= paths) { // check valid interval (not a restart or whatever) + paths_per_sec = 1000 * (paths - prev_paths) / dt; + } + prev_msec = msec; + prev_paths = paths; + } + + glLoadIdentity(); + glTranslatef((win_width - dtx_string_width("paths/s: 999999")) / 2, bbox.y + 2, 0); + if(paths_per_sec) { + dtx_printf("paths/s: %ld", paths_per_sec); + } else { + dtx_printf("paths/s: ???"); + } + glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); - - glPopAttrib(); } static void save_image(const char *fname) @@ -344,12 +375,12 @@ begin_frame(0); break; - case '`': + case '\b': printf("saving image.\n"); save_image(); break; - case 'p': + case '`': show_status = !show_status; glutPostRedisplay(); break; @@ -451,4 +482,4 @@ } return true; -} \ No newline at end of file +}