clray

view src/scene.h @ 33:931d13b72f83

forgot to add the timers
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 24 Aug 2010 05:47:04 +0100
parents 353d80127627
children 7d77ded5f890
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 padding[3];
58 };
61 class Scene {
62 private:
63 mutable Face *facebuf;
64 mutable int num_faces;
66 mutable KDNodeGPU *kdbuf;
68 public:
69 std::vector<Mesh*> meshes;
70 std::vector<Material> matlib;
71 KDNode *kdtree;
73 Scene();
74 ~Scene();
76 bool add_mesh(Mesh *m);
77 int get_num_meshes() const;
78 int get_num_materials() const;
79 int get_num_faces() const;
81 Material *get_materials();
82 const Material *get_materials() const;
84 bool load(const char *fname);
85 bool load(FILE *fp);
87 const Face *get_face_buffer() const;
88 const KDNodeGPU *get_kdtree_buffer() const;
89 int get_kdtree_buffer_size() const;
91 void draw_kdtree() const;
92 bool build_kdtree();
93 };
95 enum {
96 ACCEL_PARAM_MAX_TREE_DEPTH,
97 ACCEL_PARAM_MAX_NODE_ITEMS,
98 ACCEL_PARAM_COST_TRAVERSE,
99 ACCEL_PARAM_COST_INTERSECT,
101 NUM_ACCEL_PARAMS
102 };
104 void set_accel_param(int p, int v);
106 int kdtree_depth(const KDNode *tree);
107 int kdtree_nodes(const KDNode *tree);
109 bool kdtree_dump(const KDNode *tree, const char *fname);
110 KDNode *kdtree_restore(const char *fname);
112 #endif /* MESH_H_ */