forked from go-gl-legacy/glu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback.go
177 lines (144 loc) · 5.1 KB
/
callback.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright 2012 The go-gl Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package glu
//#include "callback.h"
import "C"
import "github.com/go-gl/gl"
import "unsafe"
// ===========================================================================
type TessBeginHandler func(tessType gl.GLenum, polygonData interface{})
//export goTessBeginData
func goTessBeginData(tessType C.GLenum, tessPtr unsafe.Pointer) {
var tess *Tesselator = (*Tesselator)(tessPtr)
if tess == nil || tess.beginData == nil {
return
}
tess.beginData(gl.GLenum(tessType), tess.polyData)
}
// ===========================================================================
type TessVertexHandler func(vertexData interface{}, polygonData interface{})
//export goTessVertexData
func goTessVertexData(vertexDataPtr, tessPtr unsafe.Pointer) {
var tess *Tesselator = (*Tesselator)(tessPtr)
if tess == nil || tess.vertexData == nil {
return
}
var wrapper *vertexDataWrapper = (*vertexDataWrapper)(vertexDataPtr)
tess.vertexData(wrapper.data, tess.polyData)
}
// ===========================================================================
type TessEndHandler func(polygonData interface{})
//export goTessEndData
func goTessEndData(tessPtr unsafe.Pointer) {
var tess *Tesselator = (*Tesselator)(tessPtr)
if tess == nil || tess.endData == nil {
return
}
tess.endData(tess.polyData)
}
// ===========================================================================
type TessErrorHandler func(errno gl.GLenum, polygonData interface{})
//export goTessErrorData
func goTessErrorData(errno C.GLenum, tessPtr unsafe.Pointer) {
var tess *Tesselator = (*Tesselator)(tessPtr)
if tess == nil || tess.errorData == nil {
return
}
tess.errorData(gl.GLenum(errno), tess.polyData)
}
// ===========================================================================
type TessEdgeFlagHandler func(flag bool, polygonData interface{})
//export goTessEdgeFlagData
func goTessEdgeFlagData(flag C.GLboolean, tessPtr unsafe.Pointer) {
var tess *Tesselator = (*Tesselator)(tessPtr)
if tess == nil || tess.edgeFlagData == nil {
return
}
var goFlag bool
if C.GLboolean(0) == flag {
goFlag = false
} else {
goFlag = true
}
tess.edgeFlagData(goFlag, tess.polyData)
}
// ===========================================================================
type TessCombineHandler func(coords [3]float64,
vertexData [4]interface{},
weight [4]float32,
polygonData interface{}) (outData interface{})
//export goTessCombineData
func goTessCombineData(coords, vertexData, weight, outData, tessPtr unsafe.Pointer) {
var tess *Tesselator = (*Tesselator)(tessPtr)
if tess == nil || tess.combineData == nil {
return
}
var _coords *[3]float64 = (*[3]float64)(coords)
var _weight *[4]float32 = (*[4]float32)(weight)
var wrappers *[4]*vertexDataWrapper = (*[4]*vertexDataWrapper)(vertexData)
var _vertexData [4]interface{}
for i, wrapper := range *wrappers {
// Work around for https://bugs.freedesktop.org/show_bug.cgi?id=51641
// According to documentation, all vertex pointers should be valid.
if wrapper == nil {
_vertexData[i] = _vertexData[0]
} else {
_vertexData[i] = wrapper.data
}
}
out := tess.combineData(*_coords, _vertexData, *_weight, tess.polyData)
outWrapper := &vertexDataWrapper{out}
tess.vertData = append(tess.vertData, outWrapper)
_outData := (**vertexDataWrapper)(outData)
*_outData = outWrapper
}
// =============================================================================
// Sets the callback for TESS_BEGIN_DATA.
func (tess *Tesselator) SetBeginCallback(f TessBeginHandler) {
if tess.tess == nil {
panic("Uninitialised Tesselator. @see glu.NewTess.")
}
tess.beginData = f
C.setGluTessCallback(tess.tess, C.GLenum(TESS_BEGIN_DATA))
}
// Sets the callback for TESS_VERTEX_DATA.
func (tess *Tesselator) SetVertexCallback(f TessVertexHandler) {
if tess.tess == nil {
panic("Uninitialised Tesselator. @see glu.NewTess.")
}
tess.vertexData = f
C.setGluTessCallback(tess.tess, C.GLenum(TESS_VERTEX_DATA))
}
// Sets the callback for TESS_END_DATA.
func (tess *Tesselator) SetEndCallback(f TessEndHandler) {
if tess.tess == nil {
panic("Uninitialised Tesselator. @see glu.NewTess.")
}
tess.endData = f
C.setGluTessCallback(tess.tess, C.GLenum(TESS_END_DATA))
}
// Sets the callback for TESS_ERROR_DATA.
func (tess *Tesselator) SetErrorCallback(f TessErrorHandler) {
if tess.tess == nil {
panic("Uninitialised Tesselator. @see glu.NewTess.")
}
tess.errorData = f
C.setGluTessCallback(tess.tess, C.GLenum(TESS_ERROR_DATA))
}
// Sets the callback for TESS_EDGE_FLAG_DATA.
func (tess *Tesselator) SetEdgeFlagCallback(f TessEdgeFlagHandler) {
if tess.tess == nil {
panic("Uninitialised Tesselator. @see glu.NewTess.")
}
tess.edgeFlagData = f
C.setGluTessCallback(tess.tess, C.GLenum(TESS_EDGE_FLAG_DATA))
}
// Sets the callback for TESS_COMBINE_DATA.
func (tess *Tesselator) SetCombineCallback(f TessCombineHandler) {
if tess.tess == nil {
panic("Uninitialised Tesselator. @see glu.NewTess.")
}
tess.combineData = f
C.setGluTessCallback(tess.tess, C.GLenum(TESS_COMBINE_DATA))
}