Ream v0.1.0-1
C++ graphics library for Linux
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
RPainter Class Referenceabstract

High-performance built-in renderer. More...

#include <RPainter.h>

+ Inheritance diagram for RPainter:

Classes

struct  State
 Snapshot of the painter's mutable rendering state. More...
 

Public Types

enum  Option : UInt32
 Rendering options. More...
 
enum  ImageEffect : UInt32
 Image effects available through drawImageEffect(). More...
 

Public Member Functions

const Statestate () const noexcept
 Returns the current painter state.
 
void setState (const State &state) noexcept
 Replaces the current painter state.
 
void save () noexcept
 Saves the current RPainter state.
 
void restore () noexcept
 Restores the most recently saved RPainter state.
 
void clearHistory () noexcept
 Clears the saved state history and resets the current state to its defaults.
 
void reset () noexcept
 Resets the current RPainter state to its default configuration.
 
void setOption (Option option, bool enabled) noexcept
 Sets an option.
 
void setOptions (CZBitset< Option > options=0)
 Sets the current rendering options, replacing any previously set flags.
 
void setBlendMode (RBlendMode mode=RBlendMode::SrcOver) noexcept
 Sets the current blend mode used for drawing operations.
 
RBlendMode blendMode () const noexcept
 Returns the current blend mode.
 
void setOpacity (SkScalar opacity=1.f) noexcept
 Sets the global opacity for drawing operations.
 
SkScalar opacity () const noexcept
 Returns the current global opacity.
 
void setColor (SkColor color=SK_ColorBLACK) noexcept
 Specifies the color used by drawColor() and clearSurface().
 
SkColor color () const noexcept
 Returns the current drawing color.
 
void setFactor (const SkColor4f &factor={1.f, 1.f, 1.f, 1.f}) noexcept
 Sets per-channel multiplication factors applied in drawColor() and drawImage().
 
const SkColor4f & factor () const noexcept
 Returns the current per-channel multiplication factors.
 
virtual bool drawImage (const RDrawImageInfo &image, const SkRegion *region=nullptr, const RDrawImageInfo *mask=nullptr) noexcept=0
 Draws an image onto the surface.
 
virtual bool drawColor (const SkRegion &region) noexcept=0
 Fills the specified region with the current color().
 
virtual bool drawImageEffect (const RDrawImageInfo &image, ImageEffect effect, const SkRegion *region=nullptr) noexcept=0
 Draws an image applying a built-in image effect.
 
virtual bool setGeometry (const RSurfaceGeometry &geometry) noexcept=0
 Sets the viewport -> (transform) -> dst mapping used by draw operations.
 
const RSurfaceGeometrygeometry () const noexcept
 Returns the current geometry.
 
void clear () noexcept
 Clears the current viewport using the current color.
 
RDevicedevice () const noexcept
 Returns the device used for rendering by this painter.
 
std::shared_ptr< RSurfacesurface () const noexcept
 Returns the surface this painter draws into.
 
- Public Member Functions inherited from RObject
 RObject ()=default
 Constructs a default RObject.
 

Detailed Description

High-performance built-in renderer.

RPainter is Ream's native drawing API, providing operations such as drawColor(), drawImage(), and drawImageEffect() with configurable blend modes, filtering, and geometry. It is implemented directly on each graphics backend (a native SPIR-V pipeline on Vulkan, GLSL on OpenGL, a software rasterizer on Raster), so it avoids the overhead of routing through Skia.

A painter is obtained from an RPass (RPass::getPainter()) and draws into the pass's surface.


Class Documentation

◆ CZ::RPainter::State

struct CZ::RPainter::State

Snapshot of the painter's mutable rendering state.

Captured and restored by save()/restore().

Class Members
CZBitset< Option > options { 0 } Enabled rendering options (see Option).
RBlendMode blendMode { RBlendMode::SrcOver } Blend mode used by draw operations.
SkScalar opacity { 1.f } Global opacity in the range [0, 1].
SkColor color { SK_ColorBLACK } Color used by drawColor() and, when ReplaceImageColor is set, by drawImage().
SkColor4f factor { 1.f, 1.f, 1.f, 1.f } Per-channel RGBA multiplication factors.
RSurfaceGeometry geometry {} Viewport -> (transform) -> dst mapping.

Member Enumeration Documentation

◆ Option

enum Option : UInt32

Rendering options.

Enumerator
ReplaceImageColor 

Replaces the image's RGB values with the value from color(), while preserving the image's alpha.

This effectively tints the image with a solid color. Disabled by default.

ColorIsPremult 

Indicates that color() is premultiplied alpha.

Disabled by default.

◆ ImageEffect

enum ImageEffect : UInt32

Image effects available through drawImageEffect().

Enumerator
VibrancyH 

Sigma 6 horizontal blur pass.

VibrancyLightV 

Sigma 3 vertical blur pass + light tone saturation.

VibrancyDarkV 

Sigma 3 vertical blur pass + dark tone saturation.

Member Function Documentation

◆ state()

const State & state ( ) const
inlinenoexcept

Returns the current painter state.

◆ setState()

void setState ( const State state)
inlinenoexcept

Replaces the current painter state.

The call is ignored if state has an invalid geometry.

Parameters
stateThe new state to apply.

◆ save()

void save ( )
noexcept

Saves the current RPainter state.

