clray

view src/scene.h @ 35:7d77ded5f890

stopped using a heap to flatten the kdtree. added explicit left/right indices
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 26 Aug 2010 20:24:07 +0100
parents 4cf4919c3812
children ca445da26588
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 struct KDNode {
44 AABBox aabb;
45 float cost;
47 KDNode *left, *right;
48 std::vector<int> face_idx;
50 KDNode();
51 };
53 struct KDNodeGPU {
54 AABBox aabb;
55 int face_idx[32];
56 int num_faces;
57 int left, right;
58 int padding;
59 };
62 class Scene {
63 private:
64 mutable Face *facebuf;
65 mutable int num_faces;
67 mutable KDNodeGPU *kdbuf;
69 public:
70 std::vector<Mesh*> meshes;
71 std::vector<Material> matlib;
72 KDNode *kdtree;
74 Scene();
75 ~Scene();
77 bool add_mesh(Mesh *m);
78 int get_num_meshes() const;
79 int get_num_faces() const;
80 int get_num_materials() const;
81 int get_num_kdnodes() const;
83 Material *get_materials();
84 const Material *get_materials() const;
86 bool load(const char *fname);
87 bool load(FILE *fp);
89 const Face *get_face_buffer() const;
90 const KDNodeGPU *get_kdtree_buffer() const;
92 void draw_kdtree() const;
93 bool build_kdtree();
94 };
96 enum {
97 ACCEL_PARAM_MAX_TREE_DEPTH,
98 ACCEL_PARAM_MAX_NODE_ITEMS,
99 ACCEL_PARAM_COST_TRAVERSE,
100 ACCEL_PARAM_COST_INTERSECT,
102 NUM_ACCEL_PARAMS
103 };
105 void set_accel_param(int p, int v);
107 int kdtree_depth(const KDNode *tree);
108 int kdtree_nodes(const KDNode *tree);
110 bool kdtree_dump(const KDNode *tree, const char *fname);
111 KDNode *kdtree_restore(const char *fname);
113 #endif /* MESH_H_ */