clray

annotate src/scene.h @ 26:c740ae431d51

continuing with the kdtree construction
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 17 Aug 2010 01:19:43 +0100
parents 58642a8316b7
children 8b2f2ad14ae7
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@23 43 enum {
nuclear@22 44 KDAXIS_X,
nuclear@22 45 KDAXIS_Y,
nuclear@22 46 KDAXIS_Z
nuclear@22 47 };
nuclear@22 48
nuclear@22 49 #define KDCLEAR(node) ((node)->axis = -1)
nuclear@22 50 #define KDUSED(node) ((node)->axis >= 0)
nuclear@22 51 #define KDPARENT(x) ((x) >> 1)
nuclear@22 52 #define KDLEFT(x) ((x) << 1)
nuclear@22 53 #define KDRIGHT(x) (((x) << 1) + 1)
nuclear@22 54
nuclear@22 55 struct KDNode {
nuclear@22 56 int axis;
nuclear@22 57 float pt;
nuclear@25 58 AABBox aabb;
nuclear@26 59 float cost;
nuclear@24 60
nuclear@24 61 KDNode *left, *right;
nuclear@26 62 int num_faces; // cause on some implementations list::size() is O(n)
nuclear@25 63 std::list<const Face*> faces;
nuclear@26 64
nuclear@26 65 KDNode();
nuclear@23 66 };
nuclear@22 67
nuclear@24 68 struct KDNodeGPU {
nuclear@24 69 int axis;
nuclear@24 70 float pt;
nuclear@24 71 };
nuclear@24 72
nuclear@24 73
nuclear@6 74 class Scene {
nuclear@24 75 private:
nuclear@24 76 mutable Face *facebuf;
nuclear@24 77 mutable int num_faces;
nuclear@24 78
nuclear@6 79 public:
nuclear@6 80 std::vector<Mesh*> meshes;
nuclear@6 81 std::vector<Material> matlib;
nuclear@24 82
nuclear@24 83 KDNode *kdtree;
nuclear@24 84 std::vector<KDNode> kdtree_gpu;
nuclear@24 85
nuclear@24 86 Scene();
nuclear@24 87 ~Scene();
nuclear@6 88
nuclear@13 89 bool add_mesh(Mesh *m);
John@14 90 int get_num_meshes() const;
John@14 91 int get_num_materials() const;
John@14 92 int get_num_faces() const;
nuclear@13 93
John@14 94 Material *get_materials();
John@14 95 const Material *get_materials() const;
nuclear@13 96
nuclear@6 97 bool load(const char *fname);
nuclear@6 98 bool load(FILE *fp);
nuclear@22 99
nuclear@24 100 const Face *get_face_buffer() const;
nuclear@23 101 void build_kdtree();
nuclear@6 102 };
nuclear@6 103
nuclear@26 104 enum {
nuclear@26 105 ACCEL_PARAM_MAX_TREE_DEPTH,
nuclear@26 106 ACCEL_PARAM_MAX_NODE_ITEMS,
nuclear@26 107 ACCEL_PARAM_COST_TRAVERSE,
nuclear@26 108 ACCEL_PARAM_COST_INTERSECT,
nuclear@26 109
nuclear@26 110 NUM_ACCEL_PARAMS
nuclear@26 111 };
nuclear@26 112
nuclear@26 113 void set_accel_param(int p, int v);
nuclear@26 114
nuclear@6 115 #endif /* MESH_H_ */