gfx

package
v0.0.0-...-87acbc0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VulkanSurfaceHandleType = "vulkan"
	MetalSurfaceHandleType  = "metal"
	Win32SurfaceHandleType  = "win32"
)

Variables

View Source
var (
	ErrInvalidDescriptor        = errors.New("invalid descriptor")
	ErrUnexpectedSystemResponse = errors.New("unexpected system response")
	ErrUnexpectedStatus         = errors.New("unexpected status")
	ErrAlreadyRunning           = errors.New("already running")
	ErrNotMainThread            = errors.New("not on main thread")
	ErrUnsupportedSurfaceHandle = errors.New("unsupported surface handle")
	ErrIncompatibleSurface      = errors.New("incompatible surface")
	ErrFunctionNotFound         = errors.New("function not found")
	ErrIncompatibleDriver       = errors.New("incompatible driver")
	ErrNoSuitableDevice         = errors.New("could not find a suitable device")
	ErrMissingFeature           = errors.New("feature missing")
	ErrInitializationFailed     = errors.New("initialization failed")
)
View Source
var (
	ErrNoGraphics          = errors.New("no graphics registered")
	ErrNoGraphicsAvailable = errors.New("no graphics available")
)
View Source
var (
	ErrNoPlatforms         = errors.New("no platforms registered")
	ErrNoPlatformAvailable = errors.New("no platforms available")
	ErrUnsupportedPlatform = errors.New("unsupported platform")
)

Functions

func RegisterGraphics

func RegisterGraphics(g Graphics)

func RegisterPlatform

func RegisterPlatform(platform Platform)

func Run

func Run(cfg Config) error

Types

type Application

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

func (*Application) CreateBuffer

func (a *Application) CreateBuffer(descriptor BufferDescriptor) (Buffer, error)

func (*Application) CreateCommandEncoder

func (a *Application) CreateCommandEncoder() (CommandEncoder, error)

func (*Application) CreateImage

func (a *Application) CreateImage(descriptor ImageDescriptor) (Image, error)

func (*Application) CreateRenderPipeline

func (a *Application) CreateRenderPipeline(descriptor RenderPipelineDescriptor) (RenderPipeline, error)

func (*Application) CreateSampler

func (a *Application) CreateSampler(descriptor SamplerDescriptor) (Sampler, error)

func (*Application) CreateShader

func (a *Application) CreateShader(config ShaderConfig) (Shader, error)

func (*Application) FrameCount

func (a *Application) FrameCount() int

func (*Application) SurfaceFormat

func (a *Application) SurfaceFormat() Format

type Buffer

type Buffer interface {
	Close()

	Size() int

	MappedPtr() (unsafe.Pointer, bool)

	CopyFrom(slice []byte) error

	Flush() error
}

type BufferDescriptor

type BufferDescriptor struct {
	Size  int
	Usage BufferUsage
}

type BufferUsage

type BufferUsage int
const (
	BufferUsageHostRandomAccess BufferUsage = 1 << iota
	BufferUsageHostUpload
	BufferUsagePersistentMap
)

type Color

type Color struct {
	R float64
	G float64
	B float64
	A float64
}

func NewColor

func NewColor(r float64, g float64, b float64, a float64) Color

type CommandEncoder

type CommandEncoder interface {
	InitImage(img Image)

	CopyBufferToImage(buffer Buffer, image Image)

	SubmitAndWait() error
}

type Config

type Config struct {
	Logger *slog.Logger

	Title  string
	Width  int
	Height int

	Init     func(app *Application) error
	OnRender func(frame *Frame) error
	OnResize func(size LogicalSize) error
}

type CullMode

type CullMode int
const (
	CullModeNone CullMode = iota
	CullModeFront
	CullModeBack
)

type Format

type Format int
const (
	FormatBGRA8UNorm Format = iota
	FormatRGBA8UNorm
	FormatRGBA16SFloat
	FormatRGB32SFloat
	FormatRG32SFloat
)

func (Format) Depth

func (f Format) Depth() bool

type Frame

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

func (*Frame) BeginRenderPass

func (f *Frame) BeginRenderPass(descriptor RenderPassDescriptor) RenderPassEncoder

func (*Frame) Index

func (f *Frame) Index() int

func (*Frame) Size

func (f *Frame) Size() LogicalSize

func (*Frame) View

func (f *Frame) View() ImageView

type Graphics

type Graphics interface {
	Name() string

	Priority() int

	Available(plt Platform) bool

	Init(init GraphicsInit) error

	CreateSurface(handle SurfaceHandle, size PhysicalSize) (Surface, error)

	CreateShader(cfg ShaderConfig) (Shader, error)

	CreateRenderPipeline(descriptor RenderPipelineDescriptor) (RenderPipeline, error)

	CreateImage(descriptor ImageDescriptor) (Image, error)

	CreateBuffer(descriptor BufferDescriptor) (Buffer, error)

	CreateCommandEncoder() (CommandEncoder, error)

	CreateSampler(descriptor SamplerDescriptor) (Sampler, error)
}

