render

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 2 Imported by: 9

Documentation

Overview

Package render exposes an abstraction API over the GPU so that various implementations (e.g. WebGPU, OpenGL, WebGL) can be substituted.

The API is heavily inspired by the WebGPU API but takes a step back towards the OpenGL API in some areas in order to make it easier to implement on top of existing APIs.

Index

Constants

View Source
const (
	// SizeU8 represents the number of bytes in a uint8.
	SizeU8 = 1

	// SizeU16 represents the number of bytes in a uint16.
	SizeU16 = 2

	// SizeU32 represents the number of bytes in a uint32.
	SizeU32 = 4

	// SizeF16 represents the number of bytes in a float16.
	SizeF16 = 2

	// SizeF32 represents the number of bytes in a float32.
	SizeF32 = 4
)

Variables

View Source
var (
	// ColorMaskFalse specifies that no color channels should be written to.
	ColorMaskFalse = [4]bool{false, false, false, false}

	// ColorMaskTrue specifies that all color channels should be written to.
	ColorMaskTrue = [4]bool{true, true, true, true}
)

Functions

This section is empty.

Types

type API added in v0.4.0

type API interface {

	// Limits returns information on the supported limits of the implementation.
	Limits() Limits

	// DefaultFramebuffer returns the default framebuffer that is provided
	// by the target window surface.
	DefaultFramebuffer() Framebuffer

	// DetermineContentFormat returns the format that should be used
	// with CopyContentToTexture and similar methods when dealing with
	// the specified Framebuffer.
	DetermineContentFormat(framebuffer Framebuffer) DataFormat

	// CreateFramebuffer creates a new Framebuffer object based on the
	// provided FramebufferInfo.
	CreateFramebuffer(info FramebufferInfo) Framebuffer

	// CreateProgram creates a new Program object based on the provided
	// ProgramInfo.
	CreateProgram(info ProgramInfo) Program

	// CreateColorTexture2D creates a new 2D Texture that can be
	// used to store color values.
	CreateColorTexture2D(info ColorTexture2DInfo) Texture

	// CreateColorTextureCube creates a new Cube Texture that can be
	// used to store color values.
	CreateColorTextureCube(info ColorTextureCubeInfo) Texture

	// CreateDepthTexture2D creates a new 2D Texture that can be
	// used to store depth values.
	CreateDepthTexture2D(info DepthTexture2DInfo) Texture

	// CreateStencilTexture2D creates a new 2D Texture that can be
	// used to store stencil values.
	CreateStencilTexture2D(info StencilTexture2DInfo) Texture

	// CreateDepthStencilTexture2D creates a new 2D Texture that can be
	// used to store depth and stencil values together.
	CreateDepthStencilTexture2D(info DepthStencilTexture2DInfo) Texture

	// CreateVertexBuffer creates a new Buffer object that can be used
	// to store vertex data.
	CreateVertexBuffer(info BufferInfo) Buffer

	// CreateIndexBuffer creates a new Buffer object that can be used
	// to store index data.
	CreateIndexBuffer(info BufferInfo) Buffer

	// CreatePixelTransferBuffer creates a new Buffer object that can be used
	// to store pixel data from a transfer operation.
	CreatePixelTransferBuffer(info BufferInfo) Buffer

	// CreateUniformBuffer creates a new Buffer object that can be used
	// to store uniform data.
	CreateUniformBuffer(info BufferInfo) Buffer

	// CreateVertexArray creates a new VertexArray object that describes
	// the layout of vertex and index data for a mesh.
	CreateVertexArray(info VertexArrayInfo) VertexArray

	// CreatePipeline creates a new Pipeline object that describes the
	// desired rendering state.
	CreatePipeline(info PipelineInfo) Pipeline

	// CreateCommandBuffer creates a new CommandBuffer object with the
	// specified initial capacity. The buffer will automatically grow
	// as needed but it is recommended to provide a reasonable initial
	// capacity to avoid unnecessary allocations.
	CreateCommandBuffer(initialCapacity int) CommandBuffer

	// Queue can be used to schedule commands to be executed on the GPU.
	Queue() Queue
}

API provides access to low-level graphics manipulation and rendering.

type Area added in v0.4.0

type Area struct {

	// X is the X coordinate of the area.
	X int

	// Y is the Y coordinate of the area.
	Y int

	// Width is the width of the area.
	Width int

	// Height is the height of the area.
	Height int
}

Area describes a rectangular area to be used for rendering.

type BlendFactor added in v0.4.0

type BlendFactor uint8

BlendFactor specifies the blend factor.

const (
	// BlendFactorZero specifies that the blend factor is zero.
	BlendFactorZero BlendFactor = iota

	// BlendFactorOne specifies that the blend factor is one.
	BlendFactorOne

	// BlendFactorSourceColor specifies that the blend factor is the source
	// color.
	BlendFactorSourceColor

	// BlendFactorOneMinusSourceColor specifies that the blend factor is one
	// minus the source color.
	BlendFactorOneMinusSourceColor

	// BlendFactorDestinationColor specifies that the blend factor is the
	// destination color.
	BlendFactorDestinationColor

	// BlendFactorOneMinusDestinationColor specifies that the blend factor is
	// one minus the destination color.
	BlendFactorOneMinusDestinationColor

	// BlendFactorSourceAlpha specifies that the blend factor is the source
	// alpha.
	BlendFactorSourceAlpha

	// BlendFactorOneMinusSourceAlpha specifies that the blend factor is one
	// minus the source alpha.
	BlendFactorOneMinusSourceAlpha

	// BlendFactorDestinationAlpha specifies that the blend factor is the
	// destination alpha.
	BlendFactorDestinationAlpha

	// BlendFactorOneMinusDestinationAlpha specifies that the blend factor is
	// one minus the destination alpha.
	BlendFactorOneMinusDestinationAlpha

	// BlendFactorConstantColor specifies that the blend factor is the constant
	// color.
	BlendFactorConstantColor

	// BlendFactorOneMinusConstantColor specifies that the blend factor is one
	// minus the constant color.
	BlendFactorOneMinusConstantColor

	// BlendFactorConstantAlpha specifies that the blend factor is the constant
	// alpha.
	BlendFactorConstantAlpha

	// BlendFactorOneMinusConstantAlpha specifies that the blend factor is one
	// minus the constant alpha.
	BlendFactorOneMinusConstantAlpha

	// BlendFactorSourceAlphaSaturate specifies that the blend factor is the
	// source alpha saturated.
	BlendFactorSourceAlphaSaturate
)

type BlendOperation added in v0.4.0

type BlendOperation uint8

BlendOperation specifies the blend operation.

const (
	// BlendOperationAdd specifies that the blend operation is addition.
	BlendOperationAdd BlendOperation = iota

	// BlendOperationSubtract specifies that the blend operation is subtraction.
	BlendOperationSubtract

	// BlendOperationReverseSubtract specifies that the blend operation is
	// reverse subtraction.
	BlendOperationReverseSubtract

	// BlendOperationMin specifies that the blend operation is minimum.
	BlendOperationMin

	// BlendOperationMax specifies that the blend operation is maximum.
	BlendOperationMax
)

type Buffer added in v0.4.0

type Buffer interface {
	BufferMarker

	// Release releases the resources associated with this Buffer.
	Release()
}

Buffer is used to store data that can be used by the GPU.

type BufferInfo added in v0.4.0

type BufferInfo struct {
	Dynamic bool
	Data    []byte
	Size    int
}

BufferInfo describes the information needed to create a new Buffer.

type BufferMarker added in v0.17.0

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

BufferMarker marks a type as being a Buffer.

type ColorAttachmentInfo added in v0.4.0

type ColorAttachmentInfo struct {

	// LoadOp describes how the contents of the color attachment should be
	// loaded.
	LoadOp LoadOperation

	// StoreOp describes how the contents of the color attachment should be
	// stored.
	StoreOp StoreOperation

	// ClearValue is the value that should be used to clear the color attachment
	// when LoadOp is LoadOperationClear.
	ClearValue [4]float32
}

ColorAttachmentInfo describes how a color attachment should be handled.

type ColorTexture2DInfo added in v0.4.0

type ColorTexture2DInfo struct {

	// Width specifies the width of the texture.
	Width int

	// Height specifies the height of the texture.
	Height int

	// Wrapping specifies the texture wrapping mode.
	Wrapping WrapMode

	// Filtering specifies the texture filtering mode.
	Filtering FilterMode

	// Mipmapping specifies whether mipmapping should be enabled and whether
	// mipmaps should be generated.
	Mipmapping bool

	// GammaCorrection specifies whether gamma correction should be performed
	// in order to convert the colors into linear space.
	GammaCorrection bool

	// Format specifies the format of the data.
	Format DataFormat

	// Data specifies the data that should be uploaded to the texture.
	Data []byte
}

ColorTexture2DInfo represents the information needed to create a 2D color Texture.

type ColorTextureCubeInfo added in v0.4.0

type ColorTextureCubeInfo struct {

	// Dimension specifies the width, height and length of the texture.
	Dimension int

	// Filtering specifies the texture filtering mode.
	Filtering FilterMode

	// Mipmapping specifies whether mipmapping should be enabled and whether
	// mipmaps should be generated.
	Mipmapping bool

	// GammaCorrection specifies whether gamma correction should be performed
	// in order to convert the colors into linear space.
	GammaCorrection bool

	// Format specifies the format of the data.
	Format DataFormat

	// FrontSideData specifies the data that should be uploaded to the front
	// side of the texture.
	FrontSideData []byte

	// BackSideData specifies the data that should be uploaded to the back
	// side of the texture.
	BackSideData []byte

	// LeftSideData specifies the data that should be uploaded to the left
	// side of the texture.
	LeftSideData []byte

	// RightSideData specifies the data that should be uploaded to the right
	// side of the texture.
	RightSideData []byte

	// TopSideData specifies the data that should be uploaded to the top
	// side of the texture.
	TopSideData []byte

	// BottomSideData specifies the data that should be uploaded to the bottom
	// side of the texture.
	BottomSideData []byte
}

ColorTextureCubeInfo represents the information needed to create a cube color Texture.

type CommandBuffer added in v0.17.0

type CommandBuffer interface {
	CommandBufferMarker

	// CopyFramebufferToBuffer copies the contents of the current framebuffer
	// to the specified buffer.
	CopyFramebufferToBuffer(info CopyFramebufferToBufferInfo)

	// CopyFramebufferToTexture copies the contents of the current framebuffer
	// to the specified texture.
	CopyFramebufferToTexture(info CopyFramebufferToTextureInfo)

	// BeginRenderPass starts a new render pass that will render to the
	// specified framebuffer.
	BeginRenderPass(info RenderPassInfo)

	// BindPipeline configures the pipeline that should be used for the
	// following draw commands.
	BindPipeline(pipeline Pipeline)

	// TextureUnit configures which texture should be used for the
	// specified texture unit.
	TextureUnit(index int, texture Texture)

	// UniformBufferUnit configures which buffer should be used for the
	// specified buffer unit.
	UniformBufferUnit(index int, buffer Buffer, offset, size int)

	// Draw uses the vertex buffer to draw primitives.
	Draw(vertexOffset, vertexCount, instanceCount int)

	// DrawIndexed uses the index buffer to draw primitives.
	DrawIndexed(indexOffset, indexCount, instanceCount int)

	// EndRenderPass ends the current render pass.
	EndRenderPass()
}

CommandBuffer is used to record commands that should be executed on the GPU.

type CommandBufferMarker added in v0.17.0

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

BufferMarker marks a type as being a CommandBuffer.

type Comparison added in v0.4.0

type Comparison uint8

Comparison specifies the comparison function.

const (
	// ComparisonNever specifies that the comparison should never pass.
	ComparisonNever Comparison = iota

	// ComparisonLess specifies that the comparison should pass if the source
	// value is less than the destination value.
	ComparisonLess

	// ComparisonEqual specifies that the comparison should pass if the source
	// value is equal to the destination value.
	ComparisonEqual

	// ComparisonLessOrEqual specifies that the comparison should pass if the
	// source value is less than or equal to the destination value.
	ComparisonLessOrEqual

	// ComparisonGreater specifies that the comparison should pass if the source
	// value is greater than the destination value.
	ComparisonGreater

	// ComparisonNotEqual specifies that the comparison should pass if the
	// source value is not equal to the destination value.
	ComparisonNotEqual

	// ComparisonGreaterOrEqual specifies that the comparison should pass if the
	// source value is greater than or equal to the destination value.
	ComparisonGreaterOrEqual

	// ComparisonAlways specifies that the comparison should always pass.
	ComparisonAlways
)

type CopyFramebufferToBufferInfo added in v0.17.0

type CopyFramebufferToBufferInfo struct {

	// Buffer is the pixel transfer buffer that should be updated with the
	// contents of the current framebuffer.
	Buffer Buffer

	// Offset is the offset into the pixel transfer buffer.
	Offset int

	// X is the X offset of the framebuffer that should be copied.
	X int

	// Y is the Y offset of the framebuffer that should be copied.
	Y int

	// Width is the width amount of the framebuffer that should be copied.
	Width int

	// Height is the height amount of the framebuffer that should be copied.
	Height int

	// Format is the format of the data.
	Format DataFormat
}

CopyFramebufferToBufferInfo describes the configuration of a copy operation from the current framebuffer to a pixel transfer buffer.

type CopyFramebufferToTextureInfo added in v0.17.0

type CopyFramebufferToTextureInfo struct {

	// Texture is the texture that should be updated with the contents of
	// the current framebuffer.
	Texture Texture

	// TextureLevel is the mipmap level of the texture that should be updated.
	TextureLevel int

	// TextureX is the X offset of the texture that should be updated.
	TextureX int

	// TextureY is the Y offset of the texture that should be updated.
	TextureY int

	// FramebufferX is the X offset of the framebuffer that should be copied.
	FramebufferX int

	// FramebufferY is the Y offset of the framebuffer that should be copied.
	FramebufferY int

	// Width is the width amount of the framebuffer that should be copied.
	Width int

	// Height is the height amount of the framebuffer that should be copied.
	Height int

	// GenerateMipmaps indicates whether or not mipmaps should be generated.
	GenerateMipmaps bool
}

CopyFramebufferToTextureInfo describes the configuration of a copy operation from the current framebuffer to a texture.

type CullMode added in v0.4.0

type CullMode uint8

CullMode specifies the culling mode.

const (
	// CullModeNone specifies that no culling should be performed.
	CullModeNone CullMode = iota

	// CullModeFront specifies that front-facing primitives should be culled.
	CullModeFront

	// CullModeBack specifies that back-facing primitives should be culled.
	CullModeBack

	// CullModeFrontAndBack specifies that all oriented primitives should be
	// culled.
	CullModeFrontAndBack
)

type DataFormat added in v0.4.0

type DataFormat int

DataFormat describes the format of the data that is stored in a Texture object.

const (
	// DataFormatUnsupported indicates that the format is not supported.
	DataFormatUnsupported DataFormat = iota

	// DataFormatRGBA8 indicates that the format is RGBA8.
	DataFormatRGBA8

	// DataFormatRGBA16F indicates that the format is RGBA16F.
	DataFormatRGBA16F

	// DataFormatRGBA32F indicates that the format is RGBA32F.
	DataFormatRGBA32F
)

func (DataFormat) String added in v0.9.0

func (f DataFormat) String() string

String returns a string representation of the DataFormat.

type DepthStencilTexture2DInfo added in v0.4.0

type DepthStencilTexture2DInfo struct {

	// Width specifies the width of the texture.
	Width int

	// Height specifies the height of the texture.
	Height int

	// DepthClippedValue specifies the value that should be used for depth
	// clipping.
	DepthClippedValue opt.T[float32]
}

DepthStencilTexture2DInfo represents the information needed to create a 2D depth-stencil Texture.

type DepthTexture2DInfo added in v0.4.0

type DepthTexture2DInfo struct {

	// Width specifies the width of the texture.
	Width int

	// Height specifies the height of the texture.
	Height int

	// ClippedValue specifies the value that should be used for depth clipping.
	ClippedValue opt.T[float32]

	// Comparable specifies whether the depth texture should be comparable.
	Comparable bool
}

DepthTexture2DInfo represents the information needed to create a 2D depth Texture.

type FaceOrientation added in v0.4.0

type FaceOrientation uint8

FaceOrientation specifies the front face orientation.

const (
	// FaceOrientationCCW specifies that counter-clockwise primitives are
	// front-facing.
	FaceOrientationCCW FaceOrientation = iota

	// FaceOrientationCW specifies that clockwise primitives are front-facing.
	FaceOrientationCW
)

type Fence added in v0.4.0

type Fence interface {
	FenceMarker

	// Status returns the current status of the fence.
	Status() FenceStatus

	// Release releases the resources associated with the fence.
	Release()
}

Fence is the interface that provides the API with the ability to synchronize with the GPU.

type FenceMarker added in v0.17.0

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

FenceMarker marks a type as being a Fence.

type FenceStatus added in v0.4.0

type FenceStatus int

FenceStatus represents the status of a Fence.

const (
	// FenceStatusNotReady indicates that the GPU has not reached the fence yet.
	FenceStatusNotReady FenceStatus = iota

	// FenceStatusSuccess indicates that the GPU has processed all commands
	// up to the fence.
	FenceStatusSuccess
)

type FilterMode added in v0.4.0

type FilterMode int

FilterMode is an enumeration of the supported texture filtering modes.

const (
	// FilterModeNearest indicates that the nearest texel should be
	// used for sampling.
	FilterModeNearest FilterMode = iota

	// FilterModeLinear indicates that the linear interpolation of
	// the nearest texels should be used for sampling.
	FilterModeLinear

	// FilterModeAnisotropic indicates that the anisotropic filtering
	// should be used for sampling.
	FilterModeAnisotropic
)

func (FilterMode) String added in v0.17.0

func (m FilterMode) String() string

String returns a string representation of the FilterMode.

type Framebuffer added in v0.4.0

type Framebuffer interface {
	FramebufferMarker

	// Release releases the resources associated with the Framebuffer.
	Release()
}

Framebuffer represents a combination of target textures to be rendered to.

type FramebufferInfo added in v0.4.0

type FramebufferInfo struct {

	// Label specifies a human-readable name for the Framebuffer. Intended
	// for debugging and logging purposes only.
	Label string

	// ColorAttachments is the list of color attachments that should be
	// attached to the Framebuffer.
	ColorAttachments [4]Texture

	// DepthAttachment is the depth attachment that should be attached to
	// the Framebuffer.
	DepthAttachment Texture

	// StencilAttachment is the stencil attachment that should be attached
	// to the Framebuffer.
	StencilAttachment Texture

	// DepthStencilAttachment is the depth+stencil attachment that should
	// be attached to the Framebuffer.
	DepthStencilAttachment Texture
}

FramebufferInfo describes the configuration of a Framebuffer.

type FramebufferMarker added in v0.17.0

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

FramebufferMarker marks a type as being a Framebuffer.

type IndexFormat added in v0.4.0

type IndexFormat uint8

IndexFormat specifies the format of an index buffer.

const (
	// IndexFormatUnsignedShort specifies that the index buffer is unsigned
	// short.
	IndexFormatUnsignedShort IndexFormat = iota

	// IndexFormatUnsignedInt specifies that the index buffer is unsigned int.
	IndexFormatUnsignedInt
)

type Limits added in v0.16.0

type Limits interface {

	// Quality returns the supported quality level by the implementation.
	// This is usually based on the performance characteristics of the
	// underlying hardware.
	//
	// This is meant to be used as a hint for the application to decide
	// on the level of detail to use for rendering.
	Quality() Quality

	// UniformBufferOffsetAlignment returns the alignment requirement
	// for uniform buffer offsets.
	UniformBufferOffsetAlignment() int
}

Limits describes the limits of the implementation.

type LoadOperation added in v0.4.0

type LoadOperation int

LoadOperation describes how the contents of a resource should be loaded.

const (
	// LoadOperationDontCare means that the contents of the resource should not
	// be loaded.
	LoadOperationDontCare LoadOperation = iota

	// LoadOperationClear means that the contents of the resource should be
	// cleared.
	LoadOperationClear
)

type Pipeline added in v0.4.0

type Pipeline interface {
	PipelineMarker

	// Release releases the resources associated with this Pipeline.
	Release()
}

Pipeline is used to configure the GPU for drawing.

type PipelineInfo added in v0.4.0

type PipelineInfo struct {

	// Program specifies the shading to use.
	Program Program

	// VertexArray specifies the mesh data.
	VertexArray VertexArray

	// Topology specifies the primitive topology.
	Topology Topology

	// Culling specifies the culling mode.
	Culling CullMode

	// FrontFace specifies the front face orientation.
	FrontFace FaceOrientation

	// DepthTest specifies whether depth testing should be enabled.
	DepthTest bool

	// DepthWrite specifies whether depth writing should be enabled.
	DepthWrite bool

	// DepthComparison specifies the depth comparison function.
	DepthComparison Comparison

	// StencilTest specifies whether stencil testing should be enabled.
	StencilTest bool

	// StencilFront specifies the stencil operation state for front-facing
	// primitives.
	StencilFront StencilOperationState

	// StencilBack specifies the stencil operation state for back-facing
	// primitives.
	StencilBack StencilOperationState

	// ColorWrite specifies which color channels should be written to.
	ColorWrite [4]bool

	// BlendEnabled specifies whether blending should be enabled.
	BlendEnabled bool

	// BlendColor specifies the constant color that should be used for blending.
	BlendColor [4]float32

	// BlendSourceColorFactor specifies the source color factor for blending.
	BlendSourceColorFactor BlendFactor

	// BlendDestinationColorFactor specifies the destination color factor for
	// blending.
	BlendDestinationColorFactor BlendFactor

	// BlendSourceAlphaFactor specifies the source alpha factor for blending.
	BlendSourceAlphaFactor BlendFactor

	// BlendDestinationAlphaFactor specifies the destination alpha factor for
	// blending.
	BlendDestinationAlphaFactor BlendFactor

	// BlendOpColor specifies the color blend operation.
	BlendOpColor BlendOperation

	// BlendOpAlpha specifies the alpha blend operation.
	BlendOpAlpha BlendOperation
}

PipelineInfo describes the information needed to create a new Pipeline.

type PipelineMarker added in v0.17.0

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

PipelineMarker marks a type as being a Pipeline.

type Program added in v0.4.0

type Program interface {
	ProgramMarker

	// Release releases the resources used by the program.
	Release()
}

Program represents a graphics program.

type ProgramCode added in v0.16.0

type ProgramCode interface {
	ProgramCodeMarker
}

ProgramCode represents the shader language source code for a program.

This can differ depending on the API implementation. It could be a single string or a struct with multiple strings for each shader stage.

type ProgramCodeMarker added in v0.17.0

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

ProgramCodeMarker marks a type as being a ProgramCode.

type ProgramInfo added in v0.4.0

type ProgramInfo struct {

	// Label specifies a human-readable label for the program. Intended for
	// debugging and logging purposes only.
	Label string

	// SourceCode specifies the source code for the program.
	SourceCode ProgramCode

	// TextureBindings specifies the texture bindings for the program, in case
	// the implementation does not support shader-specified bindings.
	TextureBindings []TextureBinding

	// UniformBindings specifies the uniform bindings for the program, in case
	// the implementation does not support shader-specified bindings.
	UniformBindings []UniformBinding
}

ProgramInfo represents the information needed to create a Program.

type ProgramMarker added in v0.17.0

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

ProgramMarker marks a type as being a Program.

type Quality added in v0.4.0

type Quality int

Quality is an enumeration of the supported render quality levels.

const (
	// QualityLow indicates that the implementation is running on hardware
	// with low performance capabilities.
	QualityLow Quality = iota

	// QualityMedium indicates that the implementation is running on hardware
	// with medium performance capabilities.
	QualityMedium

	// QualityHigh indicates that the implementation is running on hardware
	// with high performance capabilities.
	QualityHigh
)

type Queue added in v0.17.0

type Queue interface {
	QueueMarker

	// Invalidate indicates that the graphics state might have changed
	// from outside this API and any cached state by the API should
	// be discarded.
	//
	// Using this command will force a subsequent draw command to initialize
	// all graphics state (e.g. blend state, depth state, stencil state, etc.)
	// on old implementations.
	Invalidate()

	// WriteBuffer writes the provided data to the specified buffer at the
	// specified offset.
	WriteBuffer(buffer Buffer, offset int, data []byte)

	// ReadBuffer reads data from the specified buffer at the specified offset
	// into the provided target slice.
	ReadBuffer(buffer Buffer, offset int, target []byte)

	// Submit schedules the provided command buffer to be executed on the GPU.
	//
	// Once submitted the command buffer is reset and can be reused.
	Submit(commands CommandBuffer)

	// TrackSubmittedWorkDone creates a fence that will be signaled once all
	// work submitted to the queue before this call has been completed.
	TrackSubmittedWorkDone() Fence
}

Queue is the interface that provides the API with the ability to schedule commands to be executed on the GPU.

type QueueMarker added in v0.17.0

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

QueueMarker marks a type as being a Queue.

type RenderPassInfo added in v0.4.0

