2.9.16
Coherent GT
A modern user interface library for games
renoir::CommandBuffer Class Referenceabstract

Command buffer used for recording of rendering commands which can later be executed on a given renoir::Scene instance. It is represented as a linear memory blob in which command structures are recorded. Different Command Buffers can be recorded in parallel and on different threads than the rendering thread, but can only be executed on the rendering thread where the Scene instance lives. CommandBuffers are either created for a specific texture as render target or using the render target of the scene they execute on. More...

#include <Coherent/renoir/include/RenoirCore/CommandBuffer.h>

Classes

struct  StrokeDashInfo
 Struct representing dash strokes. More...
 

Public Types

enum  SaveOptions { SVOP_Clipping = 1 << 0, SVOP_Matrix = 1 << 1, SVOP_All = 0xFF }
 

Public Member Functions

virtual void ClearScreen (Color color, bool clearClipping=true)=0
 Clears the render target with the specified color and optionally clears the clipping space. Clipping space is implemented with stencil textures (effectively clearing the stencil).
 
virtual void FillRect (const Rectangle &rect, const Paint &paint)=0
 Fills the given given rect with color determined by the Paint struct. You can change the blend mode with the Paint struct as well.
 
virtual void StrokeRect (const Rectangle &rect, const Paint &paint)=0
 Strokes a given rect with color, stroke width and blend mode from the Paint struct.
 
virtual void FillConvexQuad (const float3 points[4], const Paint &paint)=0
 Fills a convex quad specified by 4 points. Uses Color and blend mode from the Paint struct.
 
virtual void FillRoundedRect (const Rectangle &rect, float4 borderRadii, const Paint &paint)=0
 Fills a rect and makes its corners rounded according to the borderRadii provided. There is one value per corner of the rect - float4{ Top Left, Top Right, Bottom Right, Bottom Left }. Uses Color and blend mode from the Paint struct.
 
virtual void StrokeRoundedRect (const Rectangle &rect, float4 borderRadii, const Paint &paint)=0
 Strokes a rect and makes its corners rounded according to the borderRadii provided. There is one value per corner of the rect - float4{ Top Left, Top Right, Bottom Right, Bottom Left }. Uses Color, stroke width and blend mode from the Paint struct.
 
virtual void FillCircle (const Circle &circle, const Paint &paint)=0
 Fills a given circle. Uses Color and blend mode from the Paint struct.
 
virtual void StrokeCircle (const Circle &circle, const Paint &paint)=0
 Strokes a given circle. Uses Color, stroke width and blend mode from the Paint struct.
 
virtual void FillEllipse (const Rectangle &ellipse, const Paint &paint)=0
 Fills a given ellipse. The ellipse diameters are the rectangle width and height. The center of the ellipse is the center of the rectangle. Uses Color and blend mode from the Paint struct.
 
virtual void StrokeEllipse (const Rectangle &ellipse, const Paint &paint)=0
 Strokes a given ellipse. The ellipse diameters are the rectangle width and height. The center of the ellipse is the center of the rectangle. Uses Color, stroke width and blend mode from the Paint struct.
 
virtual void ClearClipScreen ()=0
 Clears the clipping space. It is implemented with stencil texture so this effectively is clearing the stencil texture.
 
virtual void ClipRect (const Rectangle &rect, ClipOp op)=0
 Makes a clip operation with the given rect.
 
virtual void ClipConvexQuad (const float3 points[4], ClipOp op)=0
 Makes a clip operation with a convex quad specified by 4 points.
 
virtual void ClipRoundedRect (const Rectangle &rect, float4 borderRadii, ClipOp op)=0
 Makes a clip operation with the given rounded rect.
 
virtual void ClipCircle (const Circle &circle, ClipOp op)=0
 Makes a clip operation with the given circle.
 
virtual void ClipImageRectToRect (Image image, Rectangle srcRect, Rectangle destRect, ClipOp op)=0
 Makes a clip operation using an Image object. Uses the srcRect from the image, and applies it to the destRect on the clipping space.
 
