driver

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT, Unlicense Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NewOpenGLDevice     func(api OpenGL) (Device, error)
	NewDirect3D11Device func(api Direct3D11) (Device, error)
)

API specific device constructors.

View Source
var ErrContentLost = errors.New("buffer content lost")

Functions

func DownloadImage

func DownloadImage(d Device, f Framebuffer, r image.Rectangle) (*image.RGBA, error)

func UploadImage

func UploadImage(t Texture, offset image.Point, img *image.RGBA)

Types

type API

type API interface {
	// contains filtered or unexported methods
}

type AccessBits

type AccessBits uint8
const (
	AccessRead AccessBits = 1 + iota
	AccessWrite
)

type BlendFactor

type BlendFactor uint8
const (
	BlendFactorOne BlendFactor = iota
	BlendFactorOneMinusSrcAlpha
	BlendFactorZero
	BlendFactorDstColor
)

type Buffer

type Buffer interface {
	Release()
	Upload(data []byte)
	Download(data []byte) error
}

type BufferBinding

type BufferBinding uint8
const (
	BufferBindingIndices BufferBinding = 1 << iota
	BufferBindingVertices
	BufferBindingUniforms
	BufferBindingTexture
	BufferBindingFramebuffer
	BufferBindingShaderStorage
)

type Caps

type Caps struct {
	// BottomLeftOrigin is true if the driver has the origin in the lower left
	// corner. The OpenGL driver returns true.
	BottomLeftOrigin bool
	Features         Features
	MaxTextureSize   int
}

type DataType

type DataType uint8
const (
	DataTypeFloat DataType = iota
	DataTypeInt
	DataTypeShort
)

type DepthFunc

type DepthFunc uint8
const (
	DepthFuncGreater DepthFunc = iota
	DepthFuncGreaterEqual
)

type Device

type Device interface {
	BeginFrame(clear bool, viewport image.Point) Framebuffer
	EndFrame()
	Caps() Caps
	NewTimer() Timer
	// IsContinuousTime reports whether all timer measurements
	// are valid at the point of call.
	IsTimeContinuous() bool
	NewTexture(format TextureFormat, width, height int, minFilter, magFilter TextureFilter, bindings BufferBinding) (Texture, error)
	NewFramebuffer(tex Texture, depthBits int) (Framebuffer, error)
	NewImmutableBuffer(typ BufferBinding, data []byte) (Buffer, error)
	NewBuffer(typ BufferBinding, size int) (Buffer, error)
	NewComputeProgram(shader ShaderSources) (Program, error)
	NewProgram(vertexShader, fragmentShader ShaderSources) (Program, error)
	NewInputLayout(vertexShader ShaderSources, layout []InputDesc) (InputLayout, error)

	DepthFunc(f DepthFunc)
	ClearDepth(d float32)
	Clear(r, g, b, a float32)
	Viewport(x, y, width, height int)
	DrawArrays(mode DrawMode, off, count int)
	DrawElements(mode DrawMode, off, count int)
	SetBlend(enable bool)
	SetDepthTest(enable bool)
	DepthMask(mask bool)
	BlendFunc(sfactor, dfactor BlendFactor)

	BindInputLayout(i InputLayout)
	BindProgram(p Program)
	BindFramebuffer(f Framebuffer)
	BindTexture(unit int, t Texture)
	BindVertexBuffer(b Buffer, stride, offset int)
	BindIndexBuffer(b Buffer)
	BindImageTexture(unit int, texture Texture, access AccessBits, format TextureFormat)

	MemoryBarrier()
	DispatchCompute(x, y, z int)

	Release()
}

Device represents the abstraction of underlying GPU APIs such as OpenGL, Direct3D useful for rendering Gio operations.

func NewDevice

func NewDevice(api API) (Device, error)

NewDevice creates a new Device given the api.

Note that the device does not assume ownership of the resources contained in api; the caller must ensure the resources are valid until the device is released.

type Direct3D11

type Direct3D11 struct {
	// Device contains a *ID3D11Device.
	Device unsafe.Pointer
}

type DrawMode

type DrawMode uint8
const (
	DrawModeTriangleStrip DrawMode = iota
	DrawModeTriangles
)

type Features

type Features uint
const (
	FeatureTimers Features = 1 << iota
	FeatureFloatRenderTargets
	FeatureCompute
)

func (Features) Has

func (f Features) Has(feats Features) bool

type Framebuffer

type Framebuffer interface {
	Invalidate()
	Release()
	ReadPixels(src image.Rectangle, pixels []byte) error
}

type InputDesc

type InputDesc struct {
	Type DataType
	Size int

	Offset int
}

InputDesc describes a vertex attribute as laid out in a Buffer.

type InputLayout

type InputLayout interface {
	Release()
}

InputLayout is the driver specific representation of the mapping between Buffers and shader attributes.

type InputLocation

type InputLocation struct {
	// For GLSL.
	Name     string
	Location int
	// For HLSL.
	Semantic      string
	SemanticIndex int

	Type DataType
	Size int
}

type OpenGL

type OpenGL struct {
	// ES forces the use of ANGLE OpenGL ES libraries on macOS. It is
	// ignored on all other platforms.
	ES bool
	// Context contains the WebGL context for WebAssembly platforms. It is
	// empty for all other platforms; an OpenGL context is assumed current when
	// calling NewDevice.
	Context gl.Context
}

type Program

type Program interface {
	Release()
	SetStorageBuffer(binding int, buf Buffer)
	SetVertexUniforms(buf Buffer)
	SetFragmentUniforms(buf Buffer)
}

type ShaderSources

type ShaderSources struct {
	Name      string
	GLSL100ES string
	GLSL300ES string
	GLSL310ES string
	GLSL130   string
	GLSL150   string
	HLSL      string
	Uniforms  UniformsReflection
	Inputs    []InputLocation
	Textures  []TextureBinding
}

type Texture

type Texture interface {
	Upload(offset, size image.Point, pixels []byte)
	Release()
}

type TextureBinding

type TextureBinding struct {
	Name    string
	Binding int
}

type TextureFilter

type TextureFilter uint8
const (
	FilterNearest TextureFilter = iota
	FilterLinear
)

type TextureFormat

type TextureFormat uint8
const (
	TextureFormatSRGB TextureFormat = iota
	TextureFormatFloat
	TextureFormatRGBA8
)

type Timer

type Timer interface {
	Begin()
	End()
	Duration() (time.Duration, bool)
	Release()
}

type UniformBlock

type UniformBlock struct {
	Name    string
	Binding int
}

type UniformLocation

type UniformLocation struct {
	Name   string
	Type   DataType
	Size   int
	Offset int
}

type UniformsReflection

type UniformsReflection struct {
	Blocks    []UniformBlock
	Locations []UniformLocation
	Size      int
}

Jump to

Keyboard shortcuts

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