◆ restore()

void restore ( )
noexcept

Restores the most recently saved RPainter state.

If no saved state exists, the painter is reset to its default values.

◆ clearHistory()

void clearHistory ( )
noexcept

Clears the saved state history and resets the current state to its defaults.

◆ reset()

void reset ( )
noexcept

Resets the current RPainter state to its default configuration.

Does not affect the saved state history.

◆ setOption()

void setOption ( Option  option,
bool  enabled 
)
inlinenoexcept

Sets an option.

◆ setOptions()

void setOptions ( CZBitset< Option options = 0)
inline

Sets the current rendering options, replacing any previously set flags.

Parameters
optionsThe new set of options to apply. Defaults to none.

◆ setBlendMode()

void setBlendMode ( RBlendMode  mode = RBlendMode::SrcOver)
inlinenoexcept

Sets the current blend mode used for drawing operations.

This affects both drawColor() and drawImage(). The default blend mode is SrcOver.

Parameters
modeThe blend mode to set.

◆ blendMode()

RBlendMode blendMode ( ) const
inlinenoexcept

Returns the current blend mode.

◆ setOpacity()

void setOpacity ( SkScalar  opacity = 1.f)
inlinenoexcept

Sets the global opacity for drawing operations.

This affects both drawImage() and drawColor(). The opacity value is clamped to the range [0, 1].

Parameters
opacityThe opacity to set, where 0 is fully transparent and 1 is fully opaque. Defaults to 1.0 (fully opaque).

◆ opacity()

SkScalar opacity ( ) const
inlinenoexcept

Returns the current global opacity.

Returns
The opacity value in the range [0, 1].

◆ setColor()

void setColor ( SkColor  color = SK_ColorBLACK)
inlinenoexcept

Specifies the color used by drawColor() and clearSurface().

The default color is black.

When Option::ReplaceImageColor is enabled, this color replaces the RGB components of the RImage in drawImage().

Use Option::ColorIsPremult to indicate if this color uses premultiplied alpha.

Parameters
colorThe color to set.

◆ color()

SkColor color ( ) const
inlinenoexcept

Returns the current drawing color.

Returns
The color currently set.

◆ setFactor()

void setFactor ( const SkColor4f &  factor = {1.f, 1.f, 1.f, 1.f})
inlinenoexcept

Sets per-channel multiplication factors applied in drawColor() and drawImage().

Each RGBA component of the drawn color/image is multiplied by the corresponding factor. Factors can exceed the [0, 1] range.

A factor value of 1 disables multiplication for that channel (the shader skips it for performance).

Defaults to {1.f, 1.f, 1.f, 1.f}.

Parameters
factorMultiplication factors for red, green, blue, and alpha channels.

◆ factor()

const SkColor4f & factor ( ) const
inlinenoexcept

Returns the current per-channel multiplication factors.

Returns
The RGBA factors currently set.

◆ drawImage()

virtual bool drawImage ( const RDrawImageInfo image,
const SkRegion *  region = nullptr,
const RDrawImageInfo mask = nullptr 
)
pure virtualnoexcept

Draws an image onto the surface.

This function renders an image onto the target RSurface, clipped to a specified region.

  • If no mask is provided, the effective rendering area is the intersection between region and image.dst.
  • If a mask is provided, the region is further intersected with mask.dst.
Parameters
imageInformation about the image to draw.
regionClipping region within the RSurface viewport.
maskOptional mask image. If provided, applies alpha masking using mask.a.
Returns
true if the image was successfully drawn, false otherwise.

Implemented in RGLPainter, RRSPainter, and RVKPainter.

◆ drawColor()

virtual bool drawColor ( const SkRegion &  region)
pure virtualnoexcept

Fills the specified region with the current color().

Parameters
regionThe region within the surface to fill.
Returns
true if the operation succeeded, false otherwise.

Implemented in RGLPainter, RRSPainter, and RVKPainter.

◆ drawImageEffect()

virtual bool drawImageEffect ( const RDrawImageInfo image,
ImageEffect  effect,
const SkRegion *  region = nullptr 
)
pure virtualnoexcept

Draws an image applying a built-in image effect.

Note
The current opacity, factor, blend mode, and similar state are ignored.
Parameters
imageInformation about the image to draw.
effectThe effect to apply (see ImageEffect).
regionOptional clipping region within the RSurface viewport.
Returns
true if the image was successfully drawn, false otherwise.

Implemented in RGLPainter, RRSPainter, and RVKPainter.

◆ setGeometry()

virtual bool setGeometry ( const RSurfaceGeometry geometry)
pure virtualnoexcept

Sets the viewport -> (transform) -> dst mapping used by draw operations.

Parameters
geometryThe geometry to apply.
Returns
true if the geometry was applied, false if it is invalid.

Implemented in RGLPainter, RRSPainter, and RVKPainter.

◆ geometry()

const RSurfaceGeometry & geometry ( ) const
inlinenoexcept

Returns the current geometry.

◆ clear()

void clear ( )
noexcept

Clears the current viewport using the current color.

◆ device()

RDevice * device ( ) const
inlinenoexcept

Returns the device used for rendering by this painter.

Returns
Pointer to the associated RDevice.

◆ surface()

std::shared_ptr< RSurface > surface ( ) const
inlinenoexcept

Returns the surface this painter draws into.