dax

package module
v0.0.0-...-15a073e Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: MIT Imports: 15 Imported by: 0

README

DaX

Build Status Coverage Status GoDoc

DaX is my little creative coding experiment.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOrthographicCamera

func NewOrthographicCamera(left, right, bottom, top, near, far float32) *orthographicCamera

func NewPerspectiveCamera

func NewPerspectiveCamera(fovy, aspect, near, far float32) *perspectiveCamera

func NewScreenSpaceCamera

func NewScreenSpaceCamera(width, height int, near, far float32) *screenSpaceCamera

func Rand

func Rand(min, max float32) float32

Types

type Application

type Application struct {
	Name string
	// contains filtered or unexported fields
}

Application object is the top level object from which everything else in DaX is derived.

func NewApplication

func NewApplication(name string) *Application

NewApplication creates a new Application. This is a singleton.

func (*Application) CreateWindow

func (app *Application) CreateWindow(name string, width, height int) *Window

CreateWindow creates a window on which scene will be drawn.

func (*Application) Run

func (app *Application) Run()

Run enters the application main loop.

type Attribute

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

Attribute is per-vertex data as input to the vertex shader.

func (*Attribute) Kind

func (u *Attribute) Kind() VariableKind

Kind returns the kind of uniform

func (*Attribute) Name

func (u *Attribute) Name() string

Name returns the name of the uniform.

type AttributeBuffer

type AttributeBuffer struct {
	Name          string
	NumComponents int
	Data          []float32
}

AttributeBuffer holds per-vertex attribute. There is one AttributeBuffer per kind of data we want to keep with each vertex.

func NewAttributeBuffer

func NewAttributeBuffer(name string, size int, NumComponents int) *AttributeBuffer

func (*AttributeBuffer) GetX

func (ab *AttributeBuffer) GetX(index int) (x float32)

func (*AttributeBuffer) GetXY

func (ab *AttributeBuffer) GetXY(index int) (x, y float32)

func (*AttributeBuffer) GetXYZ

func (ab *AttributeBuffer) GetXYZ(index int) (x, y, z float32)

func (*AttributeBuffer) GetXYZW

func (ab *AttributeBuffer) GetXYZW(index int) (x, y, z, w float32)

func (*AttributeBuffer) Init

func (ab *AttributeBuffer) Init(name string, size int, NumComponents int)

func (*AttributeBuffer) InitFromData

func (ab *AttributeBuffer) InitFromData(name string, data []float32, NumComponents int)

func (*AttributeBuffer) Len

func (ab *AttributeBuffer) Len() int

Len returns the number of elements in the AttributeBuffer. Because each element has a number of components, the length of the Data array is then Len() * NumComponents.

func (*AttributeBuffer) SetX

func (ab *AttributeBuffer) SetX(index int, x float32)

func (*AttributeBuffer) SetXY

func (ab *AttributeBuffer) SetXY(index int, x, y float32)

func (*AttributeBuffer) SetXYZ

func (ab *AttributeBuffer) SetXYZ(index int, x, y, z float32)

func (*AttributeBuffer) SetXYZW

func (ab *AttributeBuffer) SetXYZW(index int, x, y, z, w float32)

type BaseCamera

type BaseCamera struct {
	Node
	// contains filtered or unexported fields
}

BaseCamera is a struct that can be embedded to make creating custom cameras easier. ScreenSpaceCamera, OrthographicCamera and PerspectiveCamera embed this type and can be used as examples.

func (*BaseCamera) AsNode

func (c *BaseCamera) AsNode() *Node

func (*BaseCamera) GetProjection

func (c *BaseCamera) GetProjection() *math.Mat4

func (*BaseCamera) Init

func (c *BaseCamera) Init()

Init initializes the BaseCamera. Call this function first before anything else.

func (*BaseCamera) LookAt

func (c *BaseCamera) LookAt(target *math.Vec3)

LookAt rotates the camera to look at the target

type BaseMaterial

type BaseMaterial struct {
	Blending  Blending
	DepthTest DepthTest
}

BaseMaterial holds the common material state and can be used to implement custom materials.

func (*BaseMaterial) GetBlending

func (m *BaseMaterial) GetBlending() *Blending

GetBlending is part of the Material interface.

func (*BaseMaterial) GetDepthTest

func (m *BaseMaterial) GetDepthTest() *DepthTest

GetDepthTest is part of the Material interface.

func (*BaseMaterial) GetFragmentShader

func (m *BaseMaterial) GetFragmentShader() *FragmentShader

GetFragmentShader is part of the Material interface.

func (*BaseMaterial) ID

func (m *BaseMaterial) ID() string

ID is part of the Material interface.

type Blending

type Blending struct {
	Enabled   bool
	ModeRGB   BlendingMode
	ModeAlpha BlendingMode
	SrcRGB    BlendingFunc
	DstRGB    BlendingFunc
	SrcAlpha  BlendingFunc
	DstAlpha  BlendingFunc
	Color     Color
}

Blending holds the entire blending state of a Material.

type BlendingFunc

type BlendingFunc int

BlendingFunc is the blending function of a Material.

const (
	BlendingOne BlendingFunc = iota
	BlendingZero

	BlendingSrcColor
	BlendingDstColor
	BlendingOneMinusSrcColor
	BlendingOneMinusDstColor

	BlendingSrcAlpha
	BlendingDstAlpha
	BlendingOneMinusSrcAlpha
	BlendingOneMinusDstAlpha

	BlendingConstantColor
	BlendingOneMinusConstantColor
	BlendingConstantAlpha
	BlendingOneMinusConstantAlpha
)

type BlendingMode

type BlendingMode int

BlendingMode is the blending mode of a Material.

const (
	BlendingAdd BlendingMode = iota
	BlendingSubstract
	BlendingReverseSubstract
	BlendingMin
	BlendingMax
)

type Camera

type Camera interface {
	AsNode() *Node
	UpdateFBSize(width, height int)
	GetProjection() *math.Mat4
}

type Color

type Color struct {
	R, G, B, A float32
}

Color represents a color encoded in RGBA.

func (*Color) FromHSL

func (color *Color) FromHSL(h, s, l float32)

FromHSL initializes a color from (h,s,l) values. h, s, l are between 0 and 1. Conversion formula is adapted from: http://en.wikipedia.org/wiki/HSL_color_space

func (*Color) FromRGB

func (color *Color) FromRGB(r, g, b float32)

FromRGB initializes a color from (r,g,b) values. Components should be between 0 and 1. The alpha is initiazed to 1 (fully opaque).

func (*Color) FromRGBA

func (color *Color) FromRGBA(r, g, b, a float32)

FromRGBA initializes a color from (r,g,b,a) values. Components should be between 0 and 1.

func (*Color) FromRGBAu8

func (color *Color) FromRGBAu8(r, g, b, a uint8)

FromRGBAu8 initializes a color from (r,g,b,a) values. Components should be between 0 and 255.

func (*Color) FromRGBu8

func (color *Color) FromRGBu8(r, g, b uint8)

FromRGBu8 initializes a color from (r,g,b) values. Components should be between 0 and 255. The alpha is initiazed to 1 (ie 255, fully opaque).

func (*Color) ToHSL

func (color *Color) ToHSL() (h, s, l float32)

ToHSL converts a color to HSL. Returned (h,s,l) components are between 0 and 1. Conversion formula adapted from: http://en.wikipedia.org/wiki/HSL_color_space.

func (*Color) Vec4

func (color *Color) Vec4() math.Vec4

Vec4 returns a Vec4 with the 4 components of the color.

type DepthTest

type DepthTest struct {
	Enabled bool
	Write   bool
	Func    DepthTestFunc
}

DepthTest holds the entire depth test state of a Material.

type DepthTestFunc

type DepthTestFunc int

DepthTestFunc is the depth test function of a Material.

const (
	DepthTestNever DepthTestFunc = iota
	DepthTestLess
	DepthTestGreater
	DepthTestEqual
	DepthTestAlways
	DepthTestLessOrEqual
	DepthTestGreaterOrEqual
	DepthTestNotEqual
)

