Adding restart button
This commit is contained in:
+1
-2
@@ -27,7 +27,6 @@ void ThreadPool::cancel()
|
||||
{
|
||||
std::unique_lock l(queueLock);
|
||||
numRemaining = numRunning;
|
||||
taskQueue.clear();
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
@@ -79,7 +78,7 @@ void ThreadPool::work()
|
||||
if (numRemaining == 0)
|
||||
{
|
||||
taskQueue.pop_front();
|
||||
completedCV.notify_one();
|
||||
completedCV.notify_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-2
@@ -22,9 +22,18 @@ int main()
|
||||
while (true)
|
||||
{
|
||||
window.beginFrame();
|
||||
if (ImGui::Button("Test"))
|
||||
if (ImGui::Button("Render"))
|
||||
{
|
||||
std::cout << "Test" << std::endl;
|
||||
scene.startRender(
|
||||
Camera{
|
||||
.position = glm::vec3(0, 10, 10),
|
||||
.direction = glm::vec3(0, -1, -1),
|
||||
},
|
||||
RenderParameter{
|
||||
.width = 1920,
|
||||
.height = 1080,
|
||||
.numSamples = 10000,
|
||||
});
|
||||
}
|
||||
window.update(scene.getImage());
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ static bool firstTime = true;
|
||||
void Scene::startRender(Camera cam, RenderParameter params)
|
||||
{
|
||||
threadPool.cancel();
|
||||
pendingCancel = true;
|
||||
if (worker.joinable())
|
||||
worker.join();
|
||||
pendingCancel = false;
|
||||
image.clear();
|
||||
accumulator.clear();
|
||||
image.resize(params.width * params.height);
|
||||
@@ -36,6 +40,8 @@ void Scene::render(Camera camera, RenderParameter params)
|
||||
{
|
||||
for (int samp = 0; samp < params.numSamples; ++samp)
|
||||
{
|
||||
if (pendingCancel)
|
||||
return;
|
||||
Batch batch;
|
||||
for (int w = 0; w < params.width; ++w)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@ class Scene
|
||||
virtual void render(Camera cam, RenderParameter params);
|
||||
ThreadPool threadPool;
|
||||
std::thread worker;
|
||||
std::atomic_bool pendingCancel = false;
|
||||
// the thing being displayed
|
||||
std::vector<glm::vec3> image;
|
||||
// radiance accumulator
|
||||
|
||||
Reference in New Issue
Block a user