Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Documentation updates for Go 1

- Updates for the go command
- Some source updates for Windows compatibility
  • Loading branch information...
commit 21a79dc7c362cb268c9ffc1542f9f10bad05f171 1 parent c9c07db
@chsc authored
View
8 README.mkd
@@ -7,11 +7,9 @@ No external dependencies like GLEW are needed.
Install the OpenGL bindings
---------------------------
-For example, OpenGL 2.1 bindings can be installed using goinstall:
+For example, OpenGL 2.1 bindings can be installed using the go comand:
- goinstall github.com/chsc/gogl/gl21
-
-The new 'go install' command should also work.
+ go get github.com/chsc/gogl/gl21
Documentation
-------------
@@ -33,7 +31,7 @@ Examples
To test the package, build and install the "spinning gopher" example:
- goinstall github.com/chsc/gogl/examples/gopher
+ go get github.com/chsc/gogl/examples/gopher
and run it from your command line.
View
4 funcreader.go
@@ -169,8 +169,8 @@ func ReadFunctions(r io.Reader) (FunctionCategories, *FunctionsInfo, error) {
} else if newcategory := funcNewCategoryRE.FindStringSubmatch(line); newcategory != nil {
currentCategory = newcategory[1]
functions[currentCategory] = make([]*Function, 0)
- //} else if funcIgnoreRE.MatchString(line) {
- // // ignore
+ //} else if funcIgnoreRE.MatchString(line) {
+ // // ignore
} else {
fmt.Fprintf(os.Stderr, "WARNING: Unable to parse line '%s'\n", line)
//return functions, finfo, fmt.Errorf("Unable to parse line: '%s'", line)
View
6 funcreader_test.go
@@ -68,7 +68,7 @@ func TestReadFunctions(t *testing.T) {
f1.Name = "Foo1"
f1.Parameters = []Parameter{{"p1", "type1", false, false}, {"p2", "type2", false, true}}
f1.Return = "void"
- f1.Version = Version{1, 0}
+ f1.Version = Version{1, 0}
f1.DeprecatedVersion = Version{0, 0}
f1.Category = "cat_1"
f1.GlxRopCode = "85"
@@ -79,12 +79,12 @@ func TestReadFunctions(t *testing.T) {
f2.Name = "Foo2"
f2.Parameters = []Parameter{{"p1", "type3", true, false}, {"p2", "type4", true, true}}
f2.Return = "void"
- f2.Version = Version{2, 1}
+ f2.Version = Version{2, 1}
f2.DeprecatedVersion = Version{0, 0}
f2.Category = "cat_2"
f2.GlxRopCode = "95"
f2.Offset = "168"
checkFunc(f2, f, t)
-
+
// TODO: add more tests: flags, categories ...
}
View
101 generator.go
@@ -109,11 +109,22 @@ func writePackage(w io.Writer, packageName string, pak *Package, functsInfo *Fun
fmt.Fprintf(w, "// %s\n", passthrus)
}
+ fmt.Fprintf(w, "// #ifdef _WIN32\n")
+ fmt.Fprintf(w, "// static HMODULE opengl32 = NULL;\n")
+ fmt.Fprintf(w, "// #endif\n// \n")
+
fmt.Fprintf(w, "// void* goglGetProcAddress(const char* name) { \n")
fmt.Fprintf(w, "// #ifdef __APPLE__\n")
fmt.Fprintf(w, "// return NULL; // TODO: Add get proc addr for Mac.\n")
fmt.Fprintf(w, "// #elif _WIN32\n")
- fmt.Fprintf(w, "// return wglGetProcAddress((LPCSTR)name); // TODO: Not tested\n")
+ fmt.Fprintf(w, "// void* pf = wglGetProcAddress((LPCSTR)name);\n")
+ fmt.Fprintf(w, "// if(pf) {\n")
+ fmt.Fprintf(w, "// return pf;\n")
+ fmt.Fprintf(w, "// }\n")
+ fmt.Fprintf(w, "// if(opengl32 == NULL) {\n")
+ fmt.Fprintf(w, "// opengl32 = LoadLibraryA(\"opengl32.dll\");\n")
+ fmt.Fprintf(w, "// }\n")
+ fmt.Fprintf(w, "// return GetProcAddress(opengl32, (LPCSTR)name);\n")
fmt.Fprintf(w, "// #else\n")
fmt.Fprintf(w, "// return glXGetProcAddress((const GLubyte*)name);\n")
fmt.Fprintf(w, "// #endif\n")
@@ -175,29 +186,11 @@ func writePackage(w io.Writer, packageName string, pak *Package, functsInfo *Fun
return nil
}
-func isOpenGL11(cat string) (bool, error) {
- pc, err := ParseCategoryString(cat)
- if err != nil {
- return false, err
- }
- if pc.Type == CategoryExtension {
- return false, nil
- }
- if pc.Version.Compare(Version{1, 1}) <= 0 {
- return true, nil
- }
- return false, nil
-}
-
func writeCFuncDeclarations(w io.Writer, functions FunctionCategories, typeMap TypeMap) error {
for cat, fs := range functions {
fmt.Fprintf(w, "// // %s\n", cat)
- isGL11, err := isOpenGL11(cat)
- if err != nil {
- return err
- }
for _, f := range fs {
- if err := writeCFuncDeclaration(w, f, typeMap, isGL11); err != nil {
+ if err := writeCFuncDeclaration(w, f, typeMap, false); err != nil {
return err
}
}
@@ -212,7 +205,7 @@ func writeCFuncDeclaration(w io.Writer, f *Function, typeMap TypeMap, prototype
return err
}
if prototype {
- fmt.Fprintf(w, "// GLAPI %s APIENTRY gl%s)(", rtype, f.Name)
+ fmt.Fprintf(w, "// GLAPI %s APIENTRY gl%s(", rtype, f.Name)
} else {
fmt.Fprintf(w, "// %s (APIENTRYP ptrgl%s)(", rtype, f.Name)
}
@@ -238,12 +231,8 @@ func writeCFuncDeclaration(w io.Writer, f *Function, typeMap TypeMap, prototype
func writeCFuncDefinitions(w io.Writer, functions FunctionCategories, typeMap TypeMap) error {
for cat, fs := range functions {
fmt.Fprintf(w, "// // %s\n", cat)
- isGL11, err := isOpenGL11(cat)
- if err != nil {
- return err
- }
for _, f := range fs {
- if err := writeCFuncDefinition(w, f, typeMap, isGL11); err != nil {
+ if err := writeCFuncDefinition(w, f, typeMap, false); err != nil {
return err
}
}
@@ -268,7 +257,7 @@ func writeCFuncDefinition(w io.Writer, f *Function, typeMap TypeMap, prototype b
if p.Out || (p.Modifier == ParamModifierReference || p.Modifier == ParamModifierArray) {
fmt.Fprint(w, "*")
}
- fmt.Fprintf(w, " %s", p.Name)
+ fmt.Fprintf(w, " %s", RenameIfReservedWord(p.Name))
if i < len(f.Parameters)-1 {
fmt.Fprintf(w, ", ")
}
@@ -286,7 +275,7 @@ func writeCFuncDefinition(w io.Writer, f *Function, typeMap TypeMap, prototype b
}
for i, _ := range f.Parameters {
p := &f.Parameters[i]
- fmt.Fprintf(w, "%s", p.Name)
+ fmt.Fprintf(w, "%s", RenameIfReservedWord(p.Name))
if i < len(f.Parameters)-1 {
fmt.Fprintf(w, ", ")
}
@@ -297,19 +286,13 @@ func writeCFuncDefinition(w io.Writer, f *Function, typeMap TypeMap, prototype b
func writeCFuncGetProcAddrs(w io.Writer, functions FunctionCategories) error {
for cat, fs := range functions {
- isGL11, err := isOpenGL11(cat)
- if err != nil {
- return err
- }
- if !isGL11 {
- fmt.Fprintf(w, "// int init_%s() {\n", cat)
- for _, f := range fs {
- fmt.Fprintf(w, "// ptrgogl%s = goglGetProcAddress(\"gl%s\");\n", f.Name, f.Name)
- fmt.Fprintf(w, "// if(ptrgogl%s == NULL) return 1;\n", f.Name)
- }
- fmt.Fprintf(w, "// \treturn 0;\n")
- fmt.Fprintf(w, "// }\n")
+ fmt.Fprintf(w, "// int init_%s() {\n", cat)
+ for _, f := range fs {
+ fmt.Fprintf(w, "// ptrgl%s = goglGetProcAddress(\"gl%s\");\n", f.Name, f.Name)
+ fmt.Fprintf(w, "// if(ptrgl%s == NULL) return 1;\n", f.Name)
}
+ fmt.Fprintf(w, "// \treturn 0;\n")
+ fmt.Fprintf(w, "// }\n")
}
fmt.Fprintf(w, "// \n")
return nil
@@ -331,12 +314,8 @@ func writeGoEnumDefinitions(w io.Writer, enumCats EnumCategories) {
func writeGoFuncDefinitions(w io.Writer, functions FunctionCategories, typeMap TypeMap, majorVersion int) error {
for cat, fs := range functions {
fmt.Fprintf(w, "// %s\n\n", cat)
- isGL11, err := isOpenGL11(cat)
- if err != nil {
- return err
- }
for _, f := range fs {
- if err := writeGoFuncDefinition(w, f, typeMap, majorVersion, isGL11); err != nil {
+ if err := writeGoFuncDefinition(w, f, typeMap, majorVersion, false); err != nil {
return err
}
}
@@ -417,32 +396,20 @@ func writeGoFuncDefinition(w io.Writer, f *Function, typeMap TypeMap, majorVersi
func writeGoInitDefinitions(w io.Writer, functions FunctionCategories) error {
for cat, _ := range functions {
- isGL11, err := isOpenGL11(cat)
- if err != nil {
- return err
- }
- if !isGL11 {
- fmt.Fprintf(w, "func Init%s() error {\n", GoName(cat))
- fmt.Fprintf(w, "\tvar ret C.int\n")
- fmt.Fprintf(w, "\tif ret = C.init_%s(); ret != 0 {\n", cat)
- fmt.Fprintf(w, "\t\treturn errors.New(\"unable to initialize %s\")\n", cat)
- fmt.Fprintf(w, "\t}\n")
- fmt.Fprintf(w, "\treturn nil\n")
- fmt.Fprintf(w, "}\n")
- }
+ fmt.Fprintf(w, "func Init%s() error {\n", GoName(cat))
+ fmt.Fprintf(w, "\tvar ret C.int\n")
+ fmt.Fprintf(w, "\tif ret = C.init_%s(); ret != 0 {\n", cat)
+ fmt.Fprintf(w, "\t\treturn errors.New(\"unable to initialize %s\")\n", cat)
+ fmt.Fprintf(w, "\t}\n")
+ fmt.Fprintf(w, "\treturn nil\n")
+ fmt.Fprintf(w, "}\n")
}
fmt.Fprintf(w, "func Init() error {\n")
fmt.Fprintf(w, "\tvar err error\n")
for cat, _ := range functions {
- isGL11, err := isOpenGL11(cat)
- if err != nil {
- return err
- }
- if !isGL11 {
- fmt.Fprintf(w, "\tif err = Init%s(); err != nil {\n", GoName(cat))
- fmt.Fprintf(w, "\t\treturn err\n")
- fmt.Fprintf(w, "\t}\n")
- }
+ fmt.Fprintf(w, "\tif err = Init%s(); err != nil {\n", GoName(cat))
+ fmt.Fprintf(w, "\t\treturn err\n")
+ fmt.Fprintf(w, "\t}\n")
}
fmt.Fprintf(w, "\treturn nil\n")
fmt.Fprintf(w, "}\n")
View
5,505 gl21/gl21.go
2,758 additions, 2,747 deletions not shown
View
6,449 gl33/gl33.go
3,230 additions, 3,219 deletions not shown
View
7,061 gl42/gl42.go
3,536 additions, 3,525 deletions not shown
View
18 util.go
@@ -7,8 +7,8 @@ package main
import (
"errors"
"fmt"
- "strings"
"strconv"
+ "strings"
"unicode"
)
@@ -29,10 +29,10 @@ const (
)
type ParsedCategory struct {
- Type CategoryType
- Version Version
- Vendor string
- Name string
+ Type CategoryType
+ Version Version
+ Vendor string
+ Name string
}
func (pc ParsedCategory) String() string {
@@ -84,12 +84,12 @@ func GoName(n string) string {
prev = r
return unicode.ToLower(r)
},
- n)
+ n)
}
func RenameIfReservedWord(word string) string {
switch word {
- case "func", "type", "struct", "range", "map", "string":
+ case "func", "type", "struct", "range", "map", "string", "near", "far":
return fmt.Sprintf("%s_", word)
}
return word
@@ -106,7 +106,7 @@ func CleanEnumName(enum string) string {
// Converts C types to Go types.
func CTypeToGoType(cType string, out bool, mod ParamModifier) (goType, cgoType string, err error) {
// special cases:
- switch cType{
+ switch cType {
case "void":
goType = ""
cgoType = ""
@@ -163,7 +163,7 @@ func CTypeToGoType(cType string, out bool, mod ParamModifier) (goType, cgoType s
}
return
case "GLhandleARB":
- goType = "Uint" // handle is uint
+ goType = "Uint" // handle is uint
cgoType = "C.GLuint"
if mod == ParamModifierArray || mod == ParamModifierReference {
goType = "*" + goType
Please sign in to comment.
Something went wrong with that request. Please try again.