Skip to content

Commit 91c6e3d

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
feat: extract #define macro constants from C headers in specgen
The spec generation pipeline was losing #define constants because clang -E preprocessing expanded them before c2ffi could see them. Fix: parse original (pre-preprocessed) headers directly with regex to extract #define NAME VALUE patterns. Store in spec as Macros map. In idiomgen: - extra_enums values auto-resolve from macros (header is authoritative) - Unmatched macros generate as untyped constants in constants.go This auto-extracts 154 EGL, 1819 GLES2, and 624 GLES3 constants from headers. Examples updated to use package constants instead of local magic values (EGL_VENDOR, GL_UNSIGNED_SHORT, GL_TIMEOUT_IGNORED, etc).
1 parent 7fb3db3 commit 91c6e3d

27 files changed

Lines changed: 4680 additions & 68 deletions

File tree

audio/constants.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

egl/constants.go

Lines changed: 139 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/camera/display/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,13 @@ func initEGL(win unsafe.Pointer) error {
491491
egl.None,
492492
}
493493
eglCtx = egl.CreateContext(eglDisp, config, nil, &ctxAttribs[0])
494-
if errCode := egl.GetError(); errCode != 0x3000 { // EGL_SUCCESS
494+
if errCode := egl.GetError(); errCode != egl.EGL_SUCCESS {
495495
return fmt.Errorf("eglCreateContext failed: 0x%x", errCode)
496496
}
497497
eglHasCtx = true
498498

499499
eglSurf = egl.CreateWindowSurface(eglDisp, config, egl.EGLNativeWindowType(win), nil)
500-
if errCode := egl.GetError(); errCode != 0x3000 { // EGL_SUCCESS
500+
if errCode := egl.GetError(); errCode != egl.EGL_SUCCESS {
501501
return fmt.Errorf("eglCreateWindowSurface failed: 0x%x", errCode)
502502
}
503503
eglHasSurf = true

examples/egl/config-query/main.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ import (
1313
"github.com/xaionaro-go/ndk/egl"
1414
)
1515

16-
// EGL attribute constants not exported by the idiomatic bindings.
17-
const (
18-
eglSamples egl.Int = 12337
19-
eglSampleBuffers egl.Int = 12338
20-
eglMaxPbufferWidth egl.Int = 12330
21-
eglMaxPbufferHeight egl.Int = 12329
22-
eglMaxPbufferPixels egl.Int = 12331
23-
eglNativeRenderable egl.Int = 12346
24-
eglNativeVisualId egl.Int = 12349
25-
eglConformant egl.Int = 12354
26-
eglConfigCaveat egl.Int = 12327
27-
eglPixmapBit egl.Int = 2
28-
)
29-
3016
func fatal(msg string) {
3117
fmt.Fprintf(os.Stderr, "error: %s (EGL error 0x%04X)\n", msg, egl.GetError())
3218
os.Exit(1)
@@ -88,17 +74,17 @@ func main() {
8874
{"Alpha Size", egl.AlphaSize},
8975
{"Depth Size", egl.DepthSize},
9076
{"Stencil Size", egl.StencilSize},
91-
{"Samples", eglSamples},
92-
{"Sample Buffers", eglSampleBuffers},
93-
{"Max Pbuffer Width", eglMaxPbufferWidth},
94-
{"Max Pbuffer Height", eglMaxPbufferHeight},
95-
{"Max Pbuffer Pixels", eglMaxPbufferPixels},
96-
{"Native Renderable", eglNativeRenderable},
97-
{"Native Visual ID", eglNativeVisualId},
77+
{"Samples", egl.EGL_SAMPLES},
78+
{"Sample Buffers", egl.EGL_SAMPLE_BUFFERS},
79+
{"Max Pbuffer Width", egl.EGL_MAX_PBUFFER_WIDTH},
80+
{"Max Pbuffer Height", egl.EGL_MAX_PBUFFER_HEIGHT},
81+
{"Max Pbuffer Pixels", egl.EGL_MAX_PBUFFER_PIXELS},
82+
{"Native Renderable", egl.EGL_NATIVE_RENDERABLE},
83+
{"Native Visual ID", egl.EGL_NATIVE_VISUAL_ID},
9884
{"Surface Type (bitmask)", egl.SurfaceType},
9985
{"Renderable Type (bitmask)", egl.RenderableType},
100-
{"Conformant (bitmask)", eglConformant},
101-
{"Config Caveat", eglConfigCaveat},
86+
{"Conformant (bitmask)", egl.EGL_CONFORMANT},
87+
{"Config Caveat", egl.EGL_CONFIG_CAVEAT},
10288
}
10389

10490
fmt.Println("Config attributes:")
@@ -112,7 +98,7 @@ func main() {
11298
surfType := getAttrib(display, config, egl.SurfaceType)
11399
printFlag(" Window", surfType, egl.WindowBit)
114100
printFlag(" Pbuffer", surfType, egl.PbufferBit)
115-
printFlag(" Pixmap", surfType, eglPixmapBit)
101+
printFlag(" Pixmap", surfType, egl.EGL_PIXMAP_BIT)
116102

117103
fmt.Println("Renderable type flags:")
118104
rendType := getAttrib(display, config, egl.RenderableType)

examples/egl/initialize/main.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ import (
1212
"github.com/xaionaro-go/ndk/egl"
1313
)
1414

15-
// Standard EGL query-string name constants (not exported by the bindings).
16-
const (
17-
eglVendor egl.Int = 0x3053
18-
eglVersion egl.Int = 0x3054
19-
eglExtensions egl.Int = 0x3055
20-
eglClientAPIs egl.Int = 0x308D
21-
)
22-
2315
func fatal(msg string) {
2416
fmt.Fprintf(os.Stderr, "error: %s (EGL error 0x%04X)\n", msg, egl.GetError())
2517
os.Exit(1)
@@ -46,10 +38,10 @@ func main() {
4638
label string
4739
name egl.Int
4840
}{
49-
{"Vendor", eglVendor},
50-
{"Version", eglVersion},
51-
{"Client APIs", eglClientAPIs},
52-
{"Extensions", eglExtensions},
41+
{"Vendor", egl.EGL_VENDOR},
42+
{"Version", egl.EGL_VERSION},
43+
{"Client APIs", egl.EGL_CLIENT_APIS},
44+
{"Extensions", egl.EGL_EXTENSIONS},
5345
}
5446
for _, q := range queries {
5547
s := egl.QueryString(display, q.name)

examples/egl/offscreen-render/main.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ import (
1919
"github.com/xaionaro-go/ndk/gles2"
2020
)
2121

22-
// EGL query-string name constants (not exported by the idiomatic bindings).
23-
const (
24-
eglVendor egl.Int = 0x3053
25-
eglVersion egl.Int = 0x3054
26-
eglExtensions egl.Int = 0x3055
27-
eglClientAPIs egl.Int = 0x308D
28-
)
29-
3022
// Pbuffer dimensions.
3123
const (
3224
pbufWidth = 64
@@ -121,10 +113,10 @@ func main() {
121113
label string
122114
name egl.Int
123115
}{
124-
{"Vendor", eglVendor},
125-
{"Version", eglVersion},
126-
{"Client APIs", eglClientAPIs},
127-
{"Extensions", eglExtensions},
116+
{"Vendor", egl.EGL_VENDOR},
117+
{"Version", egl.EGL_VERSION},
118+
{"Client APIs", egl.EGL_CLIENT_APIS},
119+
{"Extensions", egl.EGL_EXTENSIONS},
128120
}
129121
fmt.Println("\nEGL display info:")
130122
for _, q := range queries {

examples/gles2/framebuffer/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"github.com/xaionaro-go/ndk/gles2"
2626
)
2727

28-
// GL_UNSIGNED_SHORT is not in the generated enum set.
29-
const glUnsignedShort gles2.Enum = 0x1403
3028

3129
func fatal(msg string) {
3230
fmt.Fprintf(os.Stderr, "fatal: %s (EGL error 0x%04X)\n", msg, egl.GetError())
@@ -361,7 +359,7 @@ func main() {
361359
gles2.EnableVertexAttribArray(gles2.GLuint(texLoc2))
362360
gles2.VertexAttribPointer(gles2.GLuint(texLoc2), 2, gles2.Float, gles2.Boolean(gles2.False), stride, texOffset)
363361

364-
gles2.DrawElements(gles2.Triangles, 6, glUnsignedShort, nil)
362+
gles2.DrawElements(gles2.Triangles, 6, gles2.GL_UNSIGNED_SHORT, nil)
365363
checkGL("pass 2 render")
366364

367365
gles2.DisableVertexAttribArray(gles2.GLuint(posLoc2))

examples/gles2/texture/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"github.com/xaionaro-go/ndk/gles2"
2222
)
2323

24-
// GL_UNSIGNED_SHORT is not in the generated enum set.
25-
const glUnsignedShort gles2.Enum = 0x1403
2624

2725
func fatal(msg string) {
2826
fmt.Fprintf(os.Stderr, "fatal: %s (EGL error 0x%04X)\n", msg, egl.GetError())
@@ -305,7 +303,7 @@ func main() {
305303
texOffset,
306304
)
307305

308-
gles2.DrawElements(gles2.Triangles, 6, glUnsignedShort, nil)
306+
gles2.DrawElements(gles2.Triangles, 6, gles2.GL_UNSIGNED_SHORT, nil)
309307
checkGL("DrawElements")
310308

311309
gles2.DisableVertexAttribArray(gles2.GLuint(posLoc))

examples/gles3/sync-fences/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"github.com/xaionaro-go/ndk/gles3"
2323
)
2424

25-
// GL_TIMEOUT_IGNORED is defined as 0xFFFFFFFFFFFFFFFF in the spec.
26-
const glTimeoutIgnored = uint64(0xFFFFFFFFFFFFFFFF)
2725

2826
var triVertices = [...]float32{
2927
0.0, 0.5,
@@ -85,7 +83,7 @@ func main() {
8583
// SYNC_FLUSH_COMMANDS_BIT tells the driver to flush if the sync is not
8684
// already signalled, which avoids a potential deadlock when the command
8785
// queue has not been flushed yet.
88-
result := gles3.ClientWaitSync(sync, gles3.SyncFlushCommandsBit, gles3.GLuint64(glTimeoutIgnored))
86+
result := gles3.ClientWaitSync(sync, gles3.SyncFlushCommandsBit, gles3.GLuint64(gles3.GL_TIMEOUT_IGNORED))
8987
switch result {
9088
case gles3.AlreadySignaled:
9189
log.Println("ClientWaitSync: already signalled (GPU was fast)")

examples/gles3/transform-feedback/main.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ import (
2323
"github.com/xaionaro-go/ndk/gles3"
2424
)
2525

26-
// GL constants for rasterizer discard and map read.
27-
const (
28-
glRasterizerDiscard gles2.Enum = 0x8C89
29-
glMapReadBit gles3.GLbitfield = 0x0001
30-
)
3126

3227
// Input positions: three 2D points.
3328
var inputPositions = [...]float32{
@@ -109,13 +104,13 @@ func main() {
109104
gles2.UseProgram(program)
110105

111106
// Disable rasterization: we only care about the vertex shader output.
112-
gles2.Enable(glRasterizerDiscard)
107+
gles2.Enable(gles3.GL_RASTERIZER_DISCARD)
113108

114109
gles3.BeginTransformFeedback(gles3.GLenum(gles2.Points))
115110
gles2.DrawArrays(gles2.Points, 0, gles2.GLsizei(vertexCount))
116111
gles3.EndTransformFeedback()
117112

118-
gles2.Disable(glRasterizerDiscard)
113+
gles2.Disable(gles3.GL_RASTERIZER_DISCARD)
119114
checkGLError("after transform feedback")
120115

121116
// --- Read back captured data ---
@@ -130,7 +125,7 @@ func main() {
130125
gles3.TransformFeedbackBuffer,
131126
0,
132127
gles3.GLsizeiptr(feedbackBufSize),
133-
glMapReadBit,
128+
gles3.GL_MAP_READ_BIT,
134129
)
135130
if ptr == nil {
136131
log.Fatal("MapBufferRange returned nil")

0 commit comments

Comments
 (0)