2022-09-20 01:28:41 +00:00
|
|
|
#include "simple_renderer.hpp"
|
|
|
|
|
|
|
|
namespace app {
|
|
|
|
|
2022-09-25 01:16:13 +00:00
|
|
|
SimpleRenderer::SimpleRenderer(xe::Engine &xeEngine, xe::Image *xeImage) {
|
|
|
|
xeRenderSystem = xe::RenderSystem::Builder(xeEngine, "res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv")
|
2022-09-25 23:05:56 +00:00
|
|
|
.addVertexBinding(0, 3, 0) // position
|
2022-09-26 03:08:03 +00:00
|
|
|
.addVertexBinding(1, 3, 12) // normal
|
|
|
|
.addVertexBinding(2, 2, 24) // uvs
|
|
|
|
.setVertexSize(32)
|
2022-09-21 16:36:12 +00:00
|
|
|
.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-25 01:16:13 +00:00
|
|
|
void SimpleRenderer::render(std::vector<xe::GameObject> &gameObjects, xe::Camera &xeCamera, xe::Image *xeImage) {
|
2022-09-21 02:02:58 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|