Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some more work on glx/wgl extension loading

- More type mapping for wgl/glx
- Parser modifications
- Package grouping extended

... so much more complicated than I first thought.
  • Loading branch information...
commit 67a7fa31de6863a9ee6e2d87e9f9d199efdbb90c 1 parent ecf6c9f
Christoph Schunk authored
2  Makefile
View
@@ -35,3 +35,5 @@ install_all:
go install ./ati
go install ./amd
go install ./nv
+# go install ./glx
+# go install ./wgl
4 download.go
View
@@ -21,10 +21,12 @@ const (
GLXEnumSpecFile = "glxenum.spec"
GLXEnumExtSpecFile = "glxenumext.spec"
GLXSpecFile = "glx.spec"
+ GLXExtSpecFile = "glxext.spec"
GLXTypeMapFile = "glx.tm"
WGLEnumSpecFile = "wglenum.spec"
WGLEnumExtSpecFile = "wglenumext.spec"
WGLSpecFile = "wgl.spec"
+ WGLExtSpecFile = "wglext.spec"
WGLTypeMapFile = "wgl.tm"
)
@@ -66,9 +68,11 @@ func DownloadOpenGLSpecs(baseURL, outDir string) {
DownloadFile(baseURL, GLXEnumExtSpecFile, outDir)
DownloadFile(baseURL, GLXSpecFile, outDir)
+ DownloadFile(baseURL, GLXExtSpecFile, outDir)
DownloadFile(baseURL, GLXTypeMapFile, outDir)
DownloadFile(baseURL, WGLEnumExtSpecFile, outDir)
DownloadFile(baseURL, WGLSpecFile, outDir)
+ DownloadFile(baseURL, WGLExtSpecFile, outDir)
DownloadFile(baseURL, WGLTypeMapFile, outDir)
}
8 enumreader.go
View
@@ -65,6 +65,14 @@ func ReadEnums(r io.Reader) (EnumCategories, error) {
} else {
fmt.Fprintf(os.Stderr, "ERROR: Unable to find %s.\n", enum[2][3:])
}
+ } else if strings.HasPrefix(enum[2], "GLX_") {
+ //fmt.Printf("Lookup %s in %s\n", enum[2][3:], enum[1])
+ ok, val := categories.LookUpDefinition(enum[2][4:])
+ if ok {
+ categories[currentCategory][enum[1]] = val
+ } else {
+ fmt.Fprintf(os.Stderr, "ERROR: Unable to find %s.\n", enum[2][4:])
+ }
} else if strings.HasSuffix(enum[2], "u") {
categories[currentCategory][enum[1]] = enum[2][:len(enum[2])-1]
} else if strings.HasSuffix(enum[2], "ull") {
2  funcreader.go
View
@@ -133,7 +133,7 @@ func ReadFunctions(r io.Reader) (FunctionCategories, *FunctionsInfo, error) {
} else if glextmask := funcGlextMaskRE.FindStringSubmatch(line); glextmask != nil {
currentFunction.GlextMask = glextmask[1]
} else if extension := funcExtensionRE.FindStringSubmatch(line); extension != nil {
- if(len(extension) >= 2) {
+ if len(extension) >= 2 {
currentFunction.Extension = extension[1]
}
} else if vectorequiv := funcVectorEquivRE.FindStringSubmatch(line); vectorequiv != nil {
2  generator.go
View
@@ -44,7 +44,7 @@ func writePackage(w io.Writer, packageName string, pak *Package, functsInfo *Fun
highestMajorVersion := -1
isGLPackage := false
- if strings.HasPrefix(packageName, "gl") {
+ if strings.HasPrefix(packageName, "gl") && !strings.HasPrefix(packageName, "glx") {
isGLPackage = true
}
14 group.go
View
@@ -43,8 +43,12 @@ func GroupEnumsAndFunctions(enums EnumCategories, functions FunctionCategories,
}
// Default grouping function.
-// Currently only one deprecation level supported.
-func GroupPackagesByVendorFunc(category string, supportedVersions []Version, deprecatedVersions []Version) (packageNames []string) {
+// Groups packages by GL versions and vendor extensions:
+// EXT, ARB, ATI, NV -> ext, arb, ati, nv package
+// VERSION_1_0, VERSION_1_1, VERSION_1_2 -> gl12
+// ...
+// Currently only one deprecation level is supported.
+func GroupCategoriesByVendorAndVersion(category string, supportedVersions []Version, deprecatedVersions []Version) (packageNames []string) {
pc, err := ParseCategoryString(category)
if err != nil {
return nil
@@ -75,3 +79,9 @@ func GroupPackagesByVendorFunc(category string, supportedVersions []Version, dep
}
return packages
}
+
+// Put everything into one package.
+// For wgl/glx.
+func GroupCategoriesIntoOnePackage(category, packageName string) (packageNames []string) {
+ return []string{packageName}
+}
99 main.go
View
@@ -18,41 +18,46 @@ var (
// 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))
+func generatePackages(enumextFile, specFile string, typeMapFiles []string, singlePackage string) error {
+ fmt.Printf("Parsing %s file...\n", enumextFile)
+ enumCategories, err := ReadEnumsFromFile(filepath.Join(*specDir, enumextFile))
if err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
- return
+ return err
}
- fmt.Printf("Parsing gl.tm file ...\n")
- typeMap, err := ReadTypeMapFromFile(filepath.Join(*specDir, OpenGLTypeMapFile))
+ fmt.Printf("Parsing %v files ...\n", typeMapFiles)
+ tmPaths := make([]string, len(typeMapFiles))
+ for i, tmFile := range typeMapFiles {
+ tmPaths[i] = filepath.Join(*specDir, tmFile)
+ }
+ typeMap, err := ReadTypeMapFromFiles(tmPaths)
if err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
- return
+ return err
}
- fmt.Printf("Parsing gl.spec file ...\n")
- funcCategories, funcInfo, err := ReadFunctionsFromFile(filepath.Join(*specDir, OpenGLSpecFile))
+ fmt.Printf("Parsing %s file ...\n", specFile)
+ funcCategories, funcInfo, err := ReadFunctionsFromFile(filepath.Join(*specDir, specFile))
if err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
- return
+ return err
}
- fmt.Printf("Sorting extensions ...\n")
- packages := GroupEnumsAndFunctions(enumCategories, funcCategories,
- func(category string) (packageNames []string) {
- return GroupPackagesByVendorFunc(category, funcInfo.Versions, funcInfo.DeprecatedVersions)
- })
+ fmt.Printf("Grouping extensions ...\n")
+ var gf PackageGroupFunc
+ if len(singlePackage) == 0 {
+ gf = func(category string) (packageNames []string) {
+ return GroupCategoriesByVendorAndVersion(
+ category,
+ funcInfo.Versions,
+ funcInfo.DeprecatedVersions)
+ }
+ } else {
+ gf = func(category string) (packageNames []string) {
+ return GroupCategoriesIntoOnePackage(
+ category,
+ singlePackage)
+ }
+ }
+ packages := GroupEnumsAndFunctions(enumCategories, funcCategories, gf)
// TODO: This output is temporary for debugging
if false {
@@ -92,7 +97,47 @@ func main() {
fmt.Printf("Generating packages ...\n")
if err := GeneratePackages(packages, funcInfo, typeMap); err != nil {
- fmt.Fprintln(os.Stderr, err.Error())
+ return err
+ }
+
+ return nil
+}
+
+func main() {
+ fmt.Printf("OpenGL binding generator for Go. Copyright (c) 2011-2012 by Christoph Schunk.\n")
+ flag.Parse()
+
+ if *download {
+ DownloadOpenGLSpecs(*specUrl, *specDir)
return
}
+ var err error
+
+goto ll
+ err = generatePackages(
+ OpenGLEnumExtSpecFile,
+ OpenGLSpecFile,
+ []string{OpenGLTypeMapFile},
+ "")
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err.Error())
+ }
+ll:
+ err = generatePackages(
+ GLXEnumExtSpecFile,
+ GLXSpecFile,
+ []string{OpenGLTypeMapFile, GLXTypeMapFile},
+ "glx")
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err.Error())
+ }
+
+ err = generatePackages(
+ WGLEnumExtSpecFile,
+ WGLSpecFile,
+ []string{OpenGLTypeMapFile, WGLTypeMapFile},
+ "wgl")
+ if err != nil {
+ fmt.Fprintln(os.Stderr, err.Error())
+ }
}
15 tmreader.go
View
@@ -18,6 +18,21 @@ var (
tmTypePairRE = regexp.MustCompile("^([_A-Za-z0-9]+),\\*,\\*,[\\t ]*([A-Za-z0-9\\*_ ]+),\\*,\\*")
)
+
+func ReadTypeMapFromFiles(files []string) (TypeMap, error) {
+ allTypes := make(TypeMap)
+ for _, file := range files {
+ types, err := ReadTypeMapFromFile(file)
+ if err != nil {
+ return nil, err
+ }
+ for k, v := range types {
+ allTypes[k] = v
+ }
+ }
+ return allTypes, nil
+}
+
func ReadTypeMapFromFile(name string) (TypeMap, error) {
file, err := os.Open(name)
if err != nil {
30 util.go
View
@@ -207,6 +207,31 @@ func CTypeToGoType(cType string, out bool, mod ParamModifier) (goType, cgoType s
err = errors.New("Unsupported type.")
}
return
+ // glx
+ case "Display":
+ goType = "Pointer"
+ cgoType = "C.Display"
+ if mod == ParamModifierArray || mod == ParamModifierReference {
+ //goType = "*" + goType
+ cgoType = "*" + cgoType
+ }
+ return
+ case "GLXHyperpipeNetworkSGIX *":
+ goType = "Pointer"
+ cgoType = "*C.GLXHyperpipeNetworkSGIX"
+ return
+ case "GLXHyperpipeConfigSGIX *":
+ goType = "Pointer"
+ cgoType = "*C.GLXHyperpipeConfigSGIX"
+ return
+ case "GLXHyperpipeConfigSGIX":
+ if mod == ParamModifierArray || mod == ParamModifierReference || out {
+ goType = "Pointer"
+ cgoType = "*C.GLXHyperpipeConfigSGIX"
+ } else {
+ err = errors.New("Unsupported GLXHyperpipeConfigSGIX type.")
+ }
+ return
}
// standard cases for primitive data types:
switch cType {
@@ -292,6 +317,11 @@ func CTypeToGoType(cType string, out bool, mod ParamModifier) (goType, cgoType s
case "GLuint64EXT":
goType = "Uint64"
cgoType = "C.GLuint64EXT"
+ // glx
+ case "int":
+ goType = "Int"
+ cgoType = "C.int"
+
default:
err = errors.New("Unknown GL type: " + cType)
return
Please sign in to comment.
Something went wrong with that request. Please try again.