coming together

This commit is contained in:
Ben
2019-08-22 00:28:52 +01:00
parent 81d8759cf6
commit eae59ccf9b
7 changed files with 89 additions and 32 deletions

View File

@@ -1,8 +1,5 @@
#include "progressiverenderer.hpp"
#include <vector>
#include <chrono>
#include "../common.hpp"
#include "../pixel.hpp"
#include "../display/displayinterface.hpp"
@@ -23,31 +20,45 @@ void ProgressiveRenderer::Init(DisplayInterface* interface, Scene* scene) {
m_scene = scene;
}
void ProgressiveRenderer::Input() {
SDL_Event e;
while (SDL_PollEvent(&e))
if (e.type == SDL_QUIT) m_interface->Close();
if (!m_interface->ImGui) return;
ImGui::NewFrame();
ImGui::Begin("Debug");
ImGui::Text("Hello, world %d", 123);
if (ImGui::Button("Save")) {}
char* buf = ""; float f;
ImGui::InputText("string", buf, IM_ARRAYSIZE(buf));
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::End();
}
void ProgressiveRenderer::Render() {
int frames = 0;
auto startTime = std::chrono::high_resolution_clock::now();
while (m_interface->Active) {
Input();
m_interface->Update();
}
while (m_interface->Active) {
auto frameStartTime = std::chrono::high_resolution_clock::now();
ImGui::NewFrame();
ImGui::Begin("Thing");
ImGui::Text("Hello, world %d", 123);
if (ImGui::Button("Save")) {}
char* buf = ""; float f;
ImGui::InputText("string", buf, IM_ARRAYSIZE(buf));
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::End();
#pragma omp parallel for schedule(dynamic)
for (int x = 0; x < m_scene->w; x++)
for (int y = 0; y < m_scene->h; y++) {
SDL_Event e;
while (SDL_PollEvent(&e))
if (e.type == SDL_QUIT) m_interface->Close();
Ray ray = m_scene->camera->CastRay(x, y);
float t;
@@ -71,12 +82,18 @@ void ProgressiveRenderer::Render() {
frames++;
std::cout << "Frame: " << frames << std::endl;
std::cout << "Frame Time: " << std::chrono::duration_cast<std::chrono::seconds>(endTime - frameStartTime).count()
<< ":" << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - frameStartTime).count() << std::endl;
<< ":" << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - frameStartTime).count() << "s" << std::endl;
std::cout << "Avg Frame Time: " << std::chrono::duration_cast<std::chrono::seconds>(endTime - startTime).count() / frames
<< ":" << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() / frames
<< ":" << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() / frames << "s"
<< std::endl << std::endl;
// Swap framebuffers
m_interface->Update();
m_interface->ClearFramebuffer();
}
}
void ProgressiveRenderer::RenderProgressive() {
}