glad

package module
v0.0.0-...-134da50 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2019 License: MIT Imports: 6 Imported by: 0

README

go-glad

Higher level OpenGL interfaces for Go.

This package use OpenGL 4.5 and the new DSA style OpenGL.

At a lower level, it provides a simple Go interface for using OpenGL. Then, it provides utilities to make life simpler (e.g. defining geometries and working with textures).

Documentation

Overview

Package glad allows to use OpenGL in Go It uses DSA-style OpenGL, to make it easier to learn and understand https://www.khronos.org/opengl/wiki/Direct_State_Access Generally, you want to: 1. create buffer objects and fill it with data 2. create a VAO NewVertexArrayObject 3. bind the VBO to some VAOs bind index with VertexBuffer 4. specify the format of some attributes with AttribFormat 5. bind the buffer to the attribute with AttribBinding

Index

Constants

This section is empty.

Variables

View Source
var (
	Terminate         = glfw.Terminate
	PollEvents        = glfw.PollEvents
	WaitEvents        = glfw.WaitEvents
	WaitEventsTimeout = glfw.WaitEventsTimeout
	SwapInterval      = glfw.SwapInterval
)

Functions

func BlockBind

func BlockBind(objs ...Binder) func()

Binds the objects passed as arguments and return a function to unbind them in reverse order

func BlockEnable

func BlockEnable(objs ...Enabler) func()

Same as BlockBind but with Enable/Disable

func CheckError

func CheckError() bool

CheckError checks for OpenGL errors and print them if any Returns true if any error was found

func NewOGLWindow

func NewOGLWindow(width, height int, title string, opts ...WinOption) *glfw.Window

Types

type Atlas

type Atlas struct {
	// contains filtered or unexported fields
}

Function to define an atlas (for a given alphabet)

func NewAtlas

func NewAtlas(abc string) *Atlas

type Attr

type Attr struct {
	Buff int    // Which of the Data buffers will be used
	Name string // Name of the attribute in the shader
	Size int32  // Number of elements for this attribute
}

Attr describes an attribute

type AutoConfig

type AutoConfig struct {
	BgTxr    Texture
	Textures []Texture // List of pre-existing textures to use (attached before images)
	Cfg      *Config
	Prog     Program
	FBO      FramebufferObject
	VAO      VertexArrayObject
	VBOs     []VertexBufferObject
	NumVert  int32
}

func AutoBuild

func AutoBuild(cfg *Config) *AutoConfig

func (*AutoConfig) AutoDraw

func (mo *AutoConfig) AutoDraw()

func (*AutoConfig) UpdateImage

func (mo *AutoConfig) UpdateImage(i int)

UpdateImage reloads the data of the i-th image into i-th texture

type Binder

type Binder interface {
	Bind()
	Unbind()
}

type Config

type Config struct {
	Shaders    []Shader
	Attributes []Attr
	Data       [][]float32   // Multiple buffers of data (one for each VBO)
	Elements   []int16       // Indices of elements to use. If not nil, gl.DrawElements will be used instead of gl.DrawArrays
	DataUsages []uint32      // gl.STATIC_DRAW, etc. one for each slice in Data. If Elements is not nil, the last DataUsage is used for the EBO
	Primitives uint32        // gl.TRIANGLES, gl.POINTS, etc.
	ClearColor []float32     // Clear color before drawing
	Textures   []Texture     // List of pre-existing textures to use (attached before images)
	Images     []image.Image // Images to use to create new textures (attached after textures)
	Offscreen  *Rect         // If not nil, will create and render to FBO setting Viewport
}

Config contains the specifications for automated build

type Enabler

type Enabler interface {
	Enable()
	Disable()
}

type FramebufferObject

type FramebufferObject uint32

FramebufferObject represents a framebuffer in the OpenGL context A FBO is a collection of buffers that can be used as rendering destination for the OpenGL pipeline There are different attachment points in a FBO: - at least one gl.COLOR_ATTACHMENTn (n=0, 1, 2, ...) - gl.DEPTH_ATTACHMENT for the depth buffer - gl.STENCIL_ATTACHMENT for the stencil buffer

func NewFramebuffer

func NewFramebuffer() FramebufferObject

NewFramebuffer creates a new FBO

func (FramebufferObject) Bind

func (fbo FramebufferObject) Bind()

