Skip to content
Snippets Groups Projects
Commit cb5230bc authored by Evy Storozhenko's avatar Evy Storozhenko
Browse files

made rendering loop

parent 7ac1274e
No related branches found
No related tags found
No related merge requests found
...@@ -99,21 +99,20 @@ vikingScene(Scene& scene) { ...@@ -99,21 +99,20 @@ vikingScene(Scene& scene) {
int int
main() { main() {
constexpr auto aspect = 16.0 / 9.0; constexpr auto aspect = 16.0 / 9.0;
constexpr auto width = 1920; constexpr auto width = 300;
constexpr auto height = static_cast<int>(width / aspect); constexpr auto height = static_cast<int>(width / aspect);
constexpr auto lookFrom = vec3(0, 2, 1); constexpr auto lookFrom = vec3(13, 2, 3);
constexpr auto lookAt = vec3(0, 1, -1); constexpr auto lookAt = vec3(0, 0, 0);
Scene scene { { width, height } }; Scene scene { { width, height } };
// scene.getRenderPass().setMaxDepth(50).setSampleRate(100).setCamera<DepthCamera>( scene.getRenderPass().setMaxDepth(50).setSampleRate(10).setCamera<HitCamera>(
// lookFrom, lookAt, vec3(0, 1, 0), 70, aspect, 0.1, (lookAt - lookFrom).length()); lookFrom, lookAt, vec3(0, 1, 0), 20.0, aspect);
scene.getRenderPass().setMaxDepth(50).setSampleRate(100).setCamera<HitCamera>(
lookFrom, lookAt, vec3(0, 1, 0), 70.0, aspect); while (!scene.shouldClose()) {
scene.clear();
// populateScene(scene); populateScene(scene);
triangleScene(scene); scene.render(8, false, true);
vikingScene(scene); scene.waitIdle<false>();
}
scene.render(20, true, true); scene.closeWindow();
scene.waitIdle();
} }
\ No newline at end of file
...@@ -13,28 +13,42 @@ namespace pew { ...@@ -13,28 +13,42 @@ namespace pew {
str << "Rendering at " << extent.width << "x" << extent.height; str << "Rendering at " << extent.width << "x" << extent.height;
window.setTitle(str.str()); window.setTitle(str.str());
} }
void void
Scene::render(uint32_t threadCount, bool detectEdges, bool showWindow) { Scene::render(uint32_t threadCount, bool detectEdges, bool showWindow) {
if (showWindow) window.startAndFork(); static std::thread* window_thread = showWindow ? window.startAndFork() : nullptr;
if (detectEdges) { if (detectEdges) {
renderPass.renderHitStage(threadCount)->join(); renderPass.renderHitStage(threadCount)->join();
static bool isBufferAdded = false;
if (!isBufferAdded) {
hitBufferAsColor = renderPass.hitBufferAsColor(); hitBufferAsColor = renderPass.hitBufferAsColor();
window.addBuffer(&hitBufferAsColor); window.addBuffer(&hitBufferAsColor);
isBufferAdded = true;
}
} }
job = renderPass.renderColorStage(threadCount, detectEdges, true); job = renderPass.renderColorStage(threadCount, detectEdges, true);
} }
void void
Scene::waitIdle() { Scene::clear() {
if (job) job->join(); collection.collection.clear();
window.join(); materials.clear();
textures.clear();
} }
void void
Scene::onShouldClose() { Scene::onShouldClose() {
m_shouldClose = true;
}
void
Scene::closeWindow() {
window.closeWindow(); window.closeWindow();
if (job) job->stop(); if (job) job->stop();
} }
void void
Scene::onKeyInput(SDL_KeyboardEvent event, bool down) { Scene::onKeyInput(SDL_KeyboardEvent event, bool down) {
if (down) { if (down) {
......
...@@ -26,6 +26,7 @@ namespace pew { ...@@ -26,6 +26,7 @@ namespace pew {
Window window; Window window;
std::shared_ptr<RenderJob> job; std::shared_ptr<RenderJob> job;
std::vector<Color> hitBufferAsColor; std::vector<Color> hitBufferAsColor;
bool m_shouldClose = false;
public: public:
Scene(const Extent2D& extent); Scene(const Extent2D& extent);
...@@ -33,8 +34,15 @@ namespace pew { ...@@ -33,8 +34,15 @@ namespace pew {
void void
render(uint32_t threadCount, bool detectEdges, bool showWindow); render(uint32_t threadCount, bool detectEdges, bool showWindow);
template<bool CLOSE_ON_FINISH>
void void
waitIdle(); waitIdle() {
if (job) job->join();
if constexpr (CLOSE_ON_FINISH) {
closeWindow();
window.join();
}
}
private: private:
void void
...@@ -44,6 +52,9 @@ namespace pew { ...@@ -44,6 +52,9 @@ namespace pew {
onKeyInput(SDL_KeyboardEvent event, bool down); onKeyInput(SDL_KeyboardEvent event, bool down);
public: public:
void
closeWindow();
template<typename T, typename... Args> template<typename T, typename... Args>
auto& auto&
add(Args&&... args) { add(Args&&... args) {
...@@ -69,6 +80,9 @@ namespace pew { ...@@ -69,6 +80,9 @@ namespace pew {
renderPass.setCamera<T>(std::forward<Args>(args)...); renderPass.setCamera<T>(std::forward<Args>(args)...);
} }
void
clear();
inline auto& inline auto&
getRenderPass() { getRenderPass() {
return renderPass; return renderPass;
...@@ -78,6 +92,11 @@ namespace pew { ...@@ -78,6 +92,11 @@ namespace pew {
getWindow() { getWindow() {
return window; return window;
} }
inline auto
shouldClose() {
return m_shouldClose;
}
}; };
} // namespace pew } // namespace pew
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment