renderer

package
v0.11.6 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RendererLoadProjectionMatrix  = iota // 16 float32: matrix
	RendererLoadModelViewMatrix          // 16 float32: matrix
	RendererClearRGBA                    // 4 float32: RGBA
	RendererScissor                      // 4 int32: x, y, width, height
	RendererViewport                     // 4 int32: x, y, width, height
	RendererBlend                        // no args: for now always src alpha, 1-src alpha
	RendererSetRGBA                      // 4 float32: RGBA
	RendererDisableBlend                 // no args
	RendererFloatBuffer                  // int32 size, then size*float32 values
	RendererIntBuffer                    // int32: size, then size*int32 values
	RendererRawBuffer                    // int32: size *in bytes*, then (3+size)/4 int32 values
	RendererEnableTexture                // int32 handle
	RendererDisableTexture               // no args
	RendererVertexArray                  // byte offset to array values, n components, stride (bytes)
	RendererDisableVertexArray           // no args
	RendererRGB8Array                    // byte offset to array values, n components, stride (bytes)
	RendererRGB32Array                   // byte offset to array values, n components, stride (bytes)
	RendererDisableColorArray            // no args
	RendererTexCoordArray                // byte offset to array values, n components, stride (bytes)
	RendererDisableTexCoordArray         // no args
	RendererLineWidth                    // float32
	RendererDrawLines                    // 2 int32: offset to the index buffer, count
	RendererDrawTriangles                // 2 int32: offset to the index buffer, count
	RendererDrawQuads                    // 2 int32: offset to the index buffer, count
	RendererCallBuffer                   // 1 int32: buffer index
	RendererResetState                   // no args
	RendererEnablePolygonStipple         // no args
	RendererDisablePolygonStipple        // no args
	RendererPolygonStipple               // 32 uint32: stipple pattern
)

Variables

View Source
var (
	FontAwesomeIconArrowDown           = faUsedIcons["ArrowDown"]
	FontAwesomeIconArrowLeft           = faUsedIcons["ArrowLeft"]
	FontAwesomeIconArrowRight          = faUsedIcons["ArrowRight"]
	FontAwesomeIconArrowUp             = faUsedIcons["ArrowUp"]
	FontAwesomeIconBook                = faUsedIcons["Book"]
	FontAwesomeIconBug                 = faUsedIcons["Bug"]
	FontAwesomeIconCaretDown           = faUsedIcons["CaretDown"]
	FontAwesomeIconCaretRight          = faUsedIcons["CaretRight"]
	FontAwesomeIconCheckSquare         = faUsedIcons["CheckSquare"]
	FontAwesomeIconCog                 = faUsedIcons["Cog"]
	FontAwesomeIconCompressAlt         = faUsedIcons["CompressAlt"]
	FontAwesomeIconCopyright           = faUsedIcons["Copyright"]
	FontAwesomeIconDiscord             = faBrandsUsedIcons["Discord"]
	FontAwesomeIconExclamationTriangle = faUsedIcons["ExclamationTriangle"]
	FontAwesomeIconExpandAlt           = faUsedIcons["ExpandAlt"]
	FontAwesomeIconFile                = faUsedIcons["File"]
	FontAwesomeIconFolder              = faUsedIcons["Folder"]
	FontAwesomeIconGithub              = faBrandsUsedIcons["Github"]
	FontAwesomeIconHandPointLeft       = faUsedIcons["HandPointLeft"]
	FontAwesomeIconHome                = faUsedIcons["Home"]
	FontAwesomeIconInfoCircle          = faUsedIcons["InfoCircle"]
	FontAwesomeIconKeyboard            = faUsedIcons["Keyboard"]
	FontAwesomeIconLevelUpAlt          = faUsedIcons["LevelUpAlt"]
	FontAwesomeIconLock                = faUsedIcons["Lock"]
	FontAwesomeIconMouse               = faUsedIcons["Mouse"]
	FontAwesomeIconPauseCircle         = faUsedIcons["PauseCircle"]
	FontAwesomeIconPlayCircle          = faUsedIcons["PlayCircle"]
	FontAwesomeIconQuestionCircle      = faUsedIcons["QuestionCircle"]
	FontAwesomeIconPlaneDeparture      = faUsedIcons["PlaneDeparture"]
	FontAwesomeIconRedo                = faUsedIcons["Redo"]
	FontAwesomeIconSquare              = faUsedIcons["Square"]
	FontAwesomeIconTrash               = faUsedIcons["Trash"]
)

