glbuild

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

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

Go to latest
Published: Nov 11, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendDefineDecl

func AppendDefineDecl(b []byte, aliasToDefine, aliasReplace string) []byte

func AppendDistanceDecl

func AppendDistanceDecl(b []byte, floatVarname, sdfPositionArgInput string, s Shader) []byte

func AppendFloat

func AppendFloat(b []byte, neg, decimal byte, v float32) []byte

func AppendFloatDecl

func AppendFloatDecl(b []byte, floatVarname string, v float32) []byte

func AppendFloatSliceDecl

func AppendFloatSliceDecl(b []byte, floatSliceVarname string, vecs []float32) []byte

func AppendFloats

func AppendFloats(b []byte, sep, neg, decimal byte, s ...float32) []byte

func AppendMat2Decl

func AppendMat2Decl(b []byte, mat2Varname string, m22 ms2.Mat2) []byte

func AppendMat3Decl

func AppendMat3Decl(b []byte, mat3Varname string, m33 ms3.Mat3) []byte

func AppendMat4Decl

func AppendMat4Decl(b []byte, mat4Varname string, m44 ms3.Mat4) []byte

func AppendShaderBufferDecl

func AppendShaderBufferDecl(dst []byte, BlockName, instanceName string, ssbo ShaderObject) ([]byte, error)

AppendShaderBufferDecl appends the ShaderObject as a Shader Storage Buffer Object (SSBO). Returns an error if not a buffer.

layout(<ssbo.std>, binding = <base>) buffer <BlockName> {
	<ssbo.Element> <ssbo.NamePtr>[];
} <instanceName>;

func AppendShaderSource

func AppendShaderSource(dst []byte, s Shader) (result, name, body []byte)

AppendShaderSource appends the GL code of a single shader to the dst byte buffer. If dst's capacity is grown during the writing the buffer with augmented capacity is returned. If not the same input dst is returned. name and body byte slices pointing to the result buffer are also returned for convenience.

func AppendUndefineDecl

func AppendUndefineDecl(b []byte, aliasToUndefine string) []byte

func AppendVec2Decl

func AppendVec2Decl(b []byte, vec2Varname string, v ms2.Vec) []byte

func AppendVec2SliceDecl

func AppendVec2SliceDecl(b []byte, vec2Varname string, vecs []ms2.Vec) []byte

func AppendVec3Decl

func AppendVec3Decl(b []byte, vec3Varname string, v ms3.Vec) []byte

func AppendVec3SliceDecl

func AppendVec3SliceDecl(b []byte, vec3Varname string, vecs []ms3.Vec) []byte

func ShortenNames2D

func ShortenNames2D(root *Shader2D, maxRewriteLen int) error

func ShortenNames3D

func ShortenNames3D(root *Shader3D, maxRewriteLen int) error

func WriteShader

func WriteShader(w io.Writer, s Shader, scratch []byte) (int, []byte, error)

func WriteShaders

func WriteShaders(w io.Writer, nodes []Shader, scratch []byte) (n int, newscratch []byte, err error)

WriteShaders iterates over the argument nodes in reverse order and writes their GL code to the writer. scratch is an auxiliary buffer to avoid heap allocations.

WriteShaders does not check for repeated shader names nor long tokens which may yield errors in the GL.

Types

type CachedShader2D

type CachedShader2D struct {
	Shader Shader2D
	// contains filtered or unexported fields
}

CachedShader2D implements the Shader2D interface with results it caches for another Shader2D on a call to RefreshCache.

func (*CachedShader2D) AppendShaderBody

func (c2 *CachedShader2D) AppendShaderBody(b []byte) []byte

AppendShaderBody returns the cached Shader function body. Implements Shader. Update by calling RefreshCache.

func (*CachedShader2D) AppendShaderName

func (c2 *CachedShader2D) AppendShaderName(b []byte) []byte

AppendShaderName returns the cached Shader name. Implements Shader. Update by calling RefreshCache.

func (*CachedShader2D) AppendShaderObjects

func (c2 *CachedShader2D) AppendShaderObjects(objs []ShaderObject) []ShaderObject

AppendShaderObjects returns the underlying Shader's buffer declarations.

func (*CachedShader2D) Bounds

func (c2 *CachedShader2D) Bounds() ms2.Box

Bounds returns the cached 2D bounds. Implements Shader3D. Update by calling RefreshCache.

func (*CachedShader2D) Evaluate

func (c2 *CachedShader2D) Evaluate(pos []ms2.Vec, dist []float32, userData any) error

