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 Cogs::DepthStencilStateHandle leqDepthStencilStateHandle;
47
48 Cogs::DepthStencilStateHandle commonDepthStates[(int)DepthMode::Count*(int)DepthFunc::Count];
49
50 // MinMagMipLinear, Wrap, 0x Anisotropic
51 Cogs::SamplerStateHandle defaultSampler;
52
53 Cogs::SamplerStateHandle commonSamplerStates[4];
54
55 // ComparisonMinMagMipLinear, Clamp, ComparisonLessEqual
56 Cogs::SamplerStateHandle shadowSampler;
57
58 // Single triangle that covers the full screen.
59 Cogs::VertexBufferHandle fullScreenTriangle;
60
61 uint16_t COGSCORE_DLL_API getRasterizerState(const Cogs::Core::RenderPassOptions& passOptions,
63 bool wireFrame,
64 bool counterClockWise);
65
66 COGSCORE_DLL_API uint16_t getRasterizerState(const RasterizerState & rs);
67 Cogs::DepthStencilStateHandle getDepthStencilState(const DepthStencilState & ds);
68 Cogs::SamplerStateHandle getSamplerState(const SamplerState & ss);
69
70 private:
71 IGraphicsDevice* device = nullptr;
72
74 {
75 uint16_t index = 0;
77 };
78
79 std::unordered_map<RasterizerState, RasterizerStateInstance> rasterizerStates;
80 std::unordered_map<DepthStencilState, Cogs::DepthStencilStateHandle> depthStencilStates;
81 std::unordered_map<SamplerState, Cogs::SamplerStateHandle> samplerStates;
82 };
83 }
84}
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: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