Skip to content

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/7guis/circle_drawer/src/main.cpp

7GUIs Circle Drawer - Undo, redo, dialog control.

        connect(mState->circles.changed, me::redraw);
        connect(mHoveredCircle.changed, me::redraw);
    }

    void render(ARenderContext ctx) override {
        AView::render(ctx);

        for (const auto& circle : *mState->circles) {
            if (&circle == mHoveredCircle) {
                ctx.render.roundedRectangle(

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);

}

examples/ui/opengl_simple/src/main.cpp

OpenGL Example - Demonstrates how to integrate custom OpenGL rendering with AUI Framework.

        gl::State::bindVertexArray(0);
        gl::State::useProgram(0);
    }

    void render(ARenderContext ctx) override {
        AView::render(ctx);
        cleanupAUIGLState();

        // Draw triangle
        glUseProgram(mProgram);

examples/ui/embedded_sdl/src/main.cpp

SDL3 - This code demonstrates how to integrate the AUI Framework with SDL3 to create a window with OpenGL rendering.

        /// [EventProcessing]

        /// [Rendering]
        if (window.requiresRedraw()) {
            ARenderContext render_context {
                .clippingRects = {},
                .render = *renderer,
            };
            window.render(render_context);
            SDL_GL_SwapWindow(window.sdl_window);

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/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/ui/views/src/DemoGraphView.h

Views Example - All-in-one views building example.

class DemoGraphView: public AView {
public:
    DemoGraphView();

    void render(ARenderContext ctx) override;

private:
    AVector<glm::vec2> mPoints;
};

examples/app/minesweeper/src/CellView.cpp

Minesweeper Game - Minesweeper game implementation driven by ass.

        emit customCssPropertyChanged();
    });
}

void CellView::render(ARenderContext context) {
    if (mCell != mCellValueCopy) {
        mCellValueCopy = mCell;
    }
    AView::render(context);

examples/app/fractal/src/FractalView.h

Fractal Example - Fractal viewer application demonstrating usage of custom shaders.

    void handleMatrixUpdated();

public:
    FractalView();
    void render(ARenderContext context) override;

    void reset();

    void setIterations(unsigned it);

Public fields and Signals#


clippingRects#

Rectangles clippingRects

Axis aligned bounding boxes where the rendering is performed in, used for optimization.