gfx

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package gfx is a thin abstraction layer for OpenGL.

Index

Constants

This section is empty.

Variables

View Source
var (
	// FrameSync is an internal variable.
	FrameSync = make(chan chan struct{}, 1)
)

GL is the OpenGL context.

Lock should be held whenever an operation depends on or modifies global OpenGL state.

View Source
var Square = NewStaticBuffer("square", []uint8{
	m1, +1, m1, 1, 0, 0,
	m1, m1, m1, 1, 0, 1,
	+1, m1, +1, 1, 1, 1,
	+1, +1, +1, 1, 1, 0,
}, []uint8{3, 0, 2, 0, 1, 0, 0, 0, 3, 0, 1, 0}, 2)

Square is a StaticBuffer containing vertices for a square.

Functions

func HorizontalFOV added in v0.3.12

func HorizontalFOV(angle float64) float32

func Init

func Init(ctx gl.Context)

Init is an internal function that sets up the context.

func NextFrame

func NextFrame() bool

NextFrame synchronizes a frame boundary.

func PixelSize added in v0.3.6

func PixelSize() (w, h int)

PixelSize returns the screen size without compensation for pixel density.

func Release added in v0.2.70

func Release()

Release is an internal function that shuts down the context.

func SetSize

func SetSize(e size.Event)

SetSize processes a size.Event.

func Size

func Size() (w, h int)

Size returns the current screen size.

func StatRecordBufferData added in v0.3.4

func StatRecordBufferData(count int)

func StatRecordTextureUse added in v0.3.4

func StatRecordTextureUse(tex *AssetTexture)

func StatRecordTriangleBatch added in v0.3.4

func StatRecordTriangleBatch(points int)

Types

type AssetTexture added in v0.2.72

type AssetTexture struct {
	Name string
	// contains filtered or unexported fields
}

AssetTexture is a lazy-loaded texture.

func BlankAssetTexture added in v0.2.75

func BlankAssetTexture() *AssetTexture

BlankAssetTexture returns a 1x1 white square.

func DummyAssetTexture added in v0.3.5

func DummyAssetTexture(tex gl.Texture) *AssetTexture

func NewAssetTexture added in v0.2.72

func NewAssetTexture(name string, nearest, noMip bool) *AssetTexture

NewAssetTexture creates a lazy-loaded texture from an asset.

func NewCachedAssetTexture added in v0.2.75

func NewCachedAssetTexture(name string) *AssetTexture

NewCachedAssetTexture creates a lazy-loaded texture from an asset.

func NewEmbeddedTexture added in v0.2.75

func NewEmbeddedTexture(name string, nearest bool, data []byte, mimeType string, premultiplyAlpha bool) *AssetTexture

NewEmbeddedTexture creates an AssetTexture that loads from memory.

func (*AssetTexture) LazyTexture added in v0.2.73

func (a *AssetTexture) LazyTexture(def gl.Texture) gl.Texture

LazyTexture loads the texture and returns the texture handle.

func (*AssetTexture) Preload added in v0.2.72

func (a *AssetTexture) Preload() error

Preload loads the texture and returns any error encountered.

func (*AssetTexture) Ready added in v0.3.10

func (a *AssetTexture) Ready() bool

func (*AssetTexture) Release added in v0.2.73

func (a *AssetTexture) Release()

Release deletes the texture handle.

func (*AssetTexture) StartPreload added in v0.3.7

func (a *AssetTexture) StartPreload()

StartPreload is a convenience function that calls Preload in a new goroutine.

func (*AssetTexture) Texture added in v0.2.72

func (a *AssetTexture) Texture() gl.Texture

Texture loads the texture and returns the texture handle.

type Attrib added in v0.2.70

type Attrib struct {
	Attrib gl.Attrib
	Name   string
	// contains filtered or unexported fields
}

Attrib is a vertex attribute.

type Camera

type Camera struct {
	Offset      Matrix
	Rotation    Matrix
	Position    Matrix
	Perspective Matrix
	// contains filtered or unexported fields
}

Camera tracks the position and orientation of the 3D camera.

func (*Camera) Combined

func (c *Camera) Combined(m *Matrix)

Combined returns the combined transformation matrix.

func (*Camera) PopTransform

func (c *Camera) PopTransform()

PopTransform removes the last transform added via PushTransform.

func (*Camera) PushTransform

func (c *Camera) PushTransform(m *Matrix)

PushTransform adds a transform to the transform stack.

