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 ¶
- Variables
- func BlockBind(objs ...Binder) func()
- func BlockEnable(objs ...Enabler) func()
- func CheckError() bool
- func NewOGLWindow(width, height int, title string, opts ...WinOption) *glfw.Window
- type Atlas
- type Attr
- type AutoConfig
- type Binder
- type Config
- type Enabler
- type FramebufferObject
- type Program
- func (pr Program) AttachShaders(shaders ...Shader)
- func (pr Program) BindAttributeLocation(index uint32, name string)
- func (pr Program) Delete()
- func (pr Program) GetAttributeLocation(name string) VertexAttrib
- func (pr Program) GetInfoLog() string
- func (pr Program) GetParameter(pname uint32) int32
- func (pr Program) Link()
- func (pr Program) Use()
- type RBOParameter
- type Rect
- type RenderbufferObject
- type Shader
- type Texture
- func (tex Texture) Bind(unit uint32)
- func (tex Texture) Clear(r, g, b, a byte)
- func (tex Texture) Delete()
- func (tex Texture) GetImage(level int32, fmt, typ uint32, size int32, pixels unsafe.Pointer)
- func (tex Texture) Image2D(img image.Image)
- func (tex Texture) SetFilters(magFilter, minFilter int32)
- func (tex Texture) Storage(levels int32, internalFmt uint32, size []int)
- func (tex Texture) SubImage(level int32, offset, size []int, externalFmt, typ uint32, ...)
- func (tex Texture) Unbind(unit uint32)
- type VertexArrayObject
- func (vao VertexArrayObject) AttribBinding(bindIndex uint32, attr VertexAttrib)
- func (vao VertexArrayObject) AttribFormat(attr VertexAttrib, size int32, dataType uint32, normalize bool, ...)
- func (vao VertexArrayObject) AttribFormat32(attr VertexAttrib, size int32, offset uint32)
- func (vao VertexArrayObject) Bind()
- func (vao VertexArrayObject) Delete()
- func (vao VertexArrayObject) EnableAttrib(attr VertexAttrib)
- func (vao VertexArrayObject) Unbind()
- func (vao VertexArrayObject) VertexBuffer(bindIndex uint32, buffer VertexBufferObject, offset, stride int32)
- func (vao VertexArrayObject) VertexBuffer32(bindIndex uint32, buffer VertexBufferObject, offset, stride int32)
- type VertexAttrib
- type VertexBufferObject
- func (vbo VertexBufferObject) Bind(target uint32)
- func (vbo VertexBufferObject) BufferData32(data []float32, usage uint32)
- func (vbo VertexBufferObject) BufferData64(data []float64, usage uint32)
- func (vbo VertexBufferObject) BufferStorage(data []float32, flags uint32)
- func (vbo VertexBufferObject) BufferStorage32(data []float32, flags uint32)
- func (vbo VertexBufferObject) BufferStorage64(data []float64, flags uint32)
- func (vbo VertexBufferObject) BufferSubData32(data []float32, offset int)
- func (vbo VertexBufferObject) BufferSubData64(data []float64, offset int)
- func (vbo VertexBufferObject) Clear32(data []float32)
- func (vbo VertexBufferObject) CopyTo(dest VertexBufferObject, readOffset, writeOffset int, size int32)
- func (vbo VertexBufferObject) Delete()
- func (vbo VertexBufferObject) Unbind(target uint32)
- type WinOption
Constants ¶
This section is empty.
Variables ¶
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
Types ¶
type Atlas ¶
type Atlas struct {
// contains filtered or unexported fields
}
Function to define an atlas (for a given alphabet)
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 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 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 (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 PrepareProgram ¶
PrepareProgram creates a program, attaches shaders and links before returning
func (Program) AttachShaders ¶
AttachShaders attaches one or more shaders to the program
func (Program) BindAttributeLocation ¶
Call this before linking to set location of attributes
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 (Program) GetParameter ¶
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 ¶
NewShader compiles the shader source and returns a shader object errors are logged. Source code does not need to end with \x00
func (Shader) GetInfoLog ¶
func (Shader) GetParameter ¶
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 ¶
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 ¶
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) Delete ¶
func (tex Texture) Delete()
Delete the texture freeing its name, freeing the associated storage
func (Texture) Image2D ¶
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 (Texture) Storage ¶
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
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()