35#include <libFreeWRL.h>
37#include "../vrml_parser/Structs.h"
38#include "../main/headers.h"
39#include "../opengl/Frustum.h"
40#include "../opengl/Material.h"
41#include "../opengl/OpenGL_Utils.h"
42#include "Component_Shape.h"
43#include "../scenegraph/RenderFuncs.h"
44#include "../scenegraph/Polyrep.h"
46#define FW_MAXCLIPPLANES 4
50 Stack *clipplane_stack;
51 float clipplanes[4*FW_MAXCLIPPLANES];
52}* ppComponent_Rendering;
53void *Component_Rendering_constructor(){
58void Component_Rendering_init(
struct tComponent_Rendering *t){
62 t->prv = Component_Rendering_constructor();
64 ppComponent_Rendering p = (ppComponent_Rendering)t->prv;
65 p->clipplane_stack = newStack(
usehit);
68void Component_Rendering_clear(
struct tComponent_Rendering *t){
69 ppComponent_Rendering p = (ppComponent_Rendering)t->prv;
70 deleteVector(
struct X3D_Node*,p->clipplane_stack);
76void findExtentInCoord0 (
struct X3D_Node *node,
int count,
float* coord,
int dimensions) {
81 if (!coord || count < 1 || dimensions < 1)
return;
84 node->EXTENT_MAX_Z = node->EXTENT_MIN_Z = 0.0f;
86 node->EXTENT_MAX_Y = node->EXTENT_MIN_Y = 0.0f;
87 for (i=0; i<count; i++) {
88 float* point = &coord[i * dimensions];
89 if (point[0] > node->EXTENT_MAX_X) node->EXTENT_MAX_X = point[0];
90 if (point[0] < node->EXTENT_MIN_X) node->EXTENT_MIN_X = point[0];
92 if (point[1] > node->EXTENT_MAX_Y) node->EXTENT_MAX_Y = point[1];
93 if (point[1] < node->EXTENT_MIN_Y) node->EXTENT_MIN_Y = point[1];
95 if (point[2] > node->EXTENT_MAX_Z) node->EXTENT_MAX_Z = point[2];
96 if (point[2] < node->EXTENT_MIN_Z) node->EXTENT_MIN_Z = point[2];
103void findExtentInCoord(
struct X3D_Node* node,
int count,
struct SFVec3f* coord) {
104 findExtentInCoord0(node, count, (
float*)coord, 3);
108 if (!compile_poly_if_required(node, node->coord, node->fogCoord, node->color, node->normal, node->texCoord))
return;
109 CULL_FACE(node->solid)
110 render_polyrep(node);
115 if (!compile_poly_if_required(node, node->coord, node->fogCoord, node->color, node->normal, node->texCoord))
return;
116 CULL_FACE(node->solid)
117 render_polyrep(node);
123 if (!compile_poly_if_required(node, node->coord, node->fogCoord, node->color, node->normal, NULL))
return;
124 CULL_FACE(node->solid)
125 render_polyrep(node);
130 if (!compile_poly_if_required(node, node->coord, node->fogCoord, node->color, node->normal, node->texCoord))
return;
131 CULL_FACE(node->solid)
132 render_polyrep(node);
137 if (!compile_poly_if_required(node, node->coord, node->fogCoord, node->color, node->normal, node->texCoord))
return;
138 CULL_FACE(node->solid)
139 render_polyrep(node);
144 if (!compile_poly_if_required(node, node->coord, node->fogCoord, node->color, node->normal, node->texCoord))
return;
145 CULL_FACE(node->solid)
146 render_polyrep(node);
151void* set_LineRep(
void *_linerep,
struct SFVec3f *points,
struct SFVec2f *points2D,
153 int nsegments,
int *counts,
int *starts,
int *skindex)
163 linerep->point = points;
164 linerep->point2D = points2D;
165 linerep->colorRgba = colorRgba;
166 linerep->color = color;
167 linerep->fogcoord = fog;
168 linerep->skindex = skindex;
169 linerep->count = counts;
170 linerep->start = starts;
171 linerep->nsegments = nsegments;
173 for(
int i=0;i<nsegments;i++){
174 linerep->npoint += counts[i];
182void clear_LineRep(
void *_linerep){
192 FREE_IF_NZ(linerep->prev);
193 FREE_IF_NZ(linerep->next);
197#define DESIRE(whichOne,zzz) ((whichOne & zzz)==zzz)
200 if (linerep && linerep->nsegments > 0) {
201 if (linerep->color) {
202 FW_GL_COLOR_POINTER (3,GL_FLOAT,0,(
float *)linerep->color);
203 }
else if(linerep->colorRgba) {
204 FW_GL_COLOR_POINTER (4,GL_FLOAT,0,(
float *)linerep->colorRgba);
206 if (linerep->fogcoord) {
207 FW_GL_FOG_POINTER (GL_FLOAT,0,(
float*)linerep->fogcoord);
210 FW_GL_VERTEX_POINTER (3,GL_FLOAT,0,(
float *)linerep->point);
211 }
else if(linerep->point2D){
212 FW_GL_VERTEX_POINTER (2,GL_FLOAT,0,(
float *)linerep->point2D);
214 if (linerep->skindex) {
215 FW_GL_CINDEX_POINTER(GL_INT, 0, (
unsigned int*)linerep->skindex);
217 if(getAppearanceProperties()->linetype > 1){
221 linerep->prev = MALLOC(
struct SFVec3f*,linerep->npoint*3*
sizeof(
float));
222 for(
int i=1;i<linerep->npoint;i++){
223 if(linerep->point2D){
224 veccopy2f(linerep->prev[i].c,linerep->point2D[i-1].c);
225 }
else if(linerep->point){
226 veccopy3f(linerep->prev[i].c,linerep->point[i-1].c);
229 if(linerep->point2D){
230 veccopy2f(linerep->prev[0].c,linerep->point2D[0].c);
231 }
else if(linerep->point){
232 veccopy3f(linerep->prev[0].c,linerep->point[0].c);
236 if(1)
if(!linerep->next){
237 linerep->next = MALLOC(
struct SFVec3f*,linerep->npoint*3*
sizeof(
float));
240 for(
int i=0;i<linerep->npoint-1;i++){
241 if(linerep->point2D){
242 veccopy2f(linerep->next[i].c,linerep->point2D[i+1].c);
243 }
else if(linerep->point){
244 veccopy3f(linerep->next[i].c,linerep->point[i+1].c);
247 if(linerep->point2D){
248 veccopy2f(linerep->next[linerep->npoint-1].c,linerep->point2D[linerep->npoint-1].c);
249 }
else if(linerep->point){
250 veccopy3f(linerep->next[linerep->npoint-1].c,linerep->point[linerep->npoint-1].c);
257 for (
int i=0; i<linerep->nsegments; i++) {
258 for(
int j=0;j<linerep->count[i];j++) {
259 linerep->next[knext].c[0] = (float)j;
260 linerep->next[knext].c[1] = (float)linerep->count[i];
264 if(knext != linerep->npoint) printf(
"ouch in render_LineRep findexes %d points %d\n",knext,linerep->npoint);
268 s_shader_capabilities_t *me = getAppearanceProperties()->currentShaderProperties;
269 if (me->prevVertex != -1) {
270 glEnableVertexAttribArray(me->prevVertex);
271 glVertexAttribPointer(me->prevVertex, 3, GL_FLOAT, FALSE, 0, linerep->prev);
273 if (me->nextVertex != -1 && linerep->next) {
274 glEnableVertexAttribArray(me->nextVertex);
275 glVertexAttribPointer(me->nextVertex, 3, GL_FLOAT, FALSE, 0, linerep->next);
280 for (
int i=0; i<linerep->nsegments; i++) {
283 printf(
"%d %d %d\n", i, linerep->start[i], linerep->count[i]);
284 for (
int j = linerep->start[i]; j < (linerep->start[i] + linerep->count[i]); j++) {
285 struct SFVec3f pp = linerep->point[j];
286 int skindex = linerep->skindex[j];
287 printf(
"[% d(% f % f % f) % d]\n", j, pp.c[0], pp.c[1], pp.c[2], skindex);
290 sendArraysToGPU (GL_LINE_STRIP, linerep->start[i], linerep->count[i]);
331 GLfloat defcolorRGBA[] = {1.0f, 1.0f, 1.0f,1.0f};
335 colorIndShort = NULL;
339 node->__segCount = 0;
340 clear_LineRep(node->_intern);
353 dtmp = getCoordinate (node->coord,
"IndexedLineSet");
358 findExtentInCoord(X3D_NODE(node), npoints, points);
363 if (node->coordIndex.n == 0)
return;
366 maxCoordFound = -1000;
369 for (i=0; i<node->coordIndex.n; i++) {
371 if (node->coordIndex.p[i] < -1) {
372 ConsoleMessage (
"IndexedLineSet - coordIndex less than 0 at %d\n",i);
377 if (node->coordIndex.p[i] == -1) {
378 if (i!=((node->coordIndex.n)-1)) nSegments++;
382 if (node->coordIndex.p[i] > maxCoordFound) maxCoordFound = node->coordIndex.p[i];
384 if (maxCoordFound > npoints) {
418 FREE_IF_NZ (node->__vertArr);
419 node->__vertArr = MALLOC (
int *,
sizeof(
int)*(nVertices+1));
421 pt = (
int *)node->__vertArr;
425 for (vtc = 0; vtc < nVertices; vtc++) {
434 FREE_IF_NZ (node->__vertIndx);
435 FREE_IF_NZ (node->__starts);
436 node->__vertIndx = MALLOC (
int **,
sizeof(
int*)*(nSegments+2));
437 node->__starts = MALLOC (
int *,
sizeof(
int)*(nSegments+2));
440 FREE_IF_NZ (node->__vertices);
441 node->__vertices = MALLOC (
struct SFVec3f *,
sizeof(
struct SFVec3f)*(nVertices+1));
442 FREE_IF_NZ(node->__skindex);
443 node->__skindex = MALLOC(
unsigned int *,
sizeof(
unsigned int) * (nVertices + 1));
445 FREE_IF_NZ (node->__vertexCount);
446 FREE_IF_NZ (node->__counts);
447 node->__vertexCount = MALLOC (
int *,
sizeof(
int)*(nSegments+2));
448 node->__counts = MALLOC (
int *,
sizeof(
int)*(nSegments+2));
451 int *colorIndInt2 = NULL;
457 FREE_IF_NZ (node->__xcolours);
459 newcolors = (
struct SFColorRGBA *) node->__xcolours;
460 POSSIBLE_PROTO_EXPANSION(
struct X3D_Color *, node->color,cc)
463 if ((cc->_nodeType != NODE_Color) && (cc->_nodeType != NODE_ColorRGBA)) {
464 ConsoleMessage (
"make_IndexedLineSet, color node, expected %d got %d\n", NODE_Color, cc->_nodeType);
470 if (node->colorPerVertex) {
472 colorIndInt = node->coordIndex.p;
474 if ((node->colorIndex.n)>0) {
475 if ((node->colorIndex.n) < (node->coordIndex.n)) {
476 ConsoleMessage (
"IndexedLineSet - expect more colorIndexes to match coords\n");
480 colorIndInt = node->colorIndex.p;
484 colorIndInt2 = node->coordIndex.p;
489 if ((node->colorIndex.n)>0) {
490 if ((node->colorIndex.n) < (nSegments)) {
491 ConsoleMessage (
"IndexedLineSet - expect more colorIndexes to match coords\n");
495 colorIndInt = node->colorIndex.p;
499 colorIndShort = node->__vertArr;
509 FREE_IF_NZ (node->__xfog);
510 node->__xfog = MALLOC (
float *,
sizeof(
float)*(nVertices+1));
511 newfog = node->__xfog;
515 if (fc->_nodeType != NODE_FogCoordinate) {
516 ConsoleMessage (
"make_IndexedLineSet, fog node, expected %d got %d\n", NODE_FogCoordinate, fc->_nodeType);
526 indxStartPtr = (
int **)node->__vertIndx;
527 starts = (
int *)node->__starts;
530 newpoints = node->__vertices;
531 skindex = node->__skindex;
532 vertCountPtr = (
int *) node->__vertexCount;
534 counts = (
int *)node->__counts;
535 pt = (
int *)node->__vertArr;
541 int istart = 0, ip = 0;
549 for (i=0; i<node->coordIndex.n+1; i++) {
552 if (node->coordIndex.p[i] == -1 || i == (node->coordIndex.n)) {
554 *vertCountPtr = segLength;
556 counts[istart] = segLength;
560 if(i < (node->coordIndex.n)){
571 oldpoint = &points[node->coordIndex.p[i]];
572 memcpy (newpoints, oldpoint,
sizeof(
struct SFColor));
573 *skindex = node->coordIndex.p[i];
575 int index = node->coordIndex.p[i];
577 newfog[ip] = fog[index];
579 newfog[ip] = fog[nfog-1];
584 if (node->colorPerVertex) {
585 if (colorIndInt != NULL)
586 curcolor = colorIndInt[ivertex];
588 curcolor = colorIndInt2[ivertex];
591 if (colorIndInt != NULL)
592 curcolor = colorIndInt[ipoly];
598 }
while(curcolor == -1 && curcolor < cc->color.n);
599 if ((curcolor < 0) || (curcolor >= cc->color.n)) {
600 ConsoleMessage (
"IndexedLineSet, colorIndex %d (for vertex %d or segment %d) out of range (0..%d)\n",
601 curcolor, i, ipoly, cc->color.n);
607 if (cc->_nodeType == NODE_Color) {
609 memcpy (newcolors, defcolorRGBA,
sizeof (defcolorRGBA));
610 memcpy (newcolors, &oldcolor[curcolor],
sizeof(
struct SFColor));
613 memcpy (newcolors, &oldcolor[curcolor],
sizeof(
struct SFColorRGBA));
648 node->__segCount = nSegments;
652 node->_intern = set_LineRep(node->_intern,node->__vertices,NULL,node->__xcolours,NULL,node->__xfog,node->__segCount, (
int *)node->__counts,(
int*)node->__starts,node->__skindex);
654 lr->coordinate_node = node->coord;
662 ttglobal tg = gglobal();
669 setExtent( node->EXTENT_MAX_X, node->EXTENT_MIN_X, node->EXTENT_MAX_Y,
670 node->EXTENT_MIN_Y, node->EXTENT_MAX_Z, node->EXTENT_MIN_Z,
673 render_LineRep((
struct X3D_LineRep*)node->_intern);
675static struct dataType_byteSize {
678} dataTypeSize_lookup[] = {
681 {GL_UNSIGNED_SHORT,2},
689int lookup_dataType_size(
int dataType) {
690 struct dataType_byteSize* typeSize;
694 for(index = 0;; index++) {
695 if (dataTypeSize_lookup[index].dataType < 0)
break;
696 if (dataType == dataTypeSize_lookup[index].dataType) {
697 byteSize = dataTypeSize_lookup[index].byteSize;
704void add_buffer_to_broto_context0(
void *ectx,
void* buffer) {
705 struct X3D_Proto* context = X3D_PROTO(ectx);
710 context->__GC = newVector(
struct X3D_Node*, 4);
711 __GC = context->__GC;
712 stack_push(
void*, __GC, buffer);
715void add_buffer_to_broto_context(
void *buffer) {
716 struct X3D_Proto* context = X3D_PROTO(get_executionContext());
717 add_buffer_to_broto_context0(context, buffer);
719void remove_buffer_from_broto_context(
void * buffer) {
720 struct X3D_Proto* context = X3D_PROTO(get_executionContext());
724 for (i = 0; i < vectorSize(context->__GC); i++) {
725 void* ns = vector_get(
void *, context->__GC, i);
727 vector_remove_elem(
void *, context->__GC, i);
736 struct X3D_Proto* context = X3D_PROTO(ectx);
742 for (i = 0; i < vectorSize(context->__GC); i++) {
743 void* ns = vector_get(
void*, context->__GC, i);
757struct geomBuffer* add_geomBuffer0(
void *ectx,
int buffersize,
int users) {
760 gb->address = malloc(buffersize);
761 memset(gb->address, 0, buffersize);
762 gb->byteSize = buffersize;
764 add_buffer_to_broto_context0(ectx,gb);
767struct geomBuffer* add_geomBuffer(
int buffersize,
int users) {
768 struct X3D_Proto* context = X3D_PROTO(get_executionContext());
769 return add_geomBuffer0(context, buffersize, users);
773 glGenBuffers(1, (GLuint*)&gb->VBO);
775 glBindBuffer(GL_ARRAY_BUFFER, (GLuint)gb->VBO);
776 glBufferData(GL_ARRAY_BUFFER, gb->byteSize, gb->address, GL_STATIC_DRAW);
777 glBindBuffer(GL_ARRAY_BUFFER, 0);
780void update_geomBufferSize(
struct geomBuffer* gb,
int buffersize) {
781 gb->address = realloc(gb->address,buffersize);
782 memset(gb->address, 0, buffersize);
783 gb->byteSize = buffersize;
786void remove_geomBuffer(
struct geomBuffer *gb) {
787 glDeleteBuffers(1, &gb->VBO);
788 remove_buffer_from_broto_context(gb);
789 FREE_IF_NZ(gb->address);
792void subtract_geomBufferUser(
struct geomBuffer* gb) {
794 if (gb->users < 1) remove_geomBuffer(gb);
796void add_geomBufferUser(
struct geomBuffer* gb) {
799int set_Attrib(
struct bufAccess* ba,
int dataSize,
int dataType,
int byteOffset) {
801 ba->dataSize = dataSize;
803 ba->dataType = dataType;
804 ba->byteOffset = byteOffset;
805 byteSize = ba->byteSize = ba->dataSize * lookup_dataType_size(ba->dataType);
809 return &gb->address[ba->byteOffset + index * ba->byteStride];
812void* set_PointRep(
void* _pointrep,
float* points,
int pointSize,
int npoint,
813 float* color,
int colorSize,
int ncolor,
float* fog,
int nfog)
818 if (!points || npoint == 0)
return NULL;
829 int nbyte_per_point = set_Attrib(&pointrep->attrib[0], pointSize, GL_FLOAT, 0);
831 nbyte_per_point += set_Attrib(&pointrep->attrib[1], colorSize, GL_FLOAT, nbyte_per_point);
834 nbyte_per_point += set_Attrib(&pointrep->attrib[2], 1, GL_FLOAT, nbyte_per_point);
838 for (
int i = 0; i < 3; i++) pointrep->attrib[i].byteStride = nbyte_per_point;
840 pointrep->ncoord = npoint;
841 int buffersize = nbyte_per_point * pointrep->ncoord;
842 if (!pointrep->buffer)
843 pointrep->buffer = add_geomBuffer(buffersize,1);
845 update_geomBufferSize(pointrep->buffer, buffersize);
847 struct bufAccess* ba = &pointrep->attrib[0];
848 for (
int i = 0; i < pointrep->ncoord; i++) {
849 char* target = get_Attribi(ba, gb, i);
850 memcpy(target, &points[i * pointSize], pointSize *
sizeof(
float));
854 ba = &pointrep->attrib[1];
855 for (
int i = 0; i < pointrep->ncoord; i++) {
856 char* target = get_Attribi(ba, gb, i);
857 int j = min(i, ncolor - 1);
859 memcpy(target, &color[j * colorSize], colorSize *
sizeof(
float));
864 ba = &pointrep->attrib[2];
865 for (
int i = 0; i < pointrep->ncoord; i++) {
866 char* target = get_Attribi(ba, gb, i);
867 int j = min(i, nfog - 1);
868 memcpy(target, &fog[j],
sizeof(
float));
871 set_geomBuffer(pointrep->buffer);
876 int ncolor = 0, nfog = 0, npoint = 0, colorSize = 3;
879 float* points = NULL;
880 float* colors = NULL;
887 dtmp = getCoordinate (node->coord,
"PointSet");
889 points = (
float*)dtmp->p;
891 findExtentInCoord(X3D_NODE(node), dtmp->n, dtmp->p);
893 if (dtmp->n == 0)
return;
899 POSSIBLE_PROTO_EXPANSION(
struct X3D_Color *, node->color,cc)
901 ncolor = cc->color.n;
902 colors = (
float*)cc->color.p;
903 if (cc->_nodeType == NODE_Color) {
906 else if (cc->_nodeType == NODE_ColorRGBA) {
910 ConsoleMessage(
"make_PointSet, expected %d got %d\n", NODE_Color, cc->_nodeType);
915 if (node->fogCoord) {
919 if (fc->_nodeType != NODE_FogCoordinate) {
920 ConsoleMessage (
"make_PointSet fogCoord, expected %d got %d\n", NODE_FogCoordinate, fc->_nodeType);
927 node->_intern = set_PointRep(node->_intern, points, 3, npoint, colors, colorSize, ncolor, fog, nfog);
931static GLfloat quadtris [18] = {-.5f,-.5f,0.0f, .5f,-.5f,0.0f, .5f,.5f,0.0f, .5f,.5f,0.0f, -.5f,.5f,0.0f, -.5f,-.5f,0.0f,};
932static GLfloat twotrisnorms [18] = {0.f,0.f,1.f, 0.f,0.f,1.f, 0.f,0.f,1.f, 0.f,0.f,1.f, 0.f,0.f,1.f, 0.f,0.f,1.f,};
933static GLfloat twotristex [12] = {0.f,0.f, 1.f,0.f, 1.f,1.f, 1.f,1.f, 0.f,1.f, 0.f,0.f};
936void reallyDrawOnce();
938void render_PointRep(
void* _pointrep) {
940 if (getAppearanceProperties()->pointMethod == PM_NONE) {
943 if (!gb || gb->VBO < 1)
return;
946 glBindBuffer(GL_ARRAY_BUFFER, gb->VBO);
947 struct bufAccess* ba = &pointrep->attrib[0];
948 FW_GL_VERTEX_POINTER(ba->dataSize, ba->dataType, ba->byteStride, (GLfloat*)BUFFER_OFFSET(ba->byteOffset));
952 ba = &pointrep->attrib[1];
954 FW_GL_COLOR_POINTER(ba->dataSize, ba->dataType, ba->byteStride, (GLfloat*)BUFFER_OFFSET(ba->byteOffset));
957 ba = &pointrep->attrib[2];
959 FW_GL_FOG_POINTER(ba->dataType, ba->byteStride, (GLfloat*)BUFFER_OFFSET(ba->byteOffset));
961 sendArraysToGPU(GL_POINTS, 0, pointrep->ncoord);
965 for (
int i = 0; i < pointrep->ncoord; i++) {
967 ba = &pointrep->attrib[0];
968 paddress = get_Attribi(ba, gb, i);;
969 float* ai = (
float*)paddress;
970 for (
int j = 0; j < ba->dataSize; j++) {
971 printf(
"%f ", ai[j]);
974 ba = &pointrep->attrib[1];
976 paddress = get_Attribi(ba, gb, i);;
977 float* ai = (
float*)paddress;
979 for (
int j = 0; j < ba->dataSize; j++)
980 printf(
"%f ", ai[j]);
983 ba = &pointrep->attrib[2];
985 paddress = get_Attribi(ba, gb, i);;
986 float* ai = (
float*)paddress;
988 for (
int j = 0; j < ba->dataSize; j++)
989 printf(
"%f ", ai[j]);
1002 s_shader_capabilities_t* mysp = getAppearanceProperties()->currentShaderProperties;
1004 FW_GL_VERTEX_POINTER(3, GL_FLOAT, 0, (GLfloat*)quadtris);
1005 FW_GL_NORMAL_POINTER(GL_FLOAT, 0, twotrisnorms);
1006 FW_GL_TEXCOORD_POINTER(2, GL_FLOAT, 0, twotristex, 0);
1007 glUniform1i(mysp->nTexCoordChannels, 1);
1008 glUniform1i(mysp->flipuv, 0);
1009 sendArraysToGPU(GL_TRIANGLES, 0, 6);
1010 GLint ppos = mysp->pointPosition;
1011 GLint pcpv = mysp->pointCPV;
1012 GLint pfog = mysp->pointFogCoord;
1013 int markertype = getAppearanceProperties()->markerType;
1014 markertype = markertype > 1 && markertype < 27 ? markertype : 0;
1017 printf(
"push marker texture/");
1020 for (
int i = 0; i < pointrep->ncoord; i++) {
1023 memset(point, 0, 3 *
sizeof(
float));
1027 ba = &pointrep->attrib[0];
1028 paddress = get_Attribi(ba, gb, i);;
1029 memcpy(point, paddress, ba->byteSize);
1030 glUniform3fv(ppos, 1, point);
1031 ba = &pointrep->attrib[1];
1032 if (pcpv > -1 && ba->in_use) {
1035 paddress = get_Attribi(ba, gb, i);;
1036 memcpy(
rgba, paddress, ba->byteSize);
1037 glUniform4fv(pcpv, 1,
rgba);
1039 ba = &pointrep->attrib[2];
1040 if (pfog > -1 && ba->in_use) {
1042 paddress = get_Attribi(ba, gb, i);;
1043 memcpy(&fog, paddress, ba->byteSize);
1044 glUniform1f(pfog, fog );
1052 printf(
"pop marker texture/");
1058void delete_PointRep(
void* _pointrep) {
1061 subtract_geomBufferUser(pr->buffer);
1066 ttglobal tg = gglobal();
1067 if(node->coord && node->coord->_ichange != node->coord->_change)
1069 if (node->color && node->color->_ichange != node->color->_change)
1074 if (!pointrep)
return;
1076 setExtent( node->EXTENT_MAX_X, node->EXTENT_MIN_X, node->EXTENT_MAX_Y,
1077 node->EXTENT_MIN_Y, node->EXTENT_MAX_Z, node->EXTENT_MIN_Z,
1083 render_PointRep(pointrep);
1093 ttglobal tg = gglobal();
1100 setExtent( node->EXTENT_MAX_X, node->EXTENT_MIN_X, node->EXTENT_MAX_Y,
1101 node->EXTENT_MIN_Y, node->EXTENT_MAX_Z, node->EXTENT_MIN_Z,
1104 render_LineRep((
struct X3D_LineRep*)node->_intern);
1111 struct SFVec3f *coord=0;
int ncoord;
1114 int *vertexC;
int nvertexc;
1115 int totVertexRequired;
1125 node->__segCount = 0;
1126 clear_LineRep(node->_intern);
1129 nvertexc = (node->vertexCount).n; vertexC = (node->vertexCount).p;
1130 if (nvertexc==0)
return;
1131 totVertexRequired = 0;
1137 for (c=0; c<nvertexc; c++) {
1138 totVertexRequired += vertexC[c];
1140 ConsoleMessage (
"make_LineSet, we have a vertexCount of %d, must be >=2,\n",vertexC[c]);
1147 dtmp = getCoordinate (node->coord,
"IndexedLineSet");
1152 findExtentInCoord(X3D_NODE(node), ncoord, coord);
1158 if (totVertexRequired > ncoord) {
1159 ConsoleMessage (
"make_LineSet, not enough points for vertexCount (vertices:%d points:%d)\n",
1160 totVertexRequired, ncoord);
1166 POSSIBLE_PROTO_EXPANSION(
struct X3D_Color *, node->color,cc)
1168 if ((cc->_nodeType != NODE_Color) && (cc->_nodeType != NODE_ColorRGBA)) {
1169 ConsoleMessage (
"make_LineSet, expected %d got %d\n", NODE_Color, cc->_nodeType);
1171 ncolor = cc->color.n;
1176 if (totVertexRequired > ncolor) {
1177 ConsoleMessage (
"make_LineSet, not enough colors for vertexCount (vertices:%d colors:%d)\n",
1178 totVertexRequired, ncolor);
1186 FREE_IF_NZ (node->__vertArr);
1187 node->__vertArr = MALLOC (GLuint *,
sizeof(GLuint)*(ncoord));
1188 pt = (GLint *)node->__vertArr;
1190 for (vtc = 0; vtc < ncoord; vtc++) {
1199 FREE_IF_NZ (node->__vertIndx);
1200 node->__vertIndx = MALLOC (
int **,
sizeof(
int*)*(nvertexc));
1201 FREE_IF_NZ (node->__starts);
1202 node->__starts = MALLOC (
int *,
sizeof(
int)*(nvertexc));
1205 pt = (GLint *)node->__vertArr;
1206 vpt = (
int**) node->__vertIndx;
1207 starts = (
int*) node->__starts;
1211 for (vtc=0; vtc<nvertexc; vtc++) {
1213 vpt[vtc] = (
int*) pt;
1219 starts[vtc] = starts[vtc-1] + vertexC[vtc];
1223 node->__segCount = nvertexc;
1230 fog = fogcoord->depth.p;
1232 node->_intern = set_LineRep(node->_intern,coord,NULL,NULL,NULL,fog,nvertexc,vertexC,(
int*)node->__starts,node->__vertArr);
1234 lr->coordinate_node = node->coord;
1272float *getTransformedClipPlanes(){
1273 #define tactic_one_shot 1
1274 #define tactic_point_plus_normal 2
1275 int i,nsend, tactic;
1276 double modelviewmatrix[16], meinv[16], u2me[16], me2u[16], me2ut[16], u2met[16], *M, *MIT;
1277 ppComponent_Rendering p = (ppComponent_Rendering)gglobal()->Component_Rendering.prv;
1279 nsend = min(FW_MAXCLIPPLANES,vectorSize(p->clipplane_stack));
1286 tactic = tactic_point_plus_normal;
1287 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewmatrix);
1288 matinverseAFFINE(meinv,modelviewmatrix);
1290 for(i=0;i<nsend;i++){
1294 double dplane[4],dplane2[4];
1296 uhit = vector_get(
usehit,p->clipplane_stack,i);
1298 matmultiplyAFFINE(u2me,uhit.mvm,meinv);
1299 mattranspose(u2met,u2me);
1300 matinverseAFFINE(me2u,u2me);
1301 mattranspose(me2ut,me2u);
1305 for(j=0;j<4;j++) dplane[j] = cplane->plane.c[j];
1306 if(tactic == tactic_one_shot){
1308 transformFULL4d(dplane2,dplane,MIT);
1314 double O4[4], N4[4], d;
1315 vecscaled(O4,dplane,-dplane[3]);
1318 veccopyd(N4,dplane);
1321 transformAFFINEd(O4,O4,M);
1323 transformAFFINEd(N4,N4,MIT);
1325 veccopyd(dplane2,N4);
1330 for(j=0;j<4;j++) p->clipplanes[i*4 + j] = (
float) dplane2[j];
1332 return p->clipplanes;
1334int getClipPlaneCount(){
1336 ppComponent_Rendering p = (ppComponent_Rendering)gglobal()->Component_Rendering.prv;
1337 nsend = min(FW_MAXCLIPPLANES,vectorSize(p->clipplane_stack));
1341void popShaderFlags();
1343void sib_prep_ClipPlane(
struct X3D_Node *parent,
struct X3D_Node *sibAffector){
1346 if(sibAffector && sibAffector->_nodeType == NODE_ClipPlane){
1349 if(cplane->enabled == TRUE){
1352 double modelviewmatrix[16];
1354 ppComponent_Rendering p = (ppComponent_Rendering)gglobal()->Component_Rendering.prv;
1356 shaderflags = getShaderFlags();
1357 shaderflags.base |= CLIPPLANE_SHADER;
1358 pushShaderFlags(shaderflags);
1363 uhit.node = X3D_NODE(cplane);
1364 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewmatrix);
1365 memcpy(uhit.mvm,modelviewmatrix,16*
sizeof(
double));
1366 stack_push(
usehit,p->clipplane_stack,uhit);
1383void sib_fin_ClipPlane(
struct X3D_Node *parent,
struct X3D_Node *sibAffector){
1385 if(sibAffector && sibAffector->_nodeType == NODE_ClipPlane){
1387 if(cplane->enabled == TRUE){
1388 ppComponent_Rendering p = (ppComponent_Rendering)gglobal()->Component_Rendering.prv;
1389 stack_pop(
usehit,p->clipplane_stack);