maprender

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MaxRank = 12

MaxRank is the highest rank the data uses. The filter clamps to 0..12, so a pass keeps one cumulative count per rank in that range.

Variables

View Source
var MapVertexLayout = gputypes.VertexBufferLayout{
	ArrayStride: 12,
	StepMode:    gputypes.VertexStepModeVertex,
	Attributes: []gputypes.VertexAttribute{
		{Format: gputypes.VertexFormatSint32x2, Offset: 0, ShaderLocation: 0},
		{Format: gputypes.VertexFormatUnorm8x4, Offset: 8, ShaderLocation: 1},
	},
}

MapVertexLayout describes the buffer layout for MapVertex.

Functions

func BuildMapStrokes

func BuildMapStrokes(
	dev *wgpu.Device,
	strokeGeoms []StrokeGeometry,
	strokeWidthPx float32,
	minSegmentPx float32,
) (*render.StrokeBuffer, [MaxRank + 1]int)

BuildMapStrokes returns the segment buffer and, per rank, how many of its segments to draw at that level of detail. Segments are emitted in ascending rank, so a level of detail is a prefix.

It operates on generic StrokeGeometry rather than map-specific types.

func RankForZoom

func RankForZoom(zoom float32) int

RankForZoom is the maximum rank worth drawing at a given zoom, which is the filter the map data documents: the more ground a pixel covers, the fewer minor rivers and lakes are worth drawing.

Types

type DrawPassSpec

type DrawPassSpec struct {
	GeomIndices []int32
	FillColor   *render.Color
	StrokeColor *render.Color
	RankFilter  bool
}

DrawPassSpec describes one ordered group of geometries to draw together.

type FillGeometry

type FillGeometry struct {
	Coords []int32
	Tris   []int32
	Rank   int
	Fill   render.Color
}

FillGeometry is one triangulated polygon ready for GPU upload.

type MapMesh

type MapMesh struct {
	Buffer *wgpu.Buffer
	Passes []PassRange
	Total  uint32
}

MapMesh holds pre-built GPU geometry for the entire map.

func BuildMapMesh

func BuildMapMesh(
	dev *wgpu.Device,
	fillGeoms []FillGeometry,
	passes []DrawPassSpec,
	cfg MapMeshConfig,
) *MapMesh

BuildMapMesh triangulates fills and uploads them to a single GPU vertex buffer. It operates on generic FillGeometry and DrawPassSpec rather than map-specific types.

type MapMeshConfig

type MapMeshConfig struct {
	StrokeWidthPx float32
	MinSegmentPx  float32
	RefZoom       float32
	Scale         float32
}

MapMeshConfig controls how the map mesh is built.

type MapPipeline

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

MapPipeline renders pre-built map geometry through the engine's camera. Positions are int32 world-space coords; the viewProj matrix bakes in the scale divisor so the shader just multiplies.

It is an example of a pipeline built outside the engine: it lists the engine's camera layout as group 0, reads the camera at group(0) binding(0), and owns no camera buffer. render.GPU binds and updates that for it, so nothing here has to be told when the view moves.

func NewMapPipeline

func NewMapPipeline(dev *wgpu.Device, format gputypes.TextureFormat, camBGL *wgpu.BindGroupLayout) *MapPipeline

NewMapPipeline creates the pipeline for pre-built map geometry. camBGL is render.GPU.CameraLayout().

func (*MapPipeline) Pipeline

func (p *MapPipeline) Pipeline() *wgpu.RenderPipeline

func (*MapPipeline) Release

func (p *MapPipeline) Release()

type MapVertex

type MapVertex struct {
	PosX, PosY int32
	R, G, B, A uint8
}

MapVertex is a compact 12-byte vertex for pre-built map geometry. Positions are raw int32 world-space coords (divided by Scale in the shader). Colors are quantized to uint8 (2x compression vs float32 Vertex).

type PassRange

type PassRange struct {
	Offset uint32
	Count  uint32
	ByRank [MaxRank + 1]uint32
}

PassRange records the vertex range for one DrawOrder pass in the shared buffer, and how much of that range each level of detail needs.

Geometry within a pass is emitted in ascending rank order, so everything up to a given rank is a prefix of the range. Drawing a level of detail is then a smaller Count rather than a per-frame cull: ByRank[r] is how many vertices to draw when the maximum rank is r.

func (PassRange) CountFor

func (p PassRange) CountFor(maxRank int) uint32

CountFor is how many vertices to draw at the given maximum rank.

type StrokeGeometry

type StrokeGeometry struct {
	Coords []int32
	Closed bool
	Rank   int
	Color  [4]float32
}

StrokeGeometry is one polyline ready for GPU upload.

Jump to

Keyboard shortcuts

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