/
vk_renderstate.h
132 lines (108 loc) · 3.81 KB
/
vk_renderstate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#pragma once
#include "vulkan/system/vk_buffers.h"
#include "vulkan/shaders/vk_shader.h"
#include "vulkan/renderer/vk_renderpass.h"
#include "name.h"
#include "hwrenderer/scene/hw_drawstructs.h"
#include "hwrenderer/scene/hw_renderstate.h"
#include "hwrenderer/textures/hw_material.h"
class VkRenderPassSetup;
class VkRenderState : public FRenderState
{
public:
VkRenderState();
virtual ~VkRenderState() = default;
// Draw commands
void ClearScreen() override;
void Draw(int dt, int index, int count, bool apply = true) override;
void DrawIndexed(int dt, int index, int count, bool apply = true) override;
// Immediate render state change commands. These only change infrequently and should not clutter the render state.
bool SetDepthClamp(bool on) override;
void SetDepthMask(bool on) override;
void SetDepthFunc(int func) override;
void SetDepthRange(float min, float max) override;
void SetColorMask(bool r, bool g, bool b, bool a) override;
void SetStencil(int offs, int op, int flags = -1) override;
void SetCulling(int mode) override;
void EnableClipDistance(int num, bool state) override;
void Clear(int targets) override;
void EnableStencil(bool on) override;
void SetScissor(int x, int y, int w, int h) override;
void SetViewport(int x, int y, int w, int h) override;
void EnableDepthTest(bool on) override;
void EnableMultisampling(bool on) override;
void EnableLineSmooth(bool on) override;
void EnableDrawBuffers(int count) override;
void ApplySSAO(float m5, unsigned int vpindex) override;
void BeginFrame();
void SetRenderTarget(VulkanImageView *view, VulkanImageView *depthStencilView, int width, int height, VkFormat Format, VkSampleCountFlagBits samples);
void Bind(int bindingpoint, uint32_t offset);
void EndRenderPass();
void EndFrame();
protected:
void Apply(int dt);
void ApplyRenderPass(int dt);
void ApplyStencilRef();
void ApplyDepthBias();
void ApplyScissor();
void ApplyViewport();
void ApplyStreamData();
void ApplyMatrices();
void ApplyPushConstants();
void ApplyDynamicSet();
void ApplyVertexBuffers();
void ApplyMaterial();
void BeginRenderPass(VulkanCommandBuffer *cmdbuffer);
bool mDepthClamp = true;
VulkanCommandBuffer *mCommandBuffer = nullptr;
VkPipelineKey mPipelineKey = {};
VkRenderPassSetup *mPassSetup = nullptr;
int mClearTargets = 0;
bool mNeedApply = true;
int mScissorX = 0, mScissorY = 0, mScissorWidth = -1, mScissorHeight = -1;
int mViewportX = 0, mViewportY = 0, mViewportWidth = -1, mViewportHeight = -1;
float mViewportDepthMin = 0.0f, mViewportDepthMax = 1.0f;
bool mScissorChanged = true;
bool mViewportChanged = true;
bool mDepthTest = false;
bool mDepthWrite = false;
bool mStencilTest = false;
bool mStencilRefChanged = false;
int mStencilRef = 0;
int mStencilOp = 0;
int mDepthFunc = 0;
int mColorMask = 15;
int mCullMode = 0;
MatricesUBO mMatrices = {};
PushConstants mPushConstants = {};
uint32_t mLastViewpointOffset = 0xffffffff;
uint32_t mLastMatricesOffset = 0xffffffff;
uint32_t mLastStreamDataOffset = 0xffffffff;
uint32_t mViewpointOffset = 0;
uint32_t mMatricesOffset = 0;
uint32_t mDataIndex = -1;
uint32_t mStreamDataOffset = 0;
VSMatrix mIdentityMatrix;
int mLastVertexOffsets[2] = { 0, 0 };
IVertexBuffer *mLastVertexBuffer = nullptr;
IIndexBuffer *mLastIndexBuffer = nullptr;
bool mLastModelMatrixEnabled = true;
bool mLastTextureMatrixEnabled = true;
int mApplyCount = 0;
struct RenderTarget
{
VulkanImageView *View = nullptr;
VulkanImageView *DepthStencil = nullptr;
int Width = 0;
int Height = 0;
VkFormat Format = VK_FORMAT_R16G16B16A16_SFLOAT;
VkSampleCountFlagBits Samples = VK_SAMPLE_COUNT_1_BIT;
int DrawBuffers = 1;
} mRenderTarget;
};
class VkRenderStateMolten : public VkRenderState
{
public:
using VkRenderState::VkRenderState;
void Draw(int dt, int index, int count, bool apply = true) override;
};