CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::GraphicsContext Class Referencefinal

An object that represents a graphics context. More...

#include <CeresEngine/Graphics/GraphicsContext.hpp>

Public Member Functions

 GraphicsContext (GraphicsCommandBuffer &commandBuffer, const AffineTransform &transform=AffineTransform())
 
 GraphicsContext (GraphicsContext &parent, const AffineTransform &transform=AffineTransform())
 
void setClipRect (const Rect2 &area)
 Defines the area that will be clipped by subsequent draw calls.
 
void resetClipRect ()
 Resets the clip rect area.
 
void clear (const Rect2 &target, const Color &color=Color::zero)
 Clears the given target region with the given color.
 
void drawOverlay (const Rect2 &area)
 Draws an overlay that helps debugging views.
 
void draw (const HTexture &texture, const Rect2 &rect, const Color &tintColor=Color::white)
 Renders an texture within the given graphics context.
 
void draw (const TexturePtr &texture, const Rect2 &rect, const Color &tintColor=Color::white)
 Renders an texture within the given graphics context.
 
void draw (const Shape &shape)
 Draws a shape within the given graphics context.
 
void draw (Shape &&shape)
 Draws a shape within the given graphics context.
 
void fill (BezierPath &&path, const Paint &paint, Shape::BlendMode blendMode=Shape::BlendMode::Normal)
 Paints the region enclosed by the path.
 
void fill (const BezierPath &path, const Paint &paint, Shape::BlendMode blendMode=Shape::BlendMode::Normal)
 Paints the region enclosed by the path.
 
void stroke (BezierPath &&path, const Paint &paint, double lineWidth=1.0, Shape::BlendMode blendMode=Shape::BlendMode::Normal, Shape::LineCapStyle lineCapStyle=Shape::LineCapStyle::Butt, Shape::LineJoinStyle lineJoinStyle=Shape::LineJoinStyle::Miter, double miterLimit=10.0)
 Draws a line along the path using the given stroke color and drawing attributes.
 
void stroke (const BezierPath &path, const Paint &paint, double lineWidth=1.0, Shape::BlendMode blendMode=Shape::BlendMode::Normal, Shape::LineCapStyle lineCapStyle=Shape::LineCapStyle::Butt, Shape::LineJoinStyle lineJoinStyle=Shape::LineJoinStyle::Miter, double miterLimit=10.0)
 Draws a line along the path using the given stroke color and drawing attributes.
 
void draw (TextLayoutManager &layoutManager, Vector2 offset=Vector2(0.0), const Color &tintColor=Color::white)
 Draws a text within the given graphics context.
 
void draw (RawGraphicsCommand::Command &&command)
 Submits a custom command that will be run by the renderer before a new frame recording begins.
 

Public Attributes

AnyAllocatorReference allocator
 The allocator the user can use to amortize the cost the allocating memory for either temporary allocations or for data that will be stored inside the graphics context command buffer.
 
GraphicsCommandBuffermCommandBuffer
 The render context object.
 
GraphicsContextmParent = nullptr
 If this is a sub-view, points to the graphics context of the parent view.
 
GraphicsState mState
 A structure that contains the graphics state for the context.
 

Detailed Description

An object that represents a graphics context.

You can think of a graphics context as a destination to which drawing and graphics state operations are sent for execution. Each graphics context contains its own graphics environment and state.

The Graphics Context is created uniquely for each UIView and all draw calls are issued on the view coordinate system. If necessary, the graphics context will perform any necessary coordinate system conversion that might be necessary to render the requested element.

