graphics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AmbientLight

type AmbientLight interface {
	Light

	// ReflectionTexture returns the texture that is used to calculate
	// the lighting on an object as a result of reflected light rays.
	ReflectionTexture() CubeTexture

	// SetReflectionTexture changes the reflection texture.
	SetReflectionTexture(texture CubeTexture)

	// RefractionTexture returns the texture that is used to calculate
	// the lighting on an object as a result of refracted light rays.
	RefractionTexture() CubeTexture

	// SetRefractionTexture changes the refraction texture.
	SetRefractionTexture(texture CubeTexture)
}

AmbientLight is a light source that emits light from the scene surroundings.

type Camera

type Camera interface {
	Node

	// FoV returns the field-of-view angle for this camera.
	FoV() sprec.Angle

	// SetFoV changes the field-of-view angle setting of this camera.
	SetFoV(angle sprec.Angle)

	// FoVMode returns the mode of field-of-view. This determines how the
	// FoV setting is used to calculate the final image in the vertical
	// and horizontal directions.
	FoVMode() FoVMode

	// SetFoVMode changes the field-of-view mode of this camera.
	SetFoVMode(mode FoVMode)

	// AspectRatio returns the aspect ratio to be maintained when rendering
	// with this camera. This setting works in combination with FoVMode and
	// FoV settings.
	AspectRatio() float32

	// SetAspectRatio changes the aspect ratio of this camera.
	SetAspectRatio(ratio float32)

	// AutoFocus returns whether this camera will try and automatically
	// focus on objects.
	AutoFocus() bool

	// SetAutoFocus changes whether this camera should attempt to automatically
	// focus on object in the scene.
	SetAutoFocus(enabled bool)

	// FocusRange changes the range from near to far in which the image
	// will be in focus.
	FocusRange() (float32, float32)

	// SetFocusRange changes the focus range for this camera.
	SetFocusRange(near, far float32)

	// AutoExposure returns whether this camera will try and automatically
	// adjust the exposure setting to maintain a proper brightness of
	// the final image.
	AutoExposure() bool

	// SetAutoExposure changes whether this cammera should attempt to
	// do automatic exposure adjustment.
	SetAutoExposure(enabled bool)

	// Exposure returns the exposure setting of this camera.
	Exposure() float32

	// SetExposure changes the exposure setting of this camera.
	// Smaller values mean that the final image will be darker and
	// higher values mean that the final image will be brighter with
	// 1.0 being the starting point.
	SetExposure(exposure float32)

	// Delete removes this camera from the scene.
	Delete()
}

type CubeTexture

type CubeTexture interface {

	// Delete releases any resources allocated for this texture.
	Delete()
}

CubeTexture represents a cube texture.

type CubeTextureDefinition

type CubeTextureDefinition struct {
	Dimension int

	WrapS Wrap
	WrapT Wrap

	MinFilter Filter
	MagFilter Filter

	InternalFormat InternalFormat
	DataFormat     DataFormat

	FrontSideData  []byte
	BackSideData   []byte
	LeftSideData   []byte
	RightSideData  []byte
	TopSideData    []byte
	BottomSideData []byte
}

CubeTextureDefinition contains all the information needed to create a CubeTexture.

type DataFormat

type DataFormat int
const (
	DataFormatRGBA8 DataFormat = 1 + iota
	DataFormatRGBA32F
)

type DirectionalLight

type DirectionalLight interface {
	Light
}

DirectionalLight is a light object that emits parallel light rays into a single direction (going into the Z direction).

type Engine

