Documentation ¶
Index ¶
- type AtlasRegion
- type TextureAtlas
- func (a *TextureAtlas) Allocate(width, height int) (AtlasRegion, bool)
- func (a *TextureAtlas) Bind(target uint32)
- func (a *TextureAtlas) Clear()
- func (a *TextureAtlas) Commit(target uint32)
- func (a *TextureAtlas) Depth() int
- func (a *TextureAtlas) Handle() uint32
- func (a *TextureAtlas) Height() int
- func (a *TextureAtlas) Release()
- func (a *TextureAtlas) Save(file string) (err error)
- func (a *TextureAtlas) Set(region AtlasRegion, src []byte, stride int)
- func (a *TextureAtlas) Unbind(target uint32)
- func (a *TextureAtlas) Width() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtlasRegion ¶
A region denotes an allocated chunk of space in an atlas.
type TextureAtlas ¶
type TextureAtlas struct {
// contains filtered or unexported fields
}
A texture atlas is used to tightly pack arbitrarily many small images into a single texture.
The actual implementation is based on the article by Jukka Jylänki: "A Thousand Ways to Pack the Bin - A Practical Approach to Two-Dimensional Rectangle Bin Packing", February 27, 2010.
More precisely, this is an implementation of the 'Skyline Bottom-Left' algorithm.
func NewTextureAtlas ¶
func NewTextureAtlas(width, height, depth, filter int) *TextureAtlas
NewAtlas creates a new texture atlas.
The given width, height and depth determine the size and depth of the underlying texture.
depth should be 1, 3 or 4 and it will specify if the texture is created with Alpha, RGB or RGBA channels. The image data supplied through Atlas.Set() should be of the same format.
func (*TextureAtlas) Allocate ¶
func (a *TextureAtlas) Allocate(width, height int) (AtlasRegion, bool)
Allocate allocates a new region of the given dimensions in the atlas. It returns false if the allocation failed. This can happen when the specified dimensions exceed atlas bounds, or the atlas is full.
func (*TextureAtlas) Bind ¶
func (a *TextureAtlas) Bind(target uint32)
Bind binds the atlas texture, so it can be used for rendering.
func (*TextureAtlas) Clear ¶
func (a *TextureAtlas) Clear()
Clear removes all allocated regions from the atlas. This invalidates any previously allocated regions.
func (*TextureAtlas) Commit ¶
func (a *TextureAtlas) Commit(target uint32)
Commit creates the actual texture from the atlas image data. This should be called after all regions have been defined and set, and before you start using the texture for display.
func (*TextureAtlas) Depth ¶
func (a *TextureAtlas) Depth() int
Depth returns the underlying texture color depth.
func (*TextureAtlas) Handle ¶
func (a *TextureAtlas) Handle() uint32
func (*TextureAtlas) Height ¶
func (a *TextureAtlas) Height() int
Height returns the underlying texture height in pixels.
func (*TextureAtlas) Save ¶
func (a *TextureAtlas) Save(file string) (err error)
Save saves the texture as a PNG image.
func (*TextureAtlas) Set ¶
func (a *TextureAtlas) Set(region AtlasRegion, src []byte, stride int)
Set pastes the given data into the atlas buffer at the given coordinates. It assumes there is enough space available for the data to fit.
func (*TextureAtlas) Unbind ¶
func (a *TextureAtlas) Unbind(target uint32)
Unbind unbinds the current texture. Note that this applies to any texture currently active. If this is not the atlas texture, it will still perform the action.
func (*TextureAtlas) Width ¶
func (a *TextureAtlas) Width() int
Width returns the underlying texture width in pixels.