imgui lets us to embed icons within regular fonts which makes it possible to use them directly in text without changing to the icon font. However, we have a fair number of fonts and sizes. Thereore, so save space, we require that the used icons be tracked in fonts.go so that only they need to be copied into all of the regular fonts. Given that, code elsewhere uses the following variables to get the string encoding that gives the corresponding icon.

Functions

func AvailableFontSizes

func AvailableFontSizes(name string) []int

func FontAwesomeBrandsString

func FontAwesomeBrandsString(id string) string

func FontAwesomeString

func FontAwesomeString(id string) string

func FontsInit

func FontsInit(r Renderer, p platform.Platform)

func GenerateImguiCommandBuffer

func GenerateImguiCommandBuffer(cb *CommandBuffer, displaySize, framebufferSize [2]float32, lg *log.Logger)

GenerateImguiCommandBuffer retrieves the imgui draw list for the current frame and emits corresponding commands to the provided CommandBuffer.

func ReturnColoredLinesDrawBuilder

func ReturnColoredLinesDrawBuilder(ld *ColoredLinesDrawBuilder)

func ReturnColoredTrianglesDrawBuilder

func ReturnColoredTrianglesDrawBuilder(td *ColoredTrianglesDrawBuilder)

func ReturnCommandBuffer

func ReturnCommandBuffer(cb *CommandBuffer)

func ReturnLinesDrawBuilder

func ReturnLinesDrawBuilder(ld *LinesDrawBuilder)

func ReturnTextDrawBuilder

func ReturnTextDrawBuilder(td *TextDrawBuilder)

func ReturnTexturedTrianglesDrawBuilder

func ReturnTexturedTrianglesDrawBuilder(td *TexturedTrianglesDrawBuilder)

func ReturnTrianglesDrawBuilder

func ReturnTrianglesDrawBuilder(td *TrianglesDrawBuilder)

Types

type ColoredLinesDrawBuilder

type ColoredLinesDrawBuilder struct {
	LinesDrawBuilder
	// contains filtered or unexported fields
}

ColoredLinesDrawBuilder is similar to the LinesDrawBuilder though it allows specifying the color of each line individually. Its methods otherwise mostly parallel those of LinesDrawBuilder; see the documentation there.

func GetColoredLinesDrawBuilder

func GetColoredLinesDrawBuilder() *ColoredLinesDrawBuilder

func (*ColoredLinesDrawBuilder) AddCircle

func (l *ColoredLinesDrawBuilder) AddCircle(p [2]float32, radius float32, nsegs int, color RGB)

AddCircle adds lines that draw the outline of a circle with specified radius and color centered at the specified point p. The nsegs parameter specifies the tessellation rate for the circle.

func (*ColoredLinesDrawBuilder) AddLine

func (l *ColoredLinesDrawBuilder) AddLine(p0, p1 [2]float32, color RGB)

func (*ColoredLinesDrawBuilder) AddLineLoop

func (l *ColoredLinesDrawBuilder) AddLineLoop(color RGB, p [][2]float32)

func (*ColoredLinesDrawBuilder) GenerateCommands

func (l *ColoredLinesDrawBuilder) GenerateCommands(cb *CommandBuffer) (int, int)

func (*ColoredLinesDrawBuilder) Reset

func (l *ColoredLinesDrawBuilder) Reset()

type ColoredTrianglesDrawBuilder

type ColoredTrianglesDrawBuilder struct {
	TrianglesDrawBuilder
	// contains filtered or unexported fields
}

ColoredTrianglesDrawBuilder

func GetColoredTrianglesDrawBuilder

func GetColoredTrianglesDrawBuilder() *ColoredTrianglesDrawBuilder