func (*Camera) PushTranslation added in v0.3.7

func (c *Camera) PushTranslation(x, y, z float32)

PushTranslation is a helper function to push a translation-based transform to the stack.

func (*Camera) SetDefaults

func (c *Camera) SetDefaults()

SetDefaults sets the Matrix fields in Camera to default values.

type CustomInit added in v0.2.70

type CustomInit struct {
	Name string
	// contains filtered or unexported fields
}

CustomInit is a custom OpenGL init/release function pair.

func Custom added in v0.2.70

func Custom(name string, init, release func()) *CustomInit

Custom registers a CustomInit.

type ErrShaderLink struct {
	Name string
	Vert string
	Frag string
	Link string
}

func (ErrShaderLink) Error added in v0.3.7

func (err ErrShaderLink) Error() string

type Matrix

type Matrix [16]float32

Matrix is a 4x4 transformation matrix.

func (*Matrix) Identity added in v0.3.7

func (m *Matrix) Identity()

Identity returns the identity matrix.

func (*Matrix) Multiply added in v0.3.7

func (m *Matrix) Multiply(m0, m1 *Matrix)

Multiply multiplies a matrix by a matrix.

func (*Matrix) Perspective added in v0.3.7

func (m *Matrix) Perspective(fov, aspect, nearZ, farZ float32)

Perspective constructs a perspective matrix.

func (*Matrix) RotationX added in v0.3.7

func (m *Matrix) RotationX(r float32)

RotationX constructs a rotation matrix over the X axis.

func (*Matrix) RotationY added in v0.3.7

func (m *Matrix) RotationY(r float32)

RotationY constructs a rotation matrix over the Y axis.

func (*Matrix) RotationZ added in v0.3.7

func (m *Matrix) RotationZ(r float32)

RotationZ constructs a rotation matrix over the Z axis.

func (*Matrix) Scale added in v0.3.7

func (m *Matrix) Scale(x, y, z float32)

Scale constructs a scaling matrix.

func (*Matrix) Translation added in v0.3.7

func (m *Matrix) Translation(x, y, z float32)

Translation constructs translation matrix.

type Program added in v0.2.70

type Program struct {
	Name string

	Program gl.Program
	// contains filtered or unexported fields
}

Program is an OpenGL shader.

func Shader added in v0.2.70

func Shader(name, vertex, fragment string) *Program

Shader registers an OpenGL shader.

func (*Program) Attrib added in v0.2.70

func (p *Program) Attrib(name string) *Attrib

Attrib gets the location of a vertex attribute.

func (*Program) Uniform added in v0.2.70

func (p *Program) Uniform(name string) *Uniform

Uniform gets the location of a global variable.

type StaticBuffer

type StaticBuffer struct {
	Name string

	Data    gl.Buffer
	Element gl.Buffer
	Count   int
	// contains filtered or unexported fields
}

StaticBuffer is a convenience layer for OpenGL vertex buffer objects.

func NewStaticBuffer

func NewStaticBuffer(name string, data, elements []uint8, elementSize int) *StaticBuffer

NewStaticBuffer creates a StaticBuffer.

func (*StaticBuffer) Delete

func (sb *StaticBuffer) Delete()

Delete frees the GPU memory held by StaticBuffer and removes it from the list of buffers.

type Texture added in v0.2.70

type Texture struct {
	Name    string
	Texture gl.Texture
	// contains filtered or unexported fields
}

Texture is an OpenGL texture.

func NewTexture added in v0.2.70

func NewTexture(name string, img image.Image, nearest, noMip, premultiplyAlpha bool) *Texture

NewTexture creates a texture.

func (*Texture) Release added in v0.2.73

func (t *Texture) Release()

Release deletes a texture handle.

type Uniform added in v0.2.70

type Uniform struct {
	Uniform gl.Uniform
	Name    string
	// contains filtered or unexported fields
}

Uniform is a global variable.

type Vector

type Vector [4]float32

Vector is a 4-component geometric vector of (x, y, z, 1).

func (*Vector) Multiply added in v0.3.7

func (v *Vector) Multiply(m *Matrix, v0 *Vector)

Multiply multiplies a matrix by a vector.

Directories

Path Synopsis
Package crt renders a screen-space CRT monitor effect.
Package crt renders a screen-space CRT monitor effect.
Package sprites handles loading and rendering sprites.
Package sprites handles loading and rendering sprites.

Jump to

Keyboard shortcuts

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