+ | Shader class system better working

This commit is contained in:
TheRedShip
2025-02-13 00:28:20 +01:00
parent a71529312b
commit 6e3b0c44eb
11 changed files with 402 additions and 213 deletions

54
includes/RT/Buffer.hpp Normal file
View File

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Buffer.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/12 23:45:57 by TheRed #+# #+# */
/* Updated: 2025/02/12 23:45:57 by TheRed ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BUFFER_HPP
# define BUFFER_HPP
# include "RT.hpp"
class Buffer
{
public:
enum Type
{
SSBO,
UBO
};
Buffer(Type type, GLuint binding_point, GLuint size, const void *data)
: _type(type), _binding_point(binding_point)
{
glGenBuffers(1, &_buffer_id);
glBindBuffer(_type == SSBO ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER, _buffer_id);
glBufferData(_type == SSBO ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER, size, data, GL_DYNAMIC_DRAW);
glBindBufferBase(_type == SSBO ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER, _binding_point, _buffer_id);
glBindBuffer(_type == SSBO ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER, 0);
}
~Buffer() { glDeleteBuffers(1, &_buffer_id); }
void update(const void *data, GLuint size)
{
glBindBuffer(_type == SSBO ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER, _buffer_id);
glBufferSubData(_type == SSBO ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER, 0, size, data);
glBindBuffer(_type == SSBO ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER, 0);
}
GLuint getID() const { return _buffer_id; }
private:
Type _type;
GLuint _buffer_id;
GLuint _binding_point;
};
#endif

View File

@ -18,9 +18,14 @@
class Shader
{
public:
Shader(std::string vertexPath, std::string fragmentPath, std::string computePath, std::string denoisingPath);
Shader(GLenum type, const std::string &file_path);
~Shader(void);
void compile(void);
void reload();
GLuint getShader(void) const;
void attach(void);
void setupVertexBuffer();
void drawTriangles();
@ -37,7 +42,6 @@ class Shader
void set_textures(std::vector<GLuint> texture_ids, std::vector<GLuint> emissive_texture_ids);
GLuint getProgram(void) const;
GLuint getProgramCompute(void) const;
GLuint getProgramComputeDenoising(void) const;
@ -67,7 +71,12 @@ class Shader
size_t _size;
void checkCompileErrors(unsigned int shader);
void checkCompileErrors();
//
GLenum _type;
GLuint _shader_id;
std::string _file_path;
};
#endif

View File

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ShaderProgram.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: TheRed <TheRed@students.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/12 22:22:17 by TheRed #+# #+# */
/* Updated: 2025/02/12 22:22:17 by TheRed ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SHADERPROGRAM_HPP
# define SHADERPROGRAM_HPP
# include "RT.hpp"
class ShaderProgram
{
public:
ShaderProgram();
~ShaderProgram(void);
void attachShader(Shader *shader);
void link(void);
void use(void) const;
void dispathCompute(GLuint x, GLuint y, GLuint z) const;
void bindImageTexture(GLuint texture_id, GLuint unit, GLenum access, GLenum format) const;
void reloadShaders(void);
void set_int(const std::string &name, int value) const;
void set_float(const std::string &name, float value) const;
void set_vec2(const std::string &name, const glm::vec2 &value) const;
GLuint getProgram(void) const;
private:
std::vector<Shader *> _shaders;
GLuint _program;
};
#endif

View File

@ -52,7 +52,6 @@ class Portal : public Object
_rotation = glm::mat3(right, up, forward);
_normal = forward * (_invert_normal ? -1.0f : 1.0f);
std::cout << glm::to_string(_normal) << std::endl;
_linked_portal = -1;
_mat_index = mat_index;