Documentation
¶
Overview ¶
Package glsl implements a GLSL ES 1.00 / 3.00 front end (lexer, preprocessor, parser, type checker) and a closure-compiled executor for software rendering.
Index ¶
- func Float32ToHalf(f float32) uint16
- func HalfToFloat32(h uint16) float32
- type Block
- type BlockDecl
- type BlockMember
- type Decl
- type EK
- type Expr
- type ExtDirective
- type Field
- type Frame
- type FuncDef
- type IOVar
- type Instance
- type Kind
- type Options
- type Param
- type Qual
- type SK
- type SampleMode
- type SampleReq
- type Sampler
- type SamplerKind
- type Shader
- type Stage
- type Stmt
- type StructField
- type StructSpec
- type StructT
- type Tok
- type TokKind
- type Top
- type TopKind
- type Type
- type TypeSpec
- type Uniform
- type V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Float32ToHalf ¶
Float32ToHalf converts to IEEE binary16 (round to nearest even).
func HalfToFloat32 ¶
HalfToFloat32 converts IEEE binary16 to float32.
Types ¶
type Block ¶
type Block struct {
Name string
Inst string
Binding int
Members []BlockMember
ByteSize int
Used bool
ArrLen int
}
Block describes a uniform block.
type BlockMember ¶
type BlockMember struct {
Name string
T Type
Off int // register offset
Byte int // byte offset in the std140 buffer
Stride int // array stride in bytes (arrays), else 0
Mat int // matrix column stride in bytes
}
BlockMember is one member of a uniform block with its std140 placement.
type EK ¶
type EK uint8
const ( EIdent EK = iota EInt EUint EFloat EBool EUnary // S = op (prefix: - + ! ~ ++ --) EPostfix // S = ++ or -- EBinary // S = op EAssign // S = = += ... ETernary ECall // S = function name or constructor type name; Type set for constructors EIndex // Args[0][Args[1]] EField // Args[0].S EComma )
type ExtDirective ¶
ExtDirective records an #extension line.
type Frame ¶
type Frame struct {
R []uint32
Tex []Sampler
// Quad is called at derivative / implicit-LOD call sites; lanes of a
// quad are paired by site id.
Quad func(site int, in []float32) (dx, dy []float32)
Discarded bool
// contains filtered or unexported fields
}
Frame is the execution state of one shader invocation.
type IOVar ¶
type IOVar struct {
Name string
T Type
Off int
Loc int // layout(location) or -1
Flat bool
Used bool
Invariant bool
}
IOVar describes a shader input or output variable.
type Instance ¶
type Instance struct {
Frame
}
Instance executes a shader. Each goroutine needs its own Instance.
type Options ¶
type Options struct {
WebGL2 bool // allow #version 300 es
Extensions map[string]bool // extensions the context exposes (macros defined, behaviours accepted)
MaxDrawBuffers int
}
Options controls compilation.
type SampleMode ¶
type SampleMode uint8
SampleMode selects how the level of detail is chosen.
const ( SampleImplicit SampleMode = iota // derive from DX/DY (or level 0 when zero) SampleLod // explicit Lod SampleGrad // explicit DX/DY )
type SampleReq ¶
type SampleReq struct {
Coord [4]float32 // s,t,r and array layer / cube face already in Coord[2] or [3]
Ref float32 // shadow comparison value
DX, DY [3]float32 // derivatives of Coord (normalized texture coordinates)
Lod float32
Bias float32
Mode SampleMode
Offset [3]int32
}
SampleReq is a texture lookup.
type Sampler ¶
type Sampler interface {
// Sample returns the filtered RGBA (shadow samplers return the
// comparison result in all channels).
Sample(r *SampleReq) [4]float32
// SampleRaw performs a lookup in an integer texture; the result holds
// raw int32/uint32 bits.
SampleRaw(r *SampleReq) [4]uint32
// Texel fetches without filtering. For float textures the result holds
// float32 bits.
Texel(x, y, z, lod int) [4]uint32
// Size returns width, height, depth (or layers) of a level.
Size(lod int) [3]int
}
Sampler is the texture side of the executor.
type SamplerKind ¶
type SamplerKind uint8
SamplerKind describes a sampler type.
const ( Sampler2D SamplerKind = iota + 1 SamplerCube Sampler3D Sampler2DArray Sampler2DShadow SamplerCubeShadow Sampler2DArrayShadow ISampler2D ISampler3D ISamplerCube ISampler2DArray USampler2D USampler3D USamplerCube USampler2DArray )
func (SamplerKind) Dim ¶
func (k SamplerKind) Dim() int
Dim returns 2, 3 (3D), 6 (cube) or 22 (2D array).
func (SamplerKind) IsShadow ¶
func (k SamplerKind) IsShadow() bool
IsShadow reports whether k is a shadow sampler.
func (SamplerKind) ResultKind ¶
func (k SamplerKind) ResultKind() Kind
ResultKind is the component kind a sampler returns.
type Shader ¶
type Shader struct {
Stage Stage
Version int
OK bool
Log string
Exts map[string]string
Inputs []IOVar
Outputs []IOVar
Uniforms []Uniform
Blocks []*Block
// Built-in variable registers (-1 when absent).
PositionOff, PointSizeOff, VertexIDOff, InstanceIDOff int
FragCoordOff, FrontFacingOff, PointCoordOff int
FragColorOff, FragDataOff, FragDepthOff int
DepthRangeOff int
WritesFragDepth bool
WritesPointSize bool
WritesFragColor, WritesFragData bool
UsesDerivatives bool // dFdx/dFdy/fwidth
UsesImplicitLod bool // texture lookup without explicit lod
UsesDiscard bool
UsesFragCoord bool
// contains filtered or unexported fields
}
Shader is a compiled shader.
func (*Shader) NewInstance ¶
NewInstance creates an execution instance with its own register file.
type StructSpec ¶
type StructSpec struct {
Name string
Fields []*StructField
Line int
}
type Tok ¶
type Tok struct {
K TokKind
S string
Line int
BOL bool // first token on its line
Space bool // whitespace precedes the token
// contains filtered or unexported fields
}
Tok is one lexical token.
type Type ¶
type Type struct {
K Kind
N int // vector size or matrix rows (1 = scalar)
M int // matrix columns (1 = not a matrix)
Arr int
S *StructT
SK SamplerKind
}
Type is a GLSL type. Arrays are Types with Arr > 0 whose element type is the same Type with Arr == 0.