1 | #ifndef __VERTEXDATA_H__
|
---|
2 | #define __VERTEXDATA_H__
|
---|
3 |
|
---|
4 | namespace Geometry
|
---|
5 | {
|
---|
6 | class VertexData
|
---|
7 | {
|
---|
8 | private:
|
---|
9 | unsigned int numverts;
|
---|
10 | public:
|
---|
11 | VertexData(unsigned int numv):numverts(numv){}
|
---|
12 | virtual ~VertexData(void){}
|
---|
13 |
|
---|
14 | virtual void Begin(void)=0;
|
---|
15 | virtual void SetVertexCoord(unsigned int i, float x, float y, float z)=0;
|
---|
16 | virtual void SetVertexNormal(unsigned int i, float x, float y, float z)=0;
|
---|
17 | virtual void SetVertexTexCoord(unsigned int i, float x, float y)=0;
|
---|
18 | virtual void End(void)=0;
|
---|
19 |
|
---|
20 | virtual void GetVertexCoord(unsigned int i, float &x, float &y, float &z) const = 0;
|
---|
21 | virtual void GetVertexNormal(unsigned int i, float &x, float &y, float &z) const = 0;
|
---|
22 | virtual void GetVertexTexCoord(unsigned int i, float &x, float &y) const =0;
|
---|
23 |
|
---|
24 | unsigned int GetNumVertices(void) const { return numverts; }
|
---|
25 | };
|
---|
26 |
|
---|
27 | class IndexData
|
---|
28 | {
|
---|
29 | private:
|
---|
30 | unsigned int numinds, numvalidinds;
|
---|
31 | public:
|
---|
32 | IndexData(unsigned int numi):numinds(numi),numvalidinds(numi){}
|
---|
33 | virtual ~IndexData(void){}
|
---|
34 |
|
---|
35 | virtual void Begin(void)=0;
|
---|
36 | virtual void SetIndex(unsigned int i, unsigned int index)=0;
|
---|
37 | virtual void End(void)=0;
|
---|
38 |
|
---|
39 | virtual unsigned int GetIndex(unsigned int) const =0;
|
---|
40 | unsigned int GetNumMaxIndices(void) const { return numinds; }
|
---|
41 | unsigned int GetNumValidIndices(void) const { return numvalidinds; }
|
---|
42 | void SetNumValidIndices(unsigned int valid){ numvalidinds=valid; }
|
---|
43 | };
|
---|
44 |
|
---|
45 | class MultiIndexData
|
---|
46 | {
|
---|
47 | private:
|
---|
48 | unsigned int num_prims, num_total_inds, *num_max_inds, *num_valid_inds;
|
---|
49 | public:
|
---|
50 | MultiIndexData(unsigned int numprims, unsigned int *maxinds){
|
---|
51 | num_prims=numprims;
|
---|
52 | num_total_inds=0;
|
---|
53 | num_max_inds=new unsigned int[numprims];
|
---|
54 | num_valid_inds=new unsigned int[numprims];
|
---|
55 | for (unsigned int i=0; i<numprims; i++)
|
---|
56 | {
|
---|
57 | num_max_inds[i]=num_valid_inds[i]=maxinds[i];
|
---|
58 | num_total_inds += maxinds[i];
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | ~MultiIndexData(void){
|
---|
63 | delete[] num_max_inds;
|
---|
64 | delete[] num_valid_inds;
|
---|
65 | }
|
---|
66 |
|
---|
67 | virtual void Begin(void)=0;
|
---|
68 | virtual void SetIndex(unsigned int iprim, unsigned int i, unsigned int index)=0;
|
---|
69 | virtual void End(void)=0;
|
---|
70 |
|
---|
71 | virtual unsigned int GetIndex(unsigned int iprim, unsigned int index) const =0;
|
---|
72 | unsigned int GetNumMaxIndices(unsigned int iprim) const { return num_max_inds[iprim]; }
|
---|
73 | unsigned int GetNumValidIndices(unsigned int iprim) const { return num_valid_inds[iprim]; }
|
---|
74 | void SetNumValidIndices(unsigned int iprim, unsigned int valid){ num_valid_inds[iprim]=valid; }
|
---|
75 | unsigned int GetNumPrims(void) const { return num_prims; }
|
---|
76 | };
|
---|
77 |
|
---|
78 | typedef VertexData* CreateVertexDataFunc(unsigned int numv);
|
---|
79 | typedef CreateVertexDataFunc* CREATEVERTEXDATAFUNC;
|
---|
80 | typedef IndexData* CreateIndexDataFunc(unsigned int numi);
|
---|
81 | typedef CreateIndexDataFunc* CREATEINDEXDATAFUNC;
|
---|
82 | typedef MultiIndexData* CreateMultiIndexDataFunc(unsigned int numprims, unsigned int *numi);
|
---|
83 | typedef CreateMultiIndexDataFunc* CREATEMULTIINDEXDATAFUNC;
|
---|
84 |
|
---|
85 | class DefaultVertexData : public VertexData
|
---|
86 | {
|
---|
87 | private:
|
---|
88 | float *v, *n, *t;
|
---|
89 | public:
|
---|
90 | DefaultVertexData(unsigned int numv);
|
---|
91 | ~DefaultVertexData(void);
|
---|
92 |
|
---|
93 | virtual void Begin(void){}
|
---|
94 | virtual void SetVertexCoord(unsigned int i, float x, float y, float z){
|
---|
95 | v[i*3+0]=x; v[i*3+1]=y; v[i*3+2]=z; }
|
---|
96 | virtual void SetVertexNormal(unsigned int i, float x, float y, float z){
|
---|
97 | n[i*3+0]=x; n[i*3+1]=y; n[i*3+2]=z; }
|
---|
98 | virtual void SetVertexTexCoord(unsigned int i, float x, float y){
|
---|
99 | t[i*2+0]=x; t[i*2+1]=y; }
|
---|
100 |
|
---|
101 | virtual void End(void){}
|
---|
102 |
|
---|
103 | virtual void GetVertexCoord(unsigned int i, float &x, float &y, float &z) const {
|
---|
104 | x=v[i*3+0];
|
---|
105 | y=v[i*3+1];
|
---|
106 | z=v[i*3+2];
|
---|
107 | }
|
---|
108 | virtual void GetVertexNormal(unsigned int i, float &x, float &y, float &z) const {x=n[i*3+0]; y=n[i*3+1]; z=n[i*3+2]; }
|
---|
109 | virtual void GetVertexTexCoord(unsigned int i, float &x, float &y) const {x=t[i*2+0]; y=t[i*2+1]; }
|
---|
110 |
|
---|
111 | const float * GetVertexFloatBuffer(void) const { return v; }
|
---|
112 |
|
---|
113 | };
|
---|
114 | VertexData *DefaultVertexDataCreator(unsigned int numv);
|
---|
115 |
|
---|
116 |
|
---|
117 | class DefaultIndexData : public IndexData
|
---|
118 | {
|
---|
119 | private:
|
---|
120 | unsigned int *indices;
|
---|
121 | public:
|
---|
122 | DefaultIndexData(unsigned int numi);
|
---|
123 | ~DefaultIndexData(void);
|
---|
124 |
|
---|
125 | virtual void Begin(void){}
|
---|
126 | virtual void SetIndex(unsigned int i, unsigned int index){
|
---|
127 | indices[i] = index;
|
---|
128 | }
|
---|
129 | virtual void End(void){}
|
---|
130 |
|
---|
131 | virtual unsigned int GetIndex(unsigned int i) const {
|
---|
132 | return indices[i];
|
---|
133 | }
|
---|
134 |
|
---|
135 | };
|
---|
136 | IndexData *DefaultIndexDataCreator(unsigned int numi);
|
---|
137 |
|
---|
138 | class DefaultMultiIndexData : public MultiIndexData
|
---|
139 | {
|
---|
140 | private:
|
---|
141 | unsigned int **indices;
|
---|
142 | public:
|
---|
143 | DefaultMultiIndexData(unsigned int numprims, unsigned int *numi);
|
---|
144 | ~DefaultMultiIndexData(void);
|
---|
145 |
|
---|
146 | virtual void Begin(void){}
|
---|
147 | virtual void SetIndex(unsigned int iprim, unsigned int i, unsigned int index){
|
---|
148 | indices[iprim][i] = index;
|
---|
149 | }
|
---|
150 | virtual void End(void){}
|
---|
151 |
|
---|
152 | virtual unsigned int GetIndex(unsigned int iprim, unsigned int i) const {
|
---|
153 | return indices[iprim][i];
|
---|
154 | }
|
---|
155 |
|
---|
156 | };
|
---|
157 | MultiIndexData *DefaultMultiIndexDataCreator(unsigned int numprims, unsigned int *numi);
|
---|
158 |
|
---|
159 | }
|
---|
160 |
|
---|
161 | #endif |
---|