clray

view src/scene.h @ 60:8c858e1a89e8

minor cleanups
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Dec 2015 09:08:49 +0200
parents 6a30f27fa1e6
children
line source
1 #ifndef MESH_H_
2 #define MESH_H_
4 #include <stdio.h>
5 #include <vector>
6 #include <list>
7 #include "common.h"
9 struct Vertex {
10 float pos[4];
11 float normal[4];
12 float tex[4];
13 float padding[4];
14 };
16 struct Face {
17 Vertex v[3];
18 float normal[4];
19 int matid;
20 int padding[3];
21 };
23 struct Material {
24 float kd[4], ks[4];
25 float kr, kt;
26 float spow;
27 float padding;
28 };
30 struct Mesh {
31 std::vector<Face> faces;
32 int matid;
33 };
35 struct Light {
36 float pos[4], color[4];
37 };
39 class AABBox {
40 public:
41 float min[4], max[4];
43 float calc_surface_area() const;
44 };
46 struct KDNode {
47 int axis;
48 AABBox aabb;
49 float cost;
51 KDNode *left, *right;
52 std::vector<int> face_idx;
54 KDNode();
55 };
57 struct KDNodeGPU {
58 AABBox aabb;
59 int face_idx[MAX_NODE_FACES];
60 int num_faces;
61 int left, right;
62 int padding;
63 };
66 class Scene {
67 private:
68 mutable Face *facebuf;
69 mutable int num_faces;
71 mutable KDNodeGPU *kdbuf;
73 public:
74 std::vector<Mesh*> meshes;
75 std::vector<Light> lights;
76 std::vector<Material> matlib;
77 KDNode *kdtree;
79 Scene();
80 ~Scene();
82 bool add_mesh(Mesh *m);
83 bool add_light(const Light &lt);
85 int get_num_meshes() const;
86 int get_num_lights() const;
87 int get_num_faces() const;
88 int get_num_materials() const;
89 int get_num_kdnodes() const;
91 Mesh **get_meshes();
92 const Mesh * const *get_meshes() const;
94 Light *get_lights();
95 const Light *get_lights() const;
97 Material *get_materials();
98 const Material *get_materials() const;
100 bool load(const char *fname);
101 bool load(FILE *fp);
103 const Face *get_face_buffer() const;
104 const KDNodeGPU *get_kdtree_buffer() const;
106 void draw_kdtree() const;
107 bool build_kdtree();
108 };
110 enum {
111 ACCEL_PARAM_MAX_TREE_DEPTH,
112 ACCEL_PARAM_MAX_NODE_ITEMS,
113 ACCEL_PARAM_COST_TRAVERSE,
114 ACCEL_PARAM_COST_INTERSECT,
116 NUM_ACCEL_PARAMS
117 };
119 void set_accel_param(int p, int v);
121 int kdtree_depth(const KDNode *tree);
122 int kdtree_nodes(const KDNode *tree);
124 bool kdtree_dump(const KDNode *tree, const char *fname);
125 KDNode *kdtree_restore(const char *fname);
127 #endif /* MESH_H_ */