minecraftvulkan/src/skinned_renderer.cpp

42 lines
1.2 KiB
C++
Raw Permalink Normal View History

2022-10-03 10:50:49 +00:00
#include "skinned_renderer.hpp"
2022-09-27 17:35:49 +00:00
#include "chunk.hpp"
2022-09-20 01:28:41 +00:00
namespace app {
2022-10-03 10:50:49 +00:00
SkinnedRenderer::SkinnedRenderer(std::vector<xe::Image*> &images) {
2022-10-01 18:35:16 +00:00
xeRenderSystem = xe::RenderSystem::Builder("res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv")
.addVertexBindingf(0, 3, 0) // position
.addVertexBindingf(1, 3, 12) // normal
.addVertexBindingf(2, 2, 24) // uvs
.addVertexBindingi(3, 1, 32) // texture
2022-09-26 22:03:07 +00:00
.setVertexSize(36)
2022-09-21 16:36:12 +00:00
.addPushConstant(sizeof(PushConstant))
.addUniformBinding(0, sizeof(UniformBuffer))
2022-09-26 22:03:07 +00:00
.addTextureArrayBinding(1, images)
2022-09-30 05:01:52 +00:00
.setCulling(true)
2022-10-03 10:50:49 +00:00
.setWireframe(false)
2022-09-21 16:36:12 +00:00
.build();
}
2022-09-20 01:28:41 +00:00
2022-10-03 10:50:49 +00:00
void SkinnedRenderer::render(std::vector<xe::GameObject> &gameObjects, xe::Camera &xeCamera) {
2022-09-21 02:02:58 +00:00
2022-09-21 16:36:12 +00:00
xeRenderSystem->start();
2022-09-20 01:28:41 +00:00
UniformBuffer ubo{};
ubo.projectionView = xeCamera.getProjection() * xeCamera.getView();
2022-09-21 16:36:12 +00:00
xeRenderSystem->loadUniformObject(0, &ubo);
2022-09-20 01:28:41 +00:00
for(auto &obj : gameObjects) {
2022-09-30 19:40:42 +00:00
if(obj.model == nullptr) continue;
2022-09-20 01:28:41 +00:00
PushConstant pc{};
pc.modelMatrix = obj.transform.mat4();
pc.normalMatrix = obj.transform.normalMatrix();
2022-09-21 16:36:12 +00:00
xeRenderSystem->loadPushConstant(&pc);
xeRenderSystem->render(obj);
2022-09-20 01:28:41 +00:00
}
2022-09-21 16:36:12 +00:00
xeRenderSystem->stop();
2022-09-20 01:28:41 +00:00
}
}