Cleaning up shutdown
This commit is contained in:
@@ -490,7 +490,7 @@ float SampleCubemapShadow(vec3 frag_to_light, float far_plane, float view_distan
|
||||
);
|
||||
|
||||
float shadow = 0.0;
|
||||
float bias = 0.01;
|
||||
float bias = 0.05;
|
||||
int samples = 20;
|
||||
|
||||
|
||||
|
||||
@@ -34,30 +34,20 @@ layout (location=0) in GEOM_OUT
|
||||
flat uint vsMaterialID;
|
||||
}geom_out;
|
||||
|
||||
layout (location=0) out vec4 output_colour;
|
||||
|
||||
void main()
|
||||
{
|
||||
MaterialStore mat = materials[geom_out.vsMaterialID];
|
||||
vec4 diffuse_val = mat.diffuse_colour;
|
||||
|
||||
output_colour = vec4(1,0,0,1);
|
||||
|
||||
if(mat.diffuse_texture_id != INVALID_HYDRA_ID)
|
||||
{
|
||||
output_colour = vec4(0,1,0,1);
|
||||
uvec2 diffuse_handle = textures[mat.diffuse_texture_id];
|
||||
diffuse_val = diffuse_val * texture(sampler2D(diffuse_handle), geom_out.vsUV.xy);
|
||||
if(mat.diffuse_texture_id== 10)
|
||||
{
|
||||
output_colour = vec4(0,0,1,1);
|
||||
}
|
||||
}
|
||||
|
||||
if(diffuse_val[3] < 1.0)
|
||||
{
|
||||
discard;
|
||||
output_colour = vec4(0,1,1,1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class CLASS_DEFINE HydraActor : public HydraObject
|
||||
virtual void DeferredInitialiseComponents() {};
|
||||
HydraID GetID() {return m_id;}
|
||||
virtual void FixedTick(float delta_t) {};
|
||||
virtual void Destroy() = 0;
|
||||
virtual void Destroy()= 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -27,8 +27,16 @@ std::vector<HydraID> &HydraActorManager::GetChildren(HydraID actor_id)
|
||||
}
|
||||
|
||||
void HydraActorManager::DeleteActor(HydraID actorID)
|
||||
{
|
||||
m_actors_waiting_for_delete.push_back(actorID);
|
||||
{
|
||||
assert(actorID <= m_actors.size() && "DeleteActor::INVALID ACTOR ID");
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if(m_actors[actorID] != nullptr)
|
||||
{
|
||||
|
||||
m_actors[actorID]->Destroy();
|
||||
_SetActorDeleted(actorID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HydraActorManager::_SetActorDeleted(HydraID actorID)
|
||||
@@ -52,197 +60,7 @@ HydraID HydraActorManager::LoadActor(std::string filename)
|
||||
task_scheduler->WaitForTask(load_task_id);
|
||||
return actor_id;
|
||||
}
|
||||
/*
|
||||
HydraID HydraActorManager::_ProcessGLTFNode(aiScene const *scene, aiNode *parent_node, std::vector<uint32_t>material_lookup)
|
||||
{
|
||||
HydraID parent_actor_id = CreateActor<HydraGLTFActor>();
|
||||
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraECSPositionComponent position_component;
|
||||
|
||||
aiVector3D tmp_scaling = {};
|
||||
aiQuaternion tmp_rotation = {};
|
||||
aiVector3D tmp_position = {};
|
||||
|
||||
parent_node->mTransformation.Decompose(tmp_scaling, tmp_rotation, tmp_position);
|
||||
|
||||
glm::dvec3 scaling = glm::dvec3(tmp_scaling.x, tmp_scaling.y, tmp_scaling.z);
|
||||
glm::quat rotation = glm::quat(tmp_rotation.w, tmp_rotation.x, tmp_rotation.y, tmp_rotation.z);
|
||||
glm::dvec3 position = glm::dvec3(tmp_position.x, tmp_position.y, tmp_position.z);
|
||||
|
||||
ecs->AddComponent<HydraECSPositionComponent>(parent_actor_id, position_component);
|
||||
|
||||
SetPosition(parent_actor_id, position, rotation, false);
|
||||
|
||||
for (uint32_t i_mesh = 0; i_mesh < parent_node->mNumMeshes; i_mesh++)
|
||||
{
|
||||
aiMesh *mesh = scene->mMeshes[parent_node->mMeshes[i_mesh]];
|
||||
_ProcessGLTFMesh(scene, parent_actor_id, mesh, material_lookup);
|
||||
}
|
||||
|
||||
for (uint32_t i_node = 0; i_node < parent_node->mNumChildren; i_node++)
|
||||
{
|
||||
HydraID child_actor_id = _ProcessGLTFNode(scene, parent_node->mChildren[i_node], material_lookup);
|
||||
SetRelationship(parent_actor_id, child_actor_id);
|
||||
}
|
||||
return parent_actor_id;
|
||||
}
|
||||
|
||||
void HydraActorManager::_ProcessGLTFMesh(aiScene const *scene, HydraID parent_actor_id, aiMesh *mesh, std::vector<uint32_t>material_lookup)
|
||||
{
|
||||
HydraID mesh_actor_id = CreateActor<HydraGLTFActor>();
|
||||
aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex];
|
||||
std::vector<StandardVertexStruct> vertexes;
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
HydraECSPositionComponent position_component = {};
|
||||
|
||||
ecs->AddComponent<HydraECSPositionComponent>(mesh_actor_id, position_component);
|
||||
|
||||
|
||||
for (uint32_t i_face = 0; i_face < mesh->mNumFaces; i_face++)
|
||||
{
|
||||
aiFace face = mesh->mFaces[i_face];
|
||||
for (uint32_t i_index = 0; i_index < face.mNumIndices; i_index++)
|
||||
{
|
||||
uint32_t current_idx = face.mIndices[i_index];
|
||||
StandardVertexStruct vert = {};
|
||||
if (mesh->HasPositions())
|
||||
{
|
||||
vert.vertex[0] = mesh->mVertices[current_idx].x;
|
||||
vert.vertex[1] = mesh->mVertices[current_idx].y;
|
||||
vert.vertex[2] = mesh->mVertices[current_idx].z;
|
||||
}
|
||||
if (mesh->HasNormals())
|
||||
{
|
||||
vert.normal[0] = mesh->mNormals[current_idx].x;
|
||||
vert.normal[1] = mesh->mNormals[current_idx].y;
|
||||
vert.normal[2] = mesh->mNormals[current_idx].z;
|
||||
}
|
||||
if (mesh->HasTextureCoords(0))
|
||||
{
|
||||
vert.uv[0] = mesh->mTextureCoords[0][current_idx].x;
|
||||
vert.uv[1] = mesh->mTextureCoords[0][current_idx].y;
|
||||
}
|
||||
vert.indexes[0] = mesh_actor_id;
|
||||
vertexes.push_back(vert);
|
||||
}
|
||||
}
|
||||
|
||||
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
|
||||
|
||||
HydraID mesh_id = mesh_manager->CreateMesh(mesh_actor_id);
|
||||
mesh_manager->SetVertexes(mesh_id, vertexes);
|
||||
mesh_manager->CalculateNormals(mesh_id);
|
||||
|
||||
|
||||
HydraECSMeshComponent mesh_comp;
|
||||
mesh_comp.mesh_id = mesh_id;
|
||||
ecs->AddComponent<HydraECSMeshComponent>(mesh_actor_id, mesh_comp);
|
||||
aiString mat_name;
|
||||
mat->Get(AI_MATKEY_NAME, mat_name);
|
||||
|
||||
HydraID material_id = material_lookup[mesh->mMaterialIndex];
|
||||
if(material_id != INVALID_HYDRA_ID)
|
||||
{
|
||||
HydraECSMaterialComponent mat_comp;
|
||||
mat_comp.material_id = material_id;
|
||||
ecs->AddComponent<HydraECSMaterialComponent>(mesh_actor_id, mat_comp);
|
||||
HydraMaterialStruct const * const mat_data = GetEngine()->MaterialManager()->GetMaterial(material_id);
|
||||
GetEngine()->BufferManager()->AddMaterial(mesh_actor_id, material_id, *mat_data);
|
||||
}
|
||||
|
||||
mesh_manager->SetMeshWaiting(mesh_id);
|
||||
//Add renderable component
|
||||
HydraPipelineManager* pipeline_manager = GetEngine()->PipelineManager();
|
||||
|
||||
uint32_t pipeline_id = pipeline_manager->GetPipelineID("FORWARD");
|
||||
uint32_t shadow_pipeline_id = pipeline_manager->GetPipelineID("SHADOW");
|
||||
uint32_t deferred_pipeline_id = pipeline_manager->GetPipelineID("DEFERRED");
|
||||
|
||||
HydraECSRenderableComponent render_comp;
|
||||
|
||||
if(pipeline_id != INVALID_HYDRA_ID)
|
||||
{
|
||||
render_comp.pipelines.set(pipeline_id);
|
||||
}
|
||||
render_comp.pipelines.set(shadow_pipeline_id);
|
||||
render_comp.pipelines.set(deferred_pipeline_id);
|
||||
|
||||
ecs->AddComponent<HydraECSRenderableComponent>(mesh_actor_id, render_comp);
|
||||
SetRelationship(parent_actor_id, mesh_actor_id);
|
||||
}
|
||||
|
||||
/// @brief Load all of the scene textures
|
||||
/// @param scene containing scene
|
||||
/// @param texture_lookup index of texture in the scene to the Hydra texture ID
|
||||
void HydraActorManager::_ProcessGLTFTextures(aiScene const *scene, std::vector<uint32_t> &texture_lookup)
|
||||
{
|
||||
HydraTextureManager *texture_manager = GetEngine()->TextureManager();
|
||||
// Make space for the texture lookups
|
||||
texture_lookup.resize(scene->mNumTextures);
|
||||
|
||||
for (uint32_t i_tex = 0; i_tex < scene->mNumTextures; i_tex++)
|
||||
{
|
||||
aiTexture *tex = scene->mTextures[i_tex];
|
||||
// Create a holder for the texture
|
||||
HydraID texture_id = texture_manager->CreateTexture(0, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false);
|
||||
// load the texture data from the scene texture
|
||||
texture_manager->FillTexture(texture_id, reinterpret_cast<unsigned char *>(tex->pcData), tex->mWidth);
|
||||
// store the texture id against the scene index for the texture. Materials will have *n where n is the index
|
||||
texture_lookup[i_tex] = texture_id;
|
||||
texture_manager->FinaliseTexture(texture_id);
|
||||
}
|
||||
}
|
||||
|
||||
void HydraActorManager::_ProcessGLTFMaterials(aiScene const *scene,
|
||||
std::vector<uint32_t>& texture_lookup,
|
||||
std::vector<uint32_t>& material_lookup,
|
||||
std::string filename)
|
||||
{
|
||||
material_lookup.resize(scene->mNumMaterials);
|
||||
HydraTextureManager *texture_manager = GetEngine()->TextureManager();
|
||||
for (uint32_t i_mat = 0; i_mat < scene->mNumMaterials; i_mat++)
|
||||
{
|
||||
HydraMaterialStruct material;
|
||||
aiMaterial *mat = scene->mMaterials[i_mat];
|
||||
|
||||
aiColor3D color(0.f, 0.f, 0.f);
|
||||
aiString name;
|
||||
|
||||
mat->Get(AI_MATKEY_COLOR_DIFFUSE, color);
|
||||
mat->Get(AI_MATKEY_NAME, name);
|
||||
std::string mat_name = filename + std::to_string(i_mat);
|
||||
aiTexture diffuse_tex;
|
||||
|
||||
uint32_t diffuse_tex_count = mat->GetTextureCount(aiTextureType::aiTextureType_DIFFUSE);
|
||||
|
||||
// have to do something here for multiple diffuse textures at some point.
|
||||
aiString texture_path;
|
||||
aiTextureMapping texture_mapping;
|
||||
uint32_t uv_index;
|
||||
if (diffuse_tex_count > 0)
|
||||
{
|
||||
mat->GetTexture(aiTextureType::aiTextureType_DIFFUSE, 0, &texture_path, &texture_mapping, &uv_index);
|
||||
std::string path = std::string(texture_path.C_Str());
|
||||
uint32_t texture_index = atoi(path.substr(1).c_str());
|
||||
HydraID texture_id = texture_lookup[texture_index];
|
||||
|
||||
material.diffuse_texture = texture_id;
|
||||
material.texture_types += static_cast<uint32_t>(HYDRA_TEXTURE_TYPE::DIFFUSE_TEXTURE);
|
||||
}
|
||||
|
||||
material.diffuse_colour = glm::vec4(color.r, color.g, color.b, 1);
|
||||
|
||||
HydraID material_id = GetEngine()->MaterialManager()->CreateMaterial(mat_name, material);
|
||||
material_lookup[i_mat] = material_id;
|
||||
if (material_id == INVALID_HYDRA_ID)
|
||||
{
|
||||
throw std::runtime_error("Could not create material");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
HydraID HydraActorManager::_SaveActor(HydraActor *actor)
|
||||
{
|
||||
@@ -427,18 +245,7 @@ void HydraActorManager::TranslateActor(HydraID actorID, glm::dvec3 translation)
|
||||
ecs->GetSystem<HydraTransformSystem>()->UpdateTransform(actorID);
|
||||
}
|
||||
|
||||
void HydraActorManager::AddComponentType(HydraID actorID, uint32_t component_type)
|
||||
{
|
||||
if (actorID < m_actors.size())
|
||||
{
|
||||
HydraActor *actor = m_actors[actorID];
|
||||
if (actor != nullptr)
|
||||
{
|
||||
actor->m_component_types.push_back(component_type);
|
||||
actor->m_components_waiting++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
glm::mat4 HydraActorManager::GetActorPose(HydraID actorID)
|
||||
{
|
||||
@@ -474,40 +281,6 @@ glm::dvec3 HydraActorManager::GetActorPosition(HydraID actorID)
|
||||
return pos_comp.position;
|
||||
}
|
||||
|
||||
bool HydraActorManager::HasComponentType(HydraID actorID, uint32_t component_type)
|
||||
{
|
||||
if (actorID < m_actors.size())
|
||||
{
|
||||
HydraActor *actor = m_actors[actorID];
|
||||
if (actor != nullptr)
|
||||
{
|
||||
for (int i = 0; i < actor->m_component_types.size(); i++)
|
||||
{
|
||||
if (actor->m_component_types[i] == component_type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void HydraActorManager::RemoveComponentType(HydraID actorID, uint32_t component_type)
|
||||
{
|
||||
if (actorID < m_actors.size())
|
||||
{
|
||||
HydraActor *actor = m_actors[actorID];
|
||||
if (actor != nullptr)
|
||||
{
|
||||
uint32_t comp_type = static_cast<uint32_t>(component_type);
|
||||
if (actor->m_component_types.size() > comp_type)
|
||||
{
|
||||
actor->m_component_types.erase(actor->m_component_types.begin() + comp_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HydraID HydraActorManager::GetParent(HydraID actor_id)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@ class CLASS_DEFINE HydraActorManager : public HydraObject
|
||||
public:
|
||||
void Initialise(size_t max_actors);
|
||||
template<class T> HydraID CreateActor();
|
||||
|
||||
HydraID LoadActor(std::string filename);
|
||||
|
||||
void DeleteActor(HydraID actorID);
|
||||
@@ -52,9 +53,9 @@ class CLASS_DEFINE HydraActorManager : public HydraObject
|
||||
void TranslateActor(HydraID actorID, glm::dvec3 translation);
|
||||
|
||||
void SetRelationship(HydraID parent_id, HydraID child_id);
|
||||
void AddComponentType(HydraID actorID, uint32_t component_type);
|
||||
bool HasComponentType(HydraID actorID, uint32_t component_type);
|
||||
void RemoveComponentType(HydraID actorID, uint32_t component_type);
|
||||
// void AddComponentType(HydraID actorID, uint32_t component_type);
|
||||
// bool HasComponentType(HydraID actorID, uint32_t component_type);
|
||||
// void RemoveComponentType(HydraID actorID, uint32_t component_type);
|
||||
|
||||
HydraID GetParent(HydraID actor_id);
|
||||
HydraID GetRoot(HydraID actor_id);
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
#include "HydraPlanetActor.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 HydraPlanetActor::InitialiseComponents()
|
||||
{
|
||||
// HydraECS* ecs = GetEngine()->ECS();
|
||||
// HydraID entity_id = ecs->CreateEntity();
|
||||
_CreatePosition();
|
||||
// _CreatePhysics();
|
||||
|
||||
_CreateMaterial();
|
||||
_CreateMesh();
|
||||
_CreateRenderableComponent();
|
||||
_CreateQuads();
|
||||
}
|
||||
|
||||
void HydraPlanetActor::DeferredInitialiseComponents()
|
||||
{
|
||||
}
|
||||
|
||||
void HydraPlanetActor::_CreatePosition()
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraPositionComponent position_component;
|
||||
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
|
||||
}
|
||||
|
||||
void HydraPlanetActor::_CreateMesh()
|
||||
{
|
||||
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
|
||||
HydraID mesh_id = mesh_manager->CreateMesh();
|
||||
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
||||
|
||||
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
|
||||
|
||||
mesh->vertexes.resize(24);
|
||||
mesh->indexes.resize(36);
|
||||
|
||||
float scale_x = 10000.0f;
|
||||
float scale_y = 10000.0f;
|
||||
float scale_z = 10000.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 = 100;
|
||||
float min_v = 100;
|
||||
|
||||
float max_u = 0;
|
||||
float max_v = 0;
|
||||
|
||||
// 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, mat_comp.material_id, 0};
|
||||
mesh->vertexes[1] = {min_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[2] = {max_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[3] = {max_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 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;
|
||||
|
||||
mesh->vertexes[4] = {max_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[5] = {max_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[6] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[7] = {max_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[6] = 4;
|
||||
mesh->indexes[7] = 5;
|
||||
mesh->indexes[8] = 6;
|
||||
|
||||
mesh->indexes[9] = 4;
|
||||
mesh->indexes[10] = 6;
|
||||
mesh->indexes[11] = 7;
|
||||
|
||||
// Back Face
|
||||
mesh->vertexes[8] = {max_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[9] = {max_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[10] = {min_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[11] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[12] = 8;
|
||||
mesh->indexes[13] = 9;
|
||||
mesh->indexes[14] = 10;
|
||||
|
||||
mesh->indexes[15] = 8;
|
||||
mesh->indexes[16] = 10;
|
||||
mesh->indexes[17] = 11;
|
||||
|
||||
mesh->vertexes[12] = {min_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[13] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[14] = {min_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[15] = {min_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[18] = 12;
|
||||
mesh->indexes[19] = 13;
|
||||
mesh->indexes[20] = 14;
|
||||
|
||||
mesh->indexes[21] = 12;
|
||||
mesh->indexes[22] = 14;
|
||||
mesh->indexes[23] = 15;
|
||||
|
||||
mesh->vertexes[16] = {min_x, max_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[17] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[18] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[19] = {max_x, max_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[24] = 16;
|
||||
mesh->indexes[25] = 17;
|
||||
mesh->indexes[26] = 18;
|
||||
|
||||
mesh->indexes[27] = 16;
|
||||
mesh->indexes[28] = 18;
|
||||
mesh->indexes[29] = 19;
|
||||
|
||||
mesh->vertexes[20] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[21] = {max_x, min_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[22] = {max_x, min_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[23] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[30] = 20;
|
||||
mesh->indexes[31] = 21;
|
||||
mesh->indexes[32] = 22;
|
||||
|
||||
mesh->indexes[33] = 20;
|
||||
mesh->indexes[34] = 22;
|
||||
mesh->indexes[35] = 23;
|
||||
|
||||
mesh_manager->CalculateNormals(mesh->mesh_id);
|
||||
|
||||
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 HydraPlanetActor::_CreateMaterial()
|
||||
{
|
||||
|
||||
HydraEngine *engine = GetEngine();
|
||||
std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo_white.png");
|
||||
|
||||
HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
|
||||
|
||||
HydraMaterialBuffer material = {};
|
||||
|
||||
material.diffuse_texture_id = tex_id;
|
||||
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
|
||||
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
|
||||
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
|
||||
|
||||
HydraMaterialComponent mat_comp = {};
|
||||
mat_comp.material_id = mat_id;
|
||||
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
|
||||
}
|
||||
|
||||
void HydraPlanetActor::_CreatePhysics()
|
||||
{
|
||||
// HydraECSPhysicsComponent physics_component;
|
||||
// physics_component.physics_state = Hydra_State::Waiting;
|
||||
// physics_component.physics_definition.actor_id = GetID();
|
||||
// physics_component.physics_definition.physics_type = HydraPhyicsType::Static;
|
||||
// physics_component.physics_definition.physics_shape = HydraPhysicsShape::HydraBoxShape;
|
||||
// physics_component.physics_definition.mass = 100000.0f;
|
||||
// physics_component.physics_definition.extent_x = 1000.0f;
|
||||
// physics_component.physics_definition.extent_y = 0.5f;
|
||||
// physics_component.physics_definition.extent_z = 1000.0f;
|
||||
// physics_component.physics_definition.dynamic_friction = 0.5f;
|
||||
// physics_component.physics_definition.restitution = 0.5f;
|
||||
|
||||
// HydraECS* ecs = GetEngine()->ECS();
|
||||
|
||||
// ecs->AddComponent<HydraECSPhysicsComponent>(GetID(), physics_component);
|
||||
}
|
||||
void HydraPlanetActor::_CreateRenderableComponent()
|
||||
{
|
||||
HydraRenderableComponent render_comp;
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
|
||||
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
|
||||
}
|
||||
|
||||
void HydraPlanetActor::_CreateQuads()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef HYDRAPLANETACTOR
|
||||
#define HYDRAPLANETACTOR
|
||||
|
||||
#include "../HydraActor.h"
|
||||
|
||||
class CLASS_DEFINE HydraPlanetActor : public HydraActor
|
||||
{
|
||||
private:
|
||||
double m_scale = 1.0;
|
||||
double m_widthscale = 1000.0f;
|
||||
HydraID m_material_component = INVALID_HYDRA_ID;
|
||||
HydraID m_position_component = INVALID_HYDRA_ID;
|
||||
HydraID m_mesh_component = INVALID_HYDRA_ID;
|
||||
protected:
|
||||
void _CreatePosition();
|
||||
void _CreateMesh();
|
||||
void _CreateMaterial();
|
||||
void _CreatePhysics();
|
||||
void _CreateRenderableComponent();
|
||||
void _CreateQuads();
|
||||
public:
|
||||
virtual void InitialiseComponents();
|
||||
virtual void DeferredInitialiseComponents();
|
||||
virtual void Destroy(){}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* HYDRAPLANETACTOR */
|
||||
@@ -0,0 +1,208 @@
|
||||
#include "HydraPlanetQuadActor.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 HydraPlanetQuadActor::InitialiseComponents()
|
||||
{
|
||||
// HydraECS* ecs = GetEngine()->ECS();
|
||||
// HydraID entity_id = ecs->CreateEntity();
|
||||
_CreatePosition();
|
||||
// _CreatePhysics();
|
||||
|
||||
_CreateMaterial();
|
||||
_CreateMesh();
|
||||
_CreateRenderableComponent();
|
||||
}
|
||||
|
||||
void HydraPlanetQuadActor::DeferredInitialiseComponents()
|
||||
{
|
||||
}
|
||||
|
||||
void HydraPlanetQuadActor::_CreatePosition()
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
HydraPositionComponent position_component;
|
||||
ecs->AddComponent<HydraPositionComponent>(GetID(), position_component);
|
||||
}
|
||||
|
||||
void HydraPlanetQuadActor::_CreateMesh()
|
||||
{
|
||||
HydraMeshManager *mesh_manager = GetEngine()->MeshManager();
|
||||
HydraID mesh_id = mesh_manager->CreateMesh();
|
||||
HydraMesh *mesh = mesh_manager->GetMesh(mesh_id);
|
||||
|
||||
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(GetID());
|
||||
|
||||
mesh->vertexes.resize(24);
|
||||
mesh->indexes.resize(36);
|
||||
|
||||
float scale_x = 10000.0f;
|
||||
float scale_y = 10000.0f;
|
||||
float scale_z = 10000.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 = 100;
|
||||
float min_v = 100;
|
||||
|
||||
float max_u = 0;
|
||||
float max_v = 0;
|
||||
|
||||
// 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, mat_comp.material_id, 0};
|
||||
mesh->vertexes[1] = {min_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[2] = {max_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[3] = {max_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 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;
|
||||
|
||||
mesh->vertexes[4] = {max_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[5] = {max_x, max_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[6] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[7] = {max_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[6] = 4;
|
||||
mesh->indexes[7] = 5;
|
||||
mesh->indexes[8] = 6;
|
||||
|
||||
mesh->indexes[9] = 4;
|
||||
mesh->indexes[10] = 6;
|
||||
mesh->indexes[11] = 7;
|
||||
|
||||
// Back Face
|
||||
mesh->vertexes[8] = {max_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[9] = {max_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[10] = {min_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[11] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[12] = 8;
|
||||
mesh->indexes[13] = 9;
|
||||
mesh->indexes[14] = 10;
|
||||
|
||||
mesh->indexes[15] = 8;
|
||||
mesh->indexes[16] = 10;
|
||||
mesh->indexes[17] = 11;
|
||||
|
||||
mesh->vertexes[12] = {min_x, min_y, max_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[13] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[14] = {min_x, max_y, min_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[15] = {min_x, min_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[18] = 12;
|
||||
mesh->indexes[19] = 13;
|
||||
mesh->indexes[20] = 14;
|
||||
|
||||
mesh->indexes[21] = 12;
|
||||
mesh->indexes[22] = 14;
|
||||
mesh->indexes[23] = 15;
|
||||
|
||||
mesh->vertexes[16] = {min_x, max_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[17] = {min_x, max_y, max_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[18] = {max_x, max_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[19] = {max_x, max_y, min_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[24] = 16;
|
||||
mesh->indexes[25] = 17;
|
||||
mesh->indexes[26] = 18;
|
||||
|
||||
mesh->indexes[27] = 16;
|
||||
mesh->indexes[28] = 18;
|
||||
mesh->indexes[29] = 19;
|
||||
|
||||
mesh->vertexes[20] = {min_x, min_y, min_z, min_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[21] = {max_x, min_y, min_z, min_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[22] = {max_x, min_y, max_z, max_u, max_v, actor_id, mat_comp.material_id, 0};
|
||||
mesh->vertexes[23] = {min_x, min_y, max_z, max_u, min_v, actor_id, mat_comp.material_id, 0};
|
||||
|
||||
mesh->indexes[30] = 20;
|
||||
mesh->indexes[31] = 21;
|
||||
mesh->indexes[32] = 22;
|
||||
|
||||
mesh->indexes[33] = 20;
|
||||
mesh->indexes[34] = 22;
|
||||
mesh->indexes[35] = 23;
|
||||
|
||||
mesh_manager->CalculateNormals(mesh->mesh_id);
|
||||
|
||||
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 HydraPlanetQuadActor::_CreateMaterial()
|
||||
{
|
||||
|
||||
HydraEngine *engine = GetEngine();
|
||||
std::string filename = std::string(texture_base) + std::string("/DesignArea/DesignArea_Albedo_white.png");
|
||||
|
||||
HydraID tex_id = engine->TextureBufferManager()->LoadTexture(filename);
|
||||
|
||||
HydraMaterialBuffer material = {};
|
||||
|
||||
material.diffuse_texture_id = tex_id;
|
||||
material.diffuse_colour = glm::vec4(1, 1, 1, 1);
|
||||
material.metalic_rough = glm::vec4(0, 0.5, 0.3, 1);
|
||||
HydraID mat_id = engine->MaterialBufferManager()->CreateMaterial(material);
|
||||
|
||||
HydraMaterialComponent mat_comp = {};
|
||||
mat_comp.material_id = mat_id;
|
||||
engine->ECS()->AddComponent<HydraMaterialComponent>(GetID(), mat_comp);
|
||||
}
|
||||
|
||||
void HydraPlanetQuadActor::_CreatePhysics()
|
||||
{
|
||||
// HydraECSPhysicsComponent physics_component;
|
||||
// physics_component.physics_state = Hydra_State::Waiting;
|
||||
// physics_component.physics_definition.actor_id = GetID();
|
||||
// physics_component.physics_definition.physics_type = HydraPhyicsType::Static;
|
||||
// physics_component.physics_definition.physics_shape = HydraPhysicsShape::HydraBoxShape;
|
||||
// physics_component.physics_definition.mass = 100000.0f;
|
||||
// physics_component.physics_definition.extent_x = 1000.0f;
|
||||
// physics_component.physics_definition.extent_y = 0.5f;
|
||||
// physics_component.physics_definition.extent_z = 1000.0f;
|
||||
// physics_component.physics_definition.dynamic_friction = 0.5f;
|
||||
// physics_component.physics_definition.restitution = 0.5f;
|
||||
|
||||
// HydraECS* ecs = GetEngine()->ECS();
|
||||
|
||||
// ecs->AddComponent<HydraECSPhysicsComponent>(GetID(), physics_component);
|
||||
}
|
||||
void HydraPlanetQuadActor::_CreateRenderableComponent()
|
||||
{
|
||||
HydraRenderableComponent render_comp;
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
render_comp.renderable_types.set((uint32_t)HYDRA_RENDERABLE_TYPE::HYDRA_COLOUR, true);
|
||||
ecs->AddComponent<HydraRenderableComponent>(GetID(), render_comp);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef HYDRAPLANETQUADACTOR
|
||||
#define HYDRAPLANETQUADACTOR
|
||||
|
||||
|
||||
#include "../HydraActor.h"
|
||||
|
||||
class CLASS_DEFINE HydraPlanetQuadActor : public HydraActor
|
||||
{
|
||||
private:
|
||||
double m_scale = 1.0;
|
||||
double m_widthscale = 1000.0f;
|
||||
HydraID m_material_component = INVALID_HYDRA_ID;
|
||||
HydraID m_position_component = INVALID_HYDRA_ID;
|
||||
HydraID m_mesh_component = INVALID_HYDRA_ID;
|
||||
protected:
|
||||
void _CreatePosition();
|
||||
void _CreateMesh();
|
||||
void _CreateMaterial();
|
||||
void _CreatePhysics();
|
||||
void _CreateRenderableComponent();
|
||||
public:
|
||||
virtual void InitialiseComponents();
|
||||
virtual void DeferredInitialiseComponents();
|
||||
virtual void Destroy(){}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* HYDRAPLANETQUADACTOR */
|
||||
@@ -16,7 +16,8 @@ class HydraBufferManager : public HydraObject
|
||||
HydraID CreateGPUBuffer(std::string buffer_name,
|
||||
uint32_t buffer_size_bytes,
|
||||
uint32_t binding,
|
||||
HYDRA_BUFFER_TYPE buffer_type);
|
||||
HYDRA_BUFFER_TYPE buffer_type);
|
||||
|
||||
void DeleteBuffer(HydraID buffer_id);
|
||||
void UpdatePartialBuffer(HydraID buffer_id, uint32_t start, uint32_t size, void *data);
|
||||
void UpdateWholeBuffer(HydraID buffer_id, void* data);
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "../task/buffer/HydraCreateUnBoundTextureTask.hpp"
|
||||
#include "../task/renderer/HydraCreateCascadeShadowFrameBuffer.hpp"
|
||||
#include "../task/renderer/HydraCreateShadowFrameBuffer.hpp"
|
||||
#include "../task/renderer/HydraDeleteShadowFrameBufferTask.hpp"
|
||||
#include "../ecs/components/HydraDirectionalShadowSourceComponent.h"
|
||||
|
||||
void HydraShadowBufferManager::Initialise()
|
||||
{
|
||||
@@ -118,17 +120,42 @@ void HydraShadowBufferManager::UpdatePointShadow(HydraID shadow_id, HydraPointSh
|
||||
}
|
||||
}
|
||||
|
||||
void HydraShadowBufferManager::RemoveDirectionalShadow(HydraID shadow_id)
|
||||
void HydraShadowBufferManager::DeleteDirectionalShadow(HydraID shadow_id)
|
||||
{
|
||||
HydraECS* ecs = GetEngine()->ECS();
|
||||
HydraTaskScheduler* task_scheduler = GetEngine()->TaskScheduler();
|
||||
HydraDirectionalShadowSourceComponent shadow_comp = m_directional_shadow_buffer[shadow_id];
|
||||
|
||||
HydraID delete_frame_buffer_task_id = task_scheduler->CreateTask<HydraDeleteShadowFrameBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraDeleteShadowFrameBufferTask *fb_task = static_cast<HydraDeleteShadowFrameBufferTask *>(task_scheduler->GetTask(delete_frame_buffer_task_id));
|
||||
|
||||
fb_task->Initialise(shadow_comp.shadow_texture_id, shadow_comp.frame_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_frame_buffer_task_id);
|
||||
}
|
||||
void HydraShadowBufferManager::RemoveSpotShadow(HydraID shadow_id)
|
||||
void HydraShadowBufferManager::DeleteSpotShadow(HydraID shadow_id)
|
||||
{
|
||||
HydraECS* ecs = GetEngine()->ECS();
|
||||
HydraTaskScheduler* task_scheduler = GetEngine()->TaskScheduler();
|
||||
HydraSpotShadowSourceComponent shadow_comp = m_spot_shadow_buffer[shadow_id];
|
||||
|
||||
HydraID delete_frame_buffer_task_id = task_scheduler->CreateTask<HydraDeleteShadowFrameBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraDeleteShadowFrameBufferTask *fb_task = static_cast<HydraDeleteShadowFrameBufferTask *>(task_scheduler->GetTask(delete_frame_buffer_task_id));
|
||||
|
||||
fb_task->Initialise(shadow_comp.shadow_texture_id, shadow_comp.frame_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_frame_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraShadowBufferManager::RemovePointShadow(HydraID shadow_id)
|
||||
void HydraShadowBufferManager::DeletePointShadow(HydraID shadow_id)
|
||||
{
|
||||
HydraECS* ecs = GetEngine()->ECS();
|
||||
HydraTaskScheduler* task_scheduler = GetEngine()->TaskScheduler();
|
||||
HydraPointShadowSourceComponent shadow_comp = m_point_shadow_buffer[shadow_id];
|
||||
|
||||
HydraID delete_frame_buffer_task_id = task_scheduler->CreateTask<HydraDeleteShadowFrameBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraDeleteShadowFrameBufferTask *fb_task = static_cast<HydraDeleteShadowFrameBufferTask *>(task_scheduler->GetTask(delete_frame_buffer_task_id));
|
||||
|
||||
fb_task->Initialise(shadow_comp.shadow_texture_id, shadow_comp.frame_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_frame_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraShadowBufferManager::UpdateShadowBuffer()
|
||||
|
||||
@@ -23,9 +23,9 @@ class HydraShadowBufferManager : public HydraObject
|
||||
void UpdateSpotShadow(HydraID shadow_id, HydraSpotShadowSourceComponent shadow);
|
||||
void UpdatePointShadow(HydraID shadow_id, HydraPointShadowSourceComponent shadow);
|
||||
|
||||
void RemoveDirectionalShadow(HydraID shadow_id);
|
||||
void RemoveSpotShadow(HydraID shadow_id);
|
||||
void RemovePointShadow(HydraID shadow_id);
|
||||
void DeleteDirectionalShadow(HydraID shadow_id);
|
||||
void DeleteSpotShadow(HydraID shadow_id);
|
||||
void DeletePointShadow(HydraID shadow_id);
|
||||
|
||||
void UpdateShadowBuffer();
|
||||
private:
|
||||
|
||||
@@ -195,8 +195,7 @@ HydraID HydraTextureBufferManager::CreateTexture(std::string texture_name,
|
||||
glCreateTextures(GL_TEXTURE_2D, 1, &gl_tex_id);
|
||||
glBindTexture(GL_TEXTURE_2D, gl_tex_id);
|
||||
|
||||
glTextureStorage2D(gl_tex_id,1+ mip_levels, internal_format, width, height);
|
||||
|
||||
glTextureStorage2D(gl_tex_id,1+ mip_levels, internal_format, width, height);
|
||||
if (data != nullptr)
|
||||
{
|
||||
glTextureSubImage2D(
|
||||
@@ -264,4 +263,5 @@ void HydraTextureBufferManager::DeleteTexture(HydraID texture_id)
|
||||
{
|
||||
UnbindTexture(m_bindless_texture_ids[texture_id]);
|
||||
}
|
||||
glDeleteTextures(1, &m_textures[texture_id].gl_tex_id);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ void HydraECS::Init()
|
||||
|
||||
void HydraECS::Shutdown()
|
||||
{
|
||||
|
||||
m_system_manager->Shutdown();
|
||||
m_component_manager.release();
|
||||
m_entity_manager.release();
|
||||
|
||||
@@ -23,9 +23,10 @@ public:
|
||||
}
|
||||
void DestroyEntity(HydraID entity_id)
|
||||
{
|
||||
m_system_manager->EntityDeleted(entity_id);
|
||||
m_entity_manager->DeleteEntity(entity_id);
|
||||
m_component_manager->EntityDeleted(entity_id);
|
||||
m_system_manager->EntityDeleted(entity_id);
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -6,7 +6,14 @@ void HydraSystem::Update(float delta_t_seconds)
|
||||
UpdateSystem(delta_t_seconds);
|
||||
|
||||
}
|
||||
|
||||
void HydraSystem::Shutdown()
|
||||
{
|
||||
for(HydraID entity_id : Entities)
|
||||
{
|
||||
DestroyComponents(entity_id);
|
||||
}
|
||||
FreeSystemResources();
|
||||
}
|
||||
void HydraSystem::InitialiseComponents()
|
||||
{
|
||||
for(auto it = EntitiesToCreate.begin(); it != EntitiesToCreate.end(); ++it)
|
||||
@@ -16,3 +23,13 @@ void HydraSystem::InitialiseComponents()
|
||||
}
|
||||
EntitiesToCreate.clear();
|
||||
}
|
||||
|
||||
void HydraSystem::DestroyComponents(HydraID actor_id)
|
||||
{
|
||||
auto it = std::find(Entities.begin(), Entities.end(), actor_id);
|
||||
if(it == Entities.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
DestroyComponent(actor_id);
|
||||
}
|
||||
|
||||
@@ -13,13 +13,15 @@ class HydraSystem : public HydraObject
|
||||
|
||||
void Update(float delta_t_seconds);
|
||||
void InitialiseComponents();
|
||||
virtual void Shutdown() {};
|
||||
void DestroyComponents(HydraID actor_id);
|
||||
virtual void Shutdown();
|
||||
virtual void Initialise(){};
|
||||
protected:
|
||||
|
||||
virtual void UpdateSystem(float delta_t_seconds) = 0;
|
||||
virtual void InitialiseComponent(HydraID actor_id) {};
|
||||
|
||||
virtual void DestroyComponent(HydraID actor_id) {};
|
||||
virtual void FreeSystemResources(){};
|
||||
};
|
||||
|
||||
#endif /* HYDRASYSTEM */
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
// Entity signature does not match system signature - erase from set
|
||||
else
|
||||
{
|
||||
system->DestroyComponents(entity_id);
|
||||
system->Entities.erase(entity_id);
|
||||
system->EntitiesToCreate.erase(entity_id);
|
||||
}
|
||||
@@ -82,6 +83,7 @@ public:
|
||||
for (auto const& pair : m_systems)
|
||||
{
|
||||
auto const& system = pair.second;
|
||||
system->DestroyComponents(entity_id);
|
||||
system->Entities.erase(entity_id);
|
||||
system->EntitiesToCreate.erase(entity_id);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "../../task/buffer/HydraUpdateWholeGPUBufferTask.hpp"
|
||||
#include "../../task/buffer/HydraUpdatePartialGPUBufferTask.hpp"
|
||||
#include "../../task/buffer/HydraCreateUnBoundTextureTask.hpp"
|
||||
#include "../../task/buffer/HydraDeleteTextureTask.hpp"
|
||||
#include "../../task/renderer/HydraCreateCascadeShadowFrameBuffer.hpp"
|
||||
#include "../../task/renderer/HydraCreateShadowFrameBuffer.hpp"
|
||||
#include "../../actor/HydraActorManager.h"
|
||||
@@ -42,10 +43,15 @@ void HydraDirectionalShadowSourceSystem::InitialiseComponent(HydraID entity_id)
|
||||
light_comp.shadow_caster = 1;
|
||||
shadow_comp.shadow_id = shadow_id;
|
||||
_InitialiseShadowMap(entity_id);
|
||||
}
|
||||
|
||||
// m_shadow_actor_id = GetEngine()->ActorManager()->CreateActor<HydraTestCubeActor>();
|
||||
// GetEngine()->ActorManager()->InitialiseActor(m_shadow_actor_id);
|
||||
// GetEngine()->ActorManager()->SetPosition(m_shadow_actor_id, glm::dvec3(0, 0, 0));
|
||||
void HydraDirectionalShadowSourceSystem::DestroyComponent(HydraID entity_id)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraDirectionalShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
|
||||
GetEngine()->ShadowBufferManager()->DeleteDirectionalShadow(shadow_comp.shadow_id);
|
||||
|
||||
}
|
||||
|
||||
void HydraDirectionalShadowSourceSystem::UpdateSystem(float delta_t_seconds)
|
||||
@@ -119,7 +125,7 @@ void HydraDirectionalShadowSourceSystem::_InitialiseShadowMap(HydraID entity_id)
|
||||
uint32_t depth_texture_id = 0;
|
||||
HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateCascadeShadowFrameBuffer>(HydraThreadAffinity::Render);
|
||||
HydraCreateCascadeShadowFrameBuffer *fb_task = static_cast<HydraCreateCascadeShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
|
||||
fb_task->Initialise(&shad_comp.shadow_texture_id, &depth_texture_id, &shad_comp.frame_buffer_id);
|
||||
fb_task->Initialise(&depth_texture_id, &shad_comp.frame_buffer_id);
|
||||
|
||||
task_scheduler->WaitForTask(create_framebuffer_task_id);
|
||||
shad_comp.shadow_texture_id = depth_texture_id;
|
||||
|
||||
@@ -14,9 +14,11 @@ class HydraDirectionalShadowSourceSystem : public HydraSystem
|
||||
virtual void Initialise() override;
|
||||
protected:
|
||||
void InitialiseComponent(HydraID entity_id) override;
|
||||
void DestroyComponent(HydraID entity_id) override;
|
||||
void UpdateSystem(float delta_t_seconds) override;
|
||||
private:
|
||||
void _UpdateShadowMap(HydraID entity_id);
|
||||
|
||||
void _InitialiseShadowMap(HydraID entity_id);
|
||||
HydraID m_shadow_actor_id = INVALID_HYDRA_ID;
|
||||
std::mutex m_mutex;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "../../scheduler/HydraTaskScheduler.h"
|
||||
#include "../../task/buffer/HydraCreateGPUBufferTask.hpp"
|
||||
#include "../../task/buffer/HydraDeleteGPUBufferTask.hpp"
|
||||
#include "../../task/buffer/HydraUpdatePartialGPUBufferTask.hpp"
|
||||
#include "../../actor/HydraActorManager.h"
|
||||
#include <GLMIncludes.h>
|
||||
@@ -38,6 +39,15 @@ void HydraLightSystem::InitialiseComponent(HydraID entity_id)
|
||||
m_lights.push_back(light_comp);
|
||||
}
|
||||
|
||||
void HydraLightSystem::FreeSystemResources()
|
||||
{
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
HydraID delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraDeleteGPUBufferTask *task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
|
||||
task->Intialise(m_light_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraLightSystem::UpdateSystem(float delta_t_seconds)
|
||||
{
|
||||
_WriteToGPU();
|
||||
|
||||
@@ -17,6 +17,7 @@ class HydraLightSystem : public HydraSystem
|
||||
uint32_t GetLightCount();
|
||||
protected:
|
||||
void InitialiseComponent(HydraID entity_id) override;
|
||||
void FreeSystemResources() override;
|
||||
virtual void UpdateSystem(float delta_t_seconds);
|
||||
private:
|
||||
void _WriteToGPU();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "../../scheduler/HydraTaskScheduler.h"
|
||||
#include "../../task/buffer/HydraCreateGPUBufferTask.hpp"
|
||||
#include "../../task/buffer/HydraDeleteGPUBufferTask.hpp"
|
||||
#include "../../task/buffer/HydraUpdateWholeGPUBufferTask.hpp"
|
||||
#include "../../actor/HydraActorManager.h"
|
||||
|
||||
@@ -32,6 +33,21 @@ void HydraMaterialSystem::InitialiseComponent(HydraID entity_id)
|
||||
{
|
||||
}
|
||||
|
||||
void HydraMaterialSystem::FreeSystemResources()
|
||||
{
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraDeleteGPUBufferTask *task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
|
||||
task->Intialise(m_material_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
|
||||
|
||||
delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
|
||||
task->Intialise(m_texture_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraMaterialSystem::UpdateSystem(float delta_t_seconds)
|
||||
{
|
||||
_WriteToGPU();
|
||||
|
||||
@@ -15,7 +15,10 @@ class HydraMaterialSystem : public HydraSystem
|
||||
void Initialise() override;
|
||||
protected:
|
||||
void InitialiseComponent(HydraID entity_id) override;
|
||||
void FreeSystemResources() override;
|
||||
virtual void UpdateSystem(float delta_t_seconds);
|
||||
|
||||
|
||||
private:
|
||||
void _WriteToGPU();
|
||||
HydraID m_material_buffer_id = INVALID_HYDRA_ID;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "../../buffer/HydraBufferManager.h"
|
||||
#include "../../scheduler/HydraTaskScheduler.h"
|
||||
#include "../../task/buffer/HydraCreateVertexBufferTask.hpp"
|
||||
|
||||
#include "../../task/buffer/HydraDeleteVertexBufferTask.hpp"
|
||||
#include "../../task/buffer/HydraUpdateVertexBufferTask.hpp"
|
||||
#include "../../mesh/HydraMeshManager.h"
|
||||
void HydraMeshSystem::Initialise()
|
||||
@@ -13,6 +13,8 @@ void HydraMeshSystem::Initialise()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HydraMeshSystem::InitialiseComponent(HydraID entity_id)
|
||||
{
|
||||
HydraECS* ecs = GetEngine()->ECS();
|
||||
@@ -42,3 +44,19 @@ void HydraMeshSystem::InitialiseComponent(HydraID entity_id)
|
||||
task_scheduler->WaitForTask(update_buffer_task_id);
|
||||
mesh_comp.mesh_state = HYDRA_STATE::Ready;
|
||||
}
|
||||
|
||||
void HydraMeshSystem::DestroyComponent(HydraID entity_id)
|
||||
{
|
||||
HydraECS* ecs = GetEngine()->ECS();
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraBufferManager *buffer_manager = GetEngine()->BufferManager();
|
||||
HydraMeshComponent mesh_comp = ecs->GetComponent<HydraMeshComponent>(entity_id);
|
||||
|
||||
HydraID delete_vertex_task_id = task_scheduler->CreateTask<HydraDeleteVertexBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraDeleteVertexBufferTask *vertex_task = static_cast<HydraDeleteVertexBufferTask *>(task_scheduler->GetTask(delete_vertex_task_id));
|
||||
vertex_task->Intialise(mesh_comp.vertex_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_vertex_task_id);
|
||||
|
||||
GetEngine()->MeshManager()->DeleteMesh(mesh_comp.mesh_id);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,11 @@ class HydraMeshSystem : public HydraSystem
|
||||
public:
|
||||
|
||||
void Initialise() override;
|
||||
|
||||
protected:
|
||||
void InitialiseComponent(HydraID entity_id) override;
|
||||
void DestroyComponent(HydraID entity_id) override;
|
||||
|
||||
virtual void UpdateSystem(float delta_t_seconds){}
|
||||
};
|
||||
|
||||
|
||||
@@ -49,6 +49,14 @@ void HydraPointShadowSourceSystem::UpdateSystem(float delta_t_seconds)
|
||||
}
|
||||
}
|
||||
|
||||
void HydraPointShadowSourceSystem::DestroyComponent(HydraID entity_id)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraPointShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
||||
GetEngine()->ShadowBufferManager()->DeletePointShadow(shadow_comp.shadow_id);
|
||||
}
|
||||
|
||||
void HydraPointShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
|
||||
@@ -16,6 +16,7 @@ class HydraPointShadowSourceSystem : public HydraSystem
|
||||
protected:
|
||||
void InitialiseComponent(HydraID entity_id) override;
|
||||
void UpdateSystem(float delta_t_seconds) override;
|
||||
void DestroyComponent(HydraID entity_id) override;
|
||||
private:
|
||||
void _UpdateShadowMap(HydraID entity_id);
|
||||
void _InitialiseShadowMap(HydraID entity_id);
|
||||
|
||||
@@ -56,6 +56,14 @@ void HydraSpotShadowSourceSystem::UpdateSystem(float delta_t_seconds)
|
||||
|
||||
}
|
||||
|
||||
void HydraSpotShadowSourceSystem::DestroyComponent(HydraID entity_id)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraSpotShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraSpotShadowSourceComponent>(entity_id);
|
||||
GetEngine()->ShadowBufferManager()->DeleteSpotShadow(shadow_comp.shadow_id);
|
||||
}
|
||||
|
||||
void HydraSpotShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
|
||||
@@ -17,6 +17,7 @@ class HydraSpotShadowSourceSystem : public HydraSystem
|
||||
protected:
|
||||
void InitialiseComponent(HydraID entity_id) override;
|
||||
void UpdateSystem(float delta_t_seconds) override;
|
||||
void DestroyComponent(HydraID entity_id) override;
|
||||
private:
|
||||
void _UpdateShadowMap(HydraID entity_id);
|
||||
void _InitialiseShadowMap(HydraID entity_id);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../components/HydraPositionComponent.h"
|
||||
#include "../../scheduler/HydraTaskScheduler.h"
|
||||
#include "../../task/buffer/HydraCreateGPUBufferTask.hpp"
|
||||
#include "../../task/buffer/HydraDeleteGPUBufferTask.hpp"
|
||||
#include "../../task/buffer/HydraUpdateWholeGPUBufferTask.hpp"
|
||||
#include "../../actor/HydraActorManager.h"
|
||||
|
||||
@@ -27,6 +28,16 @@ void HydraTransformSystem::Initialise()
|
||||
m_model_matrix.resize(MAX_ACTORS);
|
||||
}
|
||||
|
||||
void HydraTransformSystem::FreeSystemResources()
|
||||
{
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraDeleteGPUBufferTask *task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
|
||||
task->Intialise(m_transform_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
|
||||
}
|
||||
|
||||
void HydraTransformSystem::UpdateSystem(float delta_t_seconds)
|
||||
{
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
@@ -15,6 +15,7 @@ class HydraTransformSystem : public HydraSystem
|
||||
|
||||
virtual void UpdateSystem(float delta_t_seconds) override;
|
||||
void InitialiseComponent(HydraID actor_id) override;
|
||||
void FreeSystemResources() override;
|
||||
private:
|
||||
void _UpdateChild(HydraID parent_id, HydraID actor_id, glm::mat4 parent_transform);
|
||||
void _WriteToGPU();
|
||||
|
||||
@@ -432,6 +432,7 @@ void HydraEngine::_Shutdown()
|
||||
m_ecs->Shutdown();
|
||||
|
||||
//Shutdown the buffer and vertex buffer managers
|
||||
|
||||
HydraID shutdown_buffer_mgr_id = m_task_scheduler->CreateTask<HydraShutdownBufferManagerTask>(HydraThreadAffinity::Render);
|
||||
m_task_scheduler->WaitForTask(shutdown_buffer_mgr_id);
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef HYDRADELETEGPUBUFFERTASK
|
||||
#define HYDRADELETEGPUBUFFERTASK
|
||||
|
||||
#include "../HydraTask.h"
|
||||
#include "../../engine/HydraEngine.h"
|
||||
#include "../../buffer/HydraBufferManager.h"
|
||||
#include <string>
|
||||
|
||||
class HydraDeleteGPUBufferTask : public HydraTask
|
||||
{
|
||||
private:
|
||||
HydraID m_buffer_id;
|
||||
protected:
|
||||
public:
|
||||
|
||||
virtual void Process() override
|
||||
{
|
||||
GetEngine()->BufferManager()->DeleteBuffer(m_buffer_id);
|
||||
|
||||
}
|
||||
void Intialise(uint32_t buffer_id)
|
||||
{
|
||||
|
||||
m_buffer_id = buffer_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* HYDRADELETEGPUBUFFERTASK */
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef HYDRADELETETEXTURETASK
|
||||
#define HYDRADELETETEXTURETASK
|
||||
|
||||
|
||||
#include "../HydraTask.h"
|
||||
#include "../../engine/HydraEngine.h"
|
||||
#include "../../buffer/HydraTextureBufferManager.h"
|
||||
|
||||
class HydraDeleteTextureTask : public HydraTask
|
||||
{
|
||||
private:
|
||||
|
||||
HydraID m_texture_id;
|
||||
|
||||
protected:
|
||||
public:
|
||||
virtual void Process() override
|
||||
{
|
||||
GetEngine()->TextureBufferManager()->DeleteTexture(m_texture_id);
|
||||
|
||||
|
||||
}
|
||||
void Initialise(HydraID texture_id)
|
||||
{
|
||||
m_texture_id = texture_id;
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* HYDRADELETETEXTURETASK */
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef HYDRADELETEVERTEXBUFFERTASK
|
||||
#define HYDRADELETEVERTEXBUFFERTASK
|
||||
|
||||
#include "../HydraTask.h"
|
||||
#include "../../engine/HydraEngine.h"
|
||||
#include "../../buffer/HydraVertexBufferManager.h"
|
||||
|
||||
class HydraDeleteVertexBufferTask : public HydraTask
|
||||
{
|
||||
private:
|
||||
HydraID m_buffer_id;
|
||||
|
||||
protected:
|
||||
public:
|
||||
virtual void Process() override
|
||||
{
|
||||
GetEngine()->VertexBufferManager()->DeleteVertexBuffer(m_buffer_id);
|
||||
}
|
||||
void Intialise(uint32_t buffer_id)
|
||||
{
|
||||
m_buffer_id = buffer_id;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* HYDRADELETEVERTEXBUFFERTASK */
|
||||
@@ -11,7 +11,6 @@
|
||||
class HydraCreateCascadeShadowFrameBuffer : public HydraTask
|
||||
{
|
||||
private:
|
||||
uint32_t *m_texture_id = 0;
|
||||
uint32_t *m_depth_texture_id = 0;
|
||||
uint32_t *m_frame_buffer_id = nullptr;
|
||||
|
||||
@@ -24,15 +23,6 @@ public:
|
||||
HydraTextureBufferManager *tex_buffer_manager = engine->TextureBufferManager();
|
||||
HydraRenderSettings render_settings = engine->RenderSettings();
|
||||
|
||||
*m_texture_id = tex_buffer_manager->CreateTextureArray("shadow_FB",
|
||||
DIRECTIONAL_SHADOW_MAP_SIZE, DIRECTIONAL_SHADOW_MAP_SIZE,
|
||||
GL_RGBA8,
|
||||
GL_NEAREST,
|
||||
GL_NEAREST,
|
||||
6);
|
||||
|
||||
HydraTextureBuffer texture = tex_buffer_manager->GetTexture(*m_texture_id);
|
||||
|
||||
*m_depth_texture_id = tex_buffer_manager->CreateTextureArray("shadow_depth_buffer",
|
||||
DIRECTIONAL_SHADOW_MAP_SIZE, DIRECTIONAL_SHADOW_MAP_SIZE,
|
||||
GL_DEPTH_COMPONENT32F,
|
||||
@@ -44,10 +34,6 @@ public:
|
||||
glGenFramebuffers(1, m_frame_buffer_id);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, *m_frame_buffer_id);
|
||||
|
||||
glTextureParameteri(texture.gl_tex_id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTextureParameteri(texture.gl_tex_id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
// FIX 1: Set explicit filters for the depth texture to prevent incomplete attachment
|
||||
glTextureParameteri(depth_texture.gl_tex_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTextureParameteri(depth_texture.gl_tex_id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
@@ -57,14 +43,13 @@ public:
|
||||
glTextureParameteri(depth_texture.gl_tex_id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glTextureParameterfv(depth_texture.gl_tex_id, GL_TEXTURE_BORDER_COLOR, &border[0]);
|
||||
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.gl_tex_id, 0);
|
||||
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depth_texture.gl_tex_id, 0);
|
||||
|
||||
glNamedFramebufferDrawBuffer(*m_frame_buffer_id, GL_COLOR_ATTACHMENT0);
|
||||
glNamedFramebufferReadBuffer(*m_frame_buffer_id, GL_COLOR_ATTACHMENT0);
|
||||
glNamedFramebufferDrawBuffer(*m_frame_buffer_id, GL_NONE);
|
||||
glNamedFramebufferReadBuffer(*m_frame_buffer_id, GL_NONE);
|
||||
|
||||
GLenum draw_buffers[] = {GL_COLOR_ATTACHMENT0};
|
||||
glNamedFramebufferDrawBuffers(*m_frame_buffer_id, 1, draw_buffers);
|
||||
glNamedFramebufferDrawBuffers(*m_frame_buffer_id, 0, nullptr);
|
||||
|
||||
GLenum status = glCheckNamedFramebufferStatus(*m_frame_buffer_id, GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
@@ -76,9 +61,8 @@ public:
|
||||
tex_buffer_manager->BindTexture(*m_depth_texture_id, GL_TEXTURE_2D_ARRAY);
|
||||
|
||||
}
|
||||
void Initialise(uint32_t *texture_id, uint32_t *depth_texture_id, uint32_t *frame_buffer_id)
|
||||
void Initialise( uint32_t *depth_texture_id, uint32_t *frame_buffer_id)
|
||||
{
|
||||
m_texture_id = texture_id;
|
||||
m_frame_buffer_id = frame_buffer_id;
|
||||
m_depth_texture_id = depth_texture_id;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef HYDRADELETESHADOWFRAMEBUFFERTASK
|
||||
#define HYDRADELETESHADOWFRAMEBUFFERTASK
|
||||
|
||||
#include "../HydraTask.h"
|
||||
#include "../../engine/HydraEngine.h"
|
||||
#include "../../renderer/HydraRenderer.h"
|
||||
#include <GLMIncludes.h>
|
||||
#include "../../GlewIncludes.h"
|
||||
#include "../../buffer/HydraTextureBufferManager.h"
|
||||
|
||||
class HydraDeleteShadowFrameBufferTask : public HydraTask
|
||||
{
|
||||
private:
|
||||
uint32_t m_depth_texture_id = 0;
|
||||
uint32_t m_frame_buffer_id = 0;
|
||||
|
||||
protected:
|
||||
public:
|
||||
void Process() override
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
|
||||
HydraTextureBufferManager *tex_buffer_manager = engine->TextureBufferManager();
|
||||
tex_buffer_manager->DeleteTexture(m_depth_texture_id);
|
||||
|
||||
glDeleteFramebuffers(0, &m_frame_buffer_id);
|
||||
|
||||
}
|
||||
void Initialise( uint32_t depth_texture_id, uint32_t frame_buffer_id)
|
||||
{
|
||||
m_frame_buffer_id = frame_buffer_id;
|
||||
m_depth_texture_id = depth_texture_id;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* HYDRADELETESHADOWFRAMEBUFFERTASK */
|
||||
Reference in New Issue
Block a user