clray

view src/scene.h @ 43:f9eec11e5acc

shoehorned the kdtree into an opnecl image and improved performance slightly
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 28 Aug 2010 09:38:49 +0100
parents ca445da26588
children 8047637961a2
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 int axis;
45 AABBox aabb;
46 float cost;
48 KDNode *left, *right;
49 std::vector<int> face_idx;
51 KDNode();
52 };
54 #define MAX_NODE_FACES 32
55 struct KDNodeGPU {
56 AABBox aabb;
57 int face_idx[MAX_NODE_FACES];
58 int num_faces;
59 int left, right;
60 int padding;
61 };
64 class Scene {
65 private:
66 mutable Face *facebuf;
67 mutable int num_faces;
69 mutable KDNodeGPU *kdbuf;
71 public:
72 std::vector<Mesh*> meshes;
73 std::vector<Material> matlib;
74 KDNode *kdtree;
76 Scene();
77 ~Scene();
79 bool add_mesh(Mesh *m);
80 int get_num_meshes() const;
81 int get_num_faces() const;
82 int get_num_materials() const;
83 int get_num_kdnodes() const;
85 Material *get_materials();
86 const Material *get_materials() const;
88 bool load(const char *fname);
89 bool load(FILE *fp);
91 const Face *get_face_buffer() const;
92 const KDNodeGPU *get_kdtree_buffer() const;
94 void draw_kdtree() const;
95 bool build_kdtree();
96 };
98 enum {
99 ACCEL_PARAM_MAX_TREE_DEPTH,
100 ACCEL_PARAM_MAX_NODE_ITEMS,
101 ACCEL_PARAM_COST_TRAVERSE,
102 ACCEL_PARAM_COST_INTERSECT,
104 NUM_ACCEL_PARAMS
105 };
107 void set_accel_param(int p, int v);
109 int kdtree_depth(const KDNode *tree);
110 int kdtree_nodes(const KDNode *tree);
112 bool kdtree_dump(const KDNode *tree, const char *fname);
113 KDNode *kdtree_restore(const char *fname);
115 #endif /* MESH_H_ */