Cogs.Core
RenderStates.h
1#pragma once
2#include "Base.h"
3
4#include <unordered_map>
5#include <vector>
6
7#include "Rendering/Common.h"
8#include "Rendering/RasterizerState.h"
9#include "Rendering/DepthStencilState.h"
10#include "Rendering/SamplerState.h"
11#include "Rendering/BlendState.h"
12
13#include "Resources/MaterialOptions.h"
14
15namespace Cogs
16{
17 class IGraphicsDevice;
18
19 namespace Core
20 {
21 constexpr uint16_t getDepthState(DepthMode depthMode, DepthFunc depthFunc) { return (uint16_t)depthMode + (uint16_t)DepthMode::Count * (uint16_t)depthFunc; }
22
23 struct RenderPassOptions;
24
26 {
27 void initialize(IGraphicsDevice * device);
28 void setupDepthStates(IGraphicsDevice* device);
29 void cleanup();
30
31 bool reverseDepth = false;
32
33 Cogs::RasterizerStateHandle defaultRasterizerStateHandle;
34 Cogs::RasterizerStateHandle defaultCCWasterizerStateHandle;
35
36 std::vector<Cogs::RasterizerStateHandle> rasterizerStateHandles;
37
38 struct {
42 } blendStates[size_t(BlendMode::Count)];
43
44 static constexpr uint16_t defaultDepthStencilState = getDepthState(DepthMode::Default, DepthFunc::Less);
45 static constexpr uint16_t noWriteDepthStencilState = getDepthState(DepthMode::NoWrite, DepthFunc::Less);
46 static constexpr uint16_t noDepthStencilState = getDepthState(DepthMode::Disabled, DepthFunc::Always);
47 static constexpr uint16_t noTestDepthStencilState = getDepthState(DepthMode::Default, DepthFunc::Always);
48 static constexpr uint16_t leqDepthStencilState = getDepthState(DepthMode::Default, DepthFunc::LessOrEqual);
49
50 Cogs::DepthStencilStateHandle commonDepthStates[(int)DepthMode::Count*(int)DepthFunc::Count];
51
52 // MinMagMipLinear, Wrap, 0x Anisotropic
53 Cogs::SamplerStateHandle defaultSampler;
54
55 Cogs::SamplerStateHandle commonSamplerStates[4];
56
57 // ComparisonMinMagMipLinear, Clamp, ComparisonLessEqual
58 Cogs::SamplerStateHandle shadowSampler;
59
60 // Single triangle that covers the full screen.
61 Cogs::VertexBufferHandle fullScreenTriangle;
62
63 uint16_t COGSCORE_DLL_API getRasterizerState(const Cogs::Core::RenderPassOptions& passOptions,
65 bool wireFrame,
66 bool counterClockWise);
67
68 COGSCORE_DLL_API uint16_t getRasterizerState(const RasterizerState & rs);
69 Cogs::DepthStencilStateHandle getDepthStencilState(const DepthStencilState & ds);
70 Cogs::SamplerStateHandle getSamplerState(const SamplerState & ss);
71
72 private:
73 IGraphicsDevice* device = nullptr;
74
76 {
77 uint16_t index = 0;
79 };
80
81 std::unordered_map<RasterizerState, RasterizerStateInstance> rasterizerStates;
82 std::unordered_map<DepthStencilState, Cogs::DepthStencilStateHandle> depthStencilStates;
83 std::unordered_map<SamplerState, Cogs::SamplerStateHandle> samplerStates;
84 };
85 }
86}
Represents a graphics device used to manage graphics resources and issue drawing commands.
DepthMode
Defines common depth stencil modes.
@ NoWrite
Depth test enabled, write disabled.
@ Default
Default, depth test & write enabled.
@ Disabled
Depth test/write disabled.
DepthFunc
Defines common depth functions.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Encapsulates blend state for the graphics pipeline in a state object.
Definition: BlendState.h:9
static BlendState DefaultState()
Creates a blend state object initialized with the default settings.
Definition: BlendState.h:55
Encapsulates state for depth buffer usage and stencil buffer usage in a state object.
static const Handle_t NoHandle
Represents a handle to nothing.
Definition: Common.h:78
Encapsulates state for primitive rasterization in a state object.
CullMode
Culling modes for triangle rasterization.
Encapsulates state for texture sampling in a state object.
Definition: SamplerState.h:12