Evaluate implements the gleval.SDF2 interface.

func (*CachedShader2D) ForEach2DChild

func (c2 *CachedShader2D) ForEach2DChild(userData any, fn func(userData any, s *Shader2D) error) error

ForEachChild calls the underlying Shader's ForEachChild. Implements Shader3D.

func (*CachedShader2D) RefreshCache

func (c2 *CachedShader2D) RefreshCache()

RefreshCache updates the cache with current values of the underlying shader.

type CachedShader3D

type CachedShader3D struct {
	Shader Shader3D
	// contains filtered or unexported fields
}

CachedShader3D implements the Shader3D interface with results it caches for another Shader3D on a call to RefreshCache.

func (*CachedShader3D) AppendShaderBody

func (c3 *CachedShader3D) AppendShaderBody(b []byte) []byte

AppendShaderBody returns the cached Shader function body. Implements Shader. Update by calling RefreshCache.

func (*CachedShader3D) AppendShaderName

func (c3 *CachedShader3D) AppendShaderName(b []byte) []byte

AppendShaderName returns the cached Shader name. Implements Shader. Update by calling RefreshCache.

func (*CachedShader3D) AppendShaderObjects

func (c3 *CachedShader3D) AppendShaderObjects(objs []ShaderObject) []ShaderObject

AppendShaderObjects returns the underlying Shader's buffer declarations.

func (*CachedShader3D) Bounds

func (c3 *CachedShader3D) Bounds() ms3.Box

Bounds returns the cached 3D bounds. Implements Shader3D. Update by calling RefreshCache.

func (*CachedShader3D) Evaluate

func (c3 *CachedShader3D) Evaluate(pos []ms3.Vec, dist []float32, userData any) error

Evaluate implements the gleval.SDF3 interface.

func (*CachedShader3D) ForEach2DChild

func (c3 *CachedShader3D) ForEach2DChild(userData any, fn func(userData any, s *Shader2D) error) (err error)

ForEach2DChild calls the underlying Shader's ForEach2DChild. This method is called for 3D shapes that use 2D shaders such as extrude and revolution. Implements Shader2D.

func (*CachedShader3D) ForEachChild

func (c3 *CachedShader3D) ForEachChild(userData any, fn func(userData any, s *Shader3D) error) error

ForEachChild calls the underlying Shader's ForEachChild. Implements Shader3D.

func (*CachedShader3D) RefreshCache

func (c3 *CachedShader3D) RefreshCache()

RefreshCache updates the cache with current values of the underlying shader.

type Programmer

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

Programmer implements shader generation logic for Shader type.

func NewDefaultProgrammer

func NewDefaultProgrammer() *Programmer

NewDefaultProgrammer returns a Programmer with reasonable default parameters for use with glgl package on the local machine.

func (*Programmer) ComputeInvocations

func (p *Programmer) ComputeInvocations() (int, int, int)

ComputeInvocations returns the worker group invocation size in x y and z.

func (*Programmer) SetComputeInvocations

func (p *Programmer) SetComputeInvocations(x, y, z int)

SetComputeInvocations sets the work group local-sizes. x*y*z must be less than maximum number of invocations.

func (*Programmer) WriteComputeSDF2

func (p *Programmer) WriteComputeSDF2(w io.Writer, obj Shader2D) (int, []ShaderObject, error)

WriteDistanceIO creates the bare bones I/O compute program for calculating SDF and writes it to the writer.

func (*Programmer) WriteComputeSDF3

func (p *Programmer) WriteComputeSDF3(w io.Writer, obj Shader3D) (int, []ShaderObject, error)

WriteDistanceIO creates the bare bones I/O compute program for calculating SDF and writes it to the writer.

func (*Programmer) WriteSDFDecl

func (p *Programmer) WriteSDFDecl(w io.Writer, s Shader) (baseName string, n int, objs []ShaderObject, err error)

WriteShaderDecl writes the SDF shader function declarations and returns the top-level SDF function name.

func (*Programmer) WriteShaderToyVisualizerSDF3

func (p *Programmer) WriteShaderToyVisualizerSDF3(w io.Writer, obj Shader3D) (n int, objs []ShaderObject, err error)

WriteShaderToyVisualizerSDF3 generates a OpenGL program that can be visualized in most shader visualizers such as ShaderToy.

type Shader