virtual void ClipImageRepeat (Image image, const Rectangle &srcRect, const Rectangle &destRect, float2 startPosition, float2 textureScale, ClipOp op)=0
 Makes a clip operation using an Image object. Uses the srcRect from the image, and applies it to the destRect on the clipping space. The image source is repeated in the dest rect instead of being stretched to match dimensions. "startPosition" is a position in Image space which can be used to control where to start the repetition from. textureScale is used as an optional scaling factor for the src rect of the image.
 
virtual void FillPath (class Path *path, const Paint &paint)=0
 Fills a given Path object. The buffer will keep an extra reference to the Path instance so it is safe to release it after issuing this command. Uses Color and blend mode from the Paint struct.
 
virtual void StrokePath (class Path *path, const Paint &paint, const StrokeDashInfo *dashInfo=nullptr)=0
 Strokes a path. The buffer will keep extra reference to the Path instance so it is safe to release it after issuing this command. Uses Color, stroke width, Join Style, Cap Style, Miter Limit and blend mode from the Paint struct. There is an optional dash info which can be used to stroke dash patterns.
 
virtual void ClipPath (class Path *path, ClipOp op)=0
 Does a clip operation with a Path object. The buffer will keep extra reference to the Path instance so it is safe to release it after issuing this command.
 
virtual void FillAnimatedPath (class AnimatedPath *path, const Paint &paint)=0
 Fills an animated path. The buffer will keep extra reference to the AnimatedPath instance so it is safe to release it after issuing this command. Uses Color and blend mode from the Paint struct.
 
virtual void StrokeAnimatedPath (class AnimatedPath *path, const Paint &paint)=0
 Strokes an animated path. The buffer will keep extra reference to the AnimatedPath instance so it is safe to release it after issuing this command. Uses Color, stroke width, Join Style, Cap Style, Miter Limit and blend mode from the Paint struct.
 
virtual void SetMatrix (const float4x4 &mat)=0
 Sets the current matrix. All following operations will use this matrix.
 
virtual void Translate (float2 t)=0
 Adds 2D translation to the current matrix.
 
virtual void Scale (float2 s)=0
 Adds 2D scale to the current matrix.
 
virtual void Rotate (float d)=0
 Adds rotation around the Z axis to the current matrix, i.e. 2D rotate.
 
virtual void Skew (float2 sk)=0
 Adds 2D skew to the current matrix.
 
virtual void Concatenate (const float4x4 &mat)=0
 Multiplies the current matrix with the given one.
 
virtual void FlattenZ ()=0
 Flattens the Z component of the current matrix.
 
virtual float4x4 GetMatrix ()=0
 Gets the current matrix.
 
virtual void AllocateSurface (Surface name, const SurfaceInfo &info, bool needsDepth=false)=0
 Allocates resources for a Surface object based on the SurfaceInfo. Optionally, specify if this Surface will need a stencil texture as well.
 
virtual void FreeSurface (Surface name)=0
 Frees the resource for the Surface object.
 
virtual void DrawSurface (Surface image, float3 position, const Paint &paint)=0
 Draws the surface object at the specified position. Color Mix Mode, Blend mode and modulation color is taken from the Paint struct.
 
virtual void DrawSurfaceRectToRect (Surface name, const Rectangle &srcRect, const Rectangle &destRect, const Paint &paint)=0
 Draws the srcRect part of the Surface object onto the destRect in the screen. Color Mix Mode, Blend mode and modulation color is taken from the Paint struct.
 
virtual void DrawSurfaceRectToRectWithColorMatrixFilter (Surface name, const Rectangle &srcRect, const Rectangle &destRect, const ColorMatrix &colorMatrix, const Paint &paint)=0
 Draws the srcRect part of the Surface object onto the destRect in the screen. Blend mode is taken from the Paint struct. Applies a color matrix.
 
virtual void DrawSurfaceRectToRectWithCustomEffect (Surface name, const Rectangle &srcRect, const Rectangle &destRect, const UserEffect &effect, const Paint &paint)=0
 Draws the srcRect part of the Surface object onto the destRect in the screen. Blend mode is taken from the Paint struct. Applies a UserEffect.
 
virtual void SetSurfaceDebugName (Surface name, const char *debugName)=0
 Sets the debug name for the specific Surface.
 
virtual CommandBufferBeginLayer (size_t size, const Paint &paint)=0
 Returns a command buffer representing a sublayer that is later composed. Uses the opacity value from ColorValue and blend mode from the Paint struct.
 
