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 struct RenderPassOptions;
22
24 {
25 void initialize(IGraphicsDevice * device);
26 void setupDepthStates(IGraphicsDevice* device);
27 void cleanup();
28
29 bool reverseDepth = false;
30
31 Cogs::RasterizerStateHandle defaultRasterizerStateHandle;
32 Cogs::RasterizerStateHandle defaultCCWasterizerStateHandle;
33
34 std::vector<Cogs::RasterizerStateHandle> rasterizerStateHandles;
35
36 struct {
40 } blendStates[size_t(BlendMode::Count)];
41
42 Cogs::DepthStencilStateHandle defaultDepthStencilStateHandle;
43 Cogs::DepthStencilStateHandle noWriteDepthStencilStateHandle;
44 Cogs::DepthStencilStateHandle noDepthStencilStateHandle;
45 Cogs::DepthStencilStateHandle noTestDepthStencilStateHandle;
46
47 Cogs::DepthStencilStateHandle commonDepthStates[(int)DepthMode::Count*(int)DepthFunc::Count];
48
49 // MinMagMipLinear, Wrap, 0x Anisotropic
50 Cogs::SamplerStateHandle defaultSampler;
51
52 Cogs::SamplerStateHandle commonSamplerStates[4];
53
54 // ComparisonMinMagMipLinear, Clamp, ComparisonLessEqual
55 Cogs::SamplerStateHandle shadowSampler;
56
57 // Single triangle that covers the full screen.
58 Cogs::VertexBufferHandle fullScreenTriangle;
59
60 uint16_t COGSCORE_DLL_API getRasterizerState(const Cogs::Core::RenderPassOptions& passOptions,
62 bool wireFrame,
63 bool counterClockWise);
64
65 COGSCORE_DLL_API uint16_t getRasterizerState(const RasterizerState & rs);
66 Cogs::DepthStencilStateHandle getDepthStencilState(const DepthStencilState & ds);
67 Cogs::SamplerStateHandle getSamplerState(const SamplerState & ss);
68
69 private:
70 IGraphicsDevice* device = nullptr;
71
73 {
74 uint16_t index = 0;
76 };
77
78 std::unordered_map<RasterizerState, RasterizerStateInstance> rasterizerStates;
79 std::unordered_map<DepthStencilState, Cogs::DepthStencilStateHandle> depthStencilStates;
80 std::unordered_map<SamplerState, Cogs::SamplerStateHandle> samplerStates;
81 };
82 }
83}
Represents a graphics device used to manage graphics resources and issue drawing commands.
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:77
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