And you may ask yourself \'Well, how did i get here?\' (memory leak)

This commit is contained in:
benkyd
2023-01-20 13:21:17 +00:00
parent 8dde998710
commit 200ecad6b3
3 changed files with 64 additions and 16 deletions

View File

@@ -65,7 +65,6 @@ void rayHitCallback(void* hhm, HitInfo* hit)
void HHM::rayReturn(HitInfo* hit)
{
HARTModule* mod = mDirectory.getActiveModule();
spdlog::debug("HIT!!");
Renderer->computeHit(hit);
}

View File

@@ -4,6 +4,7 @@
#include <scene/camera.hpp>
#include <scene/scene.hpp>
#include <scene/mesh.hpp>
#include <tracing/ray.hpp>
#include <tracing/hit.hpp>
@@ -99,25 +100,72 @@ void RayRenderer::draw()
}
mCurrentRefTable = &startRays.Reference;
mIface->startTrace(startRays.Field);
// mIface->startTrace(startRays.Field);
// hault wait for the module to finish
bool frameStatus = false;
while (!frameStatus)
// bool frameStatus = false;
// while (!frameStatus)
// {
// switch(mIface->getModuleState())
// {
// case EModuleState::Bad:
// spdlog::error("MODULE STATE BAD");
// break;
// case EModuleState::Build:
// spdlog::error("MODULE STATE BUILD");
// case EModuleState::Trace:
// break;
// case EModuleState::Ready:
// frameStatus = true;
// break;
// }
// }
while(!startRays.Field.empty())
{
switch(mIface->getModuleState())
void* verticies; void* normals; void* indicies;
int vertexCount = mCurrentScene->getRenderables()[0]->getVerticies(verticies, normals);
int indexCount = mCurrentScene->getRenderables()[0]->getIndicies(indicies);
float* mVert = (float*)verticies; float* mNorm = (float*)normals;
int mVc = vertexCount; uint32_t* mIndicies = (uint32_t*)indicies; int mIc = indexCount;
auto* ray = startRays.Field.front();
int bestIdx = -1;
glm::vec2 coords;
glm::vec2 bestTexcoord;
float bestDist = INFINITY;
float dist;
for (int i = 0; i < mCurrentScene->getRenderables()[0]->getIndexCount() ; i += 9)
{
case EModuleState::Bad:
spdlog::error("MODULE STATE BAD");
break;
case EModuleState::Build:
spdlog::error("MODULE STATE BUILD");
case EModuleState::Trace:
break;
case EModuleState::Ready:
frameStatus = true;
break;
uint32_t ind = mIndicies[i];
// Check if the ray intersects
const glm::vec3 a = { mVert[ind + 1], mVert[ind + 2], mVert[ind + 3] };
const glm::vec3 b = { mVert[ind + 4], mVert[ind + 5], mVert[ind + 6] };
const glm::vec3 c = { mVert[ind + 7], mVert[ind + 8], mVert[ind + 9] };
if (!glm::intersectRayTriangle(ray->Origin, ray->Direction, a, b, c, coords, dist)) { continue; }
if (dist > bestDist || dist < 0.0f) { continue; }
bestIdx = i;
bestDist = dist;
bestTexcoord = coords;
}
HitInfo* hit = new HitInfo{};
// If no hit, we still need to inform the HHM
if (bestIdx < 0)
{
startRays.Field.pop_back();
continue;
}
hit->Distance = bestDist;
hit->UV = bestTexcoord;
glm::ivec2 pos = (*mCurrentRefTable)[ray->Reference];
spdlog::debug("HIT!!");
mTarget[pos.y * mRenderTargetSize.x + pos.x] = { bestDist, bestDist, bestDist, 1.0f };
startRays.Field.pop_back();
// this->computeHit(hit);
}
spdlog::info("Sample complete");
@@ -130,6 +178,7 @@ void RayRenderer::draw()
void RayRenderer::computeHit(HitInfo* info)
{
spdlog::debug("HIT!!");
glm::ivec2 pos = (*mCurrentRefTable)[info->Caller->Reference];
std::lock_guard<std::mutex> lock(this->_mTarget);
float d = info->Distance;

View File

@@ -78,7 +78,7 @@ int Mesh::getVerticies(void*& v, void*& n)
{
v = (void*)&mObjLoader->getPositions()[0];
n = (void*)&mObjLoader->getNormals()[0];
spdlog::debug("Mesh get {} {}", v, n);
// spdlog::debug("Mesh get {} {}", v, n);
return mObjLoader->getVertCount();
}