virtual CommandBufferBeginLayerWithShaders (size_t size, const Paint &paint, Shader **shaders, size_t shadersCount)=0
 Returns a command buffer representing a sublayer that is later composed. Applies optional shaders for the composition. The buffer keeps an additional reference for each Shader object.
 
virtual CommandBufferEndLayer ()=0
 Ends the current layer and returns the parent command buffer. Should be called only on sub-layers.
 
virtual CommandBufferEndLayerWithMatrix (const float4x4 &transform)=0
 Ends the current layer and returns the parent command buffer, transofrming the layer with a matrix Should be called only on sub-layers.
 
virtual int GetLevel () const =0
 Returns the level of the current sublayer.
 
virtual void FillRectWithShaderAndMask (const Rectangle &rect, const Paint &paint, Shader *shader, Surface mask=Surface(), float4 maskScaleAndOffset=float4())=0
 Fills a rect and applies the shader. An optional mask can be passed (represented by a surface), and additional scale and offset applied to it. The buffer keeps an additional reference for each Shader object.
 
virtual void FillRectWithShaderAndMaskRepeat (const Rectangle &rect, const Paint &paint, Shader *shader, float2 startPosition, Rectangle sourceRect, float2 samplingScale, float2 textureSize, Surface mask=Surface(), float4 maskScaleAndOffset=float4())=0
 Fills a rect and applies the shader. The sourceRect is repeated in the destination rect. StartPosition is used to offset the repeating rect. SamplingScale is used to scale the source rect. TextureSize is used to control the size of the gradient if used. An optional mask represented by a surface can be passed, as well as additional scale and offset applied to it. The buffer keeps an additional reference for each Shader object.
 
virtual void ApplyBlurEffect (float width)=0
 Blurs the current render target with given kernel radius.
 
virtual StateId Save (int saveFlags=SVOP_All)=0
 Saves state based on the save flag. Returns state id which can be used to restore to specific save.
 
virtual void Restore ()=0
 Restores the previous saved state.
 
virtual void RestoreTo (StateId stateId)=0
 Restores to specific state id.
 
virtual void AllocateImage (Image image, const ImageInfo &info)=0
 Allocates resources for specific Image given the ImageInfo.
 
virtual void UpdateImage (Image image, const void *data, unsigned sizeBytes, bool copyDataInInternalBuffer)=0
 Updates the contents of an image based on the data. If copyDataInInternalBuffer is true the data is copied inside the buffer, and can be safely freed after this call. If not, you have to keep the data alive until the command buffer is executed and freed.
 
virtual void AllocateImageDataFromDecode (Image image, const ImageInfo &info, const void *data, unsigned sizeBytes, bool passOwnership)=0
 Allocates resources for a specific image given and ImageInfo. Also provides initial data to populate the image. If passOwnership is true, the command buffer will call Library::FreeDecodedImage on the data passed.
 
virtual void AllocateUserImage (Image image, const ImageInfo &info, void *userObject)=0
 Allocates resources for a specific image with the given userObject.
 
virtual void ChangeUserImage (Image image, const ImageInfo &info, void *userObject)=0
 Changes the userObject for a given Image.
 
virtual void FreeImage (Image image)=0
 Frees the resources for a Image object.
 
virtual void DrawImage (Image image, float3 position, const Paint &paint)=0
 Draws the given image to a specific position. Uses Color mix mode and blend mode from the Paint struct.
 
virtual void DrawImageRectToRect (Image image, Rectangle srcRect, Rectangle destRect, const Paint &paint)=0
 Draws the srcRect part of the image to the given destRect. Uses Color mix mode and blend mode from the Paint struct.
 
virtual void DrawImageRectToRectWithColorMatrixFilter (Image image, const Rectangle &srcRect, const Rectangle &destRect, const ColorMatrix &colorMatrix, const Paint &paint)=0
 Draws the srcRect part of the image to the given destRect. Applies a color matrix when drawing. Uses Color mix mode and blend mode from the Paint struct.
 
virtual void DrawYUVPlanesToRect (Image YPlane, Image UPlane, Image VPlane, Image AlphaPlane, const Rectangle &YSrcRect, const Rectangle &destRect, const Paint &paint)=0
 Combines YUV images and draws the to the destRect. Optionally, an alpha plane can be combined as well. YSrcRect is used to control which part of the source images to draw. Blend mode is used from the Paint struct.
 
