clray

view src/scene.h @ 29:353d80127627

doh ... it doesn't work
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Aug 2010 20:51:57 +0100
parents 97cfd9675310
children 4cf4919c3812
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 enum {
44 KDAXIS_X,
45 KDAXIS_Y,
46 KDAXIS_Z
47 };
49 struct KDNode {
50 int axis;
51 float pt;
52 AABBox aabb;
53 float cost;
55 KDNode *left, *right;
56 int num_faces; // cause on some implementations list::size() is O(n)
57 std::list<const Face*> faces;
59 KDNode();
60 };
62 struct KDNodeGPU {
63 AABBox aabb;
64 int face_idx[32];
65 int num_faces;
66 int padding[3];
67 };
70 class Scene {
71 private:
72 mutable Face *facebuf;
73 mutable int num_faces;
75 mutable KDNodeGPU *kdbuf;
77 public:
78 std::vector<Mesh*> meshes;
79 std::vector<Material> matlib;
80 KDNode *kdtree;
82 Scene();
83 ~Scene();
85 bool add_mesh(Mesh *m);
86 int get_num_meshes() const;
87 int get_num_materials() const;
88 int get_num_faces() const;
90 Material *get_materials();
91 const Material *get_materials() const;
93 bool load(const char *fname);
94 bool load(FILE *fp);
96 const Face *get_face_buffer() const;
97 const KDNodeGPU *get_kdtree_buffer() const;
98 int get_kdtree_buffer_size() const;
100 void draw_kdtree() const;
101 bool build_kdtree();
102 };
104 enum {
105 ACCEL_PARAM_MAX_TREE_DEPTH,
106 ACCEL_PARAM_MAX_NODE_ITEMS,
107 ACCEL_PARAM_COST_TRAVERSE,
108 ACCEL_PARAM_COST_INTERSECT,
110 NUM_ACCEL_PARAMS
111 };
113 void set_accel_param(int p, int v);
115 int kdtree_depth(const KDNode *tree);
116 int kdtree_nodes(const KDNode *tree);
118 #endif /* MESH_H_ */