Cogs.Core
ClipmapRenderer.h
1#pragma once
2
3#include "RenderContext.h"
4#include "RenderTexture.h"
5#include "RenderBlock.h"
6
7#include "ClipmapEffectVariables.h"
8
9#include "Rendering/IGraphicsDevice.h"
10#include "Rendering/ITextures.h"
11#include "Rendering/IBuffers.h"
12
13namespace Cogs
14{
15 struct ClipmapState;
16 struct ClipmapGeometry;
17 struct ClipmapMesh;
18
19 class ClipmapLevel;
20
21 struct GlobalParameters;
22 struct LevelParameters;
23 struct ImageryParameters;
24
25 struct IRenderTargets;
26
27 RenderTexture createClipmapTexture(IGraphicsDevice * device, int width, int height, TextureFormat textureFormat, bool mipmap = false, glm::vec4 clearColor = glm::vec4(0));
28 void releaseClipmapTexture(IGraphicsDevice * device, RenderTexture & texture);
29 void clearClipmapTexture(IGraphicsDevice * device, RenderTexture & texture);
30
32 {
33 TextureHandle depthTextureHandle;
34 int width;
35 int height;
36 bool depthRenderInitialized = false;
37 RenderTargetHandle depthRenderHandle;
38 DepthStencilHandle depthTargetHandle;
39 BufferHandle readbackBufferHandle = BufferHandle::NoHandle;
40
41 void initialize(IGraphicsDevice * device, int width, int height);
42 void cleanup(IGraphicsDevice * device);
43 };
44
46 {
47 bool initialized = false;
48 ClipmapEffectVariables effectVariables;
49 ClipmapEffectVariables depthEffectVariables;
50
51 ClipmapTextureBindings effectBindings;
52 ClipmapTextureBindings depthEffectBindings;
53 EffectHandle clipmapEffect;
54 EffectHandle clipmapDepthEffect;
55 };
56
58 {
59 void initializeTextures(ITextures * textures);
60 void initializeEffects(IBuffers * buffers, IEffects * effects, const size_t numImagery, size_t permutation);
61 void initializeConstantBuffers(IBuffers * buffers, ClipmapEffectVariables & variables);
62 void initializeEffectVariables(IEffects * effects, EffectHandle effect, ClipmapEffectVariables & variables, const size_t numImagery, bool isDepth);
63 void initializeEffectBindings(IEffects * effects, EffectHandle effect, ClipmapTextureBindings & bindings, const size_t numImagery, bool isDepth);
64 void initializeRasterizerStates(IRenderTargets * renderTargets);
65 void initializeRenderTargets(IRenderTargets * renderTargets);
66
67 void cleanup(IGraphicsDevice * device);
68
69 void updateGlobalParameters(const RenderContext & context, const RenderOptions & renderOptions, const ClipmapState & clipmapState, const GlobalParameters & globalParameters);
70 void updateLevelParameters(IContext * context, const RenderOptions & options, const LevelParameters & parameters, const ImageryParameters & imageryParameters, size_t permutation);
71 void updateLevelTextures(IContext * context, const RenderLevel * renderLevel, size_t permutation);
72
73 void setCustomParameters(const unsigned char * data, int count);
74
75 void initLevels();
76
77 bool createRenderLevel(ClipmapGeometry & clipmapGeometry,
78 ClipmapState & clipmapState,
79 ClipmapLevel & terrainLevel,
80 std::vector<std::vector<ClipmapLevel>> &,
81 ClipmapLevel * normalLevel,
82 const GlobalParameters & globalParameters,
83 const LevelParameters & parameters,
84 const ImageryParameters & imageryParameters,
85 bool fillRing,
86 bool select = false);
87
88 bool createBackgroundRenderLevel(ClipmapGeometry & clipmapGeometry,
89 ClipmapState & clipmapState,
90 ClipmapLevel & terrainLevel,
91 std::vector<std::vector<ClipmapLevel>> &,
92 ClipmapLevel * normalLevel,
93 const GlobalParameters & globalParameters,
94 const LevelParameters & parameters,
95 const ImageryParameters & imageryParameters,
96 bool useSimplifiedMesh = false);
97
98 void setupDepthPass(RenderContext & renderContext, size_t depthDataIndex);
99 void setupDepthQueryPass(RenderContext & renderContext);
100 void setupRegularPass(RenderContext & renderContext);
101
102 void render(RenderContext & renderContext, const RenderOptions & renderOptions, const WorldOptions & worldOptions, bool usePreviousCullingResults = false);
103
104 void createBlock(ClipmapMesh & mesh, int overallWest, int overallSouth, int blockWest, int blockSouth, RenderLevel & renderLevel, bool useSimplifiedMesh = false);
105 void drawBlock(const RenderBlock & renderBlock, RenderContext & renderContext);
106
107 PermutationDependentClipmapRendererData & getPermutationDependentClipmapRendererData(const size_t index)
108 {
109 if (permutationDependentClipmapRendererData.size() <= index) {
110 permutationDependentClipmapRendererData.resize(index + 4);
111 }
112
113 return permutationDependentClipmapRendererData[index];
114 }
115
116 bool depthPass;
117
118 SamplerStateHandle pointSamplerState;
119 SamplerStateHandle linearSamplerState;
120
121 RasterizerStateHandle solidRasterizerState;
122 RasterizerStateHandle solidNoDepthClipRasterizerState;
123 RasterizerStateHandle solidOffsetRasterizerState;
124 RasterizerStateHandle wireframeRasterizerState;
125
126 DepthStencilStateHandle solidDepthState;
127 DepthStencilStateHandle wireframeDepthState;
128 DepthStencilStateHandle transparentDepthState;
129 DepthStencilStateHandle transparentWireframeDepthState;
130
131 InputLayoutHandle inputLayout;
132 BufferHandle customParametersBuffer;
133
134 // One per "raypick camera":
135 std::vector<DepthRenderData> raypickDepthData;
136 const static int NoPickIndex = -1;
137 const static int DefaultPickIndex = 0;
138
139 TextureHandle depthQueryTextureHandle;
140
141 int depthQuerySize;
142 RenderTargetHandle depthQueryRenderHandle;
143 DepthStencilHandle depthQueryTargetHandle;
144 bool depthQueryRenderInitialized = false;
145
146 bool reverseDepth = false;
147
148 std::vector<unsigned char> customParameters;
149
150 RenderLevel levels[kMaxNumLevels];
151 size_t levelIndex;
152 bool visibleBlocks[Cogs::kMaxNumBlocks * Cogs::kMaxNumLevels];
153
154 struct ClipmapGeometry * geometry;
155
156 private:
157 std::vector<PermutationDependentClipmapRendererData> permutationDependentClipmapRendererData;
158 };
159}
Represents a graphics device used to manage graphics resources and issue drawing commands.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
static const Handle_t NoHandle
Represents a handle to nothing.
Definition: Common.h:77
Provides buffer management functionality.
Definition: IBuffers.h:13
Represents a graphics device context which can receive rendering commands.
Definition: IContext.h:43
Provides effects and shader management functionality.
Definition: IEffects.h:148
Provides render target management functionality.
Provides texture management functionality.
Definition: ITextures.h:40