improve docs in pixelgl

This commit is contained in:
faiface 2017-01-25 18:25:37 +01:00
parent 1894e213d2
commit 8917a09da9
4 changed files with 16 additions and 15 deletions

View File

@ -6,7 +6,7 @@ package pixelgl
// AttrFormat{{"position", Vec2}, {"color", Vec4}, {"texCoord": Vec2}} // AttrFormat{{"position", Vec2}, {"color", Vec4}, {"texCoord": Vec2}}
type AttrFormat []Attr type AttrFormat []Attr
// Size returns the total size of all attributes of an attribute format. // Size returns the total size of all attributes of the AttrFormat.
func (af AttrFormat) Size() int { func (af AttrFormat) Size() int {
total := 0 total := 0
for _, attr := range af { for _, attr := range af {

View File

@ -2,11 +2,12 @@ package pixelgl
import "github.com/go-gl/gl/v3.3-core/gl" import "github.com/go-gl/gl/v3.3-core/gl"
// Init initializes OpenGL by loading the function pointers from the active OpenGL context. // Init initializes OpenGL by loading function pointers from the active OpenGL context.
// This function must be manually run inside the main thread (Do, DoErr, DoVal, etc.). // This function must be manually run inside the main thread (using "github.com/faiface/mainthread"
// package).
// //
// It must be called under the presence of an active OpenGL context, e.g., always after calling // It must be called under the presence of an active OpenGL context, e.g., always after calling
// window.MakeContextCurrent(). Also, always call this function when switching contexts. // window.MakeContextCurrent(). Also, always call this function when switching contexts.
func Init() { func Init() {
err := gl.Init() err := gl.Init()
if err != nil { if err != nil {

View File

@ -119,17 +119,17 @@ func (s *Shader) delete() {
}) })
} }
// VertexFormat returns the vertex attribute format of this shader. Do not change it. // VertexFormat returns the vertex attribute format of this Shader. Do not change it.
func (s *Shader) VertexFormat() AttrFormat { func (s *Shader) VertexFormat() AttrFormat {
return s.vertexFmt return s.vertexFmt
} }
// UniformFormat returns the uniform attribute format of this shader. Do not change it. // UniformFormat returns the uniform attribute format of this Shader. Do not change it.
func (s *Shader) UniformFormat() AttrFormat { func (s *Shader) UniformFormat() AttrFormat {
return s.uniformFmt return s.uniformFmt
} }
// SetUniformAttr sets the value of a uniform attribute of a shader. The attribute is // SetUniformAttr sets the value of a uniform attribute of this Shader. The attribute is
// specified by the index in the Shader's uniform format. // specified by the index in the Shader's uniform format.
// //
// If the uniform attribute does not exist in the Shader, this method returns false. // If the uniform attribute does not exist in the Shader, this method returns false.
@ -152,7 +152,7 @@ func (s *Shader) UniformFormat() AttrFormat {
// Attr{Type: Mat43}: mgl32.Mat4x3 // Attr{Type: Mat43}: mgl32.Mat4x3
// No other types are supported. // No other types are supported.
// //
// The shader must be bound before calling this method. // The Shader must be bound before calling this method.
func (s *Shader) SetUniformAttr(uniform int, value interface{}) (ok bool) { func (s *Shader) SetUniformAttr(uniform int, value interface{}) (ok bool) {
if s.uniformLoc[uniform] < 0 { if s.uniformLoc[uniform] < 0 {
return false return false
@ -208,12 +208,12 @@ func (s *Shader) SetUniformAttr(uniform int, value interface{}) (ok bool) {
return true return true
} }
// Begin binds a shader program. This is necessary before using the shader. // Begin binds the Shader program. This is necessary before using the Shader.
func (s *Shader) Begin() { func (s *Shader) Begin() {
s.program.bind() s.program.bind()
} }
// End unbinds a shader program and restores the previous one. // End unbinds the Shader program and restores the previous one.
func (s *Shader) End() { func (s *Shader) End() {
s.program.restore() s.program.restore()
} }

View File

@ -15,7 +15,7 @@ type Texture struct {
} }
// NewTexture creates a new texture with the specified width and height with some initial // NewTexture creates a new texture with the specified width and height with some initial
// pixel values. The pixels must be a sequence of RGBA values. // pixel values. The pixels must be a sequence of RGBA values (one byte per component).
func NewTexture(width, height int, smooth bool, pixels []uint8) *Texture { func NewTexture(width, height int, smooth bool, pixels []uint8) *Texture {
tex := &Texture{ tex := &Texture{
tex: binder{ tex: binder{
@ -70,12 +70,12 @@ func (t *Texture) delete() {
}) })
} }
// Width returns the width of a texture in pixels. // Width returns the width of the Texture in pixels.
func (t *Texture) Width() int { func (t *Texture) Width() int {
return t.width return t.width
} }
// Height returns the height of a texture in pixels. // Height returns the height of the Texture in pixels.
func (t *Texture) Height() int { func (t *Texture) Height() int {
return t.height return t.height
} }
@ -117,12 +117,12 @@ func (t *Texture) Pixels(x, y, w, h int) []uint8 {
return subPixels return subPixels
} }
// Begin binds a texture. This is necessary before using the texture. // Begin binds the Texture. This is necessary before using the Texture.
func (t *Texture) Begin() { func (t *Texture) Begin() {
t.tex.bind() t.tex.bind()
} }
// End unbinds a texture and restores the previous one. // End unbinds the Texture and restores the previous one.
func (t *Texture) End() { func (t *Texture) End() {
t.tex.restore() t.tex.restore()
} }