Repository: google/filament
File: filament/backend/test/BackendTest.cpp (C++)

Code before:

PipelineState BackendTest::getColorWritePipelineState() {
    PipelineState result;
    result.rasterState.colorWrite = true;
    result.rasterState.depthWrite = false;
    result.rasterState.depthFunc = RasterState::DepthFunc::A;
    return result;
}

filament::backend::Viewport BackendTest::getFullViewport() const {
   const NativeView& view = getNativeView();
   return Viewport {
       .left = 0,
       .bottom = 0,
       .width = static_cast<uint32_t>(view.width),
       .height = static_cast<uint32_t>(view.height)
   };
}

filament::backend::RenderPassParams BackendTest::getClearColorRenderPass(
        std::optional<float4> color) {
    RenderPassParams params = {};
    params.flags.clear = TargetBufferFlags::COLOR;
    params.flags.discardStart = TargetBufferFlags::ALL;
    params.flags.discardEnd = TargetBufferFlags::NONE;
    params.clearColor = color.value_or(float4(0, 1, 1, 1));
    return params;
}

filament::backend::RenderPassParams BackendTest::getNoClearRenderPass() {
    return RenderPassParams{};
}

void BackendTest::renderTriangle(
        PipelineLayout const& pipelineLayout,
        Handle<filament::backend::HwRenderTarget> renderTarget,
        Handle<filament::backend::HwSwapChain> swapChain,
        Handle<filament::backend::HwProgram> program) {
    RenderPassParams params = getClearColorRenderPass();
    params.viewport.width = 512;
    params.viewport.height = 512;
    renderTriangle(pipelineLayout, renderTarget, swapChain, program, params);
}

void BackendTest::renderTriangle(
        PipelineLayout const& pipelineLayout,
        Handle<HwRenderTarget> renderTarget,
        Handle<HwSwapChain> swapChain,
        Handle<HwProgram> program,
        const RenderPassParams& params) {
    auto& api = getDriverApi();

Review comment (suggestion):
Just curious, is there an advantage to using a `std::optional` here as opposed to just a default argument? It might be better to use a default argument so the default value is clearer to the users of the API.

Code after:

PipelineState BackendTest::getColorWritePipelineState() {
    PipelineState result;
    result.rasterState.colorWrite = true;
    result.rasterState.depthWrite = false;
    result.rasterState.depthFunc = RasterState::DepthFunc::A;
    return result;
}

filament::backend::Viewport BackendTest::getFullViewport() const {
   const NativeView& view = getNativeView();
   return Viewport {
       .left = 0,
       .bottom = 0,
       .width = static_cast<uint32_t>(view.width),
       .height = static_cast<uint32_t>(view.height)
   };
}

filament::backend::RenderPassParams BackendTest::getClearColorRenderPass(float4 color) {
    RenderPassParams params = {};
    params.flags.clear = TargetBufferFlags::COLOR;
    params.flags.discardStart = TargetBufferFlags::ALL;
    params.flags.discardEnd = TargetBufferFlags::NONE;
    params.clearColor = color;
    return params;
}

filament::backend::RenderPassParams BackendTest::getNoClearRenderPass() {
    return RenderPassParams{};
}

void BackendTest::renderTriangle(
        PipelineLayout const& pipelineLayout,
        Handle<filament::backend::HwRenderTarget> renderTarget,
        Handle<filament::backend::HwSwapChain> swapChain,
        Handle<filament::backend::HwProgram> program) {
    RenderPassParams params = getClearColorRenderPass();
    params.viewport.width = 512;
    params.viewport.height = 512;
    renderTriangle(pipelineLayout, renderTarget, swapChain, program, params);
}

void BackendTest::renderTriangle(
        PipelineLayout const& pipelineLayout,
        Handle<HwRenderTarget> renderTarget,
        Handle<HwSwapChain> swapChain,
        Handle<HwProgram> program,
        const RenderPassParams& params) {
    auto& api = getDriverApi();