func (*ColoredTrianglesDrawBuilder) AddCircle

func (t *ColoredTrianglesDrawBuilder) AddCircle(p [2]float32, radius float32, nsegs int, rgb RGB)

AddCircle adds a filled circle with specified radius around the specified position to be drawn using triangles. The specified number of segments, nsegs, sets the tessellation rate for the circle.

func (*ColoredTrianglesDrawBuilder) AddQuad

func (t *ColoredTrianglesDrawBuilder) AddQuad(p0, p1, p2, p3 [2]float32, rgb RGB)

AddQuad adds a quadrilateral with the specified four vertices to be drawn; the quad is split into two triangles for drawing.

func (*ColoredTrianglesDrawBuilder) AddTriangle

func (t *ColoredTrianglesDrawBuilder) AddTriangle(p0, p1, p2 [2]float32, rgb RGB)

AddTriangle adds a triangle with the specified three vertices to be drawn.

func (*ColoredTrianglesDrawBuilder) GenerateCommands

func (t *ColoredTrianglesDrawBuilder) GenerateCommands(cb *CommandBuffer)

func (*ColoredTrianglesDrawBuilder) Reset

func (t *ColoredTrianglesDrawBuilder) Reset()

type CommandBuffer

type CommandBuffer struct {
	Buf []uint32
	// contains filtered or unexported fields
}

CommandBuffer encodes a sequence of rendering commands in an API-agnostic manner. It makes it possible for other parts of vice to "pre-bake" rendering work into a form that can be efficiently processed by a Renderer and possibly reused over multiple frames.

func GetCommandBuffer

func GetCommandBuffer() *CommandBuffer

func (*CommandBuffer) Blend

func (cb *CommandBuffer) Blend()

Blend adds a command to the command buffer enable blending. The blend mode cannot be specified currently, since only one mode (alpha over blending) is used.

func (*CommandBuffer) Call

func (cb *CommandBuffer) Call(sub CommandBuffer)

Call adds a command to the command buffer that causes the commands in the provided command buffer to be processed and executed. After the end of the command buffer is reached, processing of command in the current command buffer continues.

func (*CommandBuffer) ClearRGB

func (cb *CommandBuffer) ClearRGB(color RGB)

ClearRGB adds a command to the command buffer to clear the framebuffer to the specified RGB color.

func (*CommandBuffer) DisableBlend

func (cb *CommandBuffer) DisableBlend()

DisableBlend adds a command to the command buffer that disables blending.

func (*CommandBuffer) DisableColorArray

func (cb *CommandBuffer) DisableColorArray()

DisableColorArray adds a command to the command buffer that disables the current array of RGB per-vertex colors.

func (*CommandBuffer) DisablePolygonStipple added in v0.11.2

func (cb *CommandBuffer) DisablePolygonStipple()

DisablePolygonStipple adds a command to the command buffer that disables stipple when drawing polygons.

func (*CommandBuffer) DisableTexCoordArray

func (cb *CommandBuffer) DisableTexCoordArray()

DisableTexCoordArray adds a command to the command buffer that disables the currently-active array of texture coordinates.

func (*CommandBuffer) DisableTexture

func (cb *CommandBuffer) DisableTexture()

DisableTexture adds a command to the command buffer to disable texturing.

func (*CommandBuffer) DisableVertexArray

func (cb *CommandBuffer) DisableVertexArray()

DisableVertexArray adds a command to the command buffer to disable the current vertex array.

func (*CommandBuffer) DrawLines

func (cb *CommandBuffer) DrawLines(offset, count int)

DrawLines adds a command to the command buffer to draw a number of lines; each line is specified by two indices in the index buffer. offset gives the offset in the current command buffer where the index buffer is (e.g., as returned by IntBuffer), and count gives the total number of vertices in the vertex buffer.

func (*CommandBuffer) DrawQuads

func (cb *CommandBuffer) DrawQuads(offset, count int)

DrawTriangles adds a command to the command buffer to draw a number of quads; each is specified by four vertices in the index buffer. offset gives the offset to the start of the index buffer in the current command buffer and count gives the total number of indices.

func (*CommandBuffer) DrawTriangles