Bind the FBO to the framebuffer target, allowing to use it for GL output

func (FramebufferObject) Delete

func (fbo FramebufferObject) Delete()

Delete the FBO, freeing its name

func (FramebufferObject) Texture

func (fbo FramebufferObject) Texture(att uint32, texture Texture)

Texture attaches a texture level to the FBO

func (FramebufferObject) Unbind

func (fbo FramebufferObject) Unbind()

Unbind the FBO, restoring the default window-system framebuffer

type Program

type Program uint32

Program represents a program in the OpenGL context

func MakeProgram

func MakeProgram(shaders ...Shader) Program

Create

func NewProgram

func NewProgram() Program

NewProgram creates a program with a new name

func PrepareProgram

func PrepareProgram(shaders ...Shader) Program

PrepareProgram creates a program, attaches shaders and links before returning

func (Program) AttachShaders

func (pr Program) AttachShaders(shaders ...Shader)

AttachShaders attaches one or more shaders to the program

func (Program) BindAttributeLocation

func (pr Program) BindAttributeLocation(index uint32, name string)

Call this before linking to set location of attributes

func (Program) Delete

func (pr Program) Delete()

func (Program) GetAttributeLocation

func (pr Program) GetAttributeLocation(name string) VertexAttrib

Call this after linking to get location of attributes (e.g. if they were not set)

func (Program) GetInfoLog

func (pr Program) GetInfoLog() string

func (Program) GetParameter

func (pr Program) GetParameter(pname uint32) int32
func (pr Program) Link()

Link links the attached shaders belonging to the program logging an error if link did not succeed

func (Program) Use

func (pr Program) Use()

type RBOParameter

type RBOParameter int32

RBOParameter represent

type Rect

type Rect struct {
	X, Y, W, H int
}

Rect describes a rectangle with integer coordinates

type RenderbufferObject

type RenderbufferObject uint32

RenderbufferObject is, similarly to a texture, a destination when rendering in a FBO. RB cannot be used as textures, therefore OpenGL implementation might be optimized. Use RBOs when you want to perform off-screen rendering without using the results as a texture.

func NewRenderbuffer

func NewRenderbuffer() RenderbufferObject

NewRenderbuffer creates a new renderbuffer object

func (RenderbufferObject) Bind

func (rbo RenderbufferObject) Bind()

Bind the RBO to the renderbuffer target

func (RenderbufferObject) GetParameter

func (rbo RenderbufferObject) GetParameter(param uint32) int32

GetParameter returns the RBO parameter value

func (RenderbufferObject) Storage

func (rbo RenderbufferObject) Storage(format uint32, width, height int32)

Storage allocates the storage for the RBO format can be gl.RGB, RGBA, etc, gl.STENCIL_INDEX or gl.DEPTH_COMPONENT

func (RenderbufferObject) Unbind

func (rbo RenderbufferObject) Unbind()

Unbind the RBO from the renderbuffer target

type Shader

type Shader uint32

Shader represents a shader in the OpenGL context

func NewShader

func NewShader(source string, shaderType uint32) Shader

NewShader compiles the shader source and returns a shader object errors are logged. Source code does not need to end with \x00

func (Shader) Delete

func (sh Shader) Delete()

func (Shader) GetInfoLog

func (sh Shader) GetInfoLog() string

func (Shader) GetParameter

func (sh Shader) GetParameter(pname uint32) int32

type Texture

type Texture uint32

Texture represents a texture in the OpenGL context From the OpenGL Guide Book: "Textures may be read by a shader by associating a sampler variable with a texture unit and using GLSL’s built-in functions to fetch texels from the texture’s image. The way in which the texels are fetched depends on a number of parameters that are contained in another object called a sampler object. Sampler objects are bound to sampler units much as texture objects are bound to texture units. For convenience, a texture object may be considered to contain a built-in sampler object of its own that will be used by default to read from it, if no sampler object is bound to the corresponding sampler unit."Textures may be read by a shader by associating a sampler variable with a texture unit and using GLSL’s built-in functions to fetch texels from the texture’s image. The way in which the texels are fetched depends on a number of parameters that are contained in another object called a sampler object. Sampler objects are bound to sampler units much as texture objects are bound to texture units. For convenience, a texture object may be considered to contain a built-in sampler object of its own that will be used by default to read from it, if no sampler object is bound to the corresponding sampler unit."

