clray

view src/scene.h @ 37:ca445da26588

out of resources?!
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 Aug 2010 01:00:04 +0100
parents 7d77ded5f890
children f9eec11e5acc
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 struct KDNodeGPU {
55 AABBox aabb;
56 int face_idx[32];
57 int num_faces;
58 int left, right;
59 int padding;
60 };
63 class Scene {
64 private:
65 mutable Face *facebuf;
66 mutable int num_faces;
68 mutable KDNodeGPU *kdbuf;
70 public:
71 std::vector<Mesh*> meshes;
72 std::vector<Material> matlib;
73 KDNode *kdtree;
75 Scene();
76 ~Scene();
78 bool add_mesh(Mesh *m);
79 int get_num_meshes() const;
80 int get_num_faces() const;
81 int get_num_materials() const;
82 int get_num_kdnodes() const;
84 Material *get_materials();
85 const Material *get_materials() const;
87 bool load(const char *fname);
88 bool load(FILE *fp);
90 const Face *get_face_buffer() const;
91 const KDNodeGPU *get_kdtree_buffer() const;
93 void draw_kdtree() const;
94 bool build_kdtree();
95 };
97 enum {
98 ACCEL_PARAM_MAX_TREE_DEPTH,
99 ACCEL_PARAM_MAX_NODE_ITEMS,
100 ACCEL_PARAM_COST_TRAVERSE,
101 ACCEL_PARAM_COST_INTERSECT,
103 NUM_ACCEL_PARAMS
104 };
106 void set_accel_param(int p, int v);
108 int kdtree_depth(const KDNode *tree);
109 int kdtree_nodes(const KDNode *tree);
111 bool kdtree_dump(const KDNode *tree, const char *fname);
112 KDNode *kdtree_restore(const char *fname);
114 #endif /* MESH_H_ */