/
main.go
97 lines (85 loc) · 3.02 KB
/
main.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
// Copyright 2011 The GoGL Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.mkd file.
package main
import (
"fmt"
"flag"
"path/filepath"
)
var (
download *bool = flag.Bool("download", false, "Just download spec files from url.")
specUrl *string = flag.String("url", KhronosRegistryBaseURL, "OpenGL specification location.")
specDir *string = flag.String("dir", "khronos_specs", "OpenGL specification directory.")
// TODO: add additional flags ...
)
func main() {
fmt.Printf("OpenGL binding generator for Go. Copyright (c) 2011 by Christoph Schunk.\n")
flag.Parse()
if *download {
DownloadOpenGLSpecs(*specUrl, *specDir)
return
}
fmt.Printf("Parsing enumext.spec file...\n")
enumCategories, err := ReadEnumsFromFile(filepath.Join(*specDir, OpenGLEnumExtSpecFile))
if err != nil {
panic(err.Error())
}
fmt.Printf("Parsing gl.tm file ...\n")
typeMap, err := ReadTypeMapFromFile(filepath.Join(*specDir, OpenGLTypeMapFile))
if err != nil {
panic(err.Error())
}
fmt.Printf("Parsing gl.spec file ...\n")
functions, supportedVersions, err := ReadFunctionsFromFile(filepath.Join(*specDir, OpenGLSpecFile))
if err != nil {
panic(err.Error())
}
// TODO: This output is temporary for debugging
fmt.Println("Supported versions:")
fmt.Println(supportedVersions)
fmt.Println("Enums:")
for category, enums := range enumCategories {
fmt.Printf(" %v\n", category)
for _, enum := range enums {
fmt.Printf(" %v = %v\n", enum.Name, enum.Value)
}
}
fmt.Println("Types:")
for abstractType, cType := range typeMap {
fmt.Printf(" %v -> %v\n", abstractType, cType)
}
fmt.Println("Functions:")
for category, functions := range functions {
fmt.Printf(" %v\n", category)
for _, function := range functions {
fmt.Printf(" %v\n", function.Name)
if function.Version.Valid() {
fmt.Printf(" Version: %v\n", function.Version)
}
if function.DeprecatedVersion.Valid() {
fmt.Printf(" Deprecated Version: %v\n", function.DeprecatedVersion)
}
fmt.Printf(" Return Type: %v\n", function.Return)
if len(function.Parameters) > 0 {
fmt.Printf(" Parameters:\n")
for _, param := range function.Parameters {
if param.InArray {
fmt.Printf(" %v %v in array\n", param.Name, param.Type)
} else {
fmt.Printf(" %v %v\n", param.Name, param.Type)
}
}
} else {
fmt.Printf(" 0 Parameters\n")
}
}
}
// TODO: just a test, do real unit testing
//functions["Cat1"] = []Function{
//Function{Name: "Foo1", Parameters: []Parameter{Parameter{"p1", "int"}, Parameter{"p2", "int"}}, Return: "void"},
//Function{Name: "Foo2", Parameters: []Parameter{Parameter{"p1", "int"}, Parameter{"p2", "int"}, Parameter{"p3", "float"}}, Return: "void"},
//Function{Name: "Foo3", Parameters: []Parameter{Parameter{"p1", "int"}, Parameter{"p2", "int"}, Parameter{"p3", "float"}}, Return: "void"},
//}
//Generate(*outGLFile, enumCategories, functions, typeMap, enumFilter, functionFilter)
}