mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
renderer can now load a path
This commit is contained in:
2
Makefile
2
Makefile
@ -28,7 +28,7 @@ else
|
|||||||
RM := rm -rf
|
RM := rm -rf
|
||||||
DIR_DUP = mkdir -p $(@D)
|
DIR_DUP = mkdir -p $(@D)
|
||||||
CC := clang++
|
CC := clang++
|
||||||
CFLAGS := -Wall -Wextra -Werror -g -O3
|
CFLAGS := -Wall -Wextra -Werror -g #-O3
|
||||||
IFLAGS := -I./includes -I./includes/RT -I./includes/imgui
|
IFLAGS := -I./includes -I./includes/RT -I./includes/imgui
|
||||||
LDFLAGS += -lglfw -lGL -lGLU -lX11 -lpthread -ldl -lavformat -lavcodec -lavutil -lswscale -lswresample
|
LDFLAGS += -lglfw -lGL -lGLU -lX11 -lpthread -ldl -lavformat -lavcodec -lavutil -lswscale -lswresample
|
||||||
FILE = $(shell ls -lR srcs/ | grep -F .c | wc -l)
|
FILE = $(shell ls -lR srcs/ | grep -F .c | wc -l)
|
||||||
|
@ -29,6 +29,6 @@ Pos=1556,610
|
|||||||
Size=284,382
|
Size=284,382
|
||||||
|
|
||||||
[Window][Settings]
|
[Window][Settings]
|
||||||
Pos=532,13
|
Pos=478,75
|
||||||
Size=336,287
|
Size=336,287
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/04 01:07:08 by tomoron #+# #+# */
|
/* Created: 2025/02/04 01:07:08 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/04 03:10:58 by tomoron ### ########.fr */
|
/* Updated: 2025/02/04 17:04:59 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,10 +26,14 @@ class Arguments
|
|||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
Arguments(int argc, char **argv);
|
Arguments(int argc, char **argv);
|
||||||
bool getHeadless(void) const;
|
|
||||||
std::string &getSceneName(void);
|
bool getHeadless(void) const;
|
||||||
std::string getRenderPathName(void);
|
bool error(void) const;
|
||||||
bool error(void) const;
|
void show(void);
|
||||||
|
|
||||||
|
std::string &getSceneName(void);
|
||||||
|
std::string *getRenderPath(void);
|
||||||
|
bool getHeadless(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void printUsage();
|
void printUsage();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
|
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/04 00:41:10 by tomoron ### ########.fr */
|
/* Updated: 2025/02/04 18:46:22 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -36,8 +36,7 @@ typedef struct s_pathPoint
|
|||||||
class Renderer
|
class Renderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Renderer(Scene *scene, Window *win);
|
Renderer(Scene *scene, Window *win, Arguments &args);
|
||||||
Renderer(Scene *scene, Window *win, std::string filename);
|
|
||||||
void renderImgui(void);
|
void renderImgui(void);
|
||||||
void update(Shader &shader);
|
void update(Shader &shader);
|
||||||
int rendering(void) const;
|
int rendering(void) const;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */
|
/* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/01/25 03:09:23 by tomoron ### ########.fr */
|
/* Updated: 2025/02/04 16:46:37 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ class Scene;
|
|||||||
class Window
|
class Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Window(Scene *scene, int width, int height, const char *title, int sleep);
|
Window(Scene *scene, int width, int height, const char *title, int sleep, Arguments &args);
|
||||||
~Window(void);
|
~Window(void);
|
||||||
|
|
||||||
void display();
|
void display();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
|
/* 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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Arguments args(argc, argv);
|
Arguments args(argc, argv);
|
||||||
|
args.show();
|
||||||
if(args.error())
|
if(args.error())
|
||||||
return(1);
|
return(1);
|
||||||
Scene scene(args.getSceneName());
|
Scene scene(args.getSceneName());
|
||||||
if(scene.fail())
|
if(scene.fail())
|
||||||
return(1);
|
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/compute.glsl");
|
||||||
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/04 01:05:44 by tomoron #+# #+# */
|
/* 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)
|
void Arguments::printUsage(void)
|
||||||
{
|
{
|
||||||
std::cerr << "usage : [options] <scene name> [options]" << std::endl;
|
std::cerr << "usage : [options] <scene name> [options]" << std::endl;
|
||||||
std::cerr << R""""(options :
|
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)
|
-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
|
bool Arguments::error(void) const
|
||||||
{
|
{
|
||||||
return(_err);
|
return(_err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string &Arguments::getSceneName(void)
|
std::string &Arguments::getSceneName(void)
|
||||||
{
|
{
|
||||||
return(_values["sceneName"]);
|
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)
|
void Arguments::addArgument(char shortName, std::string longName, int isFlag)
|
||||||
{
|
{
|
||||||
t_arg arg;
|
t_arg arg;
|
||||||
@ -69,11 +96,6 @@ void Arguments::addArgument(char shortName, std::string longName, int isFlag)
|
|||||||
_args.push_back(arg);
|
_args.push_back(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Arguments::initArguments()
|
|
||||||
{
|
|
||||||
addArgument('r', "renderPath", 0);
|
|
||||||
addArgument('h', "headless", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Arguments::handleArg(char **argv, int argc, int *i)
|
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";
|
_values[(*it).longName] = "yes";
|
||||||
else if(*i == argc - 1)
|
else if(*i == argc - 1)
|
||||||
{
|
{
|
||||||
std::cerr << "missing option" << std::endl;
|
std::cerr << "missing option for --" << (*it).longName << std::endl;
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -115,7 +137,7 @@ int Arguments::handleArg(char **argv, int argc, int *i)
|
|||||||
_values[(*it).longName] = "yes";
|
_values[(*it).longName] = "yes";
|
||||||
else if(*i == argc - 1)
|
else if(*i == argc - 1)
|
||||||
{
|
{
|
||||||
std::cerr << "missing option" << std::endl;
|
std::cerr << "missing option for --" << (*it).longName << std::endl;
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -6,24 +6,33 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
|
/* 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"
|
#include "RT.hpp"
|
||||||
|
|
||||||
Renderer::Renderer(Scene *scene, Window *win)
|
Renderer::Renderer(Scene *scene, Window *win, Arguments &args)
|
||||||
{
|
{
|
||||||
init(scene, win);
|
std::string *renderPath;
|
||||||
_headless = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Renderer::Renderer(Scene *scene, Window *win, std::string filename)
|
|
||||||
{
|
|
||||||
init(scene, win);
|
init(scene, win);
|
||||||
_headless = 1;
|
_headless = args.getHeadless();
|
||||||
loadPath(filename);
|
renderPath = args.getRenderPath();
|
||||||
initRender();
|
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)
|
void Renderer::init(Scene *scene, Window *win)
|
||||||
@ -71,15 +80,20 @@ void Renderer::savePath(void)
|
|||||||
{
|
{
|
||||||
std::ofstream outputFile;
|
std::ofstream outputFile;
|
||||||
const AVCodec *codec;
|
const AVCodec *codec;
|
||||||
|
(void)codec;
|
||||||
|
|
||||||
codec = _codecList[_codecIndex];
|
codec = _codecList[_codecIndex];
|
||||||
outputFile.open("output.path", std::ios::binary);
|
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(_outputFilename.c_str(), _outputFilename.length() + 1);
|
||||||
outputFile.write((char *)&codec->id, sizeof(codec->id));
|
outputFile.write((char *)&codec->id, sizeof(codec->id));
|
||||||
outputFile.write((char *)&_samples, sizeof(_samples));
|
outputFile.write((char *)&_samples, sizeof(_samples));
|
||||||
outputFile.write((char *)&_fps, sizeof(_fps));
|
outputFile.write((char *)&_fps, sizeof(_fps));
|
||||||
for(std::vector<t_pathPoint>::iterator it = _path.begin(); it != _path.end(); it++)
|
for(std::vector<t_pathPoint>::iterator it = _path.begin(); it != _path.end(); it++)
|
||||||
|
{
|
||||||
outputFile.write((char *)&(*it), sizeof(t_pathPoint));
|
outputFile.write((char *)&(*it), sizeof(t_pathPoint));
|
||||||
|
}
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +109,8 @@ void Renderer::loadPath(std::string filename)
|
|||||||
_outputFilename = "";
|
_outputFilename = "";
|
||||||
_filenameBuffer[0] = 0;
|
_filenameBuffer[0] = 0;
|
||||||
file.open(filename);
|
file.open(filename);
|
||||||
|
if(!file.is_open())
|
||||||
|
std::cerr << "failed to open " << filename << std::endl;
|
||||||
c = 1;
|
c = 1;
|
||||||
while(c)
|
while(c)
|
||||||
{
|
{
|
||||||
@ -104,15 +120,17 @@ void Renderer::loadPath(std::string filename)
|
|||||||
if(c)
|
if(c)
|
||||||
_outputFilename += c;
|
_outputFilename += c;
|
||||||
}
|
}
|
||||||
|
memcpy(_filenameBuffer, _outputFilename.c_str(), _outputFilename.length());
|
||||||
|
_filenameBuffer[_outputFilename.length()] = 0;
|
||||||
rawRead(file, &codecId, sizeof(codecId));
|
rawRead(file, &codecId, sizeof(codecId));
|
||||||
updateAvailableCodecs(2, codecId);
|
updateAvailableCodecs(2, codecId);
|
||||||
if(_codecList.size() == 0)
|
if(_codecList.size() == 0)
|
||||||
throw std::runtime_error("codec not available");
|
throw std::runtime_error("codec not available");
|
||||||
rawRead(file, &_samples, sizeof(_samples));
|
rawRead(file, &_samples, sizeof(_samples));
|
||||||
rawRead(file, &_fps, sizeof(_fps));
|
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");
|
throw std::runtime_error("invalid value provided in fps or samples");
|
||||||
while(!file.eof())
|
while(file.peek() != EOF)
|
||||||
{
|
{
|
||||||
rawRead(file, &pathPoint, sizeof(t_pathPoint));
|
rawRead(file, &pathPoint, sizeof(t_pathPoint));
|
||||||
if(pathPoint.time < .0f)
|
if(pathPoint.time < .0f)
|
||||||
@ -201,7 +219,7 @@ void Renderer::updateAvailableCodecs(int mode, AVCodecID id)
|
|||||||
|
|
||||||
void Renderer::initRender(void)
|
void Renderer::initRender(void)
|
||||||
{
|
{
|
||||||
|
//TODO: check values
|
||||||
_codecOptions = 0;
|
_codecOptions = 0;
|
||||||
_destPathIndex = _path.size() - 1;
|
_destPathIndex = _path.size() - 1;
|
||||||
_curPathIndex = 0;
|
_curPathIndex = 0;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/23 18:29:41 by ycontre #+# #+# */
|
/* 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)
|
Scene::Scene(std::string &name)
|
||||||
{
|
{
|
||||||
std::cout << "name : " << name << std::endl;
|
|
||||||
std::ifstream file(name);
|
std::ifstream file(name);
|
||||||
std::string line;
|
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);
|
_camera = new Camera(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), -90.0f, 0.0f);
|
||||||
|
@ -6,19 +6,19 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
|
/* 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"
|
#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;
|
_scene = scene;
|
||||||
_fps = 0;
|
_fps = 0;
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
_pixelisation = 0;
|
_pixelisation = 0;
|
||||||
_renderer = new Renderer(scene, this);
|
_renderer = new Renderer(scene, this, args);
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user