type RenderPassInfo struct {

	// Framebuffer is the Framebuffer that the render pass will render to.
	Framebuffer Framebuffer

	// Viewport describes the area of the Framebuffer that the render pass will
	// render to.
	Viewport Area

	// Colors describes the color attachments that the render pass will render
	// to.
	Colors [4]ColorAttachmentInfo

	// DepthLoadOp describes how the contents of the depth attachment should be
	// loaded.
	DepthLoadOp LoadOperation

	// DepthStoreOp describes how the contents of the depth attachment should be
	// stored.
	DepthStoreOp StoreOperation

	// DepthClearValue is the value that should be used to clear the depth
	// attachment when DepthLoadOp is LoadOperationClear.
	DepthClearValue float32

	// StencilLoadOp describes how the contents of the stencil attachment should
	// be loaded.
	StencilLoadOp LoadOperation

	// StencilStoreOp describes how the contents of the stencil attachment
	// should be stored.
	StencilStoreOp StoreOperation

	// StencilClearValue is the value that should be used to clear the stencil
	// attachment when StencilLoadOp is LoadOperationClear.
	StencilClearValue int
}

RenderPassInfo describes the information needed to begin a new render pass.

type StencilOperation added in v0.4.0

type StencilOperation uint8

StencilOperation specifies the stencil operation.

const (
	// StencilOperationKeep specifies that the current stencil value should be
	// kept.
	StencilOperationKeep StencilOperation = iota

	// StencilOperationZero specifies that the stencil value should be set to
	// zero.
	StencilOperationZero

	// StencilOperationReplace specifies that the stencil value should be set to
	// the reference value.
	StencilOperationReplace

	// StencilOperationIncrease specifies that the stencil value should be
	// incremented, clamping to the maximum value.
	StencilOperationIncrease

	// StencilOperationIncreaseWrap specifies that the stencil value should be
	// incremented, wrapping to zero if the maximum value is exceeded.
	StencilOperationIncreaseWrap

	// StencilOperationDecrease specifies that the stencil value should be
	// decremented, clamping to zero.
	StencilOperationDecrease

	// StencilOperationDecreaseWrap specifies that the stencil value should be
	// decremented, wrapping to the maximum value if zero is exceeded.
	StencilOperationDecreaseWrap

	// StencilOperationInvert specifies that the stencil value should be
	// bitwise inverted.
	StencilOperationInvert
)

type StencilOperationState added in v0.4.0

type StencilOperationState struct {

	// StencilFailOp specifies the operation to perform when the stencil test
	// fails.
	StencilFailOp StencilOperation

	// DepthFailOp specifies the operation to perform when the stencil test
	// passes, but the depth test fails.
	DepthFailOp StencilOperation

	// PassOp specifies the operation to perform when both the stencil test and
	// the depth test pass.
	PassOp StencilOperation

	// Comparison specifies the comparison function.
	Comparison Comparison

	// ComparisonMask specifies the comparison mask.
	ComparisonMask uint32

	// Reference specifies the reference value.
	Reference int32

	// WriteMask specifies the write mask.
	WriteMask uint32
}

StencilOperationState specifies the stencil operation state.

type StencilTexture2DInfo added in v0.4.0

type StencilTexture2DInfo struct {

	// Width specifies the width of the texture.
	Width int

	// Height specifies the height of the texture.
	Height int
}

StencilTexture2DInfo represents the information needed to create a 2D stencil Texture.

type StoreOperation added in v0.4.0

type StoreOperation int

StoreOperation describes how the contents of a resource should be stored.

const (
	// StoreOperationDontCare means that the contents of the resource should not
	// be stored.
	StoreOperationDontCare StoreOperation = iota

	// StoreOperationStore means that the contents of the resource should be
	// stored.
	StoreOperationStore
)

type Texture added in v0.4.0

type Texture interface {
	TextureMarker

	// Release releases the resources associated with this Texture.
	Release()
}

Texture is the interface that provides the API with the ability to store image data.

type TextureBinding added in v0.9.0

type TextureBinding struct {

	// Name specifies the name of the texture in the shader.
	Name string

	// Index specifies the binding index.
	Index int
}

TextureBinding represents a texture binding for a program.

func NewTextureBinding added in v0.9.0

func NewTextureBinding(name string, index int) TextureBinding

NewTextureBinding creates a new TextureBinding with the specified name and index.

type TextureMarker added in v0.17.0

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

TextureMarker marks a type as being a Texture.

type Topology added in v0.4.0

type Topology uint8

Topology specifies the primitive topology.

const (
	// TopologyPoints specifies that the primitive topology is points.
	TopologyPoints Topology = iota

	// TopologyLineList specifies that the primitive topology is a line list.
	TopologyLineList

	// TopologyLineStrip specifies that the primitive topology is a line strip.
	TopologyLineStrip

	// TopologyTriangleList specifies that the primitive topology is a triangle
	// list.
	TopologyTriangleList

	// TopologyTriangleStrip specifies that the primitive topology is a triangle
	// strip.
	TopologyTriangleStrip

	// TopologyTriangleFan specifies that the primitive topology is a triangle
	// fan.
	//
	// TODO: This topology is not supported by WebGPU. Try to phase it out.
	TopologyTriangleFan
)

type UniformBinding added in v0.9.0

type UniformBinding struct {

	// Name specifies the name of the uniform object in the shader.
	Name string

	// Index specifies the binding index.
	Index int
}

UniformBinding represents a uniform binding for a program.

func NewUniformBinding added in v0.9.0

func NewUniformBinding(name string, index int) UniformBinding

NewUniformBinding creates a new UniformBinding with the specified name and index.

type VertexArray added in v0.4.0

type VertexArray interface {
	VertexArrayMarker

	// Release releases the resources associated with this VertexArray.
	Release()
}