type Engine interface {

	// Create initializes this 3D engine.
	Create()

	// CreateScene creates a new 3D Scene. Entities managed
	// within a given scene are isolated within that scene.
	CreateScene() Scene

	// CreateTwoDTexture creates a new TwoDTexture using the
	// specified definition.
	CreateTwoDTexture(definition TwoDTextureDefinition) TwoDTexture

	// CreateCubeTexture creates a new CubeTexture using the
	// specified definition.
	CreateCubeTexture(definition CubeTextureDefinition) CubeTexture

	// CreateMeshTemplate creates a new MeshTemplate using the specified
	// definition.
	CreateMeshTemplate(definition MeshTemplateDefinition) MeshTemplate

	// CreatePBRMaterial creates a new Material that is based on PBR
	// definition.
	CreatePBRMaterial(definition PBRMaterialDefinition) Material

	// Destroy releases resources allocated by this
	// 3D engine.
	Destroy()
}

Engine represents an entrypoint to 3D graphics rendering.

type Filter

type Filter int
const (
	FilterNearest Filter = 1 + iota
	FilterLinear
	FilterNearestMipmapNearest
	FilterNearestMipmapLinear
	FilterLinearMipmapNearest
	FilterLinearMipmapLinear
)

type FoVMode

type FoVMode string

FoVMode determines how the camera field of view is calculated in the horizontal and vertical directions.

const (
	// FoVModeAnamorphic will abide to the aspect ratio setting
	// and will pillerbox the image if necessary.
	FoVModeAnamorphic FoVMode = "anamorphic"

	// FoVModeHorizontalPlus will apply the FoV setting to the
	// vertical direction and will adjust the horizontal direction
	// accordingly to preserve the screen's aspect ratio.
	FoVModeHorizontalPlus FoVMode = "horizontal-plus"

	// FoVModeVertialMinus will apply the FoV setting to the
	// horizontal direction and will adjust the vertical direction
	// accordingly to preserve the screen's aspect ratio.
	FoVModeVertialMinus FoVMode = "vertical-minus"

	// FoVModePixelBased will use an orthogonal projection that
	// will match in side the screen pixel size.
	FoVModePixelBased FoVMode = "pixel-based"
)

type IndexFormat

type IndexFormat int
const (
	IndexFormatU16 IndexFormat = 1 + iota
)

type InternalFormat

type InternalFormat int
const (
	InternalFormatRGBA8 InternalFormat = 1 + iota
	InternalFormatRGBA32F
)

type Light

type Light interface {
	Node

	// Intensity returns the light intensity.
	Intensity() sprec.Vec3

	// SetIntensity changes the light intensity.
	SetIntensity(intensity sprec.Vec3)

	// Delete removes this light source.
	Delete()
}

Light represents a light emitting object in the scene.

type Material

type Material interface {

	// Delete releases resources allocated for this material.
	Delete()
}

Material determines the appearance of a mesh on the screen.

type Mesh

type Mesh interface {
	Node

	// Delete removes this mesh from the scene.
	Delete()
}

Mesh represents an instance of a 3D mesh.

type MeshTemplate

type MeshTemplate interface {

	// Delete releases any resources allocated by this
	// template.
	Delete()
}

MeshTemplate represents the definition of a mesh. Multiple mesh instances can be created off of one template reusing resources.

type MeshTemplateDefinition

type MeshTemplateDefinition struct {
	VertexData   []byte
	VertexFormat VertexFormat
	IndexData    []byte
	IndexFormat  IndexFormat
	SubMeshes    []SubMeshTemplateDefinition
}

MeshTemplateDefinition contains everything needed to create a new MeshTemplate.

type Node

type Node interface {

	// Position returns this entity's position.
	Position() sprec.Vec3

	// SetPosition changes this entity's position.
	SetPosition(position sprec.Vec3)

	// Rotation returns this entity's rotation.
	Rotation() sprec.Quat

	// SetRotation changes this entity's rotation.
	SetRotation(rotation sprec.Quat)

	// Scale returns this entity's scale.
	Scale() sprec.Vec3

	// SetScale changes this entity's scale.
	SetScale(scale sprec.Vec3)
}

Node represents a positioning of some entity in the 3D scene.

type PBRMaterialDefinition

