framebuffer

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: GPL-3.0 Imports: 1 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)

Clear texture. Black pixels.

func (*Sequence) Destroy

func (seq *Sequence) Destroy()

Destroy framebuffer.

func (*Sequence) Dimensions added in v0.23.0

func (seq *Sequence) Dimensions() (width int32, height int32)

Dimensions returns the width and height of the frame buffer used in the sequence

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) Setup

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

Setup framebuffer for specified dimensions

Returns true if any previous texture data has been lost. This can happen when the dimensions have changed. By definition, the first call to Setup() will always return false.

If the supplied width or height are less than zero the function will return false with no explanation.

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