VertexArray represents the geometry for a mesh.

type VertexArrayAttribute added in v0.17.0

type VertexArrayAttribute struct {

	// Binding specifies the binding inside the Vertex Array that this uses.
	Binding int

	// Location specifies the location of the attribute in the shader.
	Location int

	// Format specifies the format of the attribute.
	Format VertexAttributeFormat

	// Offset specifies the byte offset of the attribute in the buffer.
	Offset int
}

VertexArrayAttribute represents a vertex attribute for a VertexArray.

func NewVertexArrayAttribute added in v0.17.0

func NewVertexArrayAttribute(binding, location, offset int, format VertexAttributeFormat) VertexArrayAttribute

NewVertexArrayAttribute creates a new VertexArrayAttribute with the specified binding, location, offset and format.

type VertexArrayBinding added in v0.17.0

type VertexArrayBinding struct {

	// VertexBuffer specifies the vertex buffer.
	VertexBuffer Buffer

	// Stride specifies the byte stride of subsequent elements in the buffer.
	Stride int
}

VertexArrayBinding represents a vertex buffer binding for a VertexArray.

func NewVertexArrayBinding added in v0.17.0

func NewVertexArrayBinding(buffer Buffer, stride int) VertexArrayBinding

NewVertexArrayBinding creates a new VertexArrayBinding with the specified buffer and stride.

type VertexArrayInfo added in v0.4.0

type VertexArrayInfo struct {

	// Bindings specifies the vertex buffers that make up this Vertex Array.
	Bindings []VertexArrayBinding

	// Attributes specifies the vertex attributes.
	Attributes []VertexArrayAttribute

	// IndexFormat specifies the format of the index buffer.
	IndexFormat IndexFormat

	// IndexBuffer specifies the index buffer.
	IndexBuffer Buffer
}

VertexArrayInfo represents the information needed to create a VertexArray.

type VertexArrayMarker added in v0.17.0

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

VertexArrayMarker marks a type as being a VertexArray.

type VertexAttributeFormat added in v0.4.0

type VertexAttributeFormat uint8

VertexAttributeFormat specifies the format of a vertex attribute.