type Shader interface {
	// AppendShaderName appends the name of the GL shader function
	// to the buffer and returns the result. It should be unique to that shader.
	AppendShaderName(b []byte) []byte
	// AppendShaderBody appends the body of the shader function to the
	// buffer and returns the result.
	AppendShaderBody(b []byte) []byte
	// AppendShaderObject appends "objects" (read as data) needed to
	// evaluate the shader correctly. See [ShaderObject] for more information
	// on what an object can represent.
	AppendShaderObjects(objs []ShaderObject) []ShaderObject
}

Shader stores information for automatically generating SDF Shader pipelines and evaluating them correctly on a GPU.

func AppendAllNodes

func AppendAllNodes(dst []Shader, root Shader) ([]Shader, error)

AppendAllNodes BFS iterates over all of root's descendants and appends all nodes found to dst.

To generate shaders one must iterate over nodes in reverse order to ensure the first iterated nodes are the nodes with no dependencies on other nodes.

func ParseAppendNodes

func ParseAppendNodes(dst []Shader, root Shader) (baseName string, nodes []Shader, err error)

ParseAppendNodes parses the shader object tree and appends all nodes in Depth First order to the dst Shader argument buffer and returns the result.

type Shader2D

type Shader2D interface {
	Shader
	// ForEachChild iterats over the Shader2D's direct Shader2D children.
	// Unary operations have one child i.e: Translate, Scale.
	// Binary operations have two children i.e: Union, Intersection, Difference.
	ForEach2DChild(userData any, fn func(userData any, s *Shader2D) error) error
	// Bounds returns the Shader2D's bounding box where the SDF is negative.
	Bounds() ms2.Box
}

Shader2D can create SDF shader source code for an arbitrary 2D shape.

func OverloadShader2DBounds

func OverloadShader2DBounds(s Shader2D, bb ms2.Box) Shader2D

OverloadShader2DBounds overloads a Shader2D Bounds method with the argument bounding box.

type Shader3D

type Shader3D interface {
	Shader
	// ForEachChild iterats over the Shader3D's direct Shader3D children.
	// Unary operations have one child i.e: Translate, Transform, Scale.
	// Binary operations have two children i.e: Union, Intersection, Difference.
	ForEachChild(userData any, fn func(userData any, s *Shader3D) error) error
	// Bounds returns the Shader3D's bounding box where the SDF is negative.
	Bounds() ms3.Box
}

Shader3D can create SDF shader source code for an arbitrary 3D shape.

func OverloadShader3DBounds

func OverloadShader3DBounds(s Shader3D, bb ms3.Box) Shader3D

OverloadShader3DBounds overloads a Shader3D Bounds method with the argument bounding box.

type ShaderObject

type ShaderObject struct {
	// NamePtr is a pointer to the name of the buffer inside of the [Shader].
	// This lets the programmer edit the name if a naming conflict is found before generating the shader bodies.
	NamePtr []byte

	// Element is the element of the buffer.
	Element reflect.Type
	// Data points to the start of buffer data.
	Data unsafe.Pointer
	// Size of buffer in bytes.
	Size int
	// Binding specifies the resource's binding point during shader execution.
	// Binding should be equal to -1 until the final binding point is allocated in shader generation.
	Binding int
	// contains filtered or unexported fields
}

ShaderObject is a handle to data needed to evaluate a Shader correctly. A ShaderObject could represent any of the following:

  • Shader Storage Buffer Object (SSBO). Is a 1D array of structured data.
  • Texture. Represents 2D data, usually images.
  • Shader uniform. Is a single structured value.

func MakeShaderBufferReadOnly

func MakeShaderBufferReadOnly[T any](namePtr []byte, data []T) (ssbo ShaderObject, err error)

func (ShaderObject) Validate

func (obj ShaderObject) Validate() error

type XYZBits

type XYZBits uint8

func NewXYZBits

func NewXYZBits(x, y, z bool) XYZBits

func (XYZBits) AppendMapped

func (xyz XYZBits) AppendMapped(b []byte, Map [3]byte) []byte

func (XYZBits) AppendMapped_XYZ

func (xyz XYZBits) AppendMapped_XYZ(b []byte) []byte

func (XYZBits) AppendMapped_rgb

func (xyz XYZBits) AppendMapped_rgb(b []byte) []byte

func (XYZBits) AppendMapped_xyz

func (xyz XYZBits) AppendMapped_xyz(b []byte) []byte

func (XYZBits) X

func (xyz XYZBits) X() bool

func (XYZBits) Y

func (xyz XYZBits) Y() bool

func (XYZBits) Z

func (xyz XYZBits) Z() bool

Jump to

Keyboard shortcuts

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