gfxutil

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: 7 Imported by: 13

Documentation

Overview

Package gfxutil implements basic gfx utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InsertionSort

func InsertionSort(data sort.Interface)

InsertionSort performs a simple insertion sort on the sort interface. In the case of ByDist it performs generally as fast as sort.Sort except that it can exploit temporal coherence improving performance dramatically when the objects have not moved much.

func OpenShader

func OpenShader(basePath string) (*gfx.Shader, error)

OpenShader opens the GLSL shader files specified by the given base path. For example:

s := OpenShader("glsl/basic")

Would return a shader composed of the two GLSL shader sources:

glsl/basic.vert
glsl/basic.frag

The filename (e.g. "basic") will be the name of the shader (which is used for debug output only).

If a error is returned it is an IO error and a nil shader is returned.

func OpenTexture

func OpenTexture(path string) (*gfx.Texture, error)

OpenTexture opens the named image file, decodes it, and returns a texture with that image as it's source. As usual, you will also need to import a image decoder, e.g. for png:

import _ "image/png"

The returned texture will have a MinFilter == LinearMipmapLinear (trilinear filtering) a MagFilter == Linear, and Format == DXT1.

If a error is returned it is an IO or image decoding error and a nil texture is returned.

Types

type ByDist

type ByDist struct {
	// The list of objects to sort.
	Objects []*gfx.Object

	// The target position to compare against. The list is sorted based off
	// each object's distance away from this position (typically this is the
	// camera's position).
	Target lmath.Vec3
}

ByDist sorts a list of graphics objects based on their distance away from a target position (typically the camera). As such if the sorted objects are drawn in order then they are drawn back-to-front (which is useful for rendering alpha-blended objects such that transparency appears correct).

Using sort.Reverse this doubles as front-to-back sorting (which is useful for drawing opaque objects efficiently due to depth testing).

func (ByDist) Len

func (b ByDist) Len() int

Len implements the sort interface.

func (ByDist) Less

func (b ByDist) Less(ii, jj int) bool

Less implements the sort interface.

func (ByDist) Swap

func (b ByDist) Swap(i, j int)

Swap implements the sort interface.

type ByState

type ByState []*gfx.Object

ByState sorts a list of graphics objects based on the change of their graphics state in order to reduce graphics state changes and increase the overall throughput when rendering several objects whose graphics state differ.

func (ByState) Len

func (b ByState) Len() int

Len implements the sort interface.

func (ByState) Less

func (b ByState) Less(i, j int) bool

Less implements the sort interface.

func (ByState) Swap

func (b ByState) Swap(i, j int)

Swap implements the sort interface.

Jump to

Keyboard shortcuts

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