type Drawer

type Drawer interface {
	Draw(fb Framebuffer)
}

Drawer is an object that can draw on a Framebuffer.

type FragmentShader

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

FragmentShader is a program that runs for each fragment.

func NewFragmentShader

func NewFragmentShader(source string) *FragmentShader

NewFragmentShader creates a fragment shader.

func (*FragmentShader) AddUniform

func (s *FragmentShader) AddUniform(kind VariableKind, name string) Uniform

AddUniform adds a uniform to a shader.

func (*FragmentShader) Uniform

func (s *FragmentShader) Uniform(name string) Uniform

Uniform returns the uniform named name.

type Framebuffer

type Framebuffer interface {
	Size() (width, height int)
	SetSize(width, height int)

	GetCamera() Camera
	SetCamera(camera Camera)
	SetViewport(x, y, width, height int)

	Draw(d Drawer)

	Screenshot() *image.RGBA
	// contains filtered or unexported methods
}

type Getter

type Getter interface {
	Get() interface{}
}

Getter gets a value.

type Grapher

type Grapher interface {
	GetParent() Grapher
	AddChild(child Grapher)
	GetChildren() []Grapher
}

Grapher is an interface for objects that can be put into a graph.

type IndexBuffer

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

func (*IndexBuffer) Init

func (ib *IndexBuffer) Init(size int)

func (*IndexBuffer) InitFromData

func (ib *IndexBuffer) InitFromData(data []uint)

func (*IndexBuffer) Len

func (ib *IndexBuffer) Len() int

func (*IndexBuffer) Set

func (ib *IndexBuffer) Set(nth int, index uint)

type Material

type Material interface {
	// ID is the material ID. This must be unique across all materials.
	ID() string
	// GetFragmentShader returns the fragment shader used by this Material.
	GetFragmentShader() *FragmentShader
	// GetBlending returns the blending state of the Material.
	GetBlending() *Blending
	// GetDepthTest returns the depth test state of the Material.
	GetDepthTest() *DepthTest
}

Material is used to paint geometries.

type Mesh

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

func NewMesh

func NewMesh() *Mesh

func (*Mesh) AddAttribute

func (m *Mesh) AddAttribute(name string, data []float32, NumComponents int)

func (*Mesh) AddAttributeBuffer

func (m *Mesh) AddAttributeBuffer(buffer *AttributeBuffer)

func (*Mesh) AddIndices

func (m *Mesh) AddIndices(data []uint)

func (*Mesh) GetAttribute

func (m *Mesh) GetAttribute(name string) *AttributeBuffer

func (*Mesh) GetVertexMode

func (m *Mesh) GetVertexMode() VertexMode

GetVertexMode returns how vertices in the Mesh are interpreted. New meshes default to VertexModeTriangles.

func (*Mesh) HasIndices

func (m *Mesh) HasIndices() bool

func (*Mesh) SetVertexMode

func (m *Mesh) SetVertexMode(mode VertexMode)

SetVertexMode sets how vertices in the should be interpreted.

type MeshRenderer

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

MeshRenderer is a component rendering a Mesh with a Material.

func NewMeshRenderer

func NewMeshRenderer(mesher Mesher, material Material) *MeshRenderer

NewMeshRenderer creates a new MeshRenderer.

func (*MeshRenderer) Draw

func (mr *MeshRenderer) Draw()

Draw implements Drawer for MeshRenderer.

func (*MeshRenderer) Update

func (mr *MeshRenderer) Update(time float64)

Update implements Updater for MeshRenderer.

type Mesher

type Mesher interface {
	GetMesh() *Mesh
}

Mesher is an object that can produce a Mesh.

type Namer

type Namer interface {
	Name() string
}

Namer is an object with a name.

type Node

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

func NewNode

func NewNode() *Node

func (*Node) AddChild

func (n *Node) AddChild(child Grapher)

AddChild adds a child the node.

func (*Node) AddChildren

func (n *Node) AddChildren(children ...Grapher)

AddChildren adds a number of children to the node n.

func (*Node) AddComponent

