aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/config.hpp22
-rw-r--r--app/draw.cpp9
-rw-r--r--app/draw.hpp5
-rw-r--r--app/main.cpp16
-rw-r--r--app/mainwindow.cpp7
-rw-r--r--app/mainwindow.hpp5
-rw-r--r--app/rendercoord.cpp17
-rw-r--r--app/rendercoord.hpp9
8 files changed, 66 insertions, 24 deletions
diff --git a/app/config.hpp b/app/config.hpp
new file mode 100644
index 0000000..6e9962c
--- /dev/null
+++ b/app/config.hpp
@@ -0,0 +1,22 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#include <render.hpp>
+
+class Config {
+ public:
+ unsigned m_width, m_height;
+ unsigned m_maxhops, m_samples;
+
+ unsigned m_framerate, m_workers;
+};
+
+class RendererConf : public Renderer {
+ public:
+ RendererConf(const Scene &scn, Vec3d eye, Vec3d target, Config &conf)
+ : Renderer(scn, eye, target, conf.m_width, conf.m_height, conf.m_maxhops) {
+
+ }
+};
+
+#endif
diff --git a/app/draw.cpp b/app/draw.cpp
index b3187be..6cbc338 100644
--- a/app/draw.cpp
+++ b/app/draw.cpp
@@ -7,12 +7,11 @@
#include <qwindowdefs.h>
#include <iostream>
-DrawWidget::DrawWidget(unsigned width, unsigned height) : QWidget() {
- m_width = width;
- m_height = height;
- m_drawbuffer = new QRgb[width * height];
+DrawWidget::DrawWidget(const Config &conf) :
+ QWidget(), m_conf(conf) {
+ m_drawbuffer = new QRgb[conf.m_width * conf.m_height];
- m_img = QImage((uchar*)m_drawbuffer, width, height, QImage::Format_ARGB32);
+ m_img = QImage((uchar*)m_drawbuffer, conf.m_width, conf.m_height, QImage::Format_ARGB32);
}
void DrawWidget::paintEvent(QPaintEvent*) {
diff --git a/app/draw.hpp b/app/draw.hpp
index cee5734..454558c 100644
--- a/app/draw.hpp
+++ b/app/draw.hpp
@@ -1,6 +1,7 @@
#ifndef DRAW_H
#define DRAW_H
+#include "config.hpp"
#include <qimage.h>
#include <qtimer.h>
#include <qwidget.h>
@@ -9,7 +10,7 @@ class DrawWidget : public QWidget {
Q_OBJECT
public:
- DrawWidget(unsigned width, unsigned height);
+ DrawWidget(const Config &conf);
void paintEvent(QPaintEvent*);
QRgb *m_drawbuffer;
@@ -22,6 +23,8 @@ class DrawWidget : public QWidget {
private:
unsigned char i;
+
+ const Config &m_conf;
};
#endif
diff --git a/app/main.cpp b/app/main.cpp
index 48e26fe..e53b8ad 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -14,6 +14,14 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Scene scn;
+ Config conf;
+ conf.m_width = 500;
+ conf.m_height = 500;
+ conf.m_maxhops = 5;
+ conf.m_samples = 100;
+ conf.m_framerate = 3;
+ conf.m_workers = 4;
+
Material blue(Color(0.3, 0.3, 1), 1);
Material red(Color(1, 0.3, 0.3), 1);
@@ -25,15 +33,15 @@ int main(int argc, char *argv[])
scn.addShape(new Sphere(white, Vec3d(-2, 5, -2), 1.3));
scn.addShape(new Sphere(blue, Vec3d(0, 7, 0), 0.5));
- scn.addShape(new Plane(white, Vec3d(0, 0, 0), Vec3d(0, 1, 0)));
- scn.addShape(new Plane(em, Vec3d(0, 10, 0), Vec3d(0, 1, 0)));
+ scn.addShape(new Plane(em, Vec3d(0, 0, 0), Vec3d(0, 1, 0)));
+ scn.addShape(new Plane(white, Vec3d(0, 10, 0), Vec3d(0, 1, 0)));
scn.addShape(new Plane(white, Vec3d(0, 0, -5), Vec3d(0, 0, 1)));
scn.addShape(new Plane(red, Vec3d(-5, 0, 0), Vec3d(1, 0, 0)));
scn.addShape(new Plane(blue, Vec3d(5, 0, 0), Vec3d(1, 0, 0)));
- Renderer render(scn, Vec3d(0, 5, 4), Vec3d(0, 5, 0), 500, 500, 5);
+ RendererConf render(scn, Vec3d(0, 5, 4), Vec3d(0, 5, 0), conf);
- MainWindow main(render);
+ MainWindow main(render, conf);
main.show();
return a.exec();
diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp
index 3fcc9c5..eed98f9 100644
--- a/app/mainwindow.cpp
+++ b/app/mainwindow.cpp
@@ -6,10 +6,11 @@
#include <QFileDialog>
#include <QMessageBox>
-MainWindow::MainWindow(Renderer r)
- : m_drawer(500, 500),
+MainWindow::MainWindow(Renderer r, const Config &conf)
+ : m_drawer(conf),
runstatus("Not running", this),
- m_render(this, m_drawer, r, &runstatus)
+ m_render(this, m_drawer, r, conf, &runstatus),
+ m_conf(conf)
{
setCentralWidget(&m_drawer);
diff --git a/app/mainwindow.hpp b/app/mainwindow.hpp
index b2566f4..ffb4f08 100644
--- a/app/mainwindow.hpp
+++ b/app/mainwindow.hpp
@@ -6,6 +6,7 @@
#include <QMenuBar>
#include <QStatusBar>
+#include "config.hpp"
#include "draw.hpp"
#include "rendercoord.hpp"
#include <qmainwindow.h>
@@ -15,7 +16,7 @@ class MainWindow : public QMainWindow {
Q_OBJECT
public:
- MainWindow(Renderer r);
+ MainWindow(Renderer r, const Config &conf);
private slots:
void saveimage();
@@ -26,6 +27,8 @@ class MainWindow : public QMainWindow {
QMenu *fileMenu;
QMenu *helpMenu;
+
+ const Config &m_conf;
};
#endif
diff --git a/app/rendercoord.cpp b/app/rendercoord.cpp
index fd325e3..00a6437 100644
--- a/app/rendercoord.cpp
+++ b/app/rendercoord.cpp
@@ -18,10 +18,11 @@ uint32_t colorToUint32(const Color &c) {
}
// Run by main thread
-RenderThread::RenderThread(Renderer r, unsigned threads, QObject *parent, unsigned id)
+RenderThread::RenderThread(Renderer r, unsigned threads, const Config &conf, QObject *parent, unsigned id)
: QThread(parent),
m_lock(1),
m_render(r),
+ m_conf(conf),
m_pause(1)
{
m_id = id;
@@ -78,6 +79,7 @@ int RenderThread::render(QRgb *buffer, unsigned samples) {
m_writebuffer = buffer;
m_samples = samples;
m_work.release();
+ std::cout << samples << std::endl;
return 0;
}
@@ -97,17 +99,18 @@ unsigned RenderThread::current_samples() {
return m_current_samples;
}
-RenderCoordinator::RenderCoordinator(QObject *parent, DrawWidget &target, Renderer r, QLabel *status)
+RenderCoordinator::RenderCoordinator(QObject *parent, DrawWidget &target, Renderer r, const Config &conf, QLabel *status)
: QObject(parent),
m_target(target),
m_renderer(r),
- m_timer(this)
+ m_timer(this),
+ m_conf(conf)
{
m_status = status;
// Create and start workers
- for (int i = 0; i < 4; i++) {
- auto thread = new RenderThread(m_renderer, 4, this, i);
+ for (unsigned i = 0; i < conf.m_workers; i++) {
+ auto thread = new RenderThread(m_renderer, conf.m_workers, conf, this, i);
thread->start();
QObject::connect(thread, &RenderThread::done, this, &RenderCoordinator::workerDone);
@@ -122,7 +125,7 @@ RenderCoordinator::RenderCoordinator(QObject *parent, DrawWidget &target, Render
void RenderCoordinator::render() {
m_started = 0;
for (auto thd : m_workers) {
- thd->render(m_target.m_drawbuffer, 20);
+ thd->render(m_target.m_drawbuffer, m_conf.m_samples);
m_started++;
}
@@ -131,7 +134,7 @@ void RenderCoordinator::render() {
QObject::connect(&m_timer, &QTimer::timeout, this, &RenderCoordinator::updateUi);
- m_timer.start(500);
+ m_timer.start(1000.0 / m_conf.m_framerate);
}
void RenderCoordinator::stop() {
diff --git a/app/rendercoord.hpp b/app/rendercoord.hpp
index a749f8a..eea1b40 100644
--- a/app/rendercoord.hpp
+++ b/app/rendercoord.hpp
@@ -2,6 +2,7 @@
#define RENDER_THREAD_H
#include "draw.hpp"
+#include "config.hpp"
#include <atomic>
#include <qlabel.h>
#include <render.hpp>
@@ -17,7 +18,7 @@ class RenderThread : public QThread {
Q_OBJECT
public:
- RenderThread(Renderer r, unsigned threads, QObject *parent = nullptr, unsigned id = 0);
+ RenderThread(Renderer r, unsigned threads, const Config &cfg, QObject *parent = nullptr, unsigned id = 0);
// Returns 0 if successful or 1 if busy
int render(QRgb *buffer, unsigned samples);
@@ -46,6 +47,8 @@ class RenderThread : public QThread {
unsigned m_workers;
+ Config const m_conf;
+
// Value in here means work is to be done
QSemaphore m_work;
QSemaphore m_pause;
@@ -59,7 +62,7 @@ class RenderCoordinator : public QObject {
Q_OBJECT
public:
- RenderCoordinator(QObject *parent, DrawWidget &target, Renderer r, QLabel *status=nullptr);
+ RenderCoordinator(QObject *parent, DrawWidget &target, Renderer r, const Config &conf, QLabel *status=nullptr);
void setSamples(unsigned samples);
void render();
@@ -84,7 +87,7 @@ class RenderCoordinator : public QObject {
State m_state;
- unsigned m_samples;
+ const Config &m_conf;
};
#endif