func (cb *CommandBuffer) DrawTriangles(offset, count int)

DrawTriangles adds a command to the command buffer to draw a number of triangles; each is specified by three vertices in the index buffer. offset gives the offset to the start of the index buffer in the current command buffer and count gives the total number of indices.

func (*CommandBuffer) EnablePolygonStipple added in v0.11.2

func (cb *CommandBuffer) EnablePolygonStipple()

EnablePolygonStipple adds a command to the command buffer that enables stipple when drawing polygons.

func (*CommandBuffer) EnableTexture

func (cb *CommandBuffer) EnableTexture(id uint32)

EnableTexture enables texturing from the specified texture id (as returned by the Renderer CreateTextureFromImage method implementation).

func (*CommandBuffer) Float2Buffer

func (cb *CommandBuffer) Float2Buffer(buf [][2]float32) int

Float2Buffer stores the provided slice of [2]float32 values in the CommandBuffer and returns the byte offset where the first value of the slice is stored; this offset can then be passed to commands like VertexArray to specify this array.

func (*CommandBuffer) IntBuffer

func (cb *CommandBuffer) IntBuffer(buf []int32) int

IntBuffer stores the provided slice of int32 values in the command buffer and returns the byte offset where the first value of the slice is stored.

func (*CommandBuffer) LineWidth

func (cb *CommandBuffer) LineWidth(w float32, scale float32)

LineWidth adds a command to the command buffer that sets the width in pixels of subsequent lines that are drawn.

func (*CommandBuffer) LoadModelViewMatrix

func (cb *CommandBuffer) LoadModelViewMatrix(m math.Matrix3)

func (*CommandBuffer) LoadProjectionMatrix

func (cb *CommandBuffer) LoadProjectionMatrix(m math.Matrix3)

func (*CommandBuffer) PolygonStipple added in v0.11.2

func (cb *CommandBuffer) PolygonStipple(pattern [32]uint32)

PolygonStipple adds a command to the command buffer that specifies the polygon stipple pattern.

func (*CommandBuffer) RGB32Array

func (cb *CommandBuffer) RGB32Array(offset, nComps, stride int)

ColorArray adds a command to the command buffer that specifies an array of float32 RGB colors to use for a subsequent draw command. Its arguments are analogous to the ones passed to VertexArray.

func (*CommandBuffer) RGB8Array

func (cb *CommandBuffer) RGB8Array(offset, nComps, stride int)

ColorArray adds a command to the command buffer that specifies an array of 8-bit RGBA colors to use for a subsequent draw command. Its arguments are analogous to the ones passed to VertexArray.

func (*CommandBuffer) RGBBuffer

func (cb *CommandBuffer) RGBBuffer(buf []RGB) int

RGBBuffer stores the provided slice of RGB values in the command buffer and returns the byte offset where the first value of the slice is stored.

func (*CommandBuffer) RawBuffer

func (cb *CommandBuffer) RawBuffer(buf []byte) int

RawBuffer stores the provided bytes, without further interpretation in the command buffer and returns the byte offset from the start of the buffer where they begin.

func (*CommandBuffer) Reset

func (cb *CommandBuffer) Reset()

Reset resets the command buffer's length to zero so that it can be reused.

func (*CommandBuffer) ResetState

func (cb *CommandBuffer) ResetState()

ResetState adds a command to the comment buffer that resets all of the assorted graphics state (scissor rectangle, blending, texturing, vertex arrays, etc.) to default values.

func (*CommandBuffer) Scissor

func (cb *CommandBuffer) Scissor(x, y, w, h int)

Scissor adds a command to the command buffer to set the scissor rectangle as specified.

func (*CommandBuffer) SetDrawBounds

func (cb *CommandBuffer) SetDrawBounds(b math.Extent2D, scale float32)

SetDrawBounds sets the scissor rectangle and viewport according to the specified bounds so that subsequent code can assume window (or Pane) coordinates from (0,0)-(width,height) when drawing things.

One messy detail here is that these windows are specified in framebuffer coordinates, not display coordinates, so they must be scaled for e.g., retina displays; the scale takes care of this. It should be initialized as the ratio of framebuffer resolution to display resolution.

