renderer can now load a path

This commit is contained in:
2025-02-04 19:06:41 +01:00
parent 2264ed7a8f
commit 9ab0212d03
10 changed files with 84 additions and 41 deletions

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
/* Updated: 2025/02/04 03:06:51 by tomoron ### ########.fr */
/* Updated: 2025/02/04 16:45:30 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,12 +15,13 @@
int main(int argc, char **argv)
{
Arguments args(argc, argv);
args.show();
if(args.error())
return(1);
Scene scene(args.getSceneName());
if(scene.fail())
return(1);
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0);
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0, args);
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/04 01:05:44 by tomoron #+# #+# */
/* Updated: 2025/02/04 03:16:25 by tomoron ### ########.fr */
/* Updated: 2025/02/04 17:10:24 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,25 +40,52 @@ Arguments::Arguments(int argc, char **argv)
}
}
void Arguments::initArguments()
{
addArgument('r', "renderpath", 0);
addArgument('h', "headless", 1);
}
void Arguments::printUsage(void)
{
std::cerr << "usage : [options] <scene name> [options]" << std::endl;
std::cerr << R""""(options :
-r | --renderpath : filename for the renderer path
-r | --renderpath <file>: filename for the renderer path
-h | --headless : does the program need to start rendering as soon as it starts(and close automatically)
)"""";
}
void Arguments::show(void)
{
for(std::map<std::string, std::string>::iterator it = _values.begin();it != _values.end(); it++)
std::cout << (*it).first << ": " << (*it).second << std::endl;
}
bool Arguments::error(void) const
{
return(_err);
}
std::string &Arguments::getSceneName(void)
{
return(_values["sceneName"]);
}
std::string *Arguments::getRenderPath(void)
{
if(_values.find("renderpath") != _values.end())
return(&_values["renderpath"]);
else
return(0);
}
bool Arguments::getHeadless(void)
{
return(_values.find("headless") != _values.end());
}
void Arguments::addArgument(char shortName, std::string longName, int isFlag)
{
t_arg arg;
@ -69,11 +96,6 @@ void Arguments::addArgument(char shortName, std::string longName, int isFlag)
_args.push_back(arg);
}
void Arguments::initArguments()
{
addArgument('r', "renderPath", 0);
addArgument('h', "headless", 1);
}
int Arguments::handleArg(char **argv, int argc, int *i)
{
@ -92,7 +114,7 @@ int Arguments::handleArg(char **argv, int argc, int *i)
_values[(*it).longName] = "yes";
else if(*i == argc - 1)
{
std::cerr << "missing option" << std::endl;
std::cerr << "missing option for --" << (*it).longName << std::endl;
return(0);
}
else
@ -115,7 +137,7 @@ int Arguments::handleArg(char **argv, int argc, int *i)
_values[(*it).longName] = "yes";
else if(*i == argc - 1)
{
std::cerr << "missing option" << std::endl;
std::cerr << "missing option for --" << (*it).longName << std::endl;
return(0);
}
else

View File

@ -6,24 +6,33 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
/* Updated: 2025/02/04 00:43:18 by tomoron ### ########.fr */
/* Updated: 2025/02/04 19:06:00 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "RT.hpp"
Renderer::Renderer(Scene *scene, Window *win)
Renderer::Renderer(Scene *scene, Window *win, Arguments &args)
{
init(scene, win);
_headless = 0;
}
std::string *renderPath;
Renderer::Renderer(Scene *scene, Window *win, std::string filename)
{
init(scene, win);
_headless = 1;
loadPath(filename);
initRender();
_headless = args.getHeadless();
renderPath = args.getRenderPath();
if(renderPath)
{
try
{
loadPath(*renderPath);
}
catch (std::exception &e)
{
std::cout << e.what() << std::endl;
_shouldClose = 1;
}
}
if(_headless)
initRender();
}
void Renderer::init(Scene *scene, Window *win)
@ -71,15 +80,20 @@ void Renderer::savePath(void)
{
std::ofstream outputFile;
const AVCodec *codec;
(void)codec;
codec = _codecList[_codecIndex];
outputFile.open("output.path", std::ios::binary);
if(!outputFile.is_open())
std::cerr << "could open output.path for writing" << std::endl;
outputFile.write(_outputFilename.c_str(), _outputFilename.length() + 1);
outputFile.write((char *)&codec->id, sizeof(codec->id));
outputFile.write((char *)&_samples, sizeof(_samples));
outputFile.write((char *)&_fps, sizeof(_fps));
for(std::vector<t_pathPoint>::iterator it = _path.begin(); it != _path.end(); it++)
{
outputFile.write((char *)&(*it), sizeof(t_pathPoint));
}
outputFile.close();
}
@ -95,6 +109,8 @@ void Renderer::loadPath(std::string filename)
_outputFilename = "";
_filenameBuffer[0] = 0;
file.open(filename);
if(!file.is_open())
std::cerr << "failed to open " << filename << std::endl;
c = 1;
while(c)
{
@ -104,15 +120,17 @@ void Renderer::loadPath(std::string filename)
if(c)
_outputFilename += c;
}
memcpy(_filenameBuffer, _outputFilename.c_str(), _outputFilename.length());
_filenameBuffer[_outputFilename.length()] = 0;
rawRead(file, &codecId, sizeof(codecId));
updateAvailableCodecs(2, codecId);
if(_codecList.size() == 0)
throw std::runtime_error("codec not available");
rawRead(file, &_samples, sizeof(_samples));
rawRead(file, &_fps, sizeof(_fps));
if(_samples < 1 || _fps < 1)
if(_samples < 1 || _fps < 1 || _samples >= 1000 || _fps >= 120)
throw std::runtime_error("invalid value provided in fps or samples");
while(!file.eof())
while(file.peek() != EOF)
{
rawRead(file, &pathPoint, sizeof(t_pathPoint));
if(pathPoint.time < .0f)
@ -201,7 +219,7 @@ void Renderer::updateAvailableCodecs(int mode, AVCodecID id)
void Renderer::initRender(void)
{
//TODO: check values
_codecOptions = 0;
_destPathIndex = _path.size() - 1;
_curPathIndex = 0;

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 18:29:41 by ycontre #+# #+# */
/* Updated: 2025/02/04 03:11:24 by tomoron ### ########.fr */
/* Updated: 2025/02/04 16:43:33 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,6 @@
Scene::Scene(std::string &name)
{
std::cout << "name : " << name << std::endl;
std::ifstream file(name);
std::string line;
_camera = new Camera(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), -90.0f, 0.0f);

View File

@ -6,19 +6,19 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
/* Updated: 2025/02/04 00:42:01 by tomoron ### ########.fr */
/* Updated: 2025/02/04 16:46:29 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "Window.hpp"
Window::Window(Scene *scene, int width, int height, const char *title, int sleep)
Window::Window(Scene *scene, int width, int height, const char *title, int sleep, Arguments &args)
{
_scene = scene;
_fps = 0;
_frameCount = 0;
_pixelisation = 0;
_renderer = new Renderer(scene, this);
_renderer = new Renderer(scene, this, args);
if (!glfwInit())
{