render

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LightsToBytes added in v0.20.0

func LightsToBytes(lights []Light, bytes []byte) []byte

LightsToBytes converts a slice of lights to bytes. The given byte slice is zeroed and returned filled with the given light data.

func M4ToBytes added in v0.20.0

func M4ToBytes(m *lin.M4, bytes []byte) []byte

M4ToBytes returns a byte slice of float32 for the given float64 matrix. The given byte slice is zeroed and returned filled with the matrix bytes.

func U8ToBytes added in v0.20.0

func U8ToBytes(val uint8, bytes []byte) []byte

U8ToBytes returns a byte slice containing the given uint8 because the smallest uniform is an int. The given byte slice is zeroed and returned filled with the uint8.

func V4S32ToBytes added in v0.20.0

func V4S32ToBytes(x, y, z, w float32, bytes []byte) []byte

V4S32ToBytes returns a byte slice of float32 for the given float64s The given byte slice is zeroed and returned filled with the float bytes.

func V4SToBytes added in v0.20.0

func V4SToBytes(x, y, z, w float64, bytes []byte) []byte

V4SToBytes returns a byte slice of float32 for the given float64s The given byte slice is zeroed and returned filled with the vector bytes.

func V4ToBytes added in v0.20.0

func V4ToBytes(v *lin.V4, bytes []byte) []byte

V4ToBytes returns a byte slice of float32 for the given float64 vector. The given byte slice is zeroed and returned filled with the vector bytes.

Types

type Context added in v0.8.0

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

Context holds data for the rendering system and wraps the API specific renderers, ie: Vulkan, DX12, Metal.

func New

func New(api RenderAPI, dev *device.Device, appTitle string) (rc *Context, err error)

New creates an initialized renderer and returns a render context.

func (*Context) Dispose added in v0.20.0

func (c *Context) Dispose()

Dispose releases renderer resources.

func (*Context) Draw added in v0.20.0

func (c *Context) Draw(passes []Pass, dt time.Duration) (err error)

Draw renders the given render passes for one frame. Expected to be called many times per second.

func (*Context) DropInstanceData added in v0.20.0

func (c *Context) DropInstanceData(iid uint32)

DropInstanced discards the instanced resources.

func (*Context) DropMesh added in v0.20.0

func (c *Context) DropMesh(mid uint32)

DropMesh discards the mesh resources.

func (*Context) DropTexture added in v0.20.0

func (c *Context) DropTexture(tid uint32)

DropTexture removes the GPU texture resources for the given texture ID.

func (*Context) LoadInstanceData added in v0.20.0

func (c *Context) LoadInstanceData(data []load.Buffer) (iid uint32, err error)

LoadInstanceData allocates GPU resources for the instanced mesh data.

func (*Context) LoadMesh added in v0.20.0

func (c *Context) LoadMesh(msh load.MeshData) (mid uint32, err error)

LoadMesh allocates GPU resources for the mesh data.

func (*Context) LoadShader added in v0.20.0

func (c *Context) LoadShader(config *load.Shader) (sid uint16, err error)

LoadShader prepare the GPU indicated GPU shader for rendering.

func (*Context) LoadTexture added in v0.20.0

func (c *Context) LoadTexture(img *load.ImageData) (tid uint32, err error)

LoadTexture creates GPU texture resources and uploads texture data to the GPU.

func (*Context) Resize added in v0.20.0

func (c *Context) Resize(width, height uint32)

Resize updates the graphics resources to the given size. Expected to be called when the user resizes the app window.

func (*Context) SetClearColor added in v0.20.0

func (c *Context) SetClearColor(r, g, b, a float32)

SetClearColor sets the color that is used to clear the display.

func (*Context) Size added in v0.20.0

func (c *Context) Size() (width, height uint32)

Size returns the current render surface size.

type Light added in v0.20.0

type Light struct {
	X, Y, Z, W float32 // location - W is 1 for point light, 0 for directional.
	R, G, B    float32 // color
	Intensity  float32 // light intensity
}

Light holds the location and color for a directional light. Effectively 2 float32 vec4 for 32 bytes.

type Loader added in v0.20.0

type Loader interface {
	LoadTexture(img *load.ImageData) (tid uint32, err error)
	LoadMesh(mdata load.MeshData) (mid uint32, err error)
	LoadShader(config *load.Shader) (mid uint16, err error)
}

The render context implements this interface. It allows engine tests to mock this part of the render context.

type Packet added in v0.20.0

type Packet struct {
	ShaderID   uint16   // GPU shader reference
	MeshID     uint32   // GPU mesh reference.
	TextureIDs []uint32 // GPU texture references.

	// packet (model) uniform data.
	Data map[load.PacketUniform][]byte

	// used to draw instanced meshes.
	IsInstanced   bool   // true for instanced models.
	InstanceID    uint32 // GPU instance data reference.
	InstanceCount uint32 // instance count for instanced models.

	// Rendering hints.
	Tag    uint32 // Application tag (entity ID) for debugging.
	Bucket uint64 // Used to sort packets. Lower buckets rendered first.
}

Packet holds the GPU references, shader uniforms, and the model-view-projection transforms needed to draw a model in a single draw call.

func (*Packet) Reset added in v0.20.0

func (p *Packet) Reset()

Reset clears old draw data so the draw call can be reused.

type Packets added in v0.20.0

type Packets []Packet // variable number of packets.

Packets is a list of packets that is used to allocates render models. Packets are intended to be reused each render loop.

func (Packets) GetPacket added in v0.20.0

func (p Packets) GetPacket() (Packets, *Packet)

GetPacket returns a render.Packet from Packets. The list of packets is grown as needed and Packet instances are reused if available.

type Pass added in v0.20.0

type Pass struct {

	// Packets are a reusable list of packets, one per model.
	Packets Packets
	Data    map[load.PassUniform][]byte // Scene uniform data

	// Light position and color information.
	// Lights are reused to generate scene light uniform data.
	Lights []Light // max 3 scene lights.
}

Pass contains a group of Packets for rendering in this render pass.

func NewPass added in v0.20.0

func NewPass() Pass

NewPass initializes a render pass. The returned Pass is expected to be reused in render loops.

func (*Pass) Reset added in v0.20.0

func (rp *Pass) Reset()

Reset the pass data.

type PassID added in v0.20.0

type PassID uint8 // upto 256 passes should be sufficient.

PassID identifies a render.Pass. Lower number render passes are rendered before higher numbers.

const (
	Pass3D PassID = iota // 3D renderpass rendered first
	Pass2D               // 2D renderpass rendered next
)

type RenderAPI added in v0.20.0

type RenderAPI int

RenderAPI enumerates the possible render backends.

const (
	VULKAN_RENDERER RenderAPI = iota // windows, linux, android
	DX12_RENDERER                    // FUTURE: xbox
	METAL_RENDERER                   // FUTURE: iOS, macOS, tvOS, watchOS, visionOS
)

Vulkan is currently the only supported render API There are no plans to support OpenGL or any DirectX versions before DX12. Unlikely futures include:

  • Nintendo NVN - proprietary...unlikely to ship golang to this platform.
  • Playstation GNM - proprietary...unlikely to ship golang to this platform.

Jump to

Keyboard shortcuts

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