clray

view src/scene.h @ 28:97cfd9675310

trying to pass the kdtree to the kernel
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Aug 2010 03:42:49 +0100
parents 8b2f2ad14ae7
children 353d80127627
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 struct KDNode {
50 int axis;
51 float pt;
52 AABBox aabb;
53 float cost;
55 KDNode *left, *right;
56 int num_faces; // cause on some implementations list::size() is O(n)
57 std::list<const Face*> faces;
59 KDNode();
60 };
62 struct KDNodeGPU {
63 AABBox aabb;
64 int face_idx[32];
65 int num_faces;
66 int padding[3];
67 };
70 class Scene {
71 private:
72 mutable Face *facebuf;
73 mutable int num_faces;
75 mutable KDNodeGPU *kdbuf;
76 mutable int num_kdnodes;
78 public:
79 std::vector<Mesh*> meshes;
80 std::vector<Material> matlib;
81 KDNode *kdtree;
83 Scene();
84 ~Scene();
86 bool add_mesh(Mesh *m);
87 int get_num_meshes() const;
88 int get_num_materials() const;
89 int get_num_faces() const;
91 Material *get_materials();
92 const Material *get_materials() const;
94 bool load(const char *fname);
95 bool load(FILE *fp);
97 const Face *get_face_buffer() const;
98 const KDNodeGPU *get_kdtree_buffer() const;
99 int get_num_kdnodes() const;
101 void draw_kdtree() const;
102 bool build_kdtree();
103 };
105 enum {
106 ACCEL_PARAM_MAX_TREE_DEPTH,
107 ACCEL_PARAM_MAX_NODE_ITEMS,
108 ACCEL_PARAM_COST_TRAVERSE,
109 ACCEL_PARAM_COST_INTERSECT,
111 NUM_ACCEL_PARAMS
112 };
114 void set_accel_param(int p, int v);
116 int kdtree_depth(const KDNode *tree);
117 int kdtree_nodes(const KDNode *tree);
119 #endif /* MESH_H_ */