virtual void SetImageDebugName (Image image, const char *debugName)=0
 Sets the debug name for the specific Image.
 
virtual void DrawImageRepeat (Image image, const Rectangle &srcRect, const Rectangle &destRect, float2 startPosition, float2 textureScale, const Paint &paint)=0
 Draws the srcRect of the image into destRect but instead of stretching it it will repeat it. Optionally using the startPosition to control offsets and texture scale to scale the src rect. Blend mode is used from the Paint struct.
 
virtual void FillText (const char *data, unsigned bytesCount, const float3 &pos, const Paint &paint, const Rectangle *box=nullptr, float2 letterSpacing=float2(0, 0), const WordSpacing *wordSpacing=nullptr)=0
 Fills the text provided in the data starting from pos. Pos is position of the baseline of the text. Data is interpreted based on the TextType from the Paint struct. Typeface, text size, color and blend mode to use is taken from the Paint struct as well. Optionally can provide box rect, which is representing the are this text will probably occupy on the screen. If not provided the rendering will make conservative estimates how big it will be. Optionally you can provide letter spacing and word spacing struct for those features.
 
virtual void FillTextWithOffsets (const char *data, unsigned bytesCount, const float3 &pos, const GlyphOffsets &offsets, const Paint &paint, const Rectangle *box=nullptr)=0
 Fills the text provided in data starting from pos and applying the corresponding offset to each glyph. Pos is position of the baseline of the text. Offsets are the offsets from the base position used for each glyph. Data is interpreted based on the TextType from the Paint struct. Typeface, text size, color and blend mode to use is taken from the Paint struct as well. Optionally can provide box rect, which is representing the are this text will probably occupy on the screen. If not provided the rendering will make conservative estimates how big it will be.
 
virtual void FillTextBox (class TextBox *box, const float3 &position, const Paint &paint)=0
 Deprecated. Do not use! Fills a text using a text box on a given position.
 
virtual void StrokeText (const char *data, unsigned bytesCount, const float3 &pos, Color strokeColor, const Paint &paint, const Rectangle *box=nullptr, float2 letterSpacing=float2(0, 0))=0
 Strokes text. Look at FillText for explanation about params.
 
virtual void StrokeTextWithOffsets (const char *data, unsigned bytesCount, const float3 &pos, const GlyphOffsets &offsets, Color strokeColor, const Paint &paint, const Rectangle *box=nullptr)=0
 Strokes text. Look at FillTextWithOffsets for explanation about params.
 
virtual void SetMetadata (const char *meta)=0
 Sets debug metadata which will be sent to the backend.
 
virtual void ClearMetadata ()=0
 Clears the set metadata previously set.
 
virtual bool IsThinSurfaceBuffer () const =0
 Whether the buffer is considered "thin". A Thin buffer is a buffer, containing simple commands and can be merged in other buffers. Such buffers can avoid drawing into separate render targets and be directly merged in the parent layer.
 
virtual bool MergeThinSurfaceBuffer (const CommandBuffer *buffer, const SurfaceInfo &info)=0
 If clipping is needed it should be done by the client because the actual surface can be larger than the required clip size and therefore it cannot be done automatically.
 
virtual void Destroy ()=0
 Destroys the command buffer.
 
virtual size_t GetCommandsCount () const =0
 Gets the commands count in the command buffer.
 
virtual void * ReservedMethod (void *, void *)=0
 Reserved method for internal usage. Do not use.
 

Detailed Description

Command buffer used for recording of rendering commands which can later be executed on a given renoir::Scene instance. It is represented as a linear memory blob in which command structures are recorded. Different Command Buffers can be recorded in parallel and on different threads than the rendering thread, but can only be executed on the rendering thread where the Scene instance lives. CommandBuffers are either created for a specific texture as render target or using the render target of the scene they execute on.

Member Enumeration Documentation

◆ SaveOptions

Enumerator
SVOP_Clipping 

Saves the clipping space and clipping operations applied.

SVOP_Matrix 

Saves the current matrix.

SVOP_All 

Saves all possible state.