138 lines
3.8 KiB
C++
138 lines
3.8 KiB
C++
#include "HydraOutputActor.h"
|
|
#include "../engine/HydraEngine.h"
|
|
#include "../actor/HydraActorManager.h"
|
|
#include "../task/HydraTask.h"
|
|
#include "../ecs/HydraECS.h"
|
|
#include "../ecs/components/HydraPositionComponent.h"
|
|
#include "../ecs/components/HydraMeshComponent.h"
|
|
#include "../ecs/components/HydraRenderableComponent.h"
|
|
#include "../ecs/components/HydraMaterialComponent.h"
|
|
#include "../buffer/HydraMaterialBufferManager.h"
|
|
#include "../buffer/HydraTextureBufferManager.h"
|
|
#include "../buffer/HydraMaterialBuffer.h"
|
|
#include "../mesh/HydraMeshManager.h"
|
|
#include "../mesh/HydraMesh.h"
|
|
|
|
void HydraOutputActor::_CreateMaterial()
|
|
{
|
|
HydraEngine *engine = GetEngine();
|
|
HydraRenderSettings render_settings = engine->RenderSettings();
|
|
|
|
HydraID buffer_0 = engine->TextureBufferManager()->CreateTexture("deferred_buffer_0",
|
|
render_settings.DisplayWidth,
|
|
render_settings.DisplayHeight,
|
|
GL_RGBA8,
|
|
GL_NEAREST,
|
|
GL_NEAREST, 1);
|
|
|
|
HydraID depth = engine->TextureBufferManager()->CreateTexture("deferred_depth",
|
|
render_settings.DisplayWidth,
|
|
render_settings.DisplayHeight,
|
|
GL_DEPTH_COMPONENT24,
|
|
GL_NEAREST,
|
|
GL_NEAREST, 1);
|
|
|
|
HydraID metal_rough = engine->TextureBufferManager()->CreateTexture("deferred_metal_rough_buffer",
|
|
render_settings.DisplayWidth,
|
|
render_settings.DisplayHeight,
|
|
GL_RGBA8,
|
|
GL_NEAREST,
|
|
GL_NEAREST, 1);
|
|
|
|
HydraID normal = engine->TextureBufferManager()->CreateTexture("deferred_normal_buffer",
|
|
render_settings.DisplayWidth,
|
|
render_settings.DisplayHeight,
|
|
GL_RGBA32F,
|
|
GL_NEAREST,
|
|
GL_NEAREST, 1);
|
|
|
|
HydraID position = engine->TextureBufferManager()->CreateTexture("deferred_position_buffer",
|
|
render_settings.DisplayWidth,
|
|
render_settings.DisplayHeight,
|
|
GL_RGBA32F,
|
|
GL_NEAREST,
|
|
GL_NEAREST, 1);
|
|
|
|
|
|
// engine->TextureBufferManager()->BindTexture(depth);
|
|
// engine->TextureBufferManager()->BindTexture(buffer_0);
|
|
texture_buffers.resize(16);
|
|
texture_buffers[0] = depth;
|
|
texture_buffers[1] = buffer_0;
|
|
texture_buffers[2] = metal_rough;
|
|
texture_buffers[3] = normal;
|
|
texture_buffers[4] = position;
|
|
}
|
|
|
|
void HydraOutputActor::_CreateMesh()
|
|
{
|
|
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
|
|
HydraID mesh_id = mesh_manager->CreateMesh();
|
|
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
|
|
|
mesh->vertexes.resize(4);
|
|
mesh->indexes.resize(6);
|
|
|
|
float scale_x = 1.0f;
|
|
float scale_y = 1.0f;
|
|
float scale_z = 1.0f;
|
|
|
|
float min_x = -0.5f * scale_x;
|
|
float min_y = -0.5f * scale_y;
|
|
float min_z = 0.5f * scale_z;
|
|
|
|
float max_x = 0.5f * scale_x;
|
|
float max_y = 0.5f * scale_y;
|
|
float max_z = 0.5f * scale_z;
|
|
|
|
float min_u = 0;
|
|
float min_v = 0;
|
|
|
|
float max_u = 1;
|
|
float max_v = 1;
|
|
|
|
// 1---2 5---6
|
|
// | / | | / |
|
|
// 0---3 4---7
|
|
|
|
HydraID actor_id = GetID();
|
|
mesh->vertexes[0] = {min_x, min_y, min_z, min_u, min_v, actor_id, 0, 0, 0,0,0,0,0,0,0,0,0};
|
|
mesh->vertexes[1] = {min_x, max_y, min_z, min_u, max_v, actor_id, 0, 0, 0,0,0,0,0,0,0,0,0};
|
|
mesh->vertexes[2] = {max_x, max_y, min_z, max_u, max_v, actor_id, 0, 0, 0,0,0,0,0,0,0,0,0};
|
|
mesh->vertexes[3] = {max_x, min_y, min_z, max_u, min_v, actor_id, 0, 0, 0,0,0,0,0,0,0,0,0};
|
|
|
|
// Face 0
|
|
mesh->indexes[0] = 0;
|
|
mesh->indexes[1] = 1;
|
|
mesh->indexes[2] = 2;
|
|
|
|
mesh->indexes[3] = 0;
|
|
mesh->indexes[4] = 2;
|
|
mesh->indexes[5] = 3;
|
|
|
|
|
|
HydraECS *ecs = GetEngine()->ECS();
|
|
HydraMeshComponent mesh_comp;
|
|
|
|
mesh_comp.mesh_id = mesh_id;
|
|
mesh_comp.mesh_state = HYDRA_STATE::Waiting;
|
|
|
|
ecs->AddComponent<HydraMeshComponent>(GetID(), mesh_comp);
|
|
}
|
|
|
|
void HydraOutputActor::_CreateRenderableComponent()
|
|
{
|
|
HydraRenderableComponent render_comp;
|
|
HydraECS *ecs = GetEngine()->ECS();
|
|
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_OUTPUT, true);
|
|
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
|
|
}
|
|
|
|
|
|
void HydraOutputActor::InitialiseComponents()
|
|
{
|
|
_CreateMaterial();
|
|
_CreateMesh();
|
|
_CreateRenderableComponent();
|
|
}
|