clray
annotate 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 |
rev | line source |
---|---|
nuclear@6 | 1 #ifndef MESH_H_ |
nuclear@6 | 2 #define MESH_H_ |
nuclear@6 | 3 |
nuclear@23 | 4 #include <stdio.h> |
nuclear@6 | 5 #include <vector> |
nuclear@24 | 6 #include <list> |
nuclear@6 | 7 |
nuclear@6 | 8 struct Vertex { |
nuclear@9 | 9 float pos[4]; |
nuclear@9 | 10 float normal[4]; |
nuclear@12 | 11 float tex[4]; |
nuclear@12 | 12 float padding[4]; |
nuclear@6 | 13 }; |
nuclear@6 | 14 |
nuclear@6 | 15 struct Face { |
nuclear@6 | 16 Vertex v[3]; |
nuclear@9 | 17 float normal[4]; |
nuclear@6 | 18 int matid; |
nuclear@12 | 19 int padding[3]; |
John@15 | 20 |
John@15 | 21 bool operator ==(const Face &f) const; |
nuclear@6 | 22 }; |
nuclear@6 | 23 |
nuclear@6 | 24 struct Material { |
nuclear@9 | 25 float kd[4], ks[4]; |
nuclear@6 | 26 float kr, kt; |
nuclear@6 | 27 float spow; |
nuclear@12 | 28 float padding; |
nuclear@6 | 29 }; |
nuclear@6 | 30 |
nuclear@6 | 31 struct Mesh { |
nuclear@6 | 32 std::vector<Face> faces; |
nuclear@6 | 33 int matid; |
nuclear@6 | 34 }; |
nuclear@6 | 35 |
nuclear@25 | 36 class AABBox { |
nuclear@25 | 37 public: |
nuclear@25 | 38 float min[4], max[4]; |
nuclear@25 | 39 |
nuclear@25 | 40 float calc_surface_area() const; |
nuclear@25 | 41 }; |
nuclear@25 | 42 |
nuclear@22 | 43 struct KDNode { |
nuclear@25 | 44 AABBox aabb; |
nuclear@26 | 45 float cost; |
nuclear@24 | 46 |
nuclear@24 | 47 KDNode *left, *right; |
nuclear@32 | 48 std::vector<int> face_idx; |
nuclear@26 | 49 |
nuclear@26 | 50 KDNode(); |
nuclear@23 | 51 }; |
nuclear@22 | 52 |
nuclear@24 | 53 struct KDNodeGPU { |
nuclear@28 | 54 AABBox aabb; |
nuclear@28 | 55 int face_idx[32]; |
nuclear@28 | 56 int num_faces; |
nuclear@35 | 57 int left, right; |
nuclear@35 | 58 int padding; |
nuclear@24 | 59 }; |
nuclear@24 | 60 |
nuclear@24 | 61 |
nuclear@6 | 62 class Scene { |
nuclear@24 | 63 private: |
nuclear@24 | 64 mutable Face *facebuf; |
nuclear@24 | 65 mutable int num_faces; |
nuclear@24 | 66 |
nuclear@28 | 67 mutable KDNodeGPU *kdbuf; |
nuclear@28 | 68 |
nuclear@6 | 69 public: |
nuclear@6 | 70 std::vector<Mesh*> meshes; |
nuclear@6 | 71 std::vector<Material> matlib; |
nuclear@24 | 72 KDNode *kdtree; |
nuclear@24 | 73 |
nuclear@24 | 74 Scene(); |
nuclear@24 | 75 ~Scene(); |
nuclear@6 | 76 |
nuclear@13 | 77 bool add_mesh(Mesh *m); |
John@14 | 78 int get_num_meshes() const; |
nuclear@35 | 79 int get_num_faces() const; |
John@14 | 80 int get_num_materials() const; |
nuclear@35 | 81 int get_num_kdnodes() const; |
nuclear@13 | 82 |
John@14 | 83 Material *get_materials(); |
John@14 | 84 const Material *get_materials() const; |
nuclear@13 | 85 |
nuclear@6 | 86 bool load(const char *fname); |
nuclear@6 | 87 bool load(FILE *fp); |
nuclear@22 | 88 |
nuclear@24 | 89 const Face *get_face_buffer() const; |
nuclear@28 | 90 const KDNodeGPU *get_kdtree_buffer() const; |
nuclear@27 | 91 |
nuclear@27 | 92 void draw_kdtree() const; |
nuclear@27 | 93 bool build_kdtree(); |
nuclear@6 | 94 }; |
nuclear@6 | 95 |
nuclear@26 | 96 enum { |
nuclear@26 | 97 ACCEL_PARAM_MAX_TREE_DEPTH, |
nuclear@26 | 98 ACCEL_PARAM_MAX_NODE_ITEMS, |
nuclear@26 | 99 ACCEL_PARAM_COST_TRAVERSE, |
nuclear@26 | 100 ACCEL_PARAM_COST_INTERSECT, |
nuclear@26 | 101 |
nuclear@26 | 102 NUM_ACCEL_PARAMS |
nuclear@26 | 103 }; |
nuclear@26 | 104 |
nuclear@26 | 105 void set_accel_param(int p, int v); |
nuclear@26 | 106 |
nuclear@28 | 107 int kdtree_depth(const KDNode *tree); |
nuclear@28 | 108 int kdtree_nodes(const KDNode *tree); |
nuclear@28 | 109 |
nuclear@32 | 110 bool kdtree_dump(const KDNode *tree, const char *fname); |
nuclear@32 | 111 KDNode *kdtree_restore(const char *fname); |
nuclear@32 | 112 |
nuclear@6 | 113 #endif /* MESH_H_ */ |