inputs

package
v0.0.0-...-9afce65 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

inputs/image.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {

	// Render pass specific state that will be set by the renderer
	ShaderProgram uint32
	PassInputs    []IChannel
	QuadVAO       uint32
	// contains filtered or unexported fields
}

Buffer manages two sets of FBOs and textures for double-buffering. This allows for effects where a shader pass reads from the output of the previous frame.

func NewBuffer

func NewBuffer(width, height int, vao uint32) (*Buffer, error)

NewBuffer creates the necessary OpenGL resources for a render buffer. It initializes two framebuffers and two textures for double buffering.

func (*Buffer) BindForWriting

func (b *Buffer) BindForWriting()

BindForWriting binds the current write-target FBO.

func (*Buffer) ChannelRes

func (b *Buffer) ChannelRes() [3]float32

func (*Buffer) Destroy

func (b *Buffer) Destroy()

func (*Buffer) GetCType

func (b *Buffer) GetCType() string

IChannel Interface Implementation

func (*Buffer) GetSamplerType

func (b *Buffer) GetSamplerType() string

func (*Buffer) GetTextureID

func (b *Buffer) GetTextureID() uint32

GetTextureID returns the ID of the texture that should be read from (the result of the previous frame).

func (*Buffer) Resize

func (b *Buffer) Resize(width, height int)

Resize changes the size of both textures and their FBO attachments.

func (*Buffer) SwapBuffers

func (b *Buffer) SwapBuffers()

SwapBuffers toggles the read/write indices. This is called after the buffer has been rendered to.

func (*Buffer) UnbindForWriting

func (b *Buffer) UnbindForWriting()

UnbindForWriting unbinds the FBO.

func (*Buffer) Update

func (b *Buffer) Update(uniforms *Uniforms)

func (*Buffer) UpdateTextureParameters

func (b *Buffer) UpdateTextureParameters(wrap, filter string, sampler api.Sampler)

Method to update texture parameters for both textures in the buffer

type CubeMapChannel

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

CubeMapChannel represents a cube map texture input.

func NewCubeMapChannel

func NewCubeMapChannel(images [6]image.Image, sampler api.Sampler) (*CubeMapChannel, error)

NewCubeMapChannel creates and initializes a new OpenGL cube map texture from six images.

func (*CubeMapChannel) ChannelRes

func (c *CubeMapChannel) ChannelRes() [3]float32

func (*CubeMapChannel) Destroy

func (c *CubeMapChannel) Destroy()

func (*CubeMapChannel) GetCType

func (c *CubeMapChannel) GetCType() string

func (*CubeMapChannel) GetSamplerType

func (c *CubeMapChannel) GetSamplerType() string

func (*CubeMapChannel) GetTextureID

func (c *CubeMapChannel) GetTextureID() uint32

func (*CubeMapChannel) Update

func (c *CubeMapChannel) Update(uniforms *Uniforms)

type IChannel

type IChannel interface {
	// GetCType return the ctype of the input
	GetCType() string

	// Update is called once per frame, passing in the global uniforms.
	Update(uniforms *Uniforms)

	// GetTextureID returns the OpenGL texture ID that should be bound.
	GetTextureID() uint32

	// ChannelRes returns the resolution of the input channel as a vec3.
	ChannelRes() [3]float32

	// Destroy releases any resources held by the channel.
	Destroy()

	// GetSamplerType returns the GLSL sampler type (e.g., "sampler2D", "samplerCube").
	GetSamplerType() string
}

IChannel defines the contract for any Shadertoy input channel (iChannel0-3).

func GetChannels

func GetChannels(shaderInputs []*api.ShadertoyChannel, width, height int, vao uint32, buffers map[string]*Buffer, options *options.ShaderOptions, ad audio.AudioDevice) ([]IChannel, error)

type ImageChannel

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

ImageChannel represents a static image texture input.

func NewImageChannel

func NewImageChannel(img image.Image, sampler api.Sampler) (*ImageChannel, error)

NewImageChannel creates and initializes a new OpenGL texture from an image.

func (*ImageChannel) ChannelRes

func (c *ImageChannel) ChannelRes() [3]float32

func (*ImageChannel) Destroy

func (c *ImageChannel) Destroy()

func (*ImageChannel) GetCType

func (c *ImageChannel) GetCType() string

IChannel Interface Implementation

func (*ImageChannel) GetSamplerType

func (c *ImageChannel) GetSamplerType() string

func (*ImageChannel) GetTextureID

func (c *ImageChannel) GetTextureID() uint32

func (*ImageChannel) Update

func (c *ImageChannel) Update(uniforms *Uniforms)

type MicChannel

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

MicChannel acts as a consumer of an audio stream.

func NewMicChannel

func NewMicChannel(options *options.ShaderOptions, sampler api.Sampler, ad audio.AudioDevice) (*MicChannel, error)

NewMicChannel creates a channel that gets data from the default microphone.

func NewMicChannelWithDevice

func NewMicChannelWithDevice(device audio.AudioDevice, options *options.ShaderOptions, sampler api.Sampler) (*MicChannel, error)

func (*MicChannel) ChannelRes

func (c *MicChannel) ChannelRes() [3]float32

func (*MicChannel) Destroy

func (c *MicChannel) Destroy()

Destroy just calls Stop() on the device.

func (*MicChannel) GetCType

func (c *MicChannel) GetCType() string

IChannel Interface Implementation

func (*MicChannel) GetSamplerType

func (c *MicChannel) GetSamplerType() string

func (*MicChannel) GetTextureID

func (c *MicChannel) GetTextureID() uint32

func (*MicChannel) ProcessAudio

func (c *MicChannel) ProcessAudio(monoSamples []float32)

ProcessAudio performs the FFT on the provided mono samples and stores the result in the channel's internal textureData buffer. This should be called from the main render thread before Update.

func (*MicChannel) SampleRate

func (c *MicChannel) SampleRate() int

SampleRate returns the sample rate of the audio device.

func (*MicChannel) Update

func (c *MicChannel) Update(uniforms *Uniforms)

Update reads from the shared buffer for FFT analysis.

type Uniforms

type Uniforms struct {
	Time              float32
	Mouse             [4]float32
	Frame             int32 // Frame count for animations or effects
	TimeDelta         float32
	FrameRate         float32
	ChannelTime       [4]float32
	SampleRate        float32
	ChannelResolution [4][3]float32
}

Uniforms holds the global shader values that dynamic channels might need.

type VolumeChannel

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

VolumeChannel represents a 3D volume texture input.

func NewVolumeChannel

func NewVolumeChannel(vol *api.VolumeData, sampler api.Sampler) (*VolumeChannel, error)

NewVolumeChannel creates and initializes a new OpenGL 3D texture from parsed .bin volume data.

func (*VolumeChannel) ChannelRes

func (c *VolumeChannel) ChannelRes() [3]float32

func (*VolumeChannel) Destroy

func (c *VolumeChannel) Destroy()

func (*VolumeChannel) GetCType

func (c *VolumeChannel) GetCType() string

IChannel Interface Implementation

func (*VolumeChannel) GetSamplerType

func (c *VolumeChannel) GetSamplerType() string

func (*VolumeChannel) GetTextureID

func (c *VolumeChannel) GetTextureID() uint32

func (*VolumeChannel) Update

func (c *VolumeChannel) Update(uniforms *Uniforms)

Jump to

Keyboard shortcuts

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