func (*CommandBuffer) SetRGB

func (cb *CommandBuffer) SetRGB(rgb RGB)

SetRGB adds a command to the command buffer to set the current RGB color (alpha is set to 1). Subsequent draw commands will inherit this color unless they specify e.g., per-vertex colors themselves.

func (*CommandBuffer) SetRGBA

func (cb *CommandBuffer) SetRGBA(rgba RGBA)

SetRGBA adds a command to the command buffer to set the current RGBA color. Subsequent draw commands will inherit this color unless they specify e.g., per-vertex colors themselves.

func (*CommandBuffer) SetScissorBounds

func (cb *CommandBuffer) SetScissorBounds(b math.Extent2D, scale float32)

SetScissorBounds sets the scissor rectangle according to the specified bounds so that subsequent code can assume window (or Pane) coordinates from (0,0)-(width,height) when drawing things.

One messy detail here is that these windows are specified in framebuffer coordinates, not display coordinates, so they must be scaled for e.g., retina displays; the scale takes care of this. It should be initialized as the ratio of framebuffer resolution to display resolution.

func (*CommandBuffer) TexCoordArray

func (cb *CommandBuffer) TexCoordArray(offset, nComps, stride int)

TexCoordArray adds a command to the command buffer that specifies an array of per-vertex texture coordinates. Its arguments are analogous to the ones passed to VertexArray.

func (*CommandBuffer) VertexArray

func (cb *CommandBuffer) VertexArray(offset, nComps, stride int)

VertexArray adds a command to the command buffer that specifies an array of vertex coordinates to use for a subsequent draw command. offset gives the offset into the current command buffer where the vertices again (e.g., as returned by Float2Buffer), nComps is the number of components per vertex (generally 2 for vice), and stride gives the stride in bytes between vertices (e.g., 8 for densely packed 2D vertex coordinates.)

func (*CommandBuffer) Viewport

func (cb *CommandBuffer) Viewport(x, y, w, h int)

Viewport adds a command to the command buffer to set the viewport to the specified rectangle.

type Font

type Font struct {

	// Font size
	Size  int
	Mono  bool
	Ifont imgui.Font
	Id    FontIdentifier
	TexId uint32 // texture that holds the glyph texture atlas
	// contains filtered or unexported fields
}

Each loaded (font,size) combination is represented by (surprise) a Font.

func DrawFontPicker

func DrawFontPicker(id *FontIdentifier, label string) (newFont *Font, changed bool)

func DrawFontSizeSelector

func DrawFontSizeSelector(id *FontIdentifier) (newFont *Font, changed bool)

func GetDefaultFont

func GetDefaultFont() *Font

func GetFont

func GetFont(id FontIdentifier) *Font

func MakeFont

func MakeFont(size int, mono bool, id FontIdentifier, ifont *imgui.Font) *Font

func (*Font) AddGlyph

func (f *Font) AddGlyph(ch int, g *Glyph)

func (*Font) BoundText

func (font *Font) BoundText(s string, spacing int) (int, int)

Returns the bound of the specified text in the given font, assuming the given pixel spacing between lines.

func (*Font) LookupGlyph

func (f *Font) LookupGlyph(ch rune) *Glyph

LookupGlyph returns the Glyph for the specified rune.

type FontIdentifier

type FontIdentifier struct {
	Name string
	Size int
}

FontIdentifier is used for looking up

type Glyph

type Glyph struct {
	// Vertex positions for the quad to draw
	X0, Y0, X1, Y1 float32
	// Texture coordinates in the font atlas
	U0, V0, U1, V1 float32
	// Distance to advance in x after the character.
	AdvanceX float32
	// Is it a visible character (i.e., not space, tab, CR, ...)
	Visible bool
}

While the following could be found via the imgui.FontGlyph interface, cgo calls into C++ code are slow, especially if we do ~10 of them for each character drawn. So we cache the information we need to draw each one here.

func (*Glyph) Height

func (g *Glyph) Height() float32

func (*Glyph) Width

func (g *Glyph) Width() float32

type LinesDrawBuilder

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

LinesDrawBuilder accumulates lines to be drawn together. Note that it does not allow specifying the colors of the lines; instead, whatever the current color is (as set via the CommandBuffer SetRGB method) is used when drawing them. If per-line colors are required, the ColoredLinesDrawBuilder should be used instead.

func GetLinesDrawBuilder

func GetLinesDrawBuilder() *LinesDrawBuilder

func (*LinesDrawBuilder) AddCircle

func (l *LinesDrawBuilder) AddCircle(p [2]float32, radius float32, nsegs int)

AddCircle adds lines that draw the outline of a circle with specified and color centered at the specified point p. The nsegs parameter specifies the tessellation rate for the circle.

func (*LinesDrawBuilder) AddLatLongCircle

func (l *LinesDrawBuilder) AddLatLongCircle(p math.Point2LL, nmPerLongitude float32, r float32, nsegs int)

func (*LinesDrawBuilder) AddLine

func (l *LinesDrawBuilder) AddLine(p0, p1 [2]float32)

AddLine adds a lines with the specified vertex positions to the set of lines to be drawn.

func (*LinesDrawBuilder) AddLineLoop

func (l *LinesDrawBuilder) AddLineLoop(p [][2]float32)

Adds a line loop, like a line strip but where the last vertex connects to the first, a la GL_LINE_LOOP.

func (*LinesDrawBuilder) AddLineStrip

func (l *LinesDrawBuilder) AddLineStrip(p [][2]float32)

AddLineStrip adds multiple lines to the lines draw builder where each line is given by a successive pair of points, a la GL_LINE_STRIP.

func (*LinesDrawBuilder) AddNumber

func (l *LinesDrawBuilder) AddNumber(p [2]float32, sz float32, v string)

Draws a number using digits drawn with lines. This can be helpful in cases like drawing an altitude on a video map where we want the number size to change when the user zooms the scope.

func (*LinesDrawBuilder) Bounds

func (l *LinesDrawBuilder) Bounds() math.Extent2D

Bounds returns the 2D bounding box of the specified lines.

func (*LinesDrawBuilder) GenerateCommands

func (l *LinesDrawBuilder) GenerateCommands(cb *CommandBuffer)

GenerateCommands adds commands to the specified command buffer to draw the lines stored in the LinesDrawBuilder.

func (*LinesDrawBuilder) Reset

func (l *LinesDrawBuilder) Reset()

Reset resets the internal arrays used for accumulating lines, maintaining the initial allocations.

type OpenGL2Renderer

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

func (*OpenGL2Renderer) CreateTextureFromImage

func (ogl2 *OpenGL2Renderer) CreateTextureFromImage(img image.Image, magNearest bool) uint32

func (*OpenGL2Renderer) CreateTextureFromImages

func (ogl2 *OpenGL2Renderer) CreateTextureFromImages(pyramid []image.Image, magNearest bool) uint32

func (*OpenGL2Renderer) DestroyTexture

func (ogl2 *OpenGL2Renderer) DestroyTexture(texid uint32)

func (*OpenGL2Renderer) Dispose

func (ogl2 *OpenGL2Renderer) Dispose()

func (*OpenGL2Renderer) ReadPixelRGBAs added in v0.11.2

func (ogl2 *OpenGL2Renderer) ReadPixelRGBAs(x, y, width, height int) []uint8

func (*OpenGL2Renderer) RenderCommandBuffer

func (ogl2 *OpenGL2Renderer) RenderCommandBuffer(cb *CommandBuffer) RendererStats

func (*OpenGL2Renderer) UpdateTextureFromImage

func (ogl2 *OpenGL2Renderer) UpdateTextureFromImage(texid uint32, img image.Image, magNearest bool)

func (*OpenGL2Renderer) UpdateTextureFromImages

func (ogl2 *OpenGL2Renderer) UpdateTextureFromImages(texid uint32, pyramid []image.Image, magNearest bool)

type RGB

type RGB struct {
	R, G, B float32
}

func LerpRGB

func LerpRGB(x float32, a, b RGB) RGB

