vdraw

package
v1.0.34 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: BSD-3-Clause Imports: 11 Imported by: 3

README

vDraw: vGPU version of Go image/draw compositing functionality

GoDocs for ReComp

This package uses Alpha Compositing to render rectangular regions onto a render target, using vGPU, consistent with the image/draw package in Go. Although "draw" is not a great name for this functionality, it is hard to come up with a better one that isn't crazy long, so we're adopting it -- at least it is familiar.

The GoGi GUI, and probably other 2D-based GUI frameworks, uses a strategy of rendering to various rectangular sub-regions (in GoGi these are gi.Viewport objects) that are updated separately, and then the final result can be composited together into a single overall image that can be pasted onto the final window surface that the user sees. Furthermore, in Gi3D, the 3D Scene is rendered to a framebuffer, which is likewise composited into the final surface window.

This package supports these rectangular image region composition operations, via a simple render pipeline that just renders a rectangular shape with a texture. There is also a simple fill pipeline that renders a single color into a rectangle.

The max number of images that can be pre-loaded and used per set, per render pass is only 16 -- see MaxImages. Therefore, we use 4 sets of 16. The last set is configured for 3D images with 128 layers to be used as sprites.

The fill color is uploaded as a push constant and thus is not subject to any limitations.

Implementation: Var map

Set: -2
    Role: Vertex
        Var: 0:	Pos	Float32Vec2[4]	(size: 8)	Vals: 1
    Role: Index
        Var: 1:	Index	Uint16[6]	(size: 2)	Vals: 1
Set: -1
    Role: Push
        Var: 0:	Mtxs	Struct	(size: 128)	Vals: 0
Set: 0
    Role: TextureRole
        Var: 0:	Tex	ImageRGBA32	(size: 4)	Vals: 1

Documentation

Index

Constants

View Source
const (
	Over = draw.Over
	Src  = draw.Src
)

These draw.Op constants are provided so that users of this package don't have to explicitly import "image/draw".

Variables

This section is empty.

Functions

This section is empty.

Types

type Drawer

type Drawer struct {

	// drawing system
	Sys vgpu.System `desc:"drawing system"`

	// surface if render target
	Surf *vgpu.Surface `desc:"surface if render target"`

	// render frame if render target
	Frame *vgpu.RenderFrame `desc:"render frame if render target"`

	// render so the Y axis points down, with 0,0 at the upper left, which is the Vulkan standard.  default is Y is up, with 0,0 at bottom left, which is OpenGL default.  this must be set prior to configuring, the surface, as it determines the rendering parameters.
	YIsDown bool `` /* 265-byte string literal not displayed */

	// implementation state -- ignore
	Impl DrawerImpl `desc:"implementation state -- ignore"`

	// [view: -] mutex on updating
	UpdtMu sync.Mutex `view:"-" copy:"-" json:"-" xml:"-" desc:"mutex on updating"`
}

Drawer is the vDraw implementation, which draws Textures or Fills solid colors to a render target (Surface, RenderFrame). Image and color palette must be set prior to a given render pass. Multiple fill operations can be performed in one pass, but only one Image can be used at a time.

func (*Drawer) ConfigFrame

func (dw *Drawer) ConfigFrame(dev *vgpu.Device, size image.Point, maxTextures int)

ConfigFrame configures the Drawer to use a RenderFrame as a render target, of given size. Use dw.Frame.SetSize to resize later. Frame is owned and managed by the Drawer. Uses given Device -- if nil, one is made. If maxTextures > vgpu.MaxTexturesPerSet (16) then multiple descriptor sets are used to hold more textures.

func (*Drawer) ConfigImage

func (dw *Drawer) ConfigImage(idx int, fmt *vgpu.ImageFormat)

ConfigImage configures the draw image at given index to fit the given image format and number of layers as a drawing source.

func (*Drawer) ConfigImageName

func (dw *Drawer) ConfigImageName(name string, fmt *vgpu.ImageFormat)

ConfigImageName configures the draw image at given name to fit the given image format as a drawing source.

func (*Drawer) ConfigMtxs

func (dw *Drawer) ConfigMtxs(src2dst mat32.Mat3, txsz image.Point, sr image.Rectangle, op draw.Op, flipY bool) *Mtxs

ConfigMtxs configures the draw matrix for given draw parameters: src2dst is the transform mapping source to destination coordinates (translation, scaling), txsz is the size of the texture to draw, sr is the source region (set to tex.Format.Bounds() for all) op is the drawing operation: Src = copy source directly (blit), Over = alpha blend with existing flipY inverts the Y axis of the source image.

func (*Drawer) ConfigPipeline

func (dw *Drawer) ConfigPipeline(pl *vgpu.Pipeline)

ConfigPipeline configures graphics settings on the pipeline

func (*Drawer) ConfigSurface

func (dw *Drawer) ConfigSurface(sf *vgpu.Surface, maxTextures int)

ConfigSurface configures the Drawer to use given surface as a render target. maxTextures is maximum number of images that can be used per pass. If maxTextures > vgpu.MaxTexturesPerSet (16) then multiple descriptor sets are used to hold more textures.

func (*Drawer) ConfigSys

func (dw *Drawer) ConfigSys()

ConfigSys configures the vDraw System and pipelines.

func (*Drawer) Copy

func (dw *Drawer) Copy(idx, layer int, dp image.Point, sr image.Rectangle, op draw.Op, flipY bool) error

Copy copies texture at given index and layer to render target. dp is the destination point, sr is the source region (set to image.ZR zero rect for all), op is the drawing operation: Src = copy source directly (blit), Over = alpha blend with existing flipY = flipY axis when drawing this image

func (*Drawer) DestSize

func (dw *Drawer) DestSize() image.Point

DestSize returns the size of the render destination

func (*Drawer) Destroy

func (dw *Drawer) Destroy()

func (*Drawer) Draw

func (dw *Drawer) Draw(idx, layer int, src2dst mat32.Mat3, sr image.Rectangle, op draw.Op, flipY bool) error

Draw draws texture at index and layer to render target. Must have called StartDraw first. src2dst is the transform mapping source to destination coordinates (translation, scaling), sr is the source region (set to image.ZR for all) op is the drawing operation: Src = copy source directly (blit), Over = alpha blend with existing

func (*Drawer) EndDraw

func (dw *Drawer) EndDraw()

EndDraw ends image drawing rendering process on render target

func (*Drawer) EndFill

func (dw *Drawer) EndFill()

EndFill ends color filling rendering process on render target

func (*Drawer) Fill

func (dw *Drawer) Fill(clr color.Color, src2dst mat32.Mat3, reg image.Rectangle, op draw.Op) error

Fill fills given color to to render target. src2dst is the transform mapping source to destination coordinates (translation, scaling), reg is the region to fill op is the drawing operation: Src = copy source directly (blit), Over = alpha blend with existing

func (*Drawer) FillRect

func (dw *Drawer) FillRect(clr color.Color, reg image.Rectangle, op draw.Op) error

FillRect fills given color to render target, to given region. op is the drawing operation: Src = copy source directly (blit), Over = alpha blend with existing

func (*Drawer) GetImageVal added in v1.0.4

func (dw *Drawer) GetImageVal(idx int) *vgpu.Val

GetImageVal returns vgpu Val value of Image for given index

func (*Drawer) ImageIdxByName

func (dw *Drawer) ImageIdxByName(name string) int

ImageIdxByName returns index of image val by name. Logs error if not found, and returns 0.

func (*Drawer) Scale

func (dw *Drawer) Scale(idx, layer int, dr image.Rectangle, sr image.Rectangle, op draw.Op, flipY bool) error

Scale copies texture at given index and layer to render target, scaling the region defined by src and sr to the destination such that sr in src-space is mapped to dr in dst-space. dr is the destination rectangle sr is the source region (set to image.ZR zero rect for all), op is the drawing operation: Src = copy source directly (blit), Over = alpha blend with existing flipY = flipY axis when drawing this image

func (*Drawer) SelectPipeline added in v1.0.0

func (dw *Drawer) SelectPipeline(op draw.Op) *vgpu.Pipeline

SelectPipeline selects the pipeline based on draw op only changes if not last one used. Default is Src

func (*Drawer) SetFrameImage

func (dw *Drawer) SetFrameImage(idx int, fb *vgpu.Framebuffer)

SetFrameImage sets given Framebuffer image as a drawing source at index, used in subsequent Draw methods. Must have already been configured to fit!

func (*Drawer) SetFrameImageName

func (dw *Drawer) SetFrameImageName(name string, fb *vgpu.Framebuffer)

SetFrameImageName sets given Framebuffer image as a drawing source at name, used in subsequent Draw methods. Must have already been configured to fit!

func (*Drawer) SetGoImage

func (dw *Drawer) SetGoImage(idx, layer int, img image.Image, flipY bool)

SetGoImage sets given Go image as a drawing source to given image index, and layer, used in subsequent Draw methods. A standard Go image is rendered upright on a standard Vulkan surface. Set flipY to true to flip.

func (*Drawer) SetGoImageName

func (dw *Drawer) SetGoImageName(name string, layer int, img image.Image, flipY bool)

SetGoImageName sets given Go image as a drawing source to given image name, and layer, used in subsequent Draw methods. (use SetImageName to set names) A standard Go image is rendered upright on a standard Vulkan surface. Set flipY to true to flip. This can be used directly without pre-configuring.

func (*Drawer) SetImageName

func (dw *Drawer) SetImageName(idx int, name string) error

SetImageName sets name of image at given index, to enable name-based access for subsequent calls. Returns error if name already exists.

func (*Drawer) SetMaxTextures

func (dw *Drawer) SetMaxTextures(maxTextures int)

SetMaxTextures updates the max number of textures for drawing Must call this prior to doing any allocation of images.

func (*Drawer) StartDraw

func (dw *Drawer) StartDraw(descIdx int)

StartDraw starts image drawing rendering process on render target No images can be added or set after this point. descIdx is the descriptor set to use -- choose this based on the bank of 16 texture values if number of textures > MaxTexturesPerSet.

func (*Drawer) StartFill

func (dw *Drawer) StartFill()

StartFill starts color fill drawing rendering process on render target

func (*Drawer) SyncImages

func (dw *Drawer) SyncImages()

SyncImages must be called after images have been updated, to sync memory up to the GPU.

func (*Drawer) UseTextureSet

func (dw *Drawer) UseTextureSet(descIdx int)

UseTextureSet selects the descriptor set to use -- choose this based on the bank of 16 texture values if number of textures > MaxTexturesPerSet.

type DrawerImpl

type DrawerImpl struct {

	// surface index for current render process
	SurfIdx uint32 `desc:"surface index for current render process"`

	// maximum number of images per pass -- set by user at config
	MaxTextures int `desc:"maximum number of images per pass -- set by user at config"`

	// whether to render image with flipped Y
	FlipY bool `desc:"whether to render image with flipped Y"`

	// last draw operation used -- used for switching pipeline
	LastOp draw.Op `desc:"last draw operation used -- used for switching pipeline"`
}

DrawerImpl contains implementation state -- ignore..

type Mtxs

type Mtxs struct {
	MVP mat32.Mat4
	UVP mat32.Mat4
}

Mtxs are the projection matricies

Jump to

Keyboard shortcuts

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