clray

annotate 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
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 struct KDNode {
nuclear@22 50 int axis;
nuclear@22 51 float pt;
nuclear@25 52 AABBox aabb;
nuclear@26 53 float cost;
nuclear@24 54
nuclear@24 55 KDNode *left, *right;
nuclear@26 56 int num_faces; // cause on some implementations list::size() is O(n)
nuclear@25 57 std::list<const Face*> faces;
nuclear@26 58
nuclear@26 59 KDNode();
nuclear@23 60 };
nuclear@22 61
nuclear@24 62 struct KDNodeGPU {
nuclear@28 63 AABBox aabb;
nuclear@28 64 int face_idx[32];
nuclear@28 65 int num_faces;
nuclear@28 66 int padding[3];
nuclear@24 67 };
nuclear@24 68
nuclear@24 69
nuclear@6 70 class Scene {
nuclear@24 71 private:
nuclear@24 72 mutable Face *facebuf;
nuclear@24 73 mutable int num_faces;
nuclear@24 74
nuclear@28 75 mutable KDNodeGPU *kdbuf;
nuclear@28 76 mutable int num_kdnodes;
nuclear@28 77
nuclear@6 78 public:
nuclear@6 79 std::vector<Mesh*> meshes;
nuclear@6 80 std::vector<Material> matlib;
nuclear@24 81 KDNode *kdtree;
nuclear@24 82
nuclear@24 83 Scene();
nuclear@24 84 ~Scene();
nuclear@6 85
nuclear@13 86 bool add_mesh(Mesh *m);
John@14 87 int get_num_meshes() const;
John@14 88 int get_num_materials() const;
John@14 89 int get_num_faces() const;
nuclear@13 90
John@14 91 Material *get_materials();
John@14 92 const Material *get_materials() const;
nuclear@13 93
nuclear@6 94 bool load(const char *fname);
nuclear@6 95 bool load(FILE *fp);
nuclear@22 96
nuclear@24 97 const Face *get_face_buffer() const;
nuclear@28 98 const KDNodeGPU *get_kdtree_buffer() const;
nuclear@28 99 int get_num_kdnodes() const;
nuclear@27 100
nuclear@27 101 void draw_kdtree() const;
nuclear@27 102 bool build_kdtree();
nuclear@6 103 };
nuclear@6 104
nuclear@26 105 enum {
nuclear@26 106 ACCEL_PARAM_MAX_TREE_DEPTH,
nuclear@26 107 ACCEL_PARAM_MAX_NODE_ITEMS,
nuclear@26 108 ACCEL_PARAM_COST_TRAVERSE,
nuclear@26 109 ACCEL_PARAM_COST_INTERSECT,
nuclear@26 110
nuclear@26 111 NUM_ACCEL_PARAMS
nuclear@26 112 };
nuclear@26 113
nuclear@26 114 void set_accel_param(int p, int v);
nuclear@26 115
nuclear@28 116 int kdtree_depth(const KDNode *tree);
nuclear@28 117 int kdtree_nodes(const KDNode *tree);
nuclear@28 118
nuclear@6 119 #endif /* MESH_H_ */