func NewTexture

func NewTexture(target uint32) Texture

NewTexture creates a texture of given type with no attached storage For example, target could be gl.TEXTURE_2D. The target roughly specifies the texture dimensionality, which is tied to the dimensionality of the sampler. After creating the texture, you might want to attach storage to it

func (Texture) Bind

func (tex Texture) Bind(unit uint32)

Bind the texture to the specified texture unit This needs to be called before the texture can be accessed by shaders There are many texture units in the context that can be used to bind different textures: bind a texture to a unit and a sampler to the same unit to access the texture data from the shader

func (Texture) Clear

func (tex Texture) Clear(r, g, b, a byte)

func (Texture) Delete

func (tex Texture) Delete()

Delete the texture freeing its name, freeing the associated storage

func (Texture) GetImage

func (tex Texture) GetImage(level int32, fmt, typ uint32, size int32, pixels unsafe.Pointer)

GetImage copies texture data to host

func (Texture) Image2D

func (tex Texture) Image2D(img image.Image)

Image2D copies image into pre-allocated texture Call Storage with 2D size before this The passed image will be copied and can be discarded after the call

func (Texture) SetFilters

func (tex Texture) SetFilters(magFilter, minFilter int32)

func (Texture) Storage

func (tex Texture) Storage(levels int32, internalFmt uint32, size []int)

Storage allocates storage for an empty texture of given size (cast to int32) format can be, for instance, gl.RGBA8

func (Texture) SubImage

func (tex Texture) SubImage(level int32, offset, size []int, externalFmt, typ uint32, pixels unsafe.Pointer)

SubImage replaces a region of the texture with the data 1D, 2D or 3D depends on the len of offset and size (they must be equal) pixels is considered an offset to buffer start or pointer to host memory depending whether a buffer object is or is not bound to the PIXEL_UNPACK_BUFFER target

func (Texture) Unbind

func (tex Texture) Unbind(unit uint32)

Unbind the texture from the texture unit

type VertexArrayObject

type VertexArrayObject uint32

VertexArrayObject stores data relative to some vertices stored in VBOs VertexArrayObject contain information on data location and layout in memory VertexArrayObject represents the vertex attribute state In the core profile, at least one VAO is mandatory VAOs have "attribute lists", where you can store data about your mesh each attribute you might store vertex positions, colors, normals, texture coords, etc The data themselves are stored as VBOs (plain data)

func NewVertexArrayObject

func NewVertexArrayObject() VertexArrayObject

NewVertexArrayObject allocates the name for a VAO

func (VertexArrayObject) AttribBinding

func (vao VertexArrayObject) AttribBinding(bindIndex uint32, attr VertexAttrib)

AttribBinding associates the attribute to the bind index By using the same bindIndex in VertexBuffer, AttribFormat and AttribBinding, the user can create a corrispondence between the attribute and the buffer.

func (VertexArrayObject) AttribFormat

func (vao VertexArrayObject) AttribFormat(attr VertexAttrib, size int32, dataType uint32, normalize bool, relativeOffset uint32)

AttribFormat specifies the format of the data associated to the attribute The state of the attribute is stored in the VAO size: number of components per vertex, 1, 2, 3 or 4 (e.g. 3D vertices -> 3) dataType: gl.FLOAT, etc normalized: define if data have to be normalized stride: bytes between two vertices, 0 means they are tightly packed offset: bytes of offset to the first element in the array

func (VertexArrayObject) AttribFormat32

func (vao VertexArrayObject) AttribFormat32(attr VertexAttrib, size int32, offset uint32)

func (VertexArrayObject) Bind

func (vao VertexArrayObject) Bind()

Bind the VAO maing it active Use this to select the vertex data to be used in the draw calls

func (VertexArrayObject) Delete

func (vao VertexArrayObject) Delete()

Delete the VAO freeing the name

func (VertexArrayObject) EnableAttrib

func (vao VertexArrayObject) EnableAttrib(attr VertexAttrib)

EnableAttrib the vertex attribute in the VAO, storing the state in the VAO This tells OpenGL to read the attribute data from the buffer

func (VertexArrayObject) Unbind

func (vao VertexArrayObject) Unbind()

Unbind any VAO currently bound

func (VertexArrayObject) VertexBuffer

