clray

view src/scene.h @ 26:c740ae431d51

continuing with the kdtree construction
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 17 Aug 2010 01:19:43 +0100
parents 58642a8316b7
children 8b2f2ad14ae7
line source
1 #ifndef MESH_H_
2 #define MESH_H_
4 #include <stdio.h>
5 #include <vector>
6 #include <list>
8 struct Vertex {
9 float pos[4];
10 float normal[4];
11 float tex[4];
12 float padding[4];
13 };
15 struct Face {
16 Vertex v[3];
17 float normal[4];
18 int matid;
19 int padding[3];
21 bool operator ==(const Face &f) const;
22 };
24 struct Material {
25 float kd[4], ks[4];
26 float kr, kt;
27 float spow;
28 float padding;
29 };
31 struct Mesh {
32 std::vector<Face> faces;
33 int matid;
34 };
36 class AABBox {
37 public:
38 float min[4], max[4];
40 float calc_surface_area() const;
41 };
43 enum {
44 KDAXIS_X,
45 KDAXIS_Y,
46 KDAXIS_Z
47 };
49 #define KDCLEAR(node) ((node)->axis = -1)
50 #define KDUSED(node) ((node)->axis >= 0)
51 #define KDPARENT(x) ((x) >> 1)
52 #define KDLEFT(x) ((x) << 1)
53 #define KDRIGHT(x) (((x) << 1) + 1)
55 struct KDNode {
56 int axis;
57 float pt;
58 AABBox aabb;
59 float cost;
61 KDNode *left, *right;
62 int num_faces; // cause on some implementations list::size() is O(n)
63 std::list<const Face*> faces;
65 KDNode();
66 };
68 struct KDNodeGPU {
69 int axis;
70 float pt;
71 };
74 class Scene {
75 private:
76 mutable Face *facebuf;
77 mutable int num_faces;
79 public:
80 std::vector<Mesh*> meshes;
81 std::vector<Material> matlib;
83 KDNode *kdtree;
84 std::vector<KDNode> kdtree_gpu;
86 Scene();
87 ~Scene();
89 bool add_mesh(Mesh *m);
90 int get_num_meshes() const;
91 int get_num_materials() const;
92 int get_num_faces() const;
94 Material *get_materials();
95 const Material *get_materials() const;
97 bool load(const char *fname);
98 bool load(FILE *fp);
100 const Face *get_face_buffer() const;
101 void build_kdtree();
102 };
104 enum {
105 ACCEL_PARAM_MAX_TREE_DEPTH,
106 ACCEL_PARAM_MAX_NODE_ITEMS,
107 ACCEL_PARAM_COST_TRAVERSE,
108 ACCEL_PARAM_COST_INTERSECT,
110 NUM_ACCEL_PARAMS
111 };
113 void set_accel_param(int p, int v);
115 #endif /* MESH_H_ */