erebus
diff liberebus/src/erebus.cc @ 32:b1fc96c71bcc
- lambert BRDF importance sampling
- UI + commandline arguments
- font rendering for showing status/progress
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 07 Jun 2014 13:36:36 +0300 |
parents | 53a98c148bf8 |
children | d15ee526daa6 |
line diff
1.1 --- a/liberebus/src/erebus.cc Sat Jun 07 09:14:17 2014 +0300 1.2 +++ b/liberebus/src/erebus.cc Sat Jun 07 13:36:36 2014 +0300 1.3 @@ -25,10 +25,8 @@ 1.4 struct erebus *ctx = 0; 1.5 try { 1.6 ctx = new struct erebus; 1.7 - ctx->tpool = new ThreadPool; 1.8 } 1.9 catch(...) { 1.10 - delete ctx; 1.11 return 0; 1.12 } 1.13 1.14 @@ -37,6 +35,7 @@ 1.15 ctx->scn = 0; 1.16 ctx->cur_time = 0; 1.17 ctx->cur_frame = 0; 1.18 + ctx->tpool = 0; 1.19 1.20 erb_setoptf(ctx, ERB_OPT_GAMMA, 2.2); 1.21 erb_setopti(ctx, ERB_OPT_MAX_ITER, 6); 1.22 @@ -130,7 +129,11 @@ 1.23 1.24 void erb_begin_frame(struct erebus *ctx, long ms) 1.25 { 1.26 - printf("starting new frame...\n"); 1.27 + if(!ctx->tpool) { 1.28 + int num_threads = erb_getopti(ctx, ERB_OPT_NUM_THREADS); 1.29 + ctx->tpool = new ThreadPool(num_threads); 1.30 + } 1.31 + 1.32 ++ctx->cur_frame; 1.33 ctx->cur_sample = 0; 1.34 ctx->cur_time = ms; 1.35 @@ -201,7 +204,39 @@ 1.36 1.37 int erb_get_progress(struct erebus *ctx) 1.38 { 1.39 - return 0; // TODO 1.40 + struct erb_render_status st; 1.41 + if(erb_get_status(ctx, &st) == -1) { 1.42 + return 0; 1.43 + } 1.44 + return st.progress_percent; 1.45 +} 1.46 + 1.47 +int erb_get_status(struct erebus *ctx, struct erb_render_status *stat) 1.48 +{ 1.49 + long pending = ctx->tpool->pending(); 1.50 + if(!pending) { 1.51 + return -1; 1.52 + } 1.53 + int xsz = ctx->fbimg.get_width(); 1.54 + int ysz = ctx->fbimg.get_height(); 1.55 + int xblocks = (xsz + BLKSZ - 1) / BLKSZ; 1.56 + int yblocks = (ysz + BLKSZ - 1) / BLKSZ; 1.57 + long num_blocks = xblocks * yblocks; 1.58 + 1.59 + stat->frames = stat->max_frames = 0; // TODO 1.60 + 1.61 + stat->blocks = num_blocks - pending; 1.62 + stat->max_blocks = num_blocks; 1.63 + 1.64 + stat->samples = ctx->cur_sample ? ctx->cur_sample - 1 : 0; 1.65 + if((stat->max_samples = erb_getopti(ctx, ERB_OPT_MAX_SAMPLES)) == INF_SAMPLES) { 1.66 + stat->max_samples = stat->samples; 1.67 + 1.68 + stat->progress_percent = 100 * stat->blocks / stat->max_blocks; 1.69 + } else { 1.70 + stat->progress_percent = 100 * stat->samples / stat->max_samples; 1.71 + } 1.72 + return 0; 1.73 } 1.74 1.75 int erb_load_scene(struct erebus *ctx, const char *fname)