-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScene.cpp
More file actions
62 lines (50 loc) · 1.94 KB
/
Scene.cpp
File metadata and controls
62 lines (50 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// Created by 孙万捷 on 16/4/14.
//
#include "Scene.h"
#include "helper_cuda.h"
Scene::Scene()
{
}
Scene::~Scene()
{
}
void Scene::BuildSceneForGPU(cudaScene &scene)
{
//copy camera
scene.camera = this->camera;
//copy environment light
scene.env_light = this->env_light;
//copy materials
scene.num_materials = this->materials.size();
if(scene.num_materials != 0)
{
checkCudaErrors(cudaMalloc((void**)&(scene.materials), sizeof(cudaMaterial) * this->materials.size()));
checkCudaErrors(cudaMemcpy(scene.materials, this->materials.data(), sizeof(cudaMaterial) * this->materials.size(), cudaMemcpyHostToDevice));
}
//copy geometries
scene.num_spheres = this->spheres.size();
if(scene.num_spheres != 0)
{
checkCudaErrors(cudaMalloc((void**)&(scene.spheres), sizeof(cudaSphere) * this->spheres.size()));
checkCudaErrors(cudaMemcpy(scene.spheres, this->spheres.data(), sizeof(cudaSphere) * this->spheres.size(), cudaMemcpyHostToDevice));
}
scene.num_aab = this->aab.size();
if(scene.num_aab != 0)
{
checkCudaErrors(cudaMalloc((void**)&(scene.aab), sizeof(cudaAAB) * this->aab.size()));
checkCudaErrors(cudaMemcpy(scene.aab, this->aab.data(), sizeof(cudaAAB) * this->aab.size(), cudaMemcpyHostToDevice));
}
scene.num_planes = this->planes.size();
if(scene.num_planes != 0)
{
checkCudaErrors(cudaMalloc((void**)&(scene.planes), sizeof(cudaPlane) * this->planes.size()));
checkCudaErrors(cudaMemcpy(scene.planes, this->planes.data(), sizeof(cudaPlane) * this->planes.size(), cudaMemcpyHostToDevice));
}
scene.num_meshes = this->meshes.size();
if(scene.num_meshes != 0)
{
checkCudaErrors(cudaMalloc((void**)&(scene.meshes), sizeof(cudaMesh) * this->meshes.size()));
checkCudaErrors(cudaMemcpy(scene.meshes, this->meshes.data(), sizeof(cudaMesh) * this->meshes.size(), cudaMemcpyHostToDevice));
}
}