diff --git a/Makefile b/Makefile index 9cf6a1a..1d73141 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,6 @@ else CFLAGS := -Wall -Wextra -Werror -g -O3 -std=c++20 IFLAGS := -I./includes -I./includes/RT -I./includes/imgui LDFLAGS += -lglfw -lGL -lGLU -lX11 -lpthread -ldl -lavformat -lavcodec -lavutil -lswscale -lswresample - FILE = $(shell ls -lR srcs/ | grep -F .c | wc -l) CMP = 1 endif @@ -46,7 +45,8 @@ IMGUI_SRCS := imgui/imgui.cpp \ imgui/imgui_impl_glfw.cpp \ imgui/imgui_impl_opengl3.cpp -ALL_SRCS := $(IMGUI_SRCS) gl.cpp \ +ALL_SRCS := $(IMGUI_SRCS) \ + gl.cpp \ RT.cpp RT_utils.cpp \ class/Window.cpp \ class/ShaderProgram.cpp \ @@ -72,6 +72,10 @@ OBJS := $(addprefix $(OBJS_DIR)/, $(SRCS:%.cpp=%.o)) HEADERS := includes/RT.hpp MAKEFLAGS += --no-print-directory +ifneq ($(OS),Windows_NT) + FILE = $(shell echo $(SRCS) | tr " " "\n" | wc -l) +endif + all: $(NAME) ifeq ($(OS),Windows_NT) @@ -82,7 +86,7 @@ else $(NAME): $(OBJS) $(HEADERS) @printf "$(LINE_CLR)$(WHITE) $(NAME): linking ...$(RESET)" @$(CC) $(OBJS) $(IFLAGS) $(CFLAGS) $(LDFLAGS) -o $(NAME) - @printf "$(LINE_CLR)$(WHITE) $(NAME): PROJECT COMPILED !$(RESET)\n\n" + @printf "$(LINE_CLR)$(WHITE) $(NAME): PROJECT COMPILED !$(RESET)\n" endif flags: diff --git a/includes/RT/Clusterizer.hpp b/includes/RT/Clusterizer.hpp index 91608ba..31ceb54 100644 --- a/includes/RT/Clusterizer.hpp +++ b/includes/RT/Clusterizer.hpp @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/20 18:25:18 by tomoron #+# #+# */ -/* Updated: 2025/03/14 17:29:56 by tomoron ### ########.fr */ +/* Updated: 2025/03/17 18:05:15 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,7 +59,7 @@ class Clusterizer Clusterizer(Arguments &args, Renderer *renderer); ~Clusterizer(); - void update(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram); + void update(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers); bool getError(void); void imguiRender(void); bool isServer(void); @@ -84,16 +84,16 @@ class Clusterizer private: //client void initClient(std::string &dest); void openClientConnection(const char *ip, int port); - void clientHandleBuffer(Scene &scene); - void updateClient(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram); + void clientHandleBuffer(Scene &scene, std::vector &buffers, Window &win); + void updateClient(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers); void clientGetJob(void); - void clientReceive(Scene &scene); - void handleCurrentJob(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram); + void clientReceive(Scene &scene, std::vector &buffers, Window &win); + void handleCurrentJob(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers); void sendProgress(uint8_t progress); - void sendImageToServer(Scene &scene, std::vector &textures, ShaderProgram &denoisingProgram); + void sendImageToServer(Scene &scene, std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers, Window &win); std::vector rgb32fToRgb24i(std::vector &imageFloat); - void changeMap(Scene &scene); + void changeMap(Scene &scene, std::vector &buffers, Window &win); bool stringComplete(void); int _serverFd; diff --git a/includes/RT/Scene.hpp b/includes/RT/Scene.hpp index 1176055..64c9d94 100644 --- a/includes/RT/Scene.hpp +++ b/includes/RT/Scene.hpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/23 18:30:18 by ycontre #+# #+# */ -/* Updated: 2025/03/16 17:00:32 by tomoron ### ########.fr */ +/* Updated: 2025/03/17 15:26:14 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -141,7 +141,7 @@ class Scene bool fail(void) const; - void changeScene(std::string &name); + void changeScene(std::string &name, std::vector &buffers); std::vector createDataOnGPU(void); diff --git a/includes/RT/Window.hpp b/includes/RT/Window.hpp index 11b3338..26d4f8c 100644 --- a/includes/RT/Window.hpp +++ b/includes/RT/Window.hpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */ -/* Updated: 2025/02/25 01:50:04 by tomoron ### ########.fr */ +/* Updated: 2025/03/17 15:24:12 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,7 +51,7 @@ class Window bool isRendering(); void rendererUpdate(std::vector &textures, ShaderProgram &denoisingProgram); - void clusterizerUpdate(std::vector &textures, ShaderProgram &denoisingProgram); + void clusterizerUpdate(std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers); private: GLFWwindow *_window; Scene *_scene; diff --git a/srcs/RT.cpp b/srcs/RT.cpp index 2d6814c..e100760 100644 --- a/srcs/RT.cpp +++ b/srcs/RT.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */ -/* Updated: 2025/03/16 17:38:51 by tomoron ### ########.fr */ +/* Updated: 2025/03/17 14:54:43 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,7 +66,7 @@ int main(int argc, char **argv) while (!window.shouldClose()) { - window.clusterizerUpdate(textures, denoising_program); + window.clusterizerUpdate(textures, denoising_program, buffers); window.updateDeltaTime(); updateDataOnGPU(scene, buffers); diff --git a/srcs/class/Clusterizer/Clusterizer.cpp b/srcs/class/Clusterizer/Clusterizer.cpp index 8992481..31c8e4b 100644 --- a/srcs/class/Clusterizer/Clusterizer.cpp +++ b/srcs/class/Clusterizer/Clusterizer.cpp @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/20 18:24:39 by tomoron #+# #+# */ -/* Updated: 2025/02/25 22:33:01 by tomoron ### ########.fr */ +/* Updated: 2025/03/17 15:16:43 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,14 +41,14 @@ Clusterizer::~Clusterizer(void) close(_serverSocket); } -void Clusterizer::update(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram) +void Clusterizer::update(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers) { if(!_isActive) return ; if(_isServer) updateServer(); else - updateClient(scene, win, textures, denoisingProgram); + updateClient(scene, win, textures, denoisingProgram, buffers); } bool Clusterizer::getError(void) diff --git a/srcs/class/Clusterizer/client.cpp b/srcs/class/Clusterizer/client.cpp index a4fce3a..3a06f0d 100644 --- a/srcs/class/Clusterizer/client.cpp +++ b/srcs/class/Clusterizer/client.cpp @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/20 21:08:38 by tomoron #+# #+# */ -/* Updated: 2025/03/16 16:42:41 by tomoron ### ########.fr */ +/* Updated: 2025/03/17 18:05:26 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,7 +85,7 @@ bool Clusterizer::stringComplete(void) return(false); } -void Clusterizer::changeMap(Scene &scene) +void Clusterizer::changeMap(Scene &scene, std::vector &buffers, Window &win) { size_t len; @@ -95,13 +95,14 @@ void Clusterizer::changeMap(Scene &scene) _sceneName = std::string((char *)_receiveBuffer.data() + 1); _receiveBuffer.erase(_receiveBuffer.begin(), _receiveBuffer.begin() + len); std::cout << "changing scene to name :" << _sceneName << std::endl; - scene.changeScene(_sceneName); + scene.changeScene(_sceneName, buffers); + win.setFrameCount(0); if(scene.fail()) throw std::runtime_error("map change failed"); (void)write(_serverFd, (uint8_t []){RDY}, 1); } -void Clusterizer::clientHandleBuffer(Scene &scene) +void Clusterizer::clientHandleBuffer(Scene &scene, std::vector &buffers, Window &win) { std::vector sendBuf; @@ -129,7 +130,7 @@ void Clusterizer::clientHandleBuffer(Scene &scene) { std::cout << "got change map request" << std::endl; if(stringComplete()) - changeMap(scene); + changeMap(scene, buffers, win); else std::cout << "string is not complete, waiting for eof signal" << std::endl; } @@ -144,7 +145,7 @@ void Clusterizer::clientHandleBuffer(Scene &scene) (void)write(_serverFd, sendBuf.data(), sendBuf.size()); } -void Clusterizer::clientReceive(Scene &scene) +void Clusterizer::clientReceive(Scene &scene, std::vector &buffers, Window &win) { uint8_t buffer[512]; size_t ret; @@ -160,7 +161,7 @@ void Clusterizer::clientReceive(Scene &scene) } _receiveBuffer.insert(_receiveBuffer.end(), buffer, buffer + ret); } - clientHandleBuffer(scene); + clientHandleBuffer(scene, buffers, win); } void Clusterizer::sendProgress(uint8_t progress) @@ -195,7 +196,7 @@ std::vector Clusterizer::rgb32fToRgb24i(std::vector &imageFloat) return(buffer); } -void Clusterizer::sendImageToServer(Scene &scene, std::vector &textures, ShaderProgram &denoisingProgram) +void Clusterizer::sendImageToServer(Scene &scene, std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers, Window &win) { _srvReady = 0; std::vector imageFloat(WIDTH * HEIGHT * 4); @@ -204,7 +205,7 @@ void Clusterizer::sendImageToServer(Scene &scene, std::vector &textures, (void)write(_serverFd, (uint8_t []){IMG_SEND_RQ}, 1); while(!_srvReady) { - clientReceive(scene); + clientReceive(scene, buffers, win); if(!_serverFd) { delete _currentJob; @@ -231,7 +232,7 @@ void Clusterizer::sendImageToServer(Scene &scene, std::vector &textures, std::cout << "image sent" << std::endl; } -void Clusterizer::handleCurrentJob(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram) +void Clusterizer::handleCurrentJob(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers) { uint8_t progress; if(!_currentJob) @@ -264,12 +265,12 @@ void Clusterizer::handleCurrentJob(Scene &scene, Window &win, std::vectorsamples) { std::cout << "send request" << std::endl; - sendImageToServer(scene, textures, denoisingProgram); + sendImageToServer(scene, textures, denoisingProgram, buffers, win); } } -void Clusterizer::updateClient(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram) +void Clusterizer::updateClient(Scene &scene, Window &win, std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers) { if(!_serverFd) { @@ -282,6 +283,6 @@ void Clusterizer::updateClient(Scene &scene, Window &win, std::vector &t std::cout << "server reconnected." << std::endl; } - clientReceive(scene); - handleCurrentJob(scene, win, textures, denoisingProgram); + clientReceive(scene, buffers, win); + handleCurrentJob(scene, win, textures, denoisingProgram, buffers); } diff --git a/srcs/class/Scene.cpp b/srcs/class/Scene.cpp index 8c05348..680aa63 100644 --- a/srcs/class/Scene.cpp +++ b/srcs/class/Scene.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/23 18:29:41 by ycontre #+# #+# */ -/* Updated: 2025/03/16 17:49:37 by tomoron ### ########.fr */ +/* Updated: 2025/03/17 15:28:10 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -433,7 +433,7 @@ std::vector Scene::createDataOnGPU(void) return (buffers); } -void Scene::changeScene(std::string &name) +void Scene::changeScene(std::string &name, std::vector &buffers) { _gpu_bvh_data.clear(); _gpu_bvh.clear(); @@ -445,7 +445,11 @@ void Scene::changeScene(std::string &name) _gpu_textures.clear(); _gpu_emissive_textures.clear(); _gpu_lights.clear(); + for (size_t i = 0; i < buffers.size(); i++) + delete buffers[i]; + buffers.clear(); + init(name); - createDataOnGPU(); + buffers = createDataOnGPU(); loadTextures(); } diff --git a/srcs/class/Window.cpp b/srcs/class/Window.cpp index fba4912..242ab44 100644 --- a/srcs/class/Window.cpp +++ b/srcs/class/Window.cpp @@ -6,7 +6,7 @@ /* By: ycontre +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */ -/* Updated: 2025/02/25 01:51:46 by tomoron ### ########.fr */ +/* Updated: 2025/03/17 15:16:19 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -185,9 +185,9 @@ void Window::rendererUpdate(std::vector &textures, ShaderProgram &denoi _renderer->update(textures, denoisingProgram); } -void Window::clusterizerUpdate(std::vector &textures, ShaderProgram &denoisingProgram) +void Window::clusterizerUpdate(std::vector &textures, ShaderProgram &denoisingProgram, std::vector &buffers) { - _clusterizer->update(*_scene, *this, textures, denoisingProgram); + _clusterizer->update(*_scene, *this, textures, denoisingProgram, buffers); } void Window::imGuiNewFrame()