VisualCache
Description
- Derived from
-
Disposable abstract
IBeginEnd
The visual cache is a high-level utility for rendering 2D visuals, by rasterizing them into textured quadrilaterals.
To perform rendering of 2D visuals, the following steps are necessary:
-
Create a IVisualRasterizer instance, which will perform rasterization of 2D visuals.
-
Create a Sprites object, which will hold the textured quadrilaterals which represent the rasterized 2D visuals.
-
Create a VisualCache object and specify a IGraphicsContext that is compatible with the IBufferFactory and ITextureFactory of the Sprites.
-
Call IBeginEnd.Begin to begin a new render cycle. Render cycles may be nested and should wrap actual render code only, so that they will end as soon as possible.
-
Call Get to obtain the render batch for a visual instance.
-
Use the RangeI value obtained from the previous step, Geometry and Texture to render the visual instance, for example by calling IPrimitiveRenderer.DrawIndexed. Use instancing and/or indirect draw buffers to reduce the number of draw calls, if necessary.
-
Call IBeginEnd.End to end the current render cycle.
-
Use Clear and Evict to remove visuals from the cache that will no longer be used. This allows the cache to operate more efficiently.
Public / Constructors
VisualCache
Creates a new instance of VisualCache.
- RenderException
-
If a graphics subsystem error has occurred.
Public / Methods
Evict
Evicts the given visual instance from the cache.
This method should be used whenever an application has determined that it will no longer need a visual instance for some time. Evicting unused visual instances up-front will allow better use of the available cache texture space, compared to least-recently-used eviction.
Get
Returns the cached render batch of the given visual instance, building it if necessary.
The returned render batch may be used to submit GPU work during the current IBeginEnd.Begin / IBeginEnd.End cycle. After the cycle has ended, the render batch may become invalid, because of the least-recently used eviction scheme of the visual cache. The results from background rasterization (see VisualFlags.Background) will be consumed when the next outermost call to IBeginEnd.Begin is made.
Public / Attributes
RenderSize
Returns the size of the rasterized visual.
When the triangles of a rasterized visual are rendered without transformation, the top-left corner of the visual bounds (see IVisual.Bounds) appears at the screen coordinates (0,0), which is the top-left corner of the top-left pixel. The bottom-right corner of the visual bounds maps to the screen coordinates (RenderSize.X,RenderSize.Y). The render size is not necessarily the same as the pixel size of the underlying sprite, see Visual.ComputeAlignedBounds.
- See also
RenderTriangles
Returns the range of elements in Geometry that represent the rasterized visual, as an indexed triangle list. Will be RangeI.Zero if the cache does not (yet) contain a usable version of the visual instance or if the 2D visual is empty.
- See also