func RGBFromHex

func RGBFromHex(c int) RGB

RGBFromHex converts a packed integer color value to an RGB where the low 8 bits give blue, the next 8 give green, and then the next 8 give red.

func RGBFromUInt8 added in v0.11.2

func RGBFromUInt8(r uint8, g uint8, b uint8) RGB

func (RGB) Equals

func (r RGB) Equals(other RGB) bool

func (RGB) Scale

func (r RGB) Scale(v float32) RGB

type RGBA

type RGBA struct {
	R, G, B, A float32
}

type Renderer

type Renderer interface {
	// CreateTextureFromImage returns an identifier for a texture map defined
	// by the specified image.
	CreateTextureFromImage(image image.Image, magNearest bool) uint32

	// CreateTextureFromImage returns an identifier for a texture map defined
	// by the specified image pyramid.
	CreateTextureFromImages(image []image.Image, magNearest bool) uint32

	// UpdateTextureFromImage updates the contents of an existing texture
	// with the provided image.
	UpdateTextureFromImage(id uint32, image image.Image, magNearest bool)

	// UpdateTextureFromImage updates the contents of an existing texture
	// with the provided image pyramid.
	UpdateTextureFromImages(id uint32, image []image.Image, magNearest bool)

	// DestroyTexture frees the resources associated with the given texture id.
	DestroyTexture(id uint32)

	// RenderCommandBuffer executes all of the commands encoded in the
	// provided command buffer, returning statistics about what was
	// rendered.
	RenderCommandBuffer(*CommandBuffer) RendererStats

	// ReadPixelRGBAs returns the RGBA colors of a rectangular region the
	// framebuffer starting at the given (x,y) coordinate with the given
	// width and height.
	ReadPixelRGBAs(x, y, width, height int) []uint8

	// Dispose releases resources allocated by the renderer.
	Dispose()
}

Renderer defines an interface for all of the various drawing that happens in vice. There is currently a single implementation of it--OpenGL2Renderer--though having all of these details behind the Renderer interface would make it realtively easy to write a Vulkan, Metal, or DirectX rendering backend.

func NewOpenGL2Renderer

func NewOpenGL2Renderer(l *log.Logger) (Renderer, error)

NewOpenGL2Renderer creates an OpenGL context and creates a texture for the imgui fonts. Thus, all font creation must be finished before the renderer is created.

type RendererStats

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

RendererStats encapsulates assorted statistics from rendering.

func (RendererStats) LogValue

func (rs RendererStats) LogValue() slog.Value

func (*RendererStats) Merge

func (rs *RendererStats) Merge(s RendererStats)

func (*RendererStats) String

func (rs *RendererStats) String() string

type TextBuffers

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

TextBuffers is a helper class that maintains vertex and index buffers for drawing text.

func (*TextBuffers) Add

func (t *TextBuffers) Add(p [2]float32, glyph *Glyph, color RGB)

Add updates the buffers to draw the given glyph with the given color, with upper-left coordinates specified by p.

func (*TextBuffers) GenerateCommands

func (t *TextBuffers) GenerateCommands(cb *CommandBuffer)

func (*TextBuffers) Reset

func (t *TextBuffers) Reset()

type TextDrawBuilder

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

TextDrawBuilder accumulates text to be drawn, batching it up in a single draw command.

func GetTextDrawBuilder

func GetTextDrawBuilder() *TextDrawBuilder

func (*TextDrawBuilder) AddText

func (td *TextDrawBuilder) AddText(s string, p [2]float32, style TextStyle) [2]float32

AddText draws the specified text using the given position p as the upper-left corner.

func (*TextDrawBuilder) AddTextCentered

func (td *TextDrawBuilder) AddTextCentered(text string, p [2]float32, style TextStyle)

AddTextCentered draws the specified text centered at the specified position p.

func (*TextDrawBuilder) AddTextMulti

func (td *TextDrawBuilder) AddTextMulti(text []string, p [2]float32, styles []TextStyle) [2]float32

AddTextMulti draws multiple blocks of text with multiple styles, with the first block of text starting at the specified point p. Subsequent blocks begin immediately after the end of the previous block.

