clray

view src/scene.h @ 45:8047637961a2

fixed the issue of hitting maximum vertical image sizes for large kdtrees
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 29 Aug 2010 04:20:42 +0100
parents f9eec11e5acc
children 6a30f27fa1e6
line source
1 #ifndef MESH_H_
2 #define MESH_H_
4 #include <stdio.h>
5 #include <vector>
6 #include <list>
7 #include "common.h"
9 struct Vertex {
10 float pos[4];
11 float normal[4];
12 float tex[4];
13 float padding[4];
14 };
16 struct Face {
17 Vertex v[3];
18 float normal[4];
19 int matid;
20 int padding[3];
22 bool operator ==(const Face &f) const;
23 };
25 struct Material {
26 float kd[4], ks[4];
27 float kr, kt;
28 float spow;
29 float padding;
30 };
32 struct Mesh {
33 std::vector<Face> faces;
34 int matid;
35 };
37 class AABBox {
38 public:
39 float min[4], max[4];
41 float calc_surface_area() const;
42 };
44 struct KDNode {
45 int axis;
46 AABBox aabb;
47 float cost;
49 KDNode *left, *right;
50 std::vector<int> face_idx;
52 KDNode();
53 };
55 struct KDNodeGPU {
56 AABBox aabb;
57 int face_idx[MAX_NODE_FACES];
58 int num_faces;
59 int left, right;
60 int padding;
61 };
64 class Scene {
65 private:
66 mutable Face *facebuf;
67 mutable int num_faces;
69 mutable KDNodeGPU *kdbuf;
71 public:
72 std::vector<Mesh*> meshes;
73 std::vector<Material> matlib;
74 KDNode *kdtree;
76 Scene();
77 ~Scene();
79 bool add_mesh(Mesh *m);
80 int get_num_meshes() const;
81 int get_num_faces() const;
82 int get_num_materials() const;
83 int get_num_kdnodes() const;
85 Material *get_materials();
86 const Material *get_materials() const;
88 bool load(const char *fname);
89 bool load(FILE *fp);
91 const Face *get_face_buffer() const;
92 const KDNodeGPU *get_kdtree_buffer() const;
94 void draw_kdtree() const;
95 bool build_kdtree();
96 };
98 enum {
99 ACCEL_PARAM_MAX_TREE_DEPTH,
100 ACCEL_PARAM_MAX_NODE_ITEMS,
101 ACCEL_PARAM_COST_TRAVERSE,
102 ACCEL_PARAM_COST_INTERSECT,
104 NUM_ACCEL_PARAMS
105 };
107 void set_accel_param(int p, int v);
109 int kdtree_depth(const KDNode *tree);
110 int kdtree_nodes(const KDNode *tree);
112 bool kdtree_dump(const KDNode *tree, const char *fname);
113 KDNode *kdtree_restore(const char *fname);
115 #endif /* MESH_H_ */