util

package
v0.0.0-...-793ea6c Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilState    = errors.New("Draw: gfx.State is nil (ignoring object)")
	ErrNilShader   = errors.New("Draw: gfx.Shader is nil (ignoring object)")
	ErrNilSource   = errors.New("Draw: gfx.Texture has a nil Source image (ignoring object)")
	ErrNoVertices  = errors.New("Draw: gfx.Mesh has no vertices (ignoring object)")
	ErrNoMeshes    = errors.New("Draw: gfx.Object has no meshes (ignoring object)")
	ErrShaderError = errors.New("Draw: gfx.Shader has a compiler error (ignoring object)")
)

Functions

func POT

func POT(img image.Image) image.Image

POT resamples/resizes the given image to the nearest power-of-two size (if it is not a power-of-two size already).

func PreDraw

func PreDraw(dev gfx.Device, rect image.Rectangle, o *gfx.Object, c gfx.Camera) (draw bool, err error)

PreDraw performs the commonplace tasks that occur before each object is drawn in a call to gfx.Canvas.Draw. It returns a draw boolean which signals whether or not the object should be drawn, and also may return a != nil error if the developer should be warned.

It will return draw=false, err == nil in the following cases:

rect.Empty() == true
o.Shader != nil && len(o.Shader.Error) > 0

It may return the following errors:

ErrNilState
ErrNilShader
ErrNilSource
ErrNoVertices
ErrNoMeshes
ErrShaderError

If draw == true && err == nil, then it will:

Make the implicit call to o.Bounds() required by gfx.Canvas such that the object has a chance to calculate a bounding box before it's data slices are set to nil.

Ask the given device to load each shader, mesh, and texture that the object has associated with it and waits for loading to complete before returning.

func VerticalFlip

func VerticalFlip(img *image.RGBA)

VerticalFlip flips the given image in-place, vertically.

Types

type BaseCanvas

type BaseCanvas struct {
	sync.RWMutex
	VMSAA      bool            // The MSAA state.
	VPrecision gfx.Precision   // The precision of this canvas.
	VBounds    image.Rectangle // The bounding rectangle of this canvas.
}

BaseCanvas implements basic portions of a gfx.Canvas. Specifically the methods it implements are:

SetMSAA
MSAA
Precision
Bounds

func (*BaseCanvas) Bounds

func (c *BaseCanvas) Bounds() image.Rectangle

Implements the gfx.Canvas interface.

func (*BaseCanvas) MSAA

func (c *BaseCanvas) MSAA() bool

Implements gfx.Canvas interface.

func (*BaseCanvas) Precision

func (c *BaseCanvas) Precision() gfx.Precision

Implements gfx.Canvas interface.

func (*BaseCanvas) SetMSAA

func (c *BaseCanvas) SetMSAA(msaa bool)

Implements gfx.Canvas interface.

func (*BaseCanvas) UpdateBounds

func (c *BaseCanvas) UpdateBounds(bounds image.Rectangle)

UpdateBounds updates the bounds of this canvas, under c's write lock.

type Swapper

type Swapper struct {
	Yield chan struct{}
	Swap  chan gfx.Device
	// contains filtered or unexported fields
}

Swapper is a swappable gfx.Device implementation.

func NewSwapper

func NewSwapper(d gfx.Device) *Swapper

NewSwapper returns a new graphics device swapper, wrapping the given device.

func (*Swapper) Bounds

func (s *Swapper) Bounds() image.Rectangle

Bounds returns the bounds of the current graphics device.

func (*Swapper) Clear

func (s *Swapper) Clear(r image.Rectangle, bg gfx.Color)

Clear submits a clear operation to the current graphics device.

func (*Swapper) ClearDepth

func (s *Swapper) ClearDepth(r image.Rectangle, depth float64)

ClearDepth submits a depth clear operation to the current graphics device.

func (*Swapper) ClearStencil

func (s *Swapper) ClearStencil(r image.Rectangle, stencil int)

ClearStencil submits a stencil clear operation to the current graphics device.

func (*Swapper) Clock

func (s *Swapper) Clock() *clock.Clock

Clock returns this swapper's own clock.

func (*Swapper) Download

func (s *Swapper) Download(r image.Rectangle, complete chan image.Image)

Download performs a download from the current graphics device.

func (*Swapper) Draw

func (s *Swapper) Draw(r image.Rectangle, o *gfx.Object, c gfx.Camera)

Draw submits a draw operation to the current graphics device.

func (*Swapper) Info

func (s *Swapper) Info() gfx.DeviceInfo

Bounds returns the info of the current graphics device.

func (*Swapper) LoadMesh

func (s *Swapper) LoadMesh(m *gfx.Mesh, done chan *gfx.Mesh)

LoadMesh loads a mesh using the current graphics device.

func (*Swapper) LoadShader

func (s *Swapper) LoadShader(sh *gfx.Shader, done chan *gfx.Shader)

LoadShader loads a shader using the current graphics device.

func (*Swapper) LoadTexture

func (s *Swapper) LoadTexture(t *gfx.Texture, done chan *gfx.Texture)

LoadTexture loads a texture using the current graphics device.

func (*Swapper) MSAA

func (s *Swapper) MSAA() (msaa bool)

MSAA gets the MSAA status of the current graphics device.

func (*Swapper) Precision

func (s *Swapper) Precision() gfx.Precision

Bounds returns the precision of the current graphics device.

func (*Swapper) QueryWait

func (s *Swapper) QueryWait()

QueryWait waits for occlusion queries to wait on the current graphics device.

func (*Swapper) Render

func (s *Swapper) Render()

Render renders a frame using the current graphics device. When it finishes the swapper considers yielding and swapping the underlying graphics device out with another.

func (*Swapper) RenderToTexture

func (s *Swapper) RenderToTexture(cfg gfx.RTTConfig) gfx.Canvas

RenderToTexture returns a new RTT canvas using the current graphics device.

TODO(slimsag): Do we require a swappable canvas, here, too?

func (*Swapper) SetMSAA

func (s *Swapper) SetMSAA(msaa bool)

SetMSAA sets the MSAA status of the current graphics device.

type Warner

type Warner struct {
	sync.RWMutex
	W io.Writer
	// contains filtered or unexported fields
}

Warner can warn developers of a potential problem. It writes it's warnings to the underlying writer.

A map of previous warnings is used to identify previous warnings, and as such you should be concious of potential memory overhead (i.e. only use it for situations where warnings should not happen generally).

func NewWarner

func NewWarner(w io.Writer) *Warner

NewWarner initializes and returns a new warner, using the given writer.

func (*Warner) Warn

func (w *Warner) Warn(msg string)

Warn writes a single warning message out to the underlying writer (w.W). It will only write the message once even if multiple calls are made, thus:

w.Warn("Something bad has happened!")
w.Warn("Something bad has happened!")
w.Warn("Something bad has happened (again)!")

Will produce just the following output:

Something bad has happened!
Something bad has happened (again)!

func (*Warner) Warnf

func (w *Warner) Warnf(format string, args ...interface{})

Warnf is short-handed for:

w.Warn(fmt.Sprintf(format, args...))

Jump to

Keyboard shortcuts

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