func (*TextDrawBuilder) GenerateCommands

func (td *TextDrawBuilder) GenerateCommands(cb *CommandBuffer)

func (*TextDrawBuilder) Reset

func (td *TextDrawBuilder) Reset()

type TextStyle

type TextStyle struct {
	Font  *Font
	Color RGB
	// LineSpacing gives the additional spacing in pixels between lines of
	// text relative to the font's default line spacing.
	LineSpacing int
	// DrawBackground specifies if a filled quadrilateral should be drawn behind
	// the text (e.g., to offset it to make it more legible.)
	DrawBackground bool
	// BackgroundColor specifies the color of the background; it is only used if
	// DrawBackground is grue.
	BackgroundColor RGB
}

TextStyle specifies the style of text to be drawn.

type TexturedTrianglesDrawBuilder

type TexturedTrianglesDrawBuilder struct {
	TrianglesDrawBuilder
	// contains filtered or unexported fields
}

TexturedTrianglesDrawBuilder generates commands for drawing a set of triangles with associated uv texture coordinates using a specified single texture map.

func GetTexturedTrianglesDrawBuilder

func GetTexturedTrianglesDrawBuilder() *TexturedTrianglesDrawBuilder

func (*TexturedTrianglesDrawBuilder) AddQuad

func (t *TexturedTrianglesDrawBuilder) AddQuad(p0, p1, p2, p3 [2]float32, uv0, uv1, uv2, uv3 [2]float32)

AddQuad adds a quadrilateral with the specified four vertices and associated texture coordinates to the list to be drawn; the quad is split into two triangles for drawing.

func (*TexturedTrianglesDrawBuilder) AddTriangle

func (t *TexturedTrianglesDrawBuilder) AddTriangle(p0, p1, p2 [2]float32, uv0, uv1, uv2 [2]float32)

AddTriangle adds a triangle with the specified three vertices and uv coordinates to be drawn.

func (*TexturedTrianglesDrawBuilder) GenerateCommands

func (t *TexturedTrianglesDrawBuilder) GenerateCommands(cb *CommandBuffer)

func (*TexturedTrianglesDrawBuilder) Reset

func (t *TexturedTrianglesDrawBuilder) Reset()

type TrianglesDrawBuilder

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

TrianglesDrawBuilder collects triangles to be batched up in a single draw call. Note that it does not allow specifying per-vertex or per-triangle color; rather, the current color as specified by a call to the CommandBuffer SetRGB method is used for all triangles.

func GetTrianglesDrawBuilder

func GetTrianglesDrawBuilder() *TrianglesDrawBuilder

func (*TrianglesDrawBuilder) AddCircle

func (t *TrianglesDrawBuilder) AddCircle(p [2]float32, radius float32, nsegs int)

AddCircle adds a filled circle with specified radius around the specified position to be drawn using triangles. The specified number of segments, nsegs, sets the tessellation rate for the circle.

func (*TrianglesDrawBuilder) AddLatLongCircle added in v0.11.6

func (t *TrianglesDrawBuilder) AddLatLongCircle(p [2]float32, nmPerLongitude float32, r float32, nsegs int)

func (*TrianglesDrawBuilder) AddQuad

func (t *TrianglesDrawBuilder) AddQuad(p0, p1, p2, p3 [2]float32)

AddQuad adds a quadrilateral with the specified four vertices to be drawn; the quad is split into two triangles for drawing.

func (*TrianglesDrawBuilder) AddTriangle

func (t *TrianglesDrawBuilder) AddTriangle(p0, p1, p2 [2]float32)

AddTriangle adds a triangle with the specified three vertices to be drawn.

func (*TrianglesDrawBuilder) Bounds

func (t *TrianglesDrawBuilder) Bounds() math.Extent2D

func (*TrianglesDrawBuilder) GenerateCommands

func (t *TrianglesDrawBuilder) GenerateCommands(cb *CommandBuffer)

func (*TrianglesDrawBuilder) Reset

func (t *TrianglesDrawBuilder) Reset()

Jump to

Keyboard shortcuts

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