type PBRMaterialDefinition struct {
	BackfaceCulling  bool
	AlphaBlending    bool
	AlphaTesting     bool
	AlphaThreshold   float32
	Metalness        float32
	MetalnessTexture TwoDTexture
	Roughness        float32
	RoughnessTexture TwoDTexture
	AlbedoColor      sprec.Vec4
	AlbedoTexture    TwoDTexture
	NormalScale      float32
	NormalTexture    TwoDTexture
}

PBRMaterialDefinition contains the information needed to create a PBR Material.

type Primitive

type Primitive int
const (
	PrimitivePoints Primitive = 1 + iota
	PrimitiveLines
	PrimitiveLineStrip
	PrimitiveLineLoop
	PrimitiveTriangles
	PrimitiveTriangleStrip
	PrimitiveTriangleFan
)

type Scene

type Scene interface {

	// Sky returns this scene's sky object.
	// You can use the Sky object to control the
	// background appearance.
	Sky() Sky

	// CreateCamera creates a new camera object to be
	// used with this scene.
	CreateCamera() Camera

	// CreateDirectionalLight creates a new directional light object to be
	// used within this scene.
	CreateDirectionalLight() DirectionalLight

	// CreateAmbientLight creates a new ambient light object to be used
	// within this scene.
	CreateAmbientLight() AmbientLight

	// CreateMesh creates a new mesh instance from the specified
	// template and places it in the scene.
	CreateMesh(template MeshTemplate) Mesh

	// Render draws this scene to the specified viewport
	// looking through the specified camera.
	Render(viewport Viewport, camera Camera)

	// Delete removes this scene and releases all
	// entities allocated for it.
	Delete()
}

Scene represents a collection of 3D render entities that comprise a single visual scene.

type Sky

type Sky interface {

	// BackgroundColor returns the color of the background.
	BackgroundColor() sprec.Vec3

	// SetBackgroundColor changes the color of the background.
	SetBackgroundColor(color sprec.Vec3)

	// Skybox returns the cube texture to be used as the background.
	// If one has not been set, this method returns nil.
	Skybox() CubeTexture

	// SetSkybox sets a cube texture to be used as the background.
	// If nil is specified, then a texture will not be used and instead
	// the background color will be drawn instead.
	SetSkybox(skybox CubeTexture)
}

Sky represents the scene background.

type SubMeshTemplateDefinition

type SubMeshTemplateDefinition struct {
	Primitive   Primitive
	IndexOffset int
	IndexCount  int
	Material    Material
}

SubMeshTemplateDefinition represents a portion of a mesh that is drawn with a specific material.

type TwoDTexture

type TwoDTexture interface {

	// Delete releases any resources allocated for this texture.
	Delete()
}

TwoDTexture represents a two-dimensional texture.

type TwoDTextureDefinition

type TwoDTextureDefinition struct {
	Width  int
	Height int

	WrapS Wrap
	WrapT Wrap

	MinFilter Filter
	MagFilter Filter

	UseAnisotropy   bool
	GenerateMipmaps bool

	InternalFormat InternalFormat
	DataFormat     DataFormat

	Data []byte
}

TwoDTextureDefinition contains all the information needed to create a TwoDTexture.

type VertexFormat

type VertexFormat struct {
	HasCoord            bool
	CoordOffsetBytes    int
	CoordStrideBytes    int
	HasNormal           bool
	NormalOffsetBytes   int
	NormalStrideBytes   int
	HasTangent          bool
	TangentOffsetBytes  int
	TangentStrideBytes  int
	HasTexCoord         bool
	TexCoordOffsetBytes int
	TexCoordStrideBytes int
	HasColor            bool
	ColorOffsetBytes    int
	ColorStrideBytes    int
}

type Viewport

type Viewport struct {
	X      int
	Y      int
	Height int
	Width  int
}

Viewport represents an area on the screen to which rendering will occur.

func NewViewport

func NewViewport(x, y, width, height int) Viewport

NewViewport creates a new Viewport with the specified parameters.

type Wrap

type Wrap int
const (
	WrapClampToEdge Wrap = 1 + iota
	WrapRepeat
)

Jump to

Keyboard shortcuts

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