resources

package
v0.0.0-...-a463a72 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package resources defines and loads shader and mesh resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load() error

Load loads all resources.

func Release

func Release()

Release clears all resources.

Types

type CellMesh

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

CellMesh defines a set of simulation cells.

func (*CellMesh) Commitfv

func (m *CellMesh) Commitfv([]float32, uint32)

func (*CellMesh) Commitiv

func (m *CellMesh) Commitiv(set []int32, usage uint32)

func (*CellMesh) Draw

func (m *CellMesh) Draw()

Draw renders the mesh.

func (*CellMesh) Release

func (m *CellMesh) Release()

Release clears mesh resources.

type GridMesh

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

GridMesh defines a grid.

func (*GridMesh) Commitfv

func (m *GridMesh) Commitfv(set []float32, usage uint32)

func (*GridMesh) Commitiv

func (m *GridMesh) Commitiv([]int32, uint32)

func (*GridMesh) Draw

func (m *GridMesh) Draw()

Draw renders the mesh.

func (*GridMesh) Release

func (m *GridMesh) Release()

Release clears mesh resources.

type Mesh

type Mesh interface {
	Release()
	Draw()

	Commitfv([]float32, uint32)
	Commitiv([]int32, uint32)
}

Mesh defines a generic mesh object.

func GetMesh

func GetMesh(name string) Mesh

GetMesh returns the mesh for the given name.

type QuadMesh

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

QuadMesh defines a simple, untextured quad.

func (*QuadMesh) Commitfv

func (m *QuadMesh) Commitfv([]float32, uint32)

func (*QuadMesh) Commitiv

func (m *QuadMesh) Commitiv([]int32, uint32)

func (*QuadMesh) Draw

func (m *QuadMesh) Draw()

Draw renders the mesh.

func (*QuadMesh) Release

func (m *QuadMesh) Release()

Release clears mesh resources.

type Shader

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

Shader loads GLSL shader sources and facilitates setting uniform values.

func CompileShader

func CompileShader(name, vsSrc, gsSrc, fsSrc string) (*Shader, error)

CompileShader loads the given vertex-, geometry- and fragment shader sources and compiles them into a single program. The name value is used in error emssages to more easily identify the source of a problem.

func GetShader

func GetShader(name string) *Shader

GetShader returns the shader for the given name.

func (*Shader) Release

func (s *Shader) Release()

func (*Shader) Set1f

func (s *Shader) Set1f(name string, v float32) error

Set1f sets the given uniform.

func (*Shader) Set1i

func (s *Shader) Set1i(name string, v int) error

Set1i sets the given uniform.

func (*Shader) Set2f

func (s *Shader) Set2f(name string, a, b float32) error

Set2f sets the given uniform.

func (*Shader) Set4f

func (s *Shader) Set4f(name string, a, b, c, d float32) error

Set4f sets the given uniform.

func (*Shader) SetMat16

func (s *Shader) SetMat16(name string, m []float32) error

SetMat16 sets the given uniform.

func (*Shader) Unuse

func (s *Shader) Unuse()

func (*Shader) Use

func (s *Shader) Use()

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 int) *TextureAtlas

NewAtlas creates a new texture atlas.

The given width, height determine the size of the underlying texture. The values are scaled up to the nearest power-of-two value, if they are not already a power-of-two.

func (*TextureAtlas) Allocate

func (ta *TextureAtlas) Allocate(width, height int) (image.Rectangle, 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 (ta *TextureAtlas) Bind()

Bind binds the atlas texture, so it can be used for rendering. This implictely commits the texture data to the GPU if it has changed since the last Bind call.

func (*TextureAtlas) Clear

func (ta *TextureAtlas) Clear()

Clear removes all allocated regions from the atlas. This invalidates any previously allocated regions.

func (*TextureAtlas) Release

func (ta *TextureAtlas) Release()

Release clears all atlas resources.

func (*TextureAtlas) Save

func (a *TextureAtlas) Save(file string) error

Save saves the texture image as a PNG file with the given name.

func (*TextureAtlas) Set

func (ta *TextureAtlas) Set(region image.Rectangle, src *image.RGBA)

Set draws the given image into the given region of the atlas. It assumes there is enough space available for the data to fit.

func (*TextureAtlas) Size

func (ta *TextureAtlas) Size() (int, int)

Size returns the texture dimensions.

func (*TextureAtlas) Unbind

func (ta *TextureAtlas) Unbind()

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.

type TexturedQuadMesh

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

TexturedQuadMesh defines a simple quad.

func (*TexturedQuadMesh) CommitTexture

func (m *TexturedQuadMesh) CommitTexture(img *image.RGBA, w, h int)

CommitTexture uploads the given texture and sets UV coordinates for the given size. This size is not necessarily the same as the size of img. Meaning w/h define a subset of img.

func (*TexturedQuadMesh) Commitfv

func (m *TexturedQuadMesh) Commitfv([]float32, uint32)

func (*TexturedQuadMesh) Commitiv

func (m *TexturedQuadMesh) Commitiv([]int32, uint32)

func (*TexturedQuadMesh) Draw

func (m *TexturedQuadMesh) Draw()

Draw renders the mesh.

func (*TexturedQuadMesh) Release

func (m *TexturedQuadMesh) Release()

Release clears mesh resources.

Jump to

Keyboard shortcuts

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