Lysa  0.0
Lysa 3D Engine
Vector3DRenderer Class Reference

Detailed Description

3D vector renderer

+ Inheritance diagram for Vector3DRenderer:

Classes

struct  Vertex
 

Public Member Functions

 Vector3DRenderer (const RendererConfiguration &config, vireo::ImageFormat outputFormat, bool useCamera=true, bool depthTestEnable=true, bool filledTriangles=false, bool enableAlphaBlending=true, const std::string &name="VectorRenderer", const std::string &shadersName="vector", const std::string &glyphShadersName="glyph")
 
bool isUseCamera () const
 
unique_id beginDraw (unique_id sessionId=INVALID_ID)
 
void endDraw ()
 
void setVisible (unique_id sessionId, bool visible)
 
void clearSession (unique_id sessionId)
 
void restart ()
 
void drawLine (const float3 &from, const float3 &to, const float4 &color)
 
void drawTriangle (const float3 &v1, const float3 &v2, const float3 &v3, const float4 &color)
 
void drawImage (unique_id imageId, const float3 &position, const quaternion &rotation, const float2 &size, const float4 &color)
 
void drawText (const std::string &text, Font &font, float fontScale, const float3 &position, const quaternion &rotation, const float4 &innerColor, TextAlignment alignment=TextAlignment::LEFT, bool rotationGlobal=false)
 
void drawSpline (const std::vector< float3 > &points, const float4 &color, uint32 segsPerSpan=16, float tension=0.0f)
 
void update (const std::shared_ptr< vireo::CommandList > &commandList, uint32 frameIndex)
 
void resize (const vireo::Extent &extent)
 
void render (const std::shared_ptr< vireo::CommandList > &commandList, const Camera &camera, const std::shared_ptr< vireo::RenderTarget > &colorAttachment, const std::shared_ptr< vireo::RenderTarget > &depthAttachment, uint32 frameIndex)
 
void setGammaCorrectionParameters (const float gamma, const float _)
 
virtual ~Vector3DRenderer ()
 
 Vector3DRenderer (Vector3DRenderer &) = delete
 
Vector3DRenderer & operator= (Vector3DRenderer &) = delete
 

Protected Member Functions

void commitPrimitive (DrawPrimType type, uint32 vertexCount)
 
int32 addImage (const Image &texture)
 
int32 addFontAtlas (const Image &texture)
 
int32 addFont (Font &font)
 

Protected Attributes

const std::string name
 
const size_t maxVertices
 
const size_t maxParams
 
const size_t maxImages
 
const size_t maxFonts
 
ImageManagerimageManager
 
const RendererConfigurationconfig
 
float aspectRatio {}
 
std::vector< Vertexvertices
 
uint32 nextVertexOffset {0}
 
std::vector< DrawParamparams
 
uint32 nextParamOffset {0}
 
uint32 lineListCount {0}
 
uint32 lineStripCount {0}
 
uint32 triPlainCount {0}
 
uint32 triImageCount {0}
 
uint32 triGlyphCount {0}
 
std::optional< DrawSessioncurrentSession
 

Constructor & Destructor Documentation

Vector3DRenderer ( const RendererConfiguration config,
vireo::ImageFormat  outputFormat,
bool  useCamera = true,
bool  depthTestEnable = true,
bool  filledTriangles = false,
bool  enableAlphaBlending = true,
const std::string &  name = "VectorRenderer",
const std::string &  shadersName = "vector",
const std::string &  glyphShadersName = "glyph" 
)

Constructs a vector renderer.

Parameters
configRendering config.
outputFormatOutput attachment color format
useCameraTrue to apply Scene view/projection.
depthTestEnableEnable depth test for 3D primitives.
enableAlphaBlendingEnable alpha blending (for UI/text).
filledTrianglesTrue to fill the triangles; false for wireframe only.
nameDebug name for pipelines.
shadersNameBase shader name for vector primitives.
glyphShadersNameBase shader name for glyph rendering.
virtual ~Vector3DRenderer ( )
virtual
Vector3DRenderer ( Vector3DRenderer &  )
delete

Member Function Documentation

int32 addFont ( Font font)
protected
int32 addFontAtlas ( const Image texture)
protected
int32 addImage ( const Image texture)
protected
unique_id beginDraw ( unique_id  sessionId = INVALID_ID)

Starts a drawing session. Is the session already exists it will be cleared first

Parameters
sessionIdSession ID
Returns
Session ID
void clearSession ( unique_id  sessionId)