func (vao VertexArrayObject) VertexBuffer(bindIndex uint32, buffer VertexBufferObject, offset, stride int32)

VertexBuffer binds the buffer object to bindIndex bindIndex can be any value less than gl.MAX_VERTEX_ATTRIB_BINDINGS, but usually it is given the same index of the attribute offset and stride are in bytes

func (VertexArrayObject) VertexBuffer32

func (vao VertexArrayObject) VertexBuffer32(bindIndex uint32, buffer VertexBufferObject, offset, stride int32)

VertexBuffer32 is like VertexBuffer but assuming we are working with 32 bit data

type VertexAttrib

type VertexAttrib uint32

VertexAttrib represents a vertex attribute This can be obtained for example by using Program.GetAttributeLocation

type VertexBufferObject

type VertexBufferObject uint32

VertexBufferObject represents a (vertex) buffer object in OpenGL context This is memory allocated by the OpenGL server used to store data, not limited to vertices (see the Bind method for details)

func NewVertexBufferObject

func NewVertexBufferObject() VertexBufferObject

NewVertexBufferObject creates a new buffer object

func (VertexBufferObject) Bind

func (vbo VertexBufferObject) Bind(target uint32)

Bind the VBO to the specified target values for target include:

  • gl.ARRAY_BUFFER when this buffer contains vertex-attribute data to be used in conjunction with VAO attributes
  • gl.TEXTURE_BUFFER for data bound to texture object: once attached to textures, the data will be accessible from the shader
  • gl.COPY_READ_BUFFER and gl.COPY_WRITE_BUFFER two buffers that can be used to copy data between buffers
  • gl.DRAW_INDIRECT_BUFFER to store parameters when performing indirect drawing

TODO doc: add and explain other targets

func (VertexBufferObject) BufferData32

func (vbo VertexBufferObject) BufferData32(data []float32, usage uint32)

BufferData32 allocates a new data store for float32 data in the VBO usage can be gl.<frequency>_<nature> with - frequency: STREAM, STATIC, DYNAMIC - nature: DRAW, READ, COPY Pre-existing storage will be deleted, therefore size might change

func (VertexBufferObject) BufferData64

func (vbo VertexBufferObject) BufferData64(data []float64, usage uint32)

BufferData64 is the same of BufferData32 but with float32

func (VertexBufferObject) BufferStorage

func (vbo VertexBufferObject) BufferStorage(data []float32, flags uint32)

BufferStorage allocates a new immutable data store for the VBO The storage cannot change in size: to do so, the VBO must be deleted first and created again with a new size. Data can be modified using BufferSubData

func (VertexBufferObject) BufferStorage32

func (vbo VertexBufferObject) BufferStorage32(data []float32, flags uint32)

BufferStorage32 allocates the storage for the VBO and copies float32 data in it

func (VertexBufferObject) BufferStorage64

func (vbo VertexBufferObject) BufferStorage64(data []float64, flags uint32)

BufferStorage64 allocates the storage for the VBO and copies float64 data in it

func (VertexBufferObject) BufferSubData32

func (vbo VertexBufferObject) BufferSubData32(data []float32, offset int)

BufferSubData32 replaces part of the buffer content with new float32 data

func (VertexBufferObject) BufferSubData64

func (vbo VertexBufferObject) BufferSubData64(data []float64, offset int)

BufferSubData64 replaces part of the buffer content with new float64 data

func (VertexBufferObject) Clear32

func (vbo VertexBufferObject) Clear32(data []float32)

func (VertexBufferObject) CopyTo

func (vbo VertexBufferObject) CopyTo(dest VertexBufferObject, readOffset, writeOffset int, size int32)

func (VertexBufferObject) Delete

func (vbo VertexBufferObject) Delete()

Delete the VBO freeing its name

func (VertexBufferObject) Unbind

func (vbo VertexBufferObject) Unbind(target uint32)

Unbind the VBO from the specified target

type WinOption

type WinOption func()

func ContextVersion

func ContextVersion(maj, min int) WinOption

func CoreProfile

func CoreProfile(v bool) WinOption

func Decorated

func Decorated(v bool) WinOption

func ForwardCompatible

func ForwardCompatible(v bool) WinOption

func Resizable

func Resizable(v bool) WinOption

func VSync

func VSync(v bool) WinOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL