2022-09-20 01:28:41 +00:00
|
|
|
#include "simple_renderer.hpp"
|
2022-09-27 17:35:49 +00:00
|
|
|
#include "chunk.hpp"
|
2022-09-20 01:28:41 +00:00
|
|
|
|
|
|
|
namespace app {
|
|
|
|
|
2022-09-26 22:03:07 +00:00
|
|
|
SimpleRenderer::SimpleRenderer(xe::Engine &xeEngine, std::vector<xe::Image*> &images) {
|
2022-09-25 01:16:13 +00:00
|
|
|
xeRenderSystem = xe::RenderSystem::Builder(xeEngine, "res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv")
|
2022-09-27 00:57:53 +00:00
|
|
|
.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-09-21 16:36:12 +00:00
|
|
|
.build();
|
|
|
|
}
|
2022-09-20 01:28:41 +00:00
|
|
|
|
2022-09-26 22:03:07 +00:00
|
|
|
void SimpleRenderer::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
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|