minecraftvulkan/src/simple_renderer.cpp

30 lines
875 B
C++
Raw Normal View History

2022-09-20 01:28:41 +00:00
#include "simple_renderer.hpp"
namespace app {
2022-09-21 02:02:58 +00:00
SimpleRenderer::SimpleRenderer(xe::XeEngine &xeEngine, xe::XeImage *xeImage)
: xeRenderSystem{xeEngine, "res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv", sizeof(PushConstant), sizeof(UniformBuffer), xeImage} {};
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 03:04:33 +00:00
xeRenderSystem.loadTexture(xeImage);
2022-09-21 02:02:58 +00:00
xeRenderSystem.start();
2022-09-20 01:28:41 +00:00
UniformBuffer ubo{};
ubo.projectionView = xeCamera.getProjection() * xeCamera.getView();
2022-09-21 02:02:58 +00:00
xeRenderSystem.loadUniformObject(&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 02:02:58 +00:00
xeRenderSystem.loadPushConstant(&pc);
2022-09-20 01:28:41 +00:00
xeRenderSystem.render(obj);
}
xeRenderSystem.stop();
}
}