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 | unsigned int current_submesh;
|
---|
32 | public:
|
---|
33 | IndexData(unsigned int numi):numinds(numi),numvalidinds(numi){ current_submesh=0; }
|
---|
34 | virtual ~IndexData(void){}
|
---|
35 |
|
---|
36 | virtual void Begin(void)=0;
|
---|
37 | virtual void SetIndex(unsigned int i, unsigned int index)=0;
|
---|
38 | virtual void End(void)=0;
|
---|
39 |
|
---|
40 | virtual unsigned int GetIndex(unsigned int) const =0;
|
---|
41 | unsigned int GetNumMaxIndices(void) const { return numinds; }
|
---|
42 | unsigned int GetNumValidIndices(void) const { return numvalidinds; }
|
---|
43 | void SetNumValidIndices(unsigned int valid){ numvalidinds=valid; } // this should not be called from client applications
|
---|
44 | void SetCurrentSubmesh(unsigned int c){ current_submesh=c; } // this should not be called from client applications
|
---|
45 | unsigned int GetCurrentSubmesh(void) const { return current_submesh; }
|
---|
46 | };
|
---|
47 |
|
---|
48 | /* class MultiIndexData
|
---|
49 | {
|
---|
50 | private:
|
---|
51 | unsigned int num_prims, num_total_inds, *num_max_inds, *num_valid_inds;
|
---|
52 | public:
|
---|
53 | MultiIndexData(unsigned int numprims, unsigned int *maxinds){
|
---|
54 | num_prims=numprims;
|
---|
55 | num_total_inds=0;
|
---|
56 | num_max_inds=new unsigned int[numprims];
|
---|
57 | num_valid_inds=new unsigned int[numprims];
|
---|
58 | for (unsigned int i=0; i<numprims; i++)
|
---|
59 | {
|
---|
60 | num_max_inds[i]=num_valid_inds[i]=maxinds[i];
|
---|
61 | num_total_inds += maxinds[i];
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | ~MultiIndexData(void){
|
---|
66 | delete[] num_max_inds;
|
---|
67 | delete[] num_valid_inds;
|
---|
68 | }
|
---|
69 |
|
---|
70 | virtual void Begin(void)=0;
|
---|
71 | virtual void SetIndex(unsigned int iprim, unsigned int i, unsigned int index)=0;
|
---|
72 | virtual void End(void)=0;
|
---|
73 |
|
---|
74 | virtual unsigned int GetIndex(unsigned int iprim, unsigned int index) const =0;
|
---|
75 | unsigned int GetNumMaxIndices(unsigned int iprim) const { return num_max_inds[iprim]; }
|
---|
76 | unsigned int GetNumValidIndices(unsigned int iprim) const { return num_valid_inds[iprim]; }
|
---|
77 | void SetNumValidIndices(unsigned int iprim, unsigned int valid){ num_valid_inds[iprim]=valid; }
|
---|
78 | unsigned int GetNumPrims(void) const { return num_prims; }
|
---|
79 | };*/
|
---|
80 |
|
---|
81 | typedef VertexData* CreateVertexDataFunc(unsigned int numv);
|
---|
82 | typedef CreateVertexDataFunc* CREATEVERTEXDATAFUNC;
|
---|
83 | typedef IndexData* CreateIndexDataFunc(unsigned int numi);
|
---|
84 | typedef CreateIndexDataFunc* CREATEINDEXDATAFUNC;
|
---|
85 | /* typedef MultiIndexData* CreateMultiIndexDataFunc(unsigned int numprims, unsigned int *numi);
|
---|
86 | typedef CreateMultiIndexDataFunc* CREATEMULTIINDEXDATAFUNC;*/
|
---|
87 |
|
---|
88 | class DefaultVertexData : public VertexData
|
---|
89 | {
|
---|
90 | private:
|
---|
91 | float *v, *n, *t;
|
---|
92 | public:
|
---|
93 | DefaultVertexData(unsigned int numv);
|
---|
94 | ~DefaultVertexData(void);
|
---|
95 |
|
---|
96 | virtual void Begin(void){}
|
---|
97 | virtual void SetVertexCoord(unsigned int i, float x, float y, float z){
|
---|
98 | v[i*3+0]=x; v[i*3+1]=y; v[i*3+2]=z; }
|
---|
99 | virtual void SetVertexNormal(unsigned int i, float x, float y, float z){
|
---|
100 | n[i*3+0]=x; n[i*3+1]=y; n[i*3+2]=z; }
|
---|
101 | virtual void SetVertexTexCoord(unsigned int i, float x, float y){
|
---|
102 | t[i*2+0]=x; t[i*2+1]=y; }
|
---|
103 |
|
---|
104 | virtual void End(void){}
|
---|
105 |
|
---|
106 | virtual void GetVertexCoord(unsigned int i, float &x, float &y, float &z) const {
|
---|
107 | x=v[i*3+0];
|
---|
108 | y=v[i*3+1];
|
---|
109 | z=v[i*3+2];
|
---|
110 | }
|
---|
111 | 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]; }
|
---|
112 | virtual void GetVertexTexCoord(unsigned int i, float &x, float &y) const {x=t[i*2+0]; y=t[i*2+1]; }
|
---|
113 |
|
---|
114 | const float * GetVertexFloatBuffer(void) const { return v; }
|
---|
115 |
|
---|
116 | };
|
---|
117 | VertexData *DefaultVertexDataCreator(unsigned int numv);
|
---|
118 |
|
---|
119 |
|
---|
120 | class DefaultIndexData : public IndexData
|
---|
121 | {
|
---|
122 | private:
|
---|
123 | unsigned int *indices;
|
---|
124 | public:
|
---|
125 | DefaultIndexData(unsigned int numi);
|
---|
126 | ~DefaultIndexData(void);
|
---|
127 |
|
---|
128 | virtual void Begin(void){}
|
---|
129 | virtual void SetIndex(unsigned int i, unsigned int index){
|
---|
130 | indices[i] = index;
|
---|
131 | }
|
---|
132 | virtual void End(void){}
|
---|
133 |
|
---|
134 | virtual unsigned int GetIndex(unsigned int i) const {
|
---|
135 | return indices[i];
|
---|
136 | }
|
---|
137 |
|
---|
138 | };
|
---|
139 | IndexData *DefaultIndexDataCreator(unsigned int numi);
|
---|
140 |
|
---|
141 | /* class DefaultMultiIndexData : public MultiIndexData
|
---|
142 | {
|
---|
143 | private:
|
---|
144 | unsigned int **indices;
|
---|
145 | public:
|
---|
146 | DefaultMultiIndexData(unsigned int numprims, unsigned int *numi);
|
---|
147 | ~DefaultMultiIndexData(void);
|
---|
148 |
|
---|
149 | virtual void Begin(void){}
|
---|
150 | virtual void SetIndex(unsigned int iprim, unsigned int i, unsigned int index){
|
---|
151 | indices[iprim][i] = index;
|
---|
152 | }
|
---|
153 | virtual void End(void){}
|
---|
154 |
|
---|
155 | virtual unsigned int GetIndex(unsigned int iprim, unsigned int i) const {
|
---|
156 | return indices[iprim][i];
|
---|
157 | }
|
---|
158 |
|
---|
159 | };
|
---|
160 | MultiIndexData *DefaultMultiIndexDataCreator(unsigned int numprims, unsigned int *numi);
|
---|
161 | */
|
---|
162 | }
|
---|
163 |
|
---|
164 | #endif |
---|