initial commit
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
#include "HydraForwardPipeline.h"
|
||||
#include "HydraRenderStage.h"
|
||||
#include "../engine/HydraEngine.h"
|
||||
#include "../buffer/HydraBufferManager.h"
|
||||
#include "PerFrameUBO.hpp"
|
||||
#include "../camera/HydraCamera.h"
|
||||
#include "../renderer/HydraRenderer.h"
|
||||
#include "../ecs/HydraECS.h"
|
||||
#include "../ecs/systems/HydraRenderSystem.h"
|
||||
#include "../mesh/StandardVertex.h"
|
||||
|
||||
void HydraForwardPipeline::Initialise()
|
||||
{
|
||||
_EnableVertexAttributes();
|
||||
HydraRenderStage* render_stage = new HydraRenderStage();
|
||||
std::string shader_path = std::string(shader_base);
|
||||
HydraBufferManager* buffer_manager = GetEngine()->BufferManager();
|
||||
|
||||
HydraID pos_buffer_id = buffer_manager->FindBuffer("PositionsBuffer");
|
||||
HydraID mat_buffer_id = buffer_manager->FindBuffer("MaterialBuffer");
|
||||
HydraID tex_buffer_id = buffer_manager->FindBuffer("TextureBuffer");
|
||||
|
||||
HydraShaderBinding shader_binding = {};
|
||||
|
||||
shader_binding.block_name.push_back("PositionsBuffer");
|
||||
shader_binding.binding_point.push_back(1);
|
||||
shader_binding.buffer_id.push_back(pos_buffer_id);
|
||||
|
||||
shader_binding.block_name.push_back("MaterialBuffer");
|
||||
shader_binding.binding_point.push_back(2);
|
||||
shader_binding.buffer_id.push_back(mat_buffer_id);
|
||||
|
||||
shader_binding.block_name.push_back("TextureBuffer");
|
||||
shader_binding.binding_point.push_back(3);
|
||||
shader_binding.buffer_id.push_back(tex_buffer_id);
|
||||
std::vector<uint32_t> textures;
|
||||
std::vector<uint32_t> rb_attachments;
|
||||
|
||||
|
||||
|
||||
render_stage->Initialise(shader_path + "forward_shader.vert", shader_path + "forward_shader.frag", shader_binding, 0, textures, true, HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR);
|
||||
m_render_stages.push_back(render_stage);
|
||||
|
||||
|
||||
m_per_frame_ubo = buffer_manager->CreateGPUBuffer("PerFrameUBO",
|
||||
sizeof(PerFrameUBO), 0, HYDRA_BUFFER_TYPE::HYDRA_UBO_BUFFER);
|
||||
|
||||
}
|
||||
|
||||
void HydraForwardPipeline::Shutdown()
|
||||
{
|
||||
for(uint32_t rs_idx =0; rs_idx <m_render_stages.size(); rs_idx++)
|
||||
{
|
||||
m_render_stages[rs_idx]->ShutDown();
|
||||
delete m_render_stages[rs_idx];
|
||||
}
|
||||
}
|
||||
|
||||
void HydraForwardPipeline::Render()
|
||||
{
|
||||
_UpdateUBO();
|
||||
|
||||
HydraECS* ecs = GetEngine()->ECS();
|
||||
std::shared_ptr<HydraRenderSystem> render_system = ecs->GetSystem<HydraRenderSystem>();
|
||||
|
||||
GetEngine()->Renderer()->BeginFrame();
|
||||
|
||||
for(uint32_t rs_idx = 0; rs_idx <m_render_stages.size(); rs_idx++)
|
||||
{
|
||||
m_render_stages[rs_idx]->Render(render_system->Entities);
|
||||
}
|
||||
GetEngine()->Renderer()->EndFrame();
|
||||
}
|
||||
|
||||
void HydraForwardPipeline::_UpdateUBO()
|
||||
{
|
||||
HydraCamera* camera = GetEngine()->Camera();
|
||||
PerFrameUBO ubo = {};
|
||||
|
||||
ubo.view = camera->GetView();
|
||||
ubo.proj = camera->GetProjection();
|
||||
|
||||
HydraBufferManager* buffer_manager = GetEngine()->BufferManager();
|
||||
buffer_manager->UpdateWholeBuffer(m_per_frame_ubo, &ubo);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, m_per_frame_ubo);
|
||||
}
|
||||
|
||||
void HydraForwardPipeline::_EnableVertexAttributes()
|
||||
{
|
||||
|
||||
//already on the render thread so dont neet another job
|
||||
// position
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(StandardVertex), (void *)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
// texcoord01
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(StandardVertex), (void *)(3 * sizeof(float)));
|
||||
glEnableVertexAttribArray(1);
|
||||
// chunkID
|
||||
glVertexAttribIPointer(2, 3, GL_UNSIGNED_INT, sizeof(StandardVertex), (void *)(5 * sizeof(float)));
|
||||
glEnableVertexAttribArray(2);
|
||||
}
|
||||
Reference in New Issue
Block a user