framebuffer

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: GPL-3.0, GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package framebuffer provides a convenient way of working with OpenGL framebuffers. The Sequence type conceptualises a sequence of textures all of which may be attached to the framebuffer object for a drawing operation.

The key to the Sequence type is the texture index. This is not to be confused with the texture ID. The number of textures (and therefore texture indices) is defined at Seqeunce creation, with NewSequence().

For example, to create a framebuffer sequence with two textures:

seq := NewSequence(2)

The Setup() function must be called at least once after NewSequence() and called as often as necessary to ensure the dimensions (width and height) are correct.

hasChanged := seq.Setup(800, 600)

Setup() returns true if the texture data has been recreated in accordance with the new dimensions.

The Process() function is used to assign the framebuffer object and for convenience, runs the supplied the draw() function. The texture ID is returned and can be used for presentation of as the input for the next call to Process() (via the draw() function).

texture := seq.Process(0, func() {
	// 1. set up shader
	// 2. OpenGL draw (eg. gl.DrawElements()
})

Note that much of the work of chaning a sequence of shaders must be performed by the user of the package. The package does however, hide a lot of detail behind the Process() and Setup() functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sequence

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

Sequence represents the sequence of textures that can be assigned to a framebuffer.

func NewSequence

func NewSequence(numTextures int) *Sequence

NewSequence is the preferred method of initialisation of the Sequence type.

func (*Sequence) Clear added in v0.14.0

func (seq *Sequence) Clear(idxTexture int) uint32

Clear texture. Black pixels.

func (*Sequence) Destroy

func (seq *Sequence) Destroy()

Destroy framebuffer.

func (*Sequence) Len

func (seq *Sequence) Len() int

Len returns the number of textures employed in the framebuffer sequence.

func (*Sequence) Process

func (seq *Sequence) Process(idxTexture int, draw func()) uint32

Process assigns the texture related to idxTexture to the framebuffer and runs the supplied draw() function.

Returns the texture ID (not the index) that has been assigned to the framebuffer.

Changes the state of the frame buffer.

func (*Sequence) SaveJPEG

func (seq *Sequence) SaveJPEG(idxTexture int, path string, logTag string)

SavesJPEG writes the texture to the specified path. Does not return any errors but will log using logTag if logTag is not empty.

func (*Sequence) Setup

func (seq *Sequence) Setup(width int32, height int32) bool

Setup framebuffer for sepecified width and height. Previous texture data is lost. Returns true if Setup has caused a change in texture data.

Changes the state of the frame buffer.

func (*Sequence) Texture

func (seq *Sequence) Texture(idxTexture int) uint32

Texture returns the texture ID related to the idxTexture.

Jump to

Keyboard shortcuts

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