map change works now

This commit is contained in:
2025-03-17 18:10:05 +01:00
parent 3efff641ae
commit 0103c22882
9 changed files with 49 additions and 40 deletions

View File

@ -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:

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<GLuint> &textures, ShaderProgram &denoisingProgram);
void update(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &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<GLuint> &textures, ShaderProgram &denoisingProgram);
void clientHandleBuffer(Scene &scene, std::vector<Buffer *> &buffers, Window &win);
void updateClient(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &buffers);
void clientGetJob(void);
void clientReceive(Scene &scene);
void handleCurrentJob(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
void clientReceive(Scene &scene, std::vector<Buffer *> &buffers, Window &win);
void handleCurrentJob(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &buffers);
void sendProgress(uint8_t progress);
void sendImageToServer(Scene &scene, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
void sendImageToServer(Scene &scene, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &buffers, Window &win);
std::vector<uint8_t> rgb32fToRgb24i(std::vector<float> &imageFloat);
void changeMap(Scene &scene);
void changeMap(Scene &scene, std::vector<Buffer *> &buffers, Window &win);
bool stringComplete(void);
int _serverFd;

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<Buffer *> &buffers);
std::vector<Buffer *> createDataOnGPU(void);

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<GLuint> &textures, ShaderProgram &denoisingProgram);
void clusterizerUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
void clusterizerUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &buffers);
private:
GLFWwindow *_window;
Scene *_scene;

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<GLuint> &textures, ShaderProgram &denoisingProgram)
void Clusterizer::update(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &buffers)
{
if(!_isActive)
return ;
if(_isServer)
updateServer();
else
updateClient(scene, win, textures, denoisingProgram);
updateClient(scene, win, textures, denoisingProgram, buffers);
}
bool Clusterizer::getError(void)

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<Buffer *> &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<Buffer *> &buffers, Window &win)
{
std::vector<uint8_t> 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<Buffer *> &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<uint8_t> Clusterizer::rgb32fToRgb24i(std::vector<float> &imageFloat)
return(buffer);
}
void Clusterizer::sendImageToServer(Scene &scene, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
void Clusterizer::sendImageToServer(Scene &scene, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &buffers, Window &win)
{
_srvReady = 0;
std::vector<float> imageFloat(WIDTH * HEIGHT * 4);
@ -204,7 +205,7 @@ void Clusterizer::sendImageToServer(Scene &scene, std::vector<GLuint> &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<GLuint> &textures,
std::cout << "image sent" << std::endl;
}
void Clusterizer::handleCurrentJob(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
void Clusterizer::handleCurrentJob(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &buffers)
{
uint8_t progress;
if(!_currentJob)
@ -264,12 +265,12 @@ void Clusterizer::handleCurrentJob(Scene &scene, Window &win, std::vector<GLuint
if((size_t)win.getFrameCount() == _currentJob->samples)
{
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<GLuint> &textures, ShaderProgram &denoisingProgram)
void Clusterizer::updateClient(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &buffers)
{
if(!_serverFd)
{
@ -282,6 +283,6 @@ void Clusterizer::updateClient(Scene &scene, Window &win, std::vector<GLuint> &t
std::cout << "server reconnected." << std::endl;
}
clientReceive(scene);
handleCurrentJob(scene, win, textures, denoisingProgram);
clientReceive(scene, buffers, win);
handleCurrentJob(scene, win, textures, denoisingProgram, buffers);
}

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<Buffer *> Scene::createDataOnGPU(void)
return (buffers);
}
void Scene::changeScene(std::string &name)
void Scene::changeScene(std::string &name, std::vector<Buffer *> &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();
}

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<GLuint> &textures, ShaderProgram &denoi
_renderer->update(textures, denoisingProgram);
}
void Window::clusterizerUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
void Window::clusterizerUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram, std::vector<Buffer *> &buffers)
{
_clusterizer->update(*_scene, *this, textures, denoisingProgram);
_clusterizer->update(*_scene, *this, textures, denoisingProgram, buffers);
}
void Window::imGuiNewFrame()