const (
	// VertexAttributeFormatR32F specifies that the vertex attribute is a
	// single 32-bit float.
	VertexAttributeFormatR32F VertexAttributeFormat = iota

	// VertexAttributeFormatRG32F specifies that the vertex attribute is a
	// two-component 32-bit float.
	VertexAttributeFormatRG32F

	// VertexAttributeFormatRGB32F specifies that the vertex attribute is a
	// three-component 32-bit float.
	VertexAttributeFormatRGB32F

	// VertexAttributeFormatRGBA32F specifies that the vertex attribute is a
	// four-component 32-bit float.
	VertexAttributeFormatRGBA32F

	// VertexAttributeFormatR16F specifies that the vertex attribute is a
	// single 16-bit float.
	VertexAttributeFormatR16F

	// VertexAttributeFormatRG16F specifies that the vertex attribute is a
	// two-component 16-bit float.
	VertexAttributeFormatRG16F

	// VertexAttributeFormatRGB16F specifies that the vertex attribute is a
	// three-component 16-bit float.
	VertexAttributeFormatRGB16F

	// VertexAttributeFormatRGBA16F specifies that the vertex attribute is a
	// four-component 16-bit float.
	VertexAttributeFormatRGBA16F

	// VertexAttributeFormatR16S specifies that the vertex attribute is a
	// single 16-bit signed integer.
	VertexAttributeFormatR16S

	// VertexAttributeFormatRG16S specifies that the vertex attribute is a
	// two-component 16-bit signed integer.
	VertexAttributeFormatRG16S

	// VertexAttributeFormatRGB16S specifies that the vertex attribute is a
	// three-component 16-bit signed integer.
	VertexAttributeFormatRGB16S

	// VertexAttributeFormatRGBA16S specifies that the vertex attribute is a
	// four-component 16-bit signed integer.
	VertexAttributeFormatRGBA16S

	// VertexAttributeFormatR16SN specifies that the vertex attribute is a
	// single 16-bit signed integer that is normalized to [-1, 1].
	VertexAttributeFormatR16SN

	// VertexAttributeFormatRG16SN specifies that the vertex attribute is a
	// two-component 16-bit signed integer that is normalized to [-1, 1].
	VertexAttributeFormatRG16SN

	// VertexAttributeFormatRGB16SN specifies that the vertex attribute is a
	// three-component 16-bit signed integer that is normalized to [-1, 1].
	VertexAttributeFormatRGB16SN

	// VertexAttributeFormatRGBA16SN specifies that the vertex attribute is a
	// four-component 16-bit signed integer that is normalized to [-1, 1].
	VertexAttributeFormatRGBA16SN

	// VertexAttributeFormatR16U specifies that the vertex attribute is a
	// single 16-bit unsigned integer.
	VertexAttributeFormatR16U

	// VertexAttributeFormatRG16U specifies that the vertex attribute is a
	// two-component 16-bit unsigned integer.
	VertexAttributeFormatRG16U

	// VertexAttributeFormatRGB16U specifies that the vertex attribute is a
	// three-component 16-bit unsigned integer.
	VertexAttributeFormatRGB16U

	// VertexAttributeFormatRGBA16U specifies that the vertex attribute is a
	// four-component 16-bit unsigned integer.
	VertexAttributeFormatRGBA16U

	// VertexAttributeFormatR16UN specifies that the vertex attribute is a
	// single 16-bit unsigned integer that is normalized to [0, 1].
	VertexAttributeFormatR16UN

	// VertexAttributeFormatRG16UN specifies that the vertex attribute is a
	// two-component 16-bit unsigned integer that is normalized to [0, 1].
	VertexAttributeFormatRG16UN

	// VertexAttributeFormatRGB16UN specifies that the vertex attribute is a
	// three-component 16-bit unsigned integer that is normalized to [0, 1].
	VertexAttributeFormatRGB16UN

	// VertexAttributeFormatRGBA16UN specifies that the vertex attribute is a
	// four-component 16-bit unsigned integer that is normalized to [0, 1].
	VertexAttributeFormatRGBA16UN

	// VertexAttributeFormatR8S specifies that the vertex attribute is a
	// single 8-bit signed integer.
	VertexAttributeFormatR8S

	// VertexAttributeFormatRG8S specifies that the vertex attribute is a
	// two-component 8-bit signed integer.
	VertexAttributeFormatRG8S

	// VertexAttributeFormatRGB8S specifies that the vertex attribute is a
	// three-component 8-bit signed integer.
	VertexAttributeFormatRGB8S

	// VertexAttributeFormatRGBA8S specifies that the vertex attribute is a
	// four-component 8-bit signed integer.
	VertexAttributeFormatRGBA8S

	// VertexAttributeFormatR8SN specifies that the vertex attribute is a
	// single 8-bit signed integer that is normalized to [-1, 1].
	VertexAttributeFormatR8SN

	// VertexAttributeFormatRG8SN specifies that the vertex attribute is a
	// two-component 8-bit signed integer that is normalized to [-1, 1].
	VertexAttributeFormatRG8SN

	// VertexAttributeFormatRGB8SN specifies that the vertex attribute is a
	// three-component 8-bit signed integer that is normalized to [-1, 1].
	VertexAttributeFormatRGB8SN

	// VertexAttributeFormatRGBA8SN specifies that the vertex attribute is a
	// four-component 8-bit signed integer that is normalized to [-1, 1].
	VertexAttributeFormatRGBA8SN

	// VertexAttributeFormatR8U specifies that the vertex attribute is a
	// single 8-bit unsigned integer.
	VertexAttributeFormatR8U

	// VertexAttributeFormatRG8U specifies that the vertex attribute is a
	// two-component 8-bit unsigned integer.
	VertexAttributeFormatRG8U

	// VertexAttributeFormatRGB8U specifies that the vertex attribute is a
	// three-component 8-bit unsigned integer.
	VertexAttributeFormatRGB8U

	// VertexAttributeFormatRGBA8U specifies that the vertex attribute is a
	// four-component 8-bit unsigned integer.
	VertexAttributeFormatRGBA8U

	// VertexAttributeFormatR8UN specifies that the vertex attribute is a
	// single 8-bit unsigned integer that is normalized to [0, 1].
	VertexAttributeFormatR8UN

	// VertexAttributeFormatRG8UN specifies that the vertex attribute is a
	// two-component 8-bit unsigned integer that is normalized to [0, 1].
	VertexAttributeFormatRG8UN

	// VertexAttributeFormatRGB8UN specifies that the vertex attribute is a
	// three-component 8-bit unsigned integer that is normalized to [0, 1].
	VertexAttributeFormatRGB8UN

	// VertexAttributeFormatRGBA8UN specifies that the vertex attribute is a
	// four-component 8-bit unsigned integer that is normalized to [0, 1].
	VertexAttributeFormatRGBA8UN

	// VertexAttributeFormatR8IU specifies that the vertex attribute is a single
	// 8-bit unsigned integer that should be treated as an integer on the GPU.
	VertexAttributeFormatR8IU

	// VertexAttributeFormatRG8IU specifies that the vertex attribute is a
	// two-component 8-bit unsigned integer that should be treated as an integer
	// on the GPU.
	VertexAttributeFormatRG8IU

	// VertexAttributeFormatRGB8IU specifies that the vertex attribute is a
	// three-component 8-bit unsigned integer that should be treated as an
	// integer on the GPU.
	VertexAttributeFormatRGB8IU

	// VertexAttributeFormatRGBA8IU specifies that the vertex attribute is a
	// four-component 8-bit unsigned integer that should be treated as an
	// integer on the GPU.
	VertexAttributeFormatRGBA8IU
)

type WrapMode added in v0.4.0

type WrapMode int

WrapMode is an enumeration of the supported texture wrapping modes.

const (
	// WrapModeClamp indicates that the texture coordinates should
	// be clamped to the range [0, 1].
	WrapModeClamp WrapMode = iota

	// WrapModeRepeat indicates that the texture coordinates should
	// be repeated.
	WrapModeRepeat

	// WrapModeMirroredRepeat indicates that the texture coordinates
	// should be repeated with mirroring.
	WrapModeMirroredRepeat
)

func (WrapMode) String added in v0.17.0

func (m WrapMode) String() string

String returns a string representation of the WrapMode.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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