func (n *Node) AddComponent(c interface{}) *Node

func (*Node) GetChildren

func (n *Node) GetChildren() []Grapher

GetChildren returns the list of children for the node n.

func (*Node) GetParent

func (n *Node) GetParent() Grapher

GetParent returns the paren of the node n.

func (*Node) GetPosition

func (n *Node) GetPosition() *math.Vec3

func (*Node) GetRotation

func (n *Node) GetRotation() *math.Quaternion

func (*Node) GetScale

func (n *Node) GetScale() *math.Vec3

func (*Node) GetTransform

func (n *Node) GetTransform() *math.Mat4

func (*Node) Init

func (n *Node) Init()

func (*Node) RotateAroundAxis

func (n *Node) RotateAroundAxis(axis *math.Vec3, angle float32)

func (*Node) RotateX

func (n *Node) RotateX(angle float32)

func (*Node) RotateY

func (n *Node) RotateY(angle float32)

func (*Node) RotateZ

func (n *Node) RotateZ(angle float32)

func (*Node) Scale

func (n *Node) Scale(sx, sy, sz float32)

func (*Node) ScaleV

func (n *Node) ScaleV(s *math.Vec3)

func (*Node) ScaleX

func (n *Node) ScaleX(sx float32)

func (*Node) ScaleY

func (n *Node) ScaleY(sy float32)

func (*Node) ScaleZ

func (n *Node) ScaleZ(sz float32)

func (*Node) SetPosition

func (n *Node) SetPosition(x, y, z float32)

func (*Node) SetPositionV

func (n *Node) SetPositionV(position *math.Vec3)

func (*Node) SetRotation

func (n *Node) SetRotation(q *math.Quaternion)

func (*Node) SetScale

func (n *Node) SetScale(sx, sy, sz float32)

func (*Node) SetScaleV

func (n *Node) SetScaleV(s *math.Vec3)

func (*Node) Translate

func (n *Node) Translate(tx, ty, tz float32)

func (*Node) TranslateV

func (n *Node) TranslateV(t *math.Vec3)

func (*Node) TranslateX

func (n *Node) TranslateX(tx float32)

func (*Node) TranslateY

func (n *Node) TranslateY(ty float32)

func (*Node) TranslateZ

func (n *Node) TranslateZ(tz float32)

type Polyline

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

func NewPolyline

func NewPolyline() *Polyline

func NewPolylineWithSize

func NewPolylineWithSize(n_vertices int) *Polyline

func (*Polyline) Add

func (p *Polyline) Add(x, y, z float32)

func (*Polyline) AddPoint

func (p *Polyline) AddPoint(point *m.Point)

func (*Polyline) AddVertex

func (p *Polyline) AddVertex(v *m.Vec3)

func (*Polyline) Clear

func (p *Polyline) Clear()

func (*Polyline) Draw

func (p *Polyline) Draw(fb Framebuffer)

func (*Polyline) Positions

func (p *Polyline) Positions() []float32

func (*Polyline) Size

func (p *Polyline) Size() int

type Scene

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

func (*Scene) BackgroundColor

func (s *Scene) BackgroundColor() *Color

func (*Scene) CreateActor

func (s *Scene) CreateActor(mesher Mesher, material Material) *Node

CreateActor creates a new node that renders a mesh with a material. This function is a convenience function that creates a Node and adds a MeshRenderer component to it.

func (*Scene) Draw

func (s *Scene) Draw(fb Framebuffer)

func (*Scene) OnKeyPressed

func (s *Scene) OnKeyPressed()

func (*Scene) OnKeyReleased

func (s *Scene) OnKeyReleased()

func (*Scene) OnMouseButtonPressed

func (s *Scene) OnMouseButtonPressed(button MouseButton, x, y float32)

func (*Scene) OnMouseButtonReleased

func (s *Scene) OnMouseButtonReleased(button MouseButton, x, y float32)

func (*Scene) OnMouseMoved

func (s *Scene) OnMouseMoved(x, y float32)

func (*Scene) OnResize

func (s *Scene) OnResize(fb Framebuffer, width, height int)

func (*Scene) OnRuneEntered