Each UIView::draw method will receive a new GraphicsContext instance that it should use to fill commands necessary for rendering it`s visual elements.

Constructor & Destructor Documentation

◆ GraphicsContext() [1/2]

CeresEngine::GraphicsContext::GraphicsContext ( GraphicsCommandBuffer commandBuffer,
const AffineTransform &  transform = AffineTransform() 
)
explicit

◆ GraphicsContext() [2/2]

CeresEngine::GraphicsContext::GraphicsContext ( GraphicsContext parent,
const AffineTransform &  transform = AffineTransform() 
)
explicit

Member Function Documentation

◆ clear()

void CeresEngine::GraphicsContext::clear ( const Rect2 &  target,
const Color color = Color::zero 
)

Clears the given target region with the given color.

Parameters
targetThe target area do be cleared.
colorThe color to be written over the cleared area.

◆ draw() [1/6]

void CeresEngine::GraphicsContext::draw ( const HTexture texture,
const Rect2 &  rect,
const Color tintColor = Color::white 
)
inline

Renders an texture within the given graphics context.

Parameters
textureThe texture to be drawn. This texture will be uploaded to the GPU, then sent to a shader and sampled from the GPU while rendering the .
rectThe rectangle that represents the size and position the texture should be drawn to.
tintColorAn optional tint color to apply to the sampled texture. Allows easy color changing the .

◆ draw() [2/6]

void CeresEngine::GraphicsContext::draw ( const Shape shape)

Draws a shape within the given graphics context.

The shape must be in the view's coordinate space, and the system will automatically convert the shape to the appropriate coordinate space upon drawing.

Parameters
shapeA shape to be drawn on the graphics context.

◆ draw() [3/6]

void CeresEngine::GraphicsContext::draw ( const TexturePtr texture,
const Rect2 &  rect,
const Color tintColor = Color::white 
)

Renders an texture within the given graphics context.

Parameters
textureThe texture to be drawn. This texture will be uploaded to the GPU, then sent to a shader and sampled from the GPU while rendering the .
rectThe rectangle that represents the size and position the texture should be drawn to.
tintColorAn optional tint color to apply to the sampled texture. Allows easy color changing the .

◆ draw() [4/6]

void CeresEngine::GraphicsContext::draw ( RawGraphicsCommand::Command &&  command)

Submits a custom command that will be run by the renderer before a new frame recording begins.

Can be used to submit generic draw commands like a scene draw.

◆ draw() [5/6]

void CeresEngine::GraphicsContext::draw ( Shape &&  shape)

Draws a shape within the given graphics context.

The shape must be in the view's coordinate space, and the system will automatically convert the shape to the appropriate coordinate space upon drawing.

Parameters
shapeA shape to be drawn on the graphics context.

◆ draw() [6/6]

void CeresEngine::GraphicsContext::draw ( TextLayoutManager layoutManager,
Vector2  offset = Vector2(0.0),
const Color tintColor = Color::white 
)

Draws a text within the given graphics context.

Parameters
layoutManagerThe layout manager that contains the laidout text.
offsetAn offset to be applied to the text rendering.
tintColorA tint color to be applied to the entire text.

◆ drawOverlay()

void CeresEngine::GraphicsContext::drawOverlay ( const Rect2 &  area)

Draws an overlay that helps debugging views.

Parameters
areaThe area over which the debug overlay should be drawn on.

◆ fill() [1/2]

void CeresEngine::GraphicsContext::fill ( BezierPath &&  path,
const Paint paint,
Shape::BlendMode  blendMode = Shape::BlendMode::Normal 
)

Paints the region enclosed by the path.

This method fills the path using the given fill color and the receiver's current winding rule. If the path contains any open subpaths, this method implicitly closes them before painting the fill region.

The painted region includes the pixels right up to, but not including, the path line itself. For paths with large line widths, this can result in overlap between the fill region and the stroked path (which is itself centered on the path line).

Parameters
pathThe path to be filled.
paintThe color to fill the path with.

◆ fill() [2/2]

void CeresEngine::GraphicsContext::fill ( const BezierPath path,
const Paint paint,
Shape::BlendMode  blendMode = Shape::BlendMode::Normal 
)

Paints the region enclosed by the path.

This method fills the path using the given fill color and the receiver's current winding rule. If the path contains any open subpaths, this method implicitly closes them before painting the fill region.

The painted region includes the pixels right up to, but not including, the path line itself. For paths with large line widths, this can result in overlap between the fill region and the stroked path (which is itself centered on the path line).

Parameters
pathThe path to be filled.
paintThe color to fill the path with.

◆ resetClipRect()

void CeresEngine::GraphicsContext::resetClipRect ( )

Resets the clip rect area.

◆ setClipRect()

void CeresEngine::GraphicsContext::setClipRect ( const Rect2 &  area)

Defines the area that will be clipped by subsequent draw calls.

Parameters
areaThe area to be clipped.

◆ stroke() [1/2]

void CeresEngine::GraphicsContext::stroke ( BezierPath &&  path,
const Paint paint,
double  lineWidth = 1.0,
Shape::BlendMode  blendMode = Shape::BlendMode::Normal,
Shape::LineCapStyle  lineCapStyle = Shape::LineCapStyle::Butt,
Shape::LineJoinStyle  lineJoinStyle = Shape::LineJoinStyle::Miter,
double  miterLimit = 10.0 
)

Draws a line along the path using the given stroke color and drawing attributes.

The drawn line is centered on the path with its sides parallel to the path segment. This method uses the current drawing attributes associated with the receiver. If a particular attribute is not set for the receiver, this method uses the corresponding default attribute.

Parameters
pathThe path to be stroked.
paintThe paint to stroke the path with.

◆ stroke() [2/2]

void CeresEngine::GraphicsContext::stroke ( const BezierPath path,
const Paint paint,
double  lineWidth = 1.0,
Shape::BlendMode  blendMode = Shape::BlendMode::Normal,
Shape::LineCapStyle  lineCapStyle = Shape::LineCapStyle::Butt,
Shape::LineJoinStyle  lineJoinStyle = Shape::LineJoinStyle::Miter,
double  miterLimit = 10.0 
)

Draws a line along the path using the given stroke color and drawing attributes.

The drawn line is centered on the path with its sides parallel to the path segment. This method uses the current drawing attributes associated with the receiver. If a particular attribute is not set for the receiver, this method uses the corresponding default attribute.

Parameters
pathThe path to be stroked.
paintThe paint to stroke the path with.

Member Data Documentation

◆ allocator

AnyAllocatorReference CeresEngine::GraphicsContext::allocator

The allocator the user can use to amortize the cost the allocating memory for either temporary allocations or for data that will be stored inside the graphics context command buffer.

◆ mCommandBuffer

GraphicsCommandBuffer& CeresEngine::GraphicsContext::mCommandBuffer

The render context object.

Recorded commands will be included into this context for rendering later.

◆ mParent

GraphicsContext* CeresEngine::GraphicsContext::mParent = nullptr

If this is a sub-view, points to the graphics context of the parent view.

This may not be set, for instance if doing a partial redraw on an opaque view or if a view that performs internal caching of the contents.

◆ mState

GraphicsState CeresEngine::GraphicsContext::mState

A structure that contains the graphics state for the context.


The documentation for this class was generated from the following file: