driver

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT, Unlicense Imports: 8 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)
	NewMetalDevice      func(api Metal) (Device, error)
	NewVulkanDevice     func(api Vulkan) (Device, error)
)

API specific device constructors.

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

Functions

func DownloadImage

func DownloadImage(d Device, t Texture, img *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 BlendDesc

type BlendDesc struct {
	Enable               bool
	SrcFactor, DstFactor BlendFactor
}

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
	BufferBindingShaderStorageRead
	BufferBindingShaderStorageWrite
)

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 Device

type Device interface {
	BeginFrame(target RenderTarget, clear bool, viewport image.Point) Texture
	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)
	NewImmutableBuffer(typ BufferBinding, data []byte) (Buffer, error)
	NewBuffer(typ BufferBinding, size int) (Buffer, error)
	NewComputeProgram(shader shader.Sources) (Program, error)
	NewVertexShader(src shader.Sources) (VertexShader, error)
	NewFragmentShader(src shader.Sources) (FragmentShader, error)
	NewPipeline(desc PipelineDesc) (Pipeline, error)

	Viewport(x, y, width, height int)
	DrawArrays(off, count int)
	DrawElements(off, count int)

	BeginRenderPass(t Texture, desc LoadDesc)
	EndRenderPass()
	PrepareTexture(t Texture)
	BindProgram(p Program)
	BindPipeline(p Pipeline)
	BindTexture(unit int, t Texture)
	BindVertexBuffer(b Buffer, offset int)
	BindIndexBuffer(b Buffer)
	BindImageTexture(unit int, texture Texture)
	BindUniforms(buf Buffer)
	BindStorageBuffer(binding int, buf Buffer)

	BeginCompute()
	EndCompute()
	CopyTexture(dst Texture, dstOrigin image.Point, src Texture, srcRect image.Rectangle)
	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 Direct3D11RenderTarget

type Direct3D11RenderTarget struct {
	// RenderTarget is a *ID3D11RenderTargetView.
	RenderTarget unsafe.Pointer
}

func (Direct3D11RenderTarget) ImplementsRenderTarget

func (Direct3D11RenderTarget) ImplementsRenderTarget()

type Features

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

func (Features) Has

func (f Features) Has(feats Features) bool

type FragmentShader

type FragmentShader interface {
	Release()
}

type InputDesc

type InputDesc struct {
	Type shader.DataType
	Size int

	Offset int
}

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

type LoadAction

type LoadAction uint8
const (
	LoadActionKeep LoadAction = iota
	LoadActionClear
	LoadActionInvalidate
)

type LoadDesc

type LoadDesc struct {
	Action     LoadAction
	ClearColor f32color.RGBA
}

type Metal

type Metal struct {
	// Device is an MTLDevice.
	Device uintptr
	// Queue is a MTLCommandQueue.
	Queue uintptr
	// PixelFormat is the MTLPixelFormat of the default framebuffer.
	PixelFormat int
}

type MetalRenderTarget

type MetalRenderTarget struct {
	// Texture is a MTLTexture.
	Texture uintptr
}

func (MetalRenderTarget) ImplementsRenderTarget

func (MetalRenderTarget) ImplementsRenderTarget()

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
	// Shared instructs users of the context to restore the GL state after
	// use.
	Shared bool
}

type OpenGLRenderTarget

type OpenGLRenderTarget gl.Framebuffer

func (OpenGLRenderTarget) ImplementsRenderTarget

func (OpenGLRenderTarget) ImplementsRenderTarget()

type Pipeline

type Pipeline interface {
	Release()
}

type PipelineDesc

type PipelineDesc struct {
	VertexShader   VertexShader
	FragmentShader FragmentShader
	VertexLayout   VertexLayout
	BlendDesc      BlendDesc
	PixelFormat    TextureFormat
	Topology       Topology
}

type Program

type Program interface {
	Release()
}

type RenderTarget

type RenderTarget interface {
	ImplementsRenderTarget()
}

type Texture

type Texture interface {
	RenderTarget
	Upload(offset, size image.Point, pixels []byte, stride int)
	ReadPixels(src image.Rectangle, pixels []byte, stride int) error
	Release()
}

type TextureFilter

type TextureFilter uint8
const (
	FilterNearest TextureFilter = iota
	FilterLinear
	FilterLinearMipmapLinear
)

type TextureFormat

type TextureFormat uint8
const (
	TextureFormatSRGBA TextureFormat = iota
	TextureFormatFloat
	TextureFormatRGBA8
	// TextureFormatOutput denotes the format used by the output framebuffer.
	TextureFormatOutput
)

type Timer

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

type Topology

type Topology uint8
const (
	TopologyTriangleStrip Topology = iota
	TopologyTriangles
)

type VertexLayout

type VertexLayout struct {
	Inputs []InputDesc
	Stride int
}

type VertexShader

type VertexShader interface {
	Release()
}

type Vulkan

type Vulkan struct {
	// PhysDevice is a VkPhysicalDevice.
	PhysDevice unsafe.Pointer
	// Device is a VkDevice.
	Device unsafe.Pointer
	// QueueFamily is the queue familily index of the queue.
	QueueFamily int
	// QueueIndex is the logical queue index of the queue.
	QueueIndex int
	// Format is a VkFormat that matches render targets.
	Format int
}

type VulkanRenderTarget

type VulkanRenderTarget struct {
	// WaitSem is a VkSemaphore that must signaled before accessing Framebuffer.
	WaitSem uint64
	// SignalSem is a VkSemaphore that signal access to Framebuffer is complete.
	SignalSem uint64
	// Fence is a VkFence that is set when all commands to Framebuffer has completed.
	Fence uint64
	// Image is the VkImage to render into.
	Image uint64
	// Framebuffer is a VkFramebuffer for Image.
	Framebuffer uint64
}

func (VulkanRenderTarget) ImplementsRenderTarget

func (VulkanRenderTarget) ImplementsRenderTarget()

Jump to

Keyboard shortcuts

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