func (s *Scene) OnRuneEntered(r rune)

func (*Scene) SetBackgroundColor

func (s *Scene) SetBackgroundColor(r, g, b, a float32)

func (*Scene) SetCamera

func (s *Scene) SetCamera(camera Camera)

func (*Scene) Setup

func (s *Scene) Setup()

func (*Scene) TearDown

func (s *Scene) TearDown()

func (*Scene) Update

func (s *Scene) Update(time float64)

type SceneGraph

type SceneGraph struct {
	Node
}

func NewSceneGraph

func NewSceneGraph() *SceneGraph

func (*SceneGraph) Draw

func (sg *SceneGraph) Draw(fb Framebuffer)

func (*SceneGraph) Init

func (sg *SceneGraph) Init()

func (*SceneGraph) Traverse

func (sg *SceneGraph) Traverse() <-chan Grapher

Depth-first pre-order traversal of the SceneGraph

func (*SceneGraph) Update

func (sg *SceneGraph) Update(time float64)

type Scener

type Scener interface {
	Setup()
	TearDown()

	// XXX: Shouldn't probably be part of the interface, but needed to
	// generically clear the framebuffer
	BackgroundColor() *Color

	Updater
	Drawer

	// events
	OnResize(fb Framebuffer, width, height int)
	OnKeyPressed()
	OnKeyReleased()
	OnMouseMoved(x, y float32)
	OnMouseButtonPressed(button MouseButton, x, y float32)
	OnMouseButtonReleased(button MouseButton, x, y float32)
	OnRuneEntered(r rune)
}

type Setter

type Setter interface {
	Set(interface{})
}

Setter sets a value.

type Uniform

type Uniform interface {
	Namer
	Kind() VariableKind
	Getter
	Setter
}

Uniform is a shader parameter, constant per draw call.

type Updater

type Updater interface {
	Update(time float64)
}

Updater is an object that would like to be updated at very frame

type VariableKind

type VariableKind int

VariableKind defines the type of a variable in a shader.

const (
	// VariableKindFloat is a float uniform.
	VariableKindFloat VariableKind = iota
	// VariableKindVec2 is a vec2 uniform.
	VariableKindVec2
	// VariableKindVec3 is a vec3 uniform.
	VariableKindVec3
	// VariableKindVec4 is a vec4 uniform.
	VariableKindVec4
	// VariableKindMat4 is a 4x4 matrix uniform.
	VariableKindMat4
)

type VertexMode

type VertexMode int

VertexMode defines how vertices should be interpreted by the draw call.

const (
	// VertexModePoints draws a single dot for each vertex.
	VertexModePoints VertexMode = iota
	VertexModeLineStrip
	VertexModeLineLoop
	VertexModeLines
	VertexModeTriangleStrip
	VertexModeTriangleFan
	VertexModeTriangles
)

type VertexShader

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

VertexShader is a program that runs for each vertex.

func NewVertexShader

func NewVertexShader(source string) *VertexShader

NewVertexShader creates a vertex shader.

func (*VertexShader) AddAttribute

func (vs *VertexShader) AddAttribute(kind VariableKind, name string) *Attribute

AddAttribute adds an attribute to a vertex shader.

func (*VertexShader) AddUniform

func (s *VertexShader) AddUniform(kind VariableKind, name string) Uniform

AddUniform adds a uniform to a shader.

func (*VertexShader) Uniform

func (s *VertexShader) Uniform(name string) Uniform

Uniform returns the uniform named name.

type Window

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

func (*Window) Close

func (w *Window) Close()

func (*Window) Draw

func (w *Window) Draw()

func (*Window) Screenshot

func (w *Window) Screenshot() *image.RGBA

func (*Window) ScreenshotToFile

func (w *Window) ScreenshotToFile(filename string)

func (*Window) SetScene

func (w *Window) SetScene(s Scener)

func (*Window) Update

func (w *Window) Update()

Directories

Path Synopsis
cmd
Package math provides basic constants and mathematical functions.
Package math provides basic constants and mathematical functions.

Jump to

Keyboard shortcuts

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