Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
polytess.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include "polytess.h"
12#include <cgraph/alloc.h>
13#include <stddef.h>
14#include <xdot/xdot.h>
16
17#ifndef _WIN32
18#define CALLBACK
19#endif
20static void CALLBACK combineCallback(double coords[3],
21 double *vertex_data[4],
22 float weight[4],
23 double **dataOut) {
24 (void)vertex_data;
25 (void)weight;
26
27 int i;
28 double *vertex = gv_calloc(6, sizeof(double));
29 vertex[0] = coords[0];
30 vertex[1] = coords[1];
31 vertex[2] = coords[2];
32 for (i = 3; i < 6; i++)
33 {
34 vertex[i] = 0;
35
36 }
37 *dataOut = vertex;
38}
39
40static void CALLBACK vertexCallback(void *vertex) {
41 glVertex3dv(vertex);
42}
43
44// OpenGL’s `gluTessCallback` function has a prototype indicating it takes a
45// `void(*)(void)`. But its documentation describes passing in various function
46// pointers with differing calling conventions. To use this API while also
47// pacifying all the various build environments, we need this rather silly
48// wrapper.
49#ifdef _MSC_VER
50// MSVC is of the (correct) opinion that casting between function pointers of
51// incompatible calling conventions is unacceptable behavior…
52#define MAKE_GLU_CALLBACK(f) f
53#else
54// …nevertheless other compilers insist we cast or they believe we have made a
55// typo
56#define MAKE_GLU_CALLBACK(f) ((void (*)(void))(f))
57#endif
58
59static GLUtesselator* Init(void)
60{
61 // Create a new tessellation object
62 GLUtesselator* tobj = gluNewTess();
63 // Set callback functions
64 gluTessCallback(tobj, GLU_TESS_VERTEX, MAKE_GLU_CALLBACK(vertexCallback));
65 gluTessCallback(tobj, GLU_TESS_BEGIN, MAKE_GLU_CALLBACK(glBegin));
66 gluTessCallback(tobj, GLU_TESS_END, MAKE_GLU_CALLBACK(glEnd));
67 gluTessCallback(tobj, GLU_TESS_COMBINE, MAKE_GLU_CALLBACK(combineCallback));
68 return tobj;
69}
70
71static void Set_Winding_Rule(GLUtesselator *tobj, GLenum winding_rule)
72{
73// Set the winding rule
74 gluTessProperty(tobj, GLU_TESS_WINDING_RULE, winding_rule);
75}
76
77static void Render_Contour2(GLUtesselator *tobj, sdot_op* p)
78{
79 double *d = gv_calloc(p->op.u.polygon.cnt * 3, sizeof(double));
80 for (size_t x = 0; x < p->op.u.polygon.cnt; x++)
81 {
82 d[x * 3] = p->op.u.polygon.pts[x].x;
83 d[x * 3 + 1] = p->op.u.polygon.pts[x].y;
84 d[x * 3 + 2] = p->op.u.polygon.pts[x].z + view->Topview->global_z;
85 }
86 for (size_t x = 0; x < p->op.u.polygon.cnt; x++) //loop through the vertices
87 {
88 gluTessVertex(tobj, &d[x * 3], &d[x * 3]); //store the vertex
89 }
90}
91
92static void Begin_Polygon(GLUtesselator *tobj)
93{
94 gluTessBeginPolygon(tobj, NULL);
95}
96static void End_Polygon(GLUtesselator *tobj)
97{
98 gluTessEndPolygon(tobj);
99}
100static void Begin_Contour(GLUtesselator *tobj)
101{
102 gluTessBeginContour(tobj);
103}
104static void End_Contour(GLUtesselator *tobj)
105{
106 gluTessEndContour(tobj);
107}
108
110{
111 if (!TP.tobj)
112 {
113 TP.tobj=Init();
114 TP.windingRule=GLU_TESS_WINDING_ODD;
115 }
122}
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
node NULL
Definition grammar.y:149
static void Render_Contour2(GLUtesselator *tobj, sdot_op *p)
Definition polytess.c:77
static void CALLBACK vertexCallback(void *vertex)
Definition polytess.c:40
#define MAKE_GLU_CALLBACK(f)
Definition polytess.c:56
tessPoly TP
Definition polytess.c:15
static void Begin_Polygon(GLUtesselator *tobj)
Definition polytess.c:92
static void Set_Winding_Rule(GLUtesselator *tobj, GLenum winding_rule)
Definition polytess.c:71
static void End_Polygon(GLUtesselator *tobj)
Definition polytess.c:96
void drawTessPolygon(sdot_op *p)
Definition polytess.c:109
static void Begin_Contour(GLUtesselator *tobj)
Definition polytess.c:100
#define CALLBACK
Definition polytess.c:18
static GLUtesselator * Init(void)
Definition polytess.c:59
static void End_Contour(GLUtesselator *tobj)
Definition polytess.c:104
static void CALLBACK combineCallback(double coords[3], double *vertex_data[4], float weight[4], double **dataOut)
Definition polytess.c:20
ViewInfo * view
Definition viewport.c:38
topview * Topview
Definition smyrnadefs.h:334
xdot_polyline polygon
Definition xdot.h:139
union _xdot_op::@126 u
xdot_op op
Definition smyrnadefs.h:95
GLenum windingRule
Definition polytess.h:17
GLUtesselator * tobj
Definition polytess.h:16
double global_z
Definition smyrnadefs.h:255
Definition legal.c:31
double x
Definition xdot.h:82
double z
Definition xdot.h:82
double y
Definition xdot.h:82
size_t cnt
Definition xdot.h:90
xdot_point * pts
Definition xdot.h:91
parsing and deparsing of xdot operations