mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +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
|
||||
DIR_DUP = mkdir -p $(@D)
|
||||
CC := clang++
|
||||
CFLAGS := -Wall -Wextra -Werror -g -O3
|
||||
CFLAGS := -Wall -Wextra -Werror -g #-O3
|
||||
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)
|
||||
|
@ -29,6 +29,6 @@ Pos=1556,610
|
||||
Size=284,382
|
||||
|
||||
[Window][Settings]
|
||||
Pos=532,13
|
||||
Pos=478,75
|
||||
Size=336,287
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 :
|
||||
Arguments(int argc, char **argv);
|
||||
|
||||
bool getHeadless(void) const;
|
||||
std::string &getSceneName(void);
|
||||
std::string getRenderPathName(void);
|
||||
bool error(void) const;
|
||||
void show(void);
|
||||
|
||||
std::string &getSceneName(void);
|
||||
std::string *getRenderPath(void);
|
||||
bool getHeadless(void);
|
||||
|
||||
private:
|
||||
void printUsage();
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
{
|
||||
public:
|
||||
Renderer(Scene *scene, Window *win);
|
||||
Renderer(Scene *scene, Window *win, std::string filename);
|
||||
Renderer(Scene *scene, Window *win, Arguments &args);
|
||||
void renderImgui(void);
|
||||
void update(Shader &shader);
|
||||
int rendering(void) const;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
{
|
||||
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);
|
||||
|
||||
void display();
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
|
||||
/* Updated: 2025/02/06 16:30:58 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/06 16:32:04 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");
|
||||
|
||||
|
@ -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
|
||||
|
@ -6,23 +6,32 @@
|
||||
/* 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);
|
||||
_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();
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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())
|
||||
{
|
||||
|
Reference in New Issue
Block a user