FreeWRL / FreeX3D 4.3.0
Polyrep.h
1/*
2
3
4Polyrep ???
5
6*/
7
8/****************************************************************************
9 This file is part of the FreeWRL/FreeX3D Distribution.
10
11 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12
13 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25****************************************************************************/
26
27
28#include <config.h>
29#include <display.h>
30#include <internal.h>
31
32#include <libFreeWRL.h>
33
34#include "../vrml_parser/Structs.h"
35#include "../main/headers.h"
36#include "LinearAlgebra.h"
37
38#define BUFFER_OFFSET(i) ((char *)NULL + (i))
39
40//buffer list is per context (Scene, Proto, Inline)
41// ..so buffer can be shared between shape nodes in same context,
42//..unloaded when inline or scene unloaded or users = 0
43struct geomBuffer {
44 char* address; //owns it
45 char* cgltf_buffer; //used during parsing for detecting shared buffer
46 int byteSize;
47 int loaded; //FALSE until data copied in, even if allocated, alows delay-loading
48 int users; //when falls to zero, free()
49 GLuint VBO;
50};
51//in gltf the valance isn't accessor 1:1 bufferView
52// in freewrl we assume 1:1 and deep copy the bufferAccess for each GeomRep when m:1
53struct bufAccess {
54 int in_use; //1= have attribute (fog, UV, ColorPerVertex) 0= don't have.
55 //untyped access, like gltf bufferView
56 int byteOffset; //multiple arrays and even multiple shapes can share same blob buffer.
57 int byteStride; //position, normal, color-per-vertex, UV[4] can be per-vertex, index by itself
58 //typed access, like gltf accessor
59 int dataType; // componentType GL_BYTE 5120, GL_SHORT, GL_INT, GL_FLOAT. GL_DOUBLE.
60 int dataSize; // type 1-SCALAR, 2-VEC2 3 VEC3 4 VEC4 9 MAT3 16 MAT4
61 int byteSize; // = sizeof(dataType) x dataSize
62};
63
64
65
66// structs that go in void * node->_intern field
67// basically a dumping ground for node-specific states that don't belong in public fields
69 //abstract type for all that go in _intern
70 int itype; //0 PointRep 1 LineRep 2 PolyRep 3 MeshRep 4 TextureRep 5 LightRep 6 ProjectorRep 7 SoundRep 8 MidiRep 9 HanimRep
71};
72
74 int itype; //9 HanimRep
75 int* PVI; //skinning per-vertex joint matrix index, 4 per vertex
76 float* PVW; //skinning per-vertex weight applied to joint matrix, 4 per vertex
77 int NV; //number of vertices in skin
78 GLuint bo_PVI; //GPU skinning, buffer object bo_
79 GLuint bo_PVW;
80 Stack* JT; //joint transforms
81 GLuint bo_JT;
82 float* jt32;
83 GLuint bo_JN;
84 float* jn32;
85 int have_skin;
86 int joint_changed;
87 int make_joint_list; //if no humanoid.joints.p make one
88 int PVset;
89 //GPU joint displacer method: packed displace array with int displace[dindex[cindex]]
90 int joint_displacer_count;
91 int dindex_done;
92 Stack* dindex_lookup;
93 GLuint bo_dindex;
94 int* dindex; //dindex[NV] per-original-vertex index into packed displace array
95 GLuint bo_displace;
96 float* displace; //[4*(ND+1)] - 0th is 0,0,0
97 int ND; //number of unique-vertex displacements
98 int render_count; //skin GL_LINES shape bombed on 1,2 rennder, but not 3+
99};
101 int itype; //0 PointRep 1 LineRep 2 PolyRep 3 MeshRep 4 TextureRep
102 int decoded; //0=still .jgp/.png/.gif 1=parsed into rectangular rgba texture blob
103 int byteOffset; //multiple arrays and even multiple shapes can share same blob buffer.
104 int byteSize; //..and the image stored is compressed png/jpeg etc blob, needs to be parsed to get rectangular image
105 char* mimeType; //"image/png", "image/jpg" etc so correct image parser can be applied
106 //shared buffer approach:
107 // indirection to sharable, delay-loadable buffer
108 struct geomBuffer* buffer;
109 //struct bufAccess image; //
110};
111void* set_TextureRep(void* _texrep);
112
114 //abstract type for geometry node types node. _intern field
115 int itype; //0 PointRep 1 LineRep 2 PolyRep 3 MeshRep 4 TextureRep
116 int mode; //0 Points 1-3 lines 4-6 mesh
117// void* ectx; //execution context (scene, proto, inline) - where to store shareable buffers
118};
119
121 // used for node._intern field by linetype geometry nodes
122 // will hold commmon GL_LINE_STRIP parameters from
123 // PolyLine2D, Arc2D, ArcClose2D_LINE, Circle2D
124 // LineSet, IndexedLineSet
125 // analogous to PolyRep for triangle nodes
126 // motivation for this extra level of common abstraction for lines:
127 // - Appearance.LineProperties.linetype - dashed lines require extra prev,next vertices and other info sent
128 // (glLineStipple not working with our shader system)
129 int itype; //0 PointRep 1 LineRep 2 PolyRep 3 MeshRep 4 TextureRep
130 int mode; //0 Points 1-3 lines 4-6 mesh: 1 LINES 2 LINE_LOOP 3 LINE_STRIP
131 void* ectx; //execution context (scene, proto, inline)
132 int npoint;
133 struct SFVec3f* point;
134 struct SFVec2f* point2D;
135 struct SFVec3f* prev;
136 struct SFVec3f* next;
137 int nsegments;
138 int* start;
139 int* count;
140 float* fogcoord;
141 struct SFColor* color;
142 struct SFColorRGBA* colorRgba;
143 int* skindex; //LineSet, IndexedLineSet only, which have coord field which could be humanod.coord Coordinate node
144 void* coordinate_node; //we need to know when we are skinning, populate during make_polyrep for testing against a stack push of humanoid.coord
145};
146
148 //abstract type for geometry node types node. _intern field where geometry can be textured
149 int itype; //0 PointRep 1 LineRep 2 PolyRep 3 MeshRep 4 TextureRep
150 int mode; //0 Points 1-3 lines 4-6 mesh
151 char* map[4]; //strings from TextureCoordinate.mapping field, or null if .mapping is null or type-of-geometry node had no explicit TextureCoordinate field
152// void* ectx; //execution context (scene, proto, inline) - where to store shareable buffers
153};
154
156 // node._intern field for Polypoint2D and PointSet geometry nodes
157 int itype; //0 PointRep 1 LineRep 2 PolyRep 3 MeshRep 4 TextureRep
158 int mode; //0 Points 1-3 lines 4-6 mesh
159 //for pointrep the map field applies to splat multitexture from appearance.texture field
160 char* map[4]; //strings from TextureCoordinate.mapping field, or null if .mapping is null or type-of-geometry node had no explicit TextureCoordinate field
161 int ncoord;
162 //shared buffer approach:
163 // indirection to sharable, delay-loadable buffer
164 struct geomBuffer* buffer;
165 struct bufAccess attrib[3]; //vertex coord, color per vertex, fog per vertex
166 void* coordinate_node; //we need to know when we are skinning, populate during make_polyrep for testing against a stack push of humanoid.coord
167};
168int lookup_dataType_size(int dataType); //GL_FLOAT -> 4 GL_SHORT - 2
169int set_Attrib(struct bufAccess* ba, int dataSize, int dataType, int byteOffset);
170char* get_Attribi(struct bufAccess* ba, struct geomBuffer* gb, int index);
171struct geomBuffer* add_geomBuffer(int buffersize, int users);
172struct geomBuffer* add_geomBuffer0(void* ectx, int buffersize, int users);
173void set_geomBuffer(struct geomBuffer* gb);
174void update_geomBufferSize(struct geomBuffer* gb, int buffersize);
175void remove_geomBuffer(struct geomBuffer* gb);
176void subtract_geomBufferUser(struct geomBuffer* gb);
177void add_geomBufferUser(struct geomBuffer* gb);
178struct geomBuffer* find_buffer_in_broto_context_from_cgltf_buffer(void* ectx, void* cgltf_buffer);
179void* set_PointRep(void* _pointrep, float* points, int pointSize, int npoint,
180 float* color, int colorSize, int ncolor, float* fog, int nfog);
181void render_PointRep(void* pointrep);
182void delete_PointRep(void* pointrep);
183
185 //MeshRep node._intern for BufferGeometry node used by gltf_loader to load generic geometry via Inline url .gltf or .glb
186 int itype; //0 PointRep 1 LineRep 2 PolyRep 3 MeshRep 4 TextureRep
187 int mode; //0 Points 1-3 lines 4-6 mesh
188 char* map[4]; //strings from TextureCoordinate.mapping field, or null if .mapping is null or type-of-geometry node had no explicit TextureCoordinate field
189 int ncoord;
190 int nuv; //number of texture coordinate channels
191 int flipuv; // 0=uvs are y-up (x3d default), 1=uvs are y-down (gltf)
192 //shared buffer approach:
193 // indirection to sharable, delay-loadable buffer
194 struct geomBuffer* buffer;
195 struct bufAccess attrib[8]; //vertex coord, color per vertex, fog per vertex, normal per vertex, UV per vertex (up to nuv=4)
196 int nindex;
197 struct bufAccess index;
198};
199void* set_MeshRep(void* _meshrep);
200void render_MeshRep(void* meshrep);
201void delete_MeshRep(void* meshrep);
202void delete_LightRep(void* _lightrep);
203void delete_HanimRep(void* _hanimrep);
204
205/* Internal representation of IndexedFaceSet, Text, Extrusion & ElevationGrid:
206 * set of triangles.
207 * done so that we get rid of concave polygons etc.
208 */
209struct X3D_PolyRep { /* Currently a bit wasteful, because copying */
210 int itype; //0 PointRep 1 LineRep 2 PolyRep 3 MeshRep 4 TextureRep
211 int mode; //0 Points 1-3 lines 4-6 mesh: 4 TRIANGLES 5 TRIANGLE_STRIP 6 TRIANGLE_FAN
212 char* map[4]; //strings from TextureCoordinate.mapping field, or null if .mapping is null or type-of-geometry node had no explicit TextureCoordinate field
213 void* ectx; //execution context (scene, proto, inline)
214 int irep_change;
215 int ccw; /* ccw field for single faced structures */
216 int ntri; /* number of triangles */
217 int streamed; /* is this done the streaming pass? */
218
219 /* indicies for arrays. OpenGL ES 2.0 - unsigned short for the DrawArrays call */
220 GLuint* cindex; /* triples (per triangle) */
221 GLuint* colindex; /* triples (per triangle) */
222 GLuint* norindex;
223 GLuint* tcindex; /* triples or null */
224 GLuint* tri_indices;
225 GLuint* wire_indices;
226 GLuint* oindex; //original coordinate indexes before streaming
227
228 float* actualCoord; /* triples (per point) */
229 float* actualFog; /* float (per point) */
230 float* color; /* triples or null */
231 float* normal; /* triples or null */
232 float* flat_normal; /*triples or null*/
233 int last_normal_type; /* 0=regular 1=flat last normal type we put in the vbo normal buffer */
234 int last_index_type; /* 0=regular 1=wire last vertex index type we put in the vbo index buffer */
235 float* GeneratedTexCoords[4]; /* triples (per triangle) of texture coords if there is no texCoord node */
236 int ntexdim[4]; /* number of texture coordinate dimensions, normally 2 xy, 3 xyz, 4 xyzw */
237 int ntcoord; /* number of multitextureCoordinates */
238 int tcoordtype; /* type of texture coord node - is this a NODE_TextureCoordGenerator... */
239 int texgentype; /* if we do have a TextureCoordinateGenerator, what "TCGT_XXX" type is it? */
240 GLfloat minVals[3]; /* for collision and default texture coord generation */
241 GLfloat maxVals[3]; /* for collision and default texture coord generation */
242 int isRGBAcolorNode; /* color was originally an RGBA, DO NOT re-write if transparency changes */
243 GLuint VBO_buffers[VBO_COUNT]; /* VBO indexen */
244 void* coordinate_node; //we need to know when we are skinning, populate during make_polyrep for testing against a stack push of humanoid.coord
245};
246void findExtentInCoord0(struct X3D_Node* node, int count, float* coord, int dimensions);
247
248/* transformed ray */
249//extern struct point_XYZ t_r1;
250//extern struct point_XYZ t_r2;
251//extern struct point_XYZ t_r3;
252
253struct facepar {
254int OK;
255int start;
256int end;
257float normal[3];
258float color[3];
259float colorRGBA[3];
260};
261
262int count_IFS_faces(int cin, struct Multi_Int32 *coordIndex, struct facepar *faceok);
263
264int
265IFS_face_normals(struct SFVec3f *facenormals, //struct point_XYZ *facenormals,
266 struct facepar *faceok,
267 int *pointfaces,
268 int faces,
269 int npoints,
270 int cin,
271 struct SFVec3f *points,
272 struct Multi_Int32 *coordIndex,
273 int ccw);
274
275void
276IFS_check_normal(struct SFVec3f *facenormals, //struct point_XYZ *facenormals,
277 int this_face,
278 struct SFVec3f *points,
279 int base,
280 struct Multi_Int32 *coordIndex,
281 int ccw);
282
283void
284add_to_face(int point,
285 int face,
286 int *pointfaces);
287
288void
289Elev_Tri(int vertex_ind,
290 int this_face,
291 int A,
292 int D,
293 int E,
294 int NONORMALS,
295 struct X3D_PolyRep *this_Elev,
296 struct SFVec3f *facenormals, //struct point_XYZ *facenormals,
297 int *pointfaces,
298 int ccw);
299
300void
301Extru_tex(int vertex_ind,
302 int tci_ct,
303 int A,
304 int B,
305 int C,
306 GLuint *tcindex,
307 int ccw,
308 int tcindexsize);
309
310void Extru_ST_map(
311 int triind_start,
312 int start,
313 int end,
314 float *Vals,
315 int nsec,
316 GLuint *tcindex,
317 GLuint *cindex,
318 float *GeneratedTexCoords,
319 int tcoordsize);
320
321void
322Extru_check_normal(struct SFVec3f *facenormals, //struct point_XYZ *facenormals,
323 int this_face,
324 int dire,
325 struct X3D_PolyRep *rep_,
326 int ccw);
327
328void
329do_color_normal_reset(void);
330
331void
332do_glNormal3fv(struct SFVec3f *dest, GLfloat *param);
333
334void stream_polyrep(void *node, void *coord, void *fogCoord, void *color, void *normal, struct X3D_TextureCoordinate *texCoord);
335void compile_polyrep(void *node, void *coord, void *fogCoord, void *color, void *normal, struct X3D_TextureCoordinate *texCoord);
336
338 float dist;
339 float p[3];
340 float normal[3];
341 float texcoord[3];
342};
343int intersect_polyrep2(struct X3D_Node *node, float *p1, float *p2, Stack *intersection_stack);
344void render_ray_polyrep(void *node);