+ | Multiple sphere sent to GPU working

This commit is contained in:
TheRedShip
2024-12-24 01:44:53 +01:00
parent 7b56daf149
commit 216e9a684a
10 changed files with 166 additions and 62 deletions

View File

@ -16,7 +16,6 @@
# define WIDTH 1920
# define HEIGHT 1080
# include "glm/glm.hpp"
# include "glm/gtc/matrix_transform.hpp"
# include "glm/gtc/type_ptr.hpp"
@ -24,14 +23,17 @@
# include "glad/gl.h"
# include "GLFW/glfw3.h"
# include <iostream>
# include <memory>
struct Vertex {
glm::vec2 position;
glm::vec2 texCoord;
};
# include "Object.hpp"
# include "objects/Sphere.hpp"
# include "Camera.hpp"
# include "Window.hpp"
# include "Shader.hpp"

View File

@ -13,20 +13,33 @@
#ifndef RT_OBJECT__HPP
# define RT_OBJECT__HPP
#include "RT.hpp"
# include "RT.hpp"
typedef struct s_Material
{
glm::vec3 color;
float roughness;
float specular;
} Material;
class Object
{
public:
glm::vec3 position;
glm::vec3 color;
Object(const glm::vec3& pos, const glm::vec3& col) : position(pos), color(col) {}
virtual ~Object() = default;
// virtual bool hit(const glm::vec3& rayOrigin, const glm::vec3& rayDir, float& t, glm::vec3& hitNormal) const = 0;
protected:
glm::vec3 _position;
Material _material;
public:
Object(const glm::vec3& position, const Material& material) : _position(position), _material(material) {}
virtual ~Object() = default;
const glm::vec3& getPosition() const { return (_position); }
const Material& getMaterial() const { return (_material); }
enum class Type {
SPHERE,
};
virtual Type getType() const = 0;
};
#endif

View File

@ -15,6 +15,19 @@
# include "RT.hpp"
struct GPUObject
{
glm::vec3 position;
int padding_1;
glm::vec3 color;
int padding_2;
float roughness;
float specular;
float radius;
int type;
};
class Sphere;
class Camera;
class Scene
@ -23,11 +36,16 @@ class Scene
Scene();
~Scene();
Camera *getCamera(void) const;
// Object *getObjects(void) const;
Camera *getCamera(void) const;
void addObject(std::unique_ptr<Object> object);
void updateGPUData();
const std::vector<GPUObject>& getGPUData() const;
private:
// Object *_objects;
std::vector<std::unique_ptr<Object>> _objects;
std::vector<GPUObject> _gpuObjects;
Camera *_camera;
};

View File

@ -21,7 +21,6 @@ class Shader
Shader(std::string vertexPath, std::string fragmentPath, std::string computePath);
~Shader(void);
// void compile(const char *vertexSource, const char *fragmentSource);
void attach(void);
void setupVertexBuffer(const Vertex* vertices, size_t size);
void drawTriangles(size_t size);
@ -29,7 +28,7 @@ class Shader
// void setBool(const std::string &name, bool value) const;
// void setInt(const std::string &name, int value) const;
void set_int(const std::string &name, int value) const;
// void setFloat(const std::string &name, float value) const;
void set_vec2(const std::string &name, const glm::vec2 &value) const;
void set_vec3(const std::string &name, const glm::vec3 &value) const;

View File

@ -18,13 +18,14 @@
class Sphere : public Object
{
public:
float radius;
glm::vec3 position;
Sphere(const glm::vec3& position, float radius, const Material& material)
: Object(position, material), _radius(radius) {}
float getRadius() const { return (_radius); }
Type getType() const override { return Type::SPHERE; }
private:
float _radius;
};
#endif