type GraphicsInit

type GraphicsInit struct {
	Logger   *slog.Logger
	Platform Platform
}

type Image

type Image interface {
	DefaultView() ImageView
}

type ImageDescriptor

type ImageDescriptor struct {
	Type   ImageType
	Width  int
	Height int
	Depth  int
	Format Format
	Usage  ImageUsage
}

type ImageType

type ImageType int
const (
	ImageType1D ImageType = iota
	ImageType2D
	ImageType3D
)

type ImageUsage

type ImageUsage int
const (
	ImageUsageAttachment ImageUsage = 1 << iota
	ImageUsageSampled
	ImageUsageCopySrc
	ImageUsageCopyDst
)

type ImageView

type ImageView interface {
	ID() uint32
	Width() int
	Height() int
}

type LogicalSize

type LogicalSize struct {
	Width  float64
	Height float64
	Scale  float64
}

func (LogicalSize) PhysicalSize

func (l LogicalSize) PhysicalSize() PhysicalSize

type MetalSurfaceHandle

type MetalSurfaceHandle interface {
	SurfaceHandle
	MetalLayer() unsafe.Pointer
}

type PhysicalSize

type PhysicalSize struct {
	Width  int
	Height int
}

type Platform

type Platform interface {
	Name() string

	Priority() int

	Available() bool

	Run(init PlatformInit) error

	PrimarySurface() SurfaceHandle
}

type PlatformInit

type PlatformInit struct {
	Logger  *slog.Logger
	Cfg     Config
	Init    func() error
	Render  func() error
	Resized func(size LogicalSize) error
}

type RenderPassColorAttachment

type RenderPassColorAttachment struct {
	Target     ImageView
	Load       bool
	ClearColor Color
	Discard    bool
}

type RenderPassDescriptor

type RenderPassDescriptor struct {
	ColorAttachments []RenderPassColorAttachment
}

type RenderPassEncoder

type RenderPassEncoder interface {
	SetRenderPipeline(pipeline RenderPipeline)

	SetVertexBuffer(binding int, buffer Buffer, offset int)

	SetIndexBuffer(buffer Buffer, offset int)

	SetPushConstants(offset int, size int, data unsafe.Pointer)

	Draw(start int, count int)

	DrawIndexed(start int, count int, vertexOffset int)

	End()
}

type RenderPipeline

type RenderPipeline interface{}

type RenderPipelineColorAttachment

type RenderPipelineColorAttachment struct {
	Format Format
}

type RenderPipelineDescriptor

type RenderPipelineDescriptor struct {
	VertexFunction     ShaderFunction
	VertexBindings     []VertexBinding
	FragmentFunction   ShaderFunction
	ColorAttachments   []RenderPipelineColorAttachment
	CullMode           CullMode
	FrontFaceClockwise bool
}

type Sampler

type Sampler interface {
	ID() uint32
}

type SamplerDescriptor

type SamplerDescriptor struct {
}

type Shader

type Shader interface {
	Function(name string) (ShaderFunction, error)
}

type ShaderConfig

type ShaderConfig struct {
	SPIRV []byte
}

type ShaderFunction

type ShaderFunction interface{}

type Surface

type Surface interface {
	Resize(size PhysicalSize) error

	Acquire() (SurfaceFrame, error)

	Format() Format

	FrameCount() int
}

type SurfaceFrame

type SurfaceFrame interface {
	View() ImageView

	Index() int

	BeginRenderPass(descriptor RenderPassDescriptor) RenderPassEncoder

	Present() error
}

type SurfaceHandle

type SurfaceHandle interface {
	SurfaceHandleType() SurfaceHandleType

	Size() LogicalSize
}

type SurfaceHandleType

type SurfaceHandleType string

type VertexAttribute

type VertexAttribute struct {
	Location int
	Offset   int
	Format   Format
}

type VertexBinding

type VertexBinding struct {
	Binding    int
	Stride     int
	Rate       VertexRate
	Attributes []VertexAttribute
}

type VertexRate

type VertexRate int
const VertexRateInstance VertexRate = 1
const VertexRateVertex VertexRate = 0

type VulkanPlatform

type VulkanPlatform interface {
	Platform

	LoadVulkan() error

	VKInstanceProcAddr() unsafe.Pointer

	RequiredVKExtensions() []string
}

type VulkanSurfaceHandle

type VulkanSurfaceHandle interface {
	SurfaceHandle
	CreateVkSurface(instance unsafe.Pointer) (unsafe.Pointer, error)
}

type Win32SurfaceHandle

type Win32SurfaceHandle interface {
	SurfaceHandle
	Win32Instance() unsafe.Pointer
	Win32Handle() unsafe.Pointer
}

Jump to

Keyboard shortcuts

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