Pipelines

Pipeline objects are a concept that are familiar to Vulkan or D3D12 users, but new to OpenGL users. Essentially, they allow us to specify the entire state of the graphics pipeline (shaders, vertex input, blending, depth stencil, etc.) up-front.

To use a pipeline, we first bind it in a rendering scope. All draw calls issued thereafter will use the state encapsulated in the pipeline.

Fwog::BeginRendering(...);
Fwog::Cmd::BindGraphicsPipeline(fooPipeline);
Fwog::Cmd::Draw(...); // Will use the state from fooPipeline
Fwog::Cmd::BindGraphicsPipeline(barPipeline);
Fwog::Cmd::Draw(...); // Will use the state from barPipeline
Fwog::EndRendering();

Note that it’s illegal to issue a draw in a rendering scope without first binding a pipeline. This means you cannot rely on stale bindings from other scopes.

Under the Hood

Internally, Fwog tracks relevant OpenGL state to ensure that binding pipelines won’t set redundant state. Pipeline binding will only incur the cost of setting the difference between that pipeline and the previous (and the cost to find the difference).

#include “Fwog/Pipeline.h”

namespace Fwog
struct ColorBlendAttachmentState

Public Functions

bool operator==(const ColorBlendAttachmentState&) const noexcept = default

Public Members

bool blendEnable = false
BlendFactor srcColorBlendFactor = BlendFactor::ONE
BlendFactor dstColorBlendFactor = BlendFactor::ZERO
BlendOp colorBlendOp = BlendOp::ADD
BlendFactor srcAlphaBlendFactor = BlendFactor::ONE
BlendFactor dstAlphaBlendFactor = BlendFactor::ZERO
BlendOp alphaBlendOp = BlendOp::ADD
ColorComponentFlags colorWriteMask = ColorComponentFlag::RGBA_BITS
struct ColorBlendState

Public Members

bool logicOpEnable = false
LogicOp logicOp = LogicOp::COPY
std::span<const ColorBlendAttachmentState> attachments = {}
float blendConstants[4] = {0, 0, 0, 0}
struct ComputePipeline
#include <Pipeline.h>

An object that encapsulates the state needed to issue dispatches.

Public Functions

explicit ComputePipeline(const ComputePipelineInfo &info)
Throws:

PipelineCompilationException

~ComputePipeline()
ComputePipeline(ComputePipeline &&old) noexcept
ComputePipeline &operator=(ComputePipeline &&old) noexcept
ComputePipeline(const ComputePipeline&) = delete
ComputePipeline &operator=(const ComputePipeline&) = delete
bool operator==(const ComputePipeline&) const = default
inline Extent3D WorkgroupSize() const
inline uint64_t Handle() const

Gets the handle of the underlying OpenGL program object.

Returns:

The program

Private Members

uint64_t id_
Extent3D workgroupSize_
struct ComputePipelineInfo
#include <Pipeline.h>

Parameters for the constructor of ComputePipeline.

Public Members

std::string_view name

An optional name for viewing in a graphics debugger.

const Shader *shader

Non-null pointer to a compute shader.

struct DepthState

Public Members

bool depthTestEnable = false
bool depthWriteEnable = false
CompareOp depthCompareOp = CompareOp::LESS
struct GraphicsPipeline
#include <Pipeline.h>

An object that encapsulates the state needed to issue draws.

Public Functions

explicit GraphicsPipeline(const GraphicsPipelineInfo &info)
Throws:

PipelineCompilationException

~GraphicsPipeline()
GraphicsPipeline(GraphicsPipeline &&old) noexcept
GraphicsPipeline &operator=(GraphicsPipeline &&old) noexcept
GraphicsPipeline(const GraphicsPipeline&) = delete
GraphicsPipeline &operator=(const GraphicsPipeline&) = delete
bool operator==(const GraphicsPipeline&) const = default
inline uint64_t Handle() const

Gets the handle of the underlying OpenGL program object.

Returns:

The program

Private Members

uint64_t id_
struct GraphicsPipelineInfo
#include <Pipeline.h>

Parameters for the constructor of GraphicsPipeline.

Public Members

std::string_view name

An optional name for viewing in a graphics debugger.

const Shader *vertexShader = nullptr

Non-null pointer to a vertex shader.

const Shader *fragmentShader = nullptr

Optional pointer to a fragment shader.

const Shader *tessellationControlShader = nullptr

Optional pointer to a tessellation control shader.

const Shader *tessellationEvaluationShader = nullptr

Optional pointer to a tessellation evaluation shader.

InputAssemblyState inputAssemblyState = {}
VertexInputState vertexInputState = {}
TessellationState tessellationState = {}
RasterizationState rasterizationState = {}
MultisampleState multisampleState = {}
DepthState depthState = {}
StencilState stencilState = {}
ColorBlendState colorBlendState = {}
struct InputAssemblyState

Public Members

PrimitiveTopology topology = PrimitiveTopology::TRIANGLE_LIST
bool primitiveRestartEnable = false
struct MultisampleState

Public Members

bool sampleShadingEnable = false
float minSampleShading = 1
uint32_t sampleMask = 0xFFFFFFFF
bool alphaToCoverageEnable = false
bool alphaToOneEnable = false
struct RasterizationState

Public Members

bool depthClampEnable = false
PolygonMode polygonMode = PolygonMode::FILL
CullMode cullMode = CullMode::BACK
FrontFace frontFace = FrontFace::COUNTERCLOCKWISE
bool depthBiasEnable = false
float depthBiasConstantFactor = 0
float depthBiasSlopeFactor = 0
float lineWidth = 1
float pointSize = 1
struct StencilOpState

Public Functions

bool operator==(const StencilOpState&) const noexcept = default

Public Members

StencilOp passOp = StencilOp::KEEP
StencilOp failOp = StencilOp::KEEP
StencilOp depthFailOp = StencilOp::KEEP
CompareOp compareOp = CompareOp::ALWAYS
uint32_t compareMask = 0
uint32_t writeMask = 0
uint32_t reference = 0
struct StencilState

Public Members

bool stencilTestEnable = false
StencilOpState front = {}
StencilOpState back = {}
struct TessellationState

Public Members

uint32_t patchControlPoints
struct VertexInputBindingDescription

Public Members

uint32_t location
uint32_t binding
Format format
uint32_t offset
struct VertexInputState

Public Members

std::span<const VertexInputBindingDescription> vertexBindingDescriptions = {}