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:
@ -1,12 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Object.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/23 18:44:00 by ycontre #+# #+# */
|
||||
/* Updated: 2024/12/23 18:44:01 by ycontre ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
@ -19,10 +19,43 @@ Scene::Scene()
|
||||
|
||||
Scene::~Scene()
|
||||
{
|
||||
delete _camera;
|
||||
delete (_camera);
|
||||
}
|
||||
|
||||
Camera *Scene::getCamera(void) const
|
||||
{
|
||||
return (_camera);
|
||||
}
|
||||
|
||||
void Scene::addObject(std::unique_ptr<Object> object)
|
||||
{
|
||||
_objects.push_back(std::move(object));
|
||||
|
||||
this->updateGPUData();
|
||||
}
|
||||
|
||||
void Scene::updateGPUData()
|
||||
{
|
||||
_gpuObjects.clear();
|
||||
for (const auto& obj : _objects)
|
||||
{
|
||||
GPUObject gpuObj;
|
||||
gpuObj.position = obj->getPosition();
|
||||
gpuObj.color = obj->getMaterial().color;
|
||||
gpuObj.roughness = obj->getMaterial().roughness;
|
||||
gpuObj.specular = obj->getMaterial().specular;
|
||||
gpuObj.type = static_cast<int>(obj->getType());
|
||||
|
||||
if (obj->getType() == Object::Type::SPHERE) {
|
||||
auto sphere = static_cast<const Sphere*>(obj.get());
|
||||
gpuObj.radius = sphere->getRadius();
|
||||
}
|
||||
|
||||
_gpuObjects.push_back(gpuObj);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<GPUObject>& Scene::getGPUData() const
|
||||
{
|
||||
return (_gpuObjects);
|
||||
}
|
@ -142,17 +142,18 @@ void Shader::drawTriangles(size_t size)
|
||||
glDrawArrays(GL_TRIANGLES, 0, size * 3);
|
||||
}
|
||||
|
||||
|
||||
void Shader::set_int(const std::string &name, int value) const
|
||||
{
|
||||
glUniform1i(glGetUniformLocation(_program_compute, name.c_str()), value);
|
||||
}
|
||||
void Shader::set_vec2(const std::string &name, const glm::vec2 &value) const
|
||||
{
|
||||
glUniform2fv(glGetUniformLocation(_program_compute, name.c_str()), 1, glm::value_ptr(value));
|
||||
}
|
||||
|
||||
void Shader::set_vec3(const std::string &name, const glm::vec3 &value) const
|
||||
{
|
||||
glUniform3fv(glGetUniformLocation(_program_compute, name.c_str()), 1, glm::value_ptr(value));
|
||||
}
|
||||
|
||||
void Shader::set_mat4(const std::string &name, const glm::mat4 &value) const
|
||||
{
|
||||
glUniformMatrix4fv(glGetUniformLocation(_program_compute, name.c_str()), 1, GL_FALSE, glm::value_ptr(value));
|
||||
|
Reference in New Issue
Block a user