minecraftvulkan/src/simple_renderer.cpp

36 lines
1,023 B
C++
Raw Normal View History

2022-09-20 01:28:41 +00:00
#include "simple_renderer.hpp"
namespace app {
2022-09-21 16:36:12 +00:00
SimpleRenderer::SimpleRenderer(xe::XeEngine &xeEngine, xe::XeImage *xeImage) {
xeRenderSystem = xe::XeRenderSystem::Builder(xeEngine, "res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv")
.addPushConstant(sizeof(PushConstant))
.addUniformBinding(0, sizeof(UniformBuffer))
.addTextureBinding(1, xeImage)
2022-09-21 20:49:43 +00:00
.setCulling(true)
2022-09-21 16:36:12 +00:00
.build();
}
2022-09-20 01:28:41 +00:00
2022-09-21 02:02:58 +00:00
void SimpleRenderer::render(std::vector<xe::XeGameObject> &gameObjects, xe::XeCamera &xeCamera, xe::XeImage *xeImage) {
2022-09-21 16:36:12 +00:00
xeRenderSystem->loadTexture(1, xeImage);
2022-09-21 03:04:33 +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) {
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
}
}