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
-
BlendFactor srcAlphaBlendFactor = BlendFactor::ONE
-
BlendFactor dstAlphaBlendFactor = BlendFactor::ZERO
-
ColorComponentFlags colorWriteMask = ColorComponentFlag::RGBA_BITS
-
bool operator==(const ColorBlendAttachmentState&) const noexcept = default
-
struct ColorBlendState
-
struct ComputePipeline
- #include <Pipeline.h>
An object that encapsulates the state needed to issue dispatches.
Public Functions
-
explicit ComputePipeline(const ComputePipelineInfo &info)
- Throws:
-
~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 uint64_t Handle() const
Gets the handle of the underlying OpenGL program object.
- Returns:
The program
-
explicit ComputePipeline(const ComputePipelineInfo &info)
-
struct ComputePipelineInfo
- #include <Pipeline.h>
Parameters for the constructor of ComputePipeline.
-
struct DepthState
-
struct GraphicsPipeline
- #include <Pipeline.h>
An object that encapsulates the state needed to issue draws.
Public Functions
-
explicit GraphicsPipeline(const GraphicsPipelineInfo &info)
- Throws:
-
~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_
-
explicit GraphicsPipeline(const GraphicsPipelineInfo &info)
-
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 *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 = {}
-
std::string_view name
-
struct InputAssemblyState
Public Members
-
PrimitiveTopology topology = PrimitiveTopology::TRIANGLE_LIST
-
bool primitiveRestartEnable = false
-
PrimitiveTopology topology = PrimitiveTopology::TRIANGLE_LIST
-
struct MultisampleState
-
struct RasterizationState
Public Members
-
bool depthClampEnable = false
-
PolygonMode polygonMode = PolygonMode::FILL
-
FrontFace frontFace = FrontFace::COUNTERCLOCKWISE
-
bool depthBiasEnable = false
-
float depthBiasConstantFactor = 0
-
float depthBiasSlopeFactor = 0
-
float lineWidth = 1
-
float pointSize = 1
-
bool depthClampEnable = false
-
struct StencilOpState
Public Functions
-
bool operator==(const StencilOpState&) const noexcept = default
-
bool operator==(const StencilOpState&) const noexcept = default
-
struct StencilState
-
struct VertexInputBindingDescription
-
struct VertexInputState
Public Members
-
std::span<const VertexInputBindingDescription> vertexBindingDescriptions = {}
-
std::span<const VertexInputBindingDescription> vertexBindingDescriptions = {}
-
struct ColorBlendAttachmentState