Clear a drawing session and all of the corresponding elements (vertices, params)

Parameters
sessionIdSession ID
void commitPrimitive ( DrawPrimType  type,
uint32  vertexCount 
)
protected
void drawImage ( unique_id  imageId,
const float3 &  position,
const quaternion &  rotation,
const float2 &  size,
const float4 &  color 
)

Draws a textured quad

Parameters
imageIdResource ID of the image to display, or INVALID_ID for a solid-color quad.
positionBottom-left corner of the quad in world space.
rotationOrientation applied to the quad around its bottom-left corner.
sizeWidth (x) and height (y) of the quad in world units.
colorTint color multiplied with the texture sample.
void drawLine ( const float3 &  from,
const float3 &  to,
const float4 &  color 
)

Draws a colored line segment

void drawSpline ( const std::vector< float3 > &  points,
const float4 &  color,
uint32  segsPerSpan = 16,
float  tension = 0.0f 
)

Draws a cardinal spline through the given control points.

Parameters
pointsOrdered list of control points the curve passes through (at least 2).
colorColor applied to the entire spline.
segsPerSpanNumber of line segments used to approximate each span between two consecutive points.
tensionCurve tension in [0, 1]: 0 = Catmull-Rom, 1 = straight segments.
void drawText ( const std::string &  text,
Font font,
float  fontScale,
const float3 &  position,
const quaternion &  rotation,
const float4 &  innerColor,
TextAlignment  alignment = TextAlignment::LEFT,
bool  rotationGlobal = false 
)

Draws text using the provided font.

Parameters
textUTF-8 string to render.
fontFont object providing glyph atlas/metrics.
fontScaleScaling factor applied to glyph metrics.
positionAnchor point in world space (meaning depends on alignment).
rotationOrientation for the text in world space.
innerColorColor applied to glyphs (vertex alpha can modulate it).
alignmentLEFT: position = left edge; CENTER: position = center; RIGHT: position = right edge.
rotationGlobalfalse (default): rotation is local around position. true: rotation is global around world origin.
void drawTriangle ( const float3 &  v1,
const float3 &  v2,
const float3 &  v3,
const float4 &  color 
)

Draws a filled triangle .

void endDraw ( )

Close a drawing session

bool isUseCamera ( ) const
inline

Returns true if the renderer applies the scene camera's view/projection transform.

Vector3DRenderer& operator= ( Vector3DRenderer &  )
delete
void render ( const std::shared_ptr< vireo::CommandList > &  commandList,
const Camera camera,
const std::shared_ptr< vireo::RenderTarget > &  colorAttachment,
const std::shared_ptr< vireo::RenderTarget > &  depthAttachment,
uint32  frameIndex 
)

Renders accumulated primitives using the given Scene (with camera).

Parameters
commandListCommand buffer to record into.
cameraCurrent camera (ignored if useCamera is false)
colorAttachmentTarget color surface.
depthAttachmentTarget depth surface (may be null if no depth).
frameIndexIndex of the current frame in flight.
void resize ( const vireo::Extent &  extent)

Resizes the renderer's viewport

Parameters
extentThe new extent
void restart ( )

Removes all sessions, vertices and params, resetting the renderer to its initial empty state.

void setGammaCorrectionParameters ( const float  gamma,
const float  _ 
)
inline
void setVisible ( unique_id  sessionId,
bool  visible 
)

Shows or hides a draw session without clearing its primitives. Hidden sessions are skipped by the GPU indirect command generator but remain in the vertex and params buffers so they can be made visible again cheaply.

Parameters
sessionIdSession ID returned by beginDraw().
visibleTrue to show, false to hide.
void update ( const std::shared_ptr< vireo::CommandList > &  commandList,
uint32  frameIndex 
)

Uploads dirty vertex & params buffers.

Member Data Documentation

float aspectRatio {}
protected
const RendererConfiguration& config
protected
std::optional<DrawSession> currentSession
protected
ImageManager& imageManager
protected
uint32 lineListCount {0}
protected
uint32 lineStripCount {0}
protected
const size_t maxFonts
protected
const size_t maxImages
protected
const size_t maxParams
protected
const size_t maxVertices
protected
const std::string name
protected
uint32 nextParamOffset {0}
protected
uint32 nextVertexOffset {0}
protected
std::vector<DrawParam> params
protected
uint32 triGlyphCount {0}
protected
uint32 triImageCount {0}
protected
uint32 triPlainCount {0}
protected
std::vector<Vertex> vertices
protected