Skip to content

Commit 5f66a73

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
docs: remove magic constants and int32 casts from README examples
Replace local hex constants with auto-generated package constants (egl.EGL_VENDOR, gles2.GL_VENDOR, etc.) and remove int32() casts for DefaultSensor calls that now accept sensor.Type.
1 parent c7e450e commit 5f66a73

1 file changed

Lines changed: 10 additions & 26 deletions

File tree

README.md

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Discover device sensors through the singleton sensor manager:
140140
import "github.com/xaionaro-go/ndk/sensor"
141141

142142
mgr := sensor.GetInstance()
143-
accel := mgr.DefaultSensor(int32(sensor.Accelerometer))
143+
accel := mgr.DefaultSensor(sensor.Accelerometer)
144144

145145
fmt.Printf("Sensor: %s (%s)\n", accel.Name(), accel.Vendor())
146146
fmt.Printf("Resolution: %g, min delay: %d µs\n",
@@ -517,7 +517,7 @@ func printSensor(mgr *sensor.Manager, label string, sensorType sensor.Type) (ok
517517
}
518518
}()
519519

520-
s := mgr.DefaultSensor(int32(sensorType))
520+
s := mgr.DefaultSensor(sensorType)
521521

522522
// Trigger a method call; if the internal pointer is NULL the NDK
523523
// dereferences a null pointer and Go's signal handler turns it
@@ -643,22 +643,6 @@ func goString(p *gles2.GLubyte) string {
643643
}
644644

645645
func main() {
646-
// EGL constants not in the generated package.
647-
const (
648-
eglVendor egl.Int = 0x3053
649-
eglVersion egl.Int = 0x3054
650-
eglExtensions egl.Int = 0x3055
651-
eglClientAPIs egl.Int = 0x308D
652-
)
653-
654-
// GL constants not in the generated package.
655-
const (
656-
glVendor gles2.Enum = 0x1F00
657-
glRenderer gles2.Enum = 0x1F01
658-
glVersion gles2.Enum = 0x1F02
659-
glExtensions gles2.Enum = 0x1F03
660-
)
661-
662646
// 1. Get the default EGL display and initialize it.
663647
dpy := egl.GetDisplay(egl.EGLNativeDisplayType(0))
664648
if dpy == nil {
@@ -672,10 +656,10 @@ func main() {
672656
defer egl.Terminate(dpy)
673657

674658
fmt.Printf("EGL %d.%d\n", major, minor)
675-
fmt.Printf(" Vendor: %s\n", egl.QueryString(dpy, eglVendor))
676-
fmt.Printf(" Version: %s\n", egl.QueryString(dpy, eglVersion))
677-
fmt.Printf(" Client APIs: %s\n", egl.QueryString(dpy, eglClientAPIs))
678-
fmt.Printf(" Extensions: %s\n", egl.QueryString(dpy, eglExtensions))
659+
fmt.Printf(" Vendor: %s\n", egl.QueryString(dpy, egl.EGL_VENDOR))
660+
fmt.Printf(" Version: %s\n", egl.QueryString(dpy, egl.EGL_VERSION))
661+
fmt.Printf(" Client APIs: %s\n", egl.QueryString(dpy, egl.EGL_CLIENT_APIS))
662+
fmt.Printf(" Extensions: %s\n", egl.QueryString(dpy, egl.EGL_EXTENSIONS))
679663

680664
// 2. Choose a config with ES2 support and pbuffer surface type.
681665
attribs := []egl.Int{
@@ -708,10 +692,10 @@ func main() {
708692

709693
// 4. Query OpenGL ES strings.
710694
fmt.Println()
711-
fmt.Printf("GL Vendor: %s\n", goString(gles2.GetString(glVendor)))
712-
fmt.Printf("GL Renderer: %s\n", goString(gles2.GetString(glRenderer)))
713-
fmt.Printf("GL Version: %s\n", goString(gles2.GetString(glVersion)))
714-
fmt.Printf("GL Extensions: %s\n", goString(gles2.GetString(glExtensions)))
695+
fmt.Printf("GL Vendor: %s\n", goString(gles2.GetString(gles2.GL_VENDOR)))
696+
fmt.Printf("GL Renderer: %s\n", goString(gles2.GetString(gles2.GL_RENDERER)))
697+
fmt.Printf("GL Version: %s\n", goString(gles2.GetString(gles2.GL_VERSION)))
698+
fmt.Printf("GL Extensions: %s\n", goString(gles2.GetString(gles2.GL_EXTENSIONS)))
715699

716700
egl.MakeCurrent(dpy, nil, nil, nil)
717701
}

0 commit comments

Comments
 (0)