-
Notifications
You must be signed in to change notification settings - Fork 0
/
r_commands.c
97 lines (72 loc) · 3.21 KB
/
r_commands.c
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
#include "r_commands.h"
#include "r_render.h"
#include "v_video.h"
#include "w_world.h"
#include "r_pipeline.h"
#include "def.h"
#include <assert.h>
#include <vulkan/vulkan_core.h>
void r_InitRenderCommands(void)
{
for (int i = 0; i < FRAME_COUNT; i++)
{
r_RequestFrame();
r_UpdateRenderCommands();
r_PresentFrame();
}
}
static void recordPostProcessRenderPass(Frame* frame)
{
VkClearValue clearValue = {0.002f, 0.003f, 0.009f, 1.0f};
const VkRenderPassBeginInfo rpassInfo = {
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
.clearValueCount = 1,
.pClearValues = &clearValue,
.renderArea = {{0, 0}, {WINDOW_WIDTH, WINDOW_HEIGHT}},
.renderPass = *frame->pRenderPass,
.framebuffer = frame->frameBuffer
};
vkCmdBeginRenderPass(frame->commandBuffer, &rpassInfo, VK_SUBPASS_CONTENTS_INLINE);
vkCmdBindPipeline(frame->commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines[R_POST_PROC_PIPELINE]);
vkCmdBindDescriptorSets(frame->commandBuffer,
VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayoutPostProcess,
0, 1, descriptorSets, 0, NULL);
vkCmdDraw(frame->commandBuffer, 3, 1, 0, 0);
vkCmdEndRenderPass(frame->commandBuffer);
}
void r_UpdateRenderCommands(void)
{
VkResult r;
Frame* frame = &frames[curFrameIndex];
vkResetCommandPool(device, frame->commandPool, 0);
VkCommandBufferBeginInfo cbbi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
r = vkBeginCommandBuffer(frame->commandBuffer, &cbbi);
VkClearValue clearValue = {0.002f, 0.003f, 0.009f, 1.0f};
const VkRenderPassBeginInfo rpassInfoFirst = {
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
.clearValueCount = 1,
.pClearValues = &clearValue,
.renderArea = {{0, 0}, {WINDOW_WIDTH, WINDOW_HEIGHT}},
.renderPass = *offscreenFrameBuffer.pRenderPass,
.framebuffer = offscreenFrameBuffer.handle
};
vkCmdBeginRenderPass(frame->commandBuffer, &rpassInfoFirst, VK_SUBPASS_CONTENTS_INLINE);
vkCmdBindPipeline(frame->commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines[R_OBJ_PIPELINE]);
VkDeviceSize vertBufferOffset = w_ObjectVertexBlock->vOffset;
assert( 0 == vertBufferOffset ); // should be the offset of the very first vert in the buffer
// which happens to be 0 right now (though does not have to be)
vkCmdBindVertexBuffers(frame->commandBuffer, 0, 1, w_ObjectVertexBlock->vBuffer, &vertBufferOffset);
for (int i = 0; i < w_ObjectCount; i++)
{
vkCmdDraw(frame->commandBuffer, w_Geos[i].vertCount, 1, w_Geos[i].vertIndex, 0);
}
vkCmdBindPipeline(frame->commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines[R_EMIT_PIPELINE]);
VkDeviceSize emitVertBufferOffset = w_EmitableVertexBlock->vOffset;
vkCmdBindVertexBuffers(frame->commandBuffer, 0, 1, w_EmitableVertexBlock->vBuffer, &emitVertBufferOffset);
if (w_EmitableCount)
vkCmdDraw(frame->commandBuffer, w_EmitableCount, 1, 0, 0);
vkCmdEndRenderPass(frame->commandBuffer);
recordPostProcessRenderPass(frame);
r = vkEndCommandBuffer(frame->commandBuffer);
assert ( VK_SUCCESS == r );
}