Graphviz 14.1.2~dev.20260118.1035
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 "config.h"
12
13#include "polytess.h"
14#include <stddef.h>
15#include <util/alloc.h>
16#include <xdot/xdot.h>
18
19#ifndef _WIN32
20#define CALLBACK
21#endif
22static void CALLBACK combineCallback(double coords[3],
23 double *vertex_data[4],
24 float weight[4],
25 double **dataOut) {
26 (void)vertex_data;
27 (void)weight;
28
29 int i;
30 double *vertex = gv_calloc(6, sizeof(double));
31 vertex[0] = coords[0];
32 vertex[1] = coords[1];
33 vertex[2] = coords[2];
34 for (i = 3; i < 6; i++)
35 {
36 vertex[i] = 0;
37
38 }
39 *dataOut = vertex;
40}
41
42static void CALLBACK vertexCallback(void *vertex) {
43 glVertex3dv(vertex);
44}
45
46// OpenGL’s `gluTessCallback` function has a prototype indicating it takes a
47// `void(*)(void)`. But its documentation describes passing in various function
48// pointers with differing calling conventions. To use this API while also
49// pacifying all the various build environments, we need this rather silly
50// wrapper.
51#ifdef _MSC_VER
52// MSVC is of the (correct) opinion that casting between function pointers of
53// incompatible calling conventions is unacceptable behavior…
54#define MAKE_GLU_CALLBACK(f) f
55#else
56// …nevertheless other compilers insist we cast or they believe we have made a
57// typo
58#define MAKE_GLU_CALLBACK(f) ((void (*)(void))(f))
59#endif
60
61static GLUtesselator* Init(void)
62{
63 // Create a new tessellation object
64 GLUtesselator* tobj = gluNewTess();
65 // Set callback functions
66 gluTessCallback(tobj, GLU_TESS_VERTEX, MAKE_GLU_CALLBACK(vertexCallback));
67 gluTessCallback(tobj, GLU_TESS_BEGIN, MAKE_GLU_CALLBACK(glBegin));
68 gluTessCallback(tobj, GLU_TESS_END, MAKE_GLU_CALLBACK(glEnd));
69 gluTessCallback(tobj, GLU_TESS_COMBINE, MAKE_GLU_CALLBACK(combineCallback));
70 return tobj;
71}
72
73static void Set_Winding_Rule(GLUtesselator *tobj, GLenum winding_rule)
74{
75// Set the winding rule
76 gluTessProperty(tobj, GLU_TESS_WINDING_RULE, winding_rule);
77}
78
79static void Render_Contour2(GLUtesselator *tobj, sdot_op* p)
80{
81 double *d = gv_calloc(p->op.u.polygon.cnt * 3, sizeof(double));
82 for (size_t x = 0; x < p->op.u.polygon.cnt; x++)
83 {
84 d[x * 3] = p->op.u.polygon.pts[x].x;
85 d[x * 3 + 1] = p->op.u.polygon.pts[x].y;
86 d[x * 3 + 2] = p->op.u.polygon.pts[x].z + view->Topview->global_z;
87 }
88 for (size_t x = 0; x < p->op.u.polygon.cnt; x++) //loop through the vertices
89 {
90 gluTessVertex(tobj, &d[x * 3], &d[x * 3]); //store the vertex
91 }
92}
93
94static void Begin_Polygon(GLUtesselator *tobj)
95{
96 gluTessBeginPolygon(tobj, NULL);
97}
98static void End_Polygon(GLUtesselator *tobj)
99{
100 gluTessEndPolygon(tobj);
101}
102static void Begin_Contour(GLUtesselator *tobj)
103{
104 gluTessBeginContour(tobj);
105}
106static void End_Contour(GLUtesselator *tobj)
107{
108 gluTessEndContour(tobj);
109}
110
112{
113 if (!TP.tobj)
114 {
115 TP.tobj=Init();
116 TP.windingRule=GLU_TESS_WINDING_ODD;
117 }
124}
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:181
static void Render_Contour2(GLUtesselator *tobj, sdot_op *p)
Definition polytess.c:79
static void CALLBACK vertexCallback(void *vertex)
Definition polytess.c:42
#define MAKE_GLU_CALLBACK(f)
Definition polytess.c:58
tessPoly TP
Definition polytess.c:17
static void Begin_Polygon(GLUtesselator *tobj)
Definition polytess.c:94
static void Set_Winding_Rule(GLUtesselator *tobj, GLenum winding_rule)
Definition polytess.c:73
static void End_Polygon(GLUtesselator *tobj)
Definition polytess.c:98
void drawTessPolygon(sdot_op *p)
Definition polytess.c:111
static void Begin_Contour(GLUtesselator *tobj)
Definition polytess.c:102
#define CALLBACK
Definition polytess.c:20
static GLUtesselator * Init(void)
Definition polytess.c:61
static void End_Contour(GLUtesselator *tobj)
Definition polytess.c:106
static void CALLBACK combineCallback(double coords[3], double *vertex_data[4], float weight[4], double **dataOut)
Definition polytess.c:22
ViewInfo * view
Definition viewport.c:40
topview * Topview
Definition smyrnadefs.h:305
union _xdot_op::@106 u
xdot_polyline polygon
Definition xdot.h:150
xdot_op op
Definition smyrnadefs.h:82
GLenum windingRule
Definition polytess.h:17
GLUtesselator * tobj
Definition polytess.h:16
double global_z
Definition smyrnadefs.h:231
Definition legal.c:34
double x
Definition xdot.h:79
double z
Definition xdot.h:79
double y
Definition xdot.h:79
size_t cnt
Definition xdot.h:87
xdot_point * pts
Definition xdot.h:88
parsing and deparsing of xdot operations