mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Multiple sphere sent to GPU working
This commit is contained in:
@ -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
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
Reference in New Issue
Block a user