ARenderContext#
Render context passed to AView::render.
Header: | #include <AUI/Render/ARenderContext.h> |
CMake: | aui_link(my_target PUBLIC aui::views) |
Detailed Description#
View containers are responsible to modify (by withShiftedPosition) and passthrough clip optimization context in order to determine which views do not affect actual renderbuffer image and thus should not be rendered either. It's applicable for AScrollArea in the first place, or any other container with AOverflow::HIDDEN and a possibility to either direct or indirect children to run out (render outside) of that container.
View containers are also responsible to skip rendering of views that are outside of the clipping.
ARenderContext is useful only for container views.
ARenderContext passed to the view (possibly AViewContainer) describes an axis aligned bounding box relative to it's coordinate space (position).
Root (window) and AOverflow::HIDDEN containers should create ARenderContext with position = {0, 0} and size = it's size. Other containers should not affect ARenderContext and pass it to it's children as is, in exception to position, which should be subtracted by view's position.
See UIRenderOptimizationTest for tests.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
mTexture = _new<gl::Texture2D>();
mTexture->tex2D(*AImage::fromUrl(":img/color_scheme_wikipedia.png"));
}
void FractalView::render(ARenderContext context) {
AView::render(context);
mShader.use();
mTexture->bind();
context.render.rectangle(ACustomShaderBrush {}, { 0, 0 }, getSize());
examples/app/game_of_life/src/main.cpp
Game of Life - Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.
static constexpr auto SCALE = 8_dp;
CellsView(_<Cells> cells) : mCells(std::move(cells)) { connect(mCells->frameComplete, me::updateTexture); }
void render(ARenderContext ctx) override {
AView::render(ctx);
if (mTexture) {
ctx.render.rectangle(ATexturedBrush { mTexture }, { 0, 0 }, float(SCALE) * glm::vec2(mCells->size()));
}
auto drawGrid = [&] {
examples/app/minesweeper/src/CellView.h
Minesweeper Game - Minesweeper game implementation driven by ass.
class CellView : public AView {
public:
CellView(FieldCell& cell);
void render(ARenderContext context) override;
[[nodiscard]]
FieldCell fieldCell() const { return mCell; }
private:
examples/ui/views/src/DemoGraphView.h
Views Example - All-in-one views building example.
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer - Undo, redo, dialog control.
examples/app/fractal/src/FractalView.h
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
examples/app/minesweeper/src/CellView.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
examples/ui/views/src/DemoGraphView.cpp
Views Example - All-in-one views building example.
mPoints << glm::vec2{ 5_dp * float(i), 100_dp * ((glm::sin(i / 10.f) + 1.f) / 2.f) };
}
}
void DemoGraphView::render(ARenderContext ctx) {
AView::render(ctx);
ctx.render.lines(ASolidBrush{0xff0000_rgb }, mPoints, ABorderStyle::Dashed{}, 4_dp);
}
Public fields and Signals#
clippingRects#
Rectangles clippingRects
Axis aligned bounding boxes where the rendering is performed in, used for optimization.