Adding progress bar for rt application

This commit is contained in:
IlyaShurupov 2023-10-18 13:45:47 +03:00
parent 414d4e6411
commit 2e0d0e0050
3 changed files with 37 additions and 1 deletions

View file

@ -37,6 +37,19 @@ void writeImage(const RayTracer::RenderBuffer& output) {
}
}
static void* printStatus(void* arg) {
auto percentage = (const halnf*) arg;
auto old = *percentage;
while (*percentage < 0.99f) {
sleep(500);
if (old != *percentage && (*percentage - old) > 0.01) {
printf("Progress - %f\n", (*percentage) * 100);
old = *percentage;
}
}
pthread_exit(NULL);
}
void renderCommand(const String& scenePath) {
Scene scene;
@ -49,13 +62,26 @@ void renderCommand(const String& scenePath) {
RayTracer rayt;
pthread_t my_thread;
int ret;
printf("\nStarting Render:\n\n");
ret = pthread_create(&my_thread, NULL, &printStatus, &rayt.mProgress.percentage);
if (ret != 0) {
printf("Error: pthread_create() failed\n");
exit(EXIT_FAILURE);
}
auto start = get_time();
rayt.render(scene, output, settings);
auto end = get_time();
printf("\n Render finished with average render time per sample - %i (ms)\n", end - start);
pthread_join(my_thread, NULL);
printf("\nRender finished with average render time per sample - %i (ms)\n", end - start);
writeImage(output);
}

View file

@ -149,6 +149,9 @@ void RayTracer::render(const Scene& scene, RayTracer::RenderBuffer& buff, const
Vec3F deltaX = right * halnf(width / (alnf) buff.size().x);
Vec3F deltaY = up * halnf(-height / (alnf) buff.size().y);
ualni maxIterations = buff.size().x * buff.size().y;
ualni currIter = 0;
for (RayTracer::RenderBuffer::Index i = 0; i < buff.size().x; i++) {
for (RayTracer::RenderBuffer::Index j = 0; j < buff.size().y; j++) {
iterPoint = planeLeftTop + ((deltaX * (halnf) i) + (deltaY * (halnf) j));
@ -167,6 +170,9 @@ void RayTracer::render(const Scene& scene, RayTracer::RenderBuffer& buff, const
} else {
buff.set({i, j}, 0.f);
}
mProgress.percentage = (halnf) currIter / (halnf) maxIterations;
currIter++;
}
}
}

View file

@ -41,6 +41,10 @@ namespace tp {
public:
typedef Buffer2D<RGBA> RenderBuffer;
struct Progress {
halnf percentage = 0.f;
} mProgress;
struct RenderSettings {
uhalni depth = 2;
uhalni spray = 1;