fleshing out the modules a touch
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
#include <inferno_hart.hpp>
|
||||
#include <hart_graphics.hpp>
|
||||
|
||||
#include <tracing/ray.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -21,19 +24,15 @@ public:
|
||||
void* norm,
|
||||
int vc,
|
||||
void* indicies,
|
||||
int ic) override {}
|
||||
void updateTris(void* vert,
|
||||
void* norm,
|
||||
int vc,
|
||||
void* indicies,
|
||||
int ic) override {}
|
||||
|
||||
void submitQueue(std::vector<Ray*> queue) override
|
||||
int ic) override
|
||||
{
|
||||
|
||||
std::cout << "INFERNO HART CPU RECIEVED " << vc / 3 << " VERTICIES AND " << ic / 3 << " INDICIES" << std::endl;
|
||||
}
|
||||
|
||||
void updateTris() override {}
|
||||
|
||||
|
||||
|
||||
void pushtoQueue(Ray* ray) override {}
|
||||
};
|
||||
|
||||
HART_INTERFACE void* _GET()
|
||||
|
||||
@@ -22,14 +22,7 @@ public:
|
||||
int vc,
|
||||
void* indicies,
|
||||
int ic) override {}
|
||||
void updateTris(void* vert,
|
||||
void* norm,
|
||||
int vc,
|
||||
void* indicies,
|
||||
int ic) override {}
|
||||
|
||||
void submitQueue(std::vector<Ray*> queue) override {}
|
||||
void pushtoQueue(Ray* ray) override {}
|
||||
void updateTris() override {}
|
||||
};
|
||||
|
||||
HART_INTERFACE void* _GET()
|
||||
|
||||
@@ -13,3 +13,4 @@ extern "C"
|
||||
|
||||
// glm
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/intersect.hpp>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
namespace inferno {
|
||||
@@ -27,43 +28,52 @@ struct ModuleCredit
|
||||
|
||||
class Ray;
|
||||
class HitInfo;
|
||||
class Material;
|
||||
|
||||
HART_INTERFACE typedef void* (*HART_INIT_F)(void);
|
||||
HART_INTERFACE typedef void (*HART_DESTROY_F)(void*);
|
||||
HART_INTERFACE typedef void* (*HART_CREDIT_F)(void);
|
||||
|
||||
typedef void (*HART_HIT_CALLBACK)(HitInfo* hit);
|
||||
typedef void (*HART_HIT_CALLBACK)(void* context, HitInfo* hit);
|
||||
|
||||
// Module should set up it's worker in the constructor
|
||||
// worker(s) pop items from mToTrace, intersect with
|
||||
// programmer-defined structure from submitTris and calls
|
||||
// Hit() with the context and the result of the trace
|
||||
class HARTModule
|
||||
{
|
||||
public:
|
||||
// Constructor & destructor is done in the module
|
||||
virtual void submitTris(void* vert,
|
||||
void* norm,
|
||||
int vc,
|
||||
void* indicies,
|
||||
int ic) = 0;
|
||||
virtual void updateTris(void* vert,
|
||||
void* norm,
|
||||
int vc,
|
||||
void* indicies,
|
||||
int ic) = 0;
|
||||
virtual void submitTris(void* vert, void* norm, int vc, void* indicies, int ic) = 0;
|
||||
virtual void updateTris() = 0;
|
||||
|
||||
// module keeps queue reference
|
||||
virtual void submitQueue(std::vector<Ray*> queue) = 0;
|
||||
virtual void pushtoQueue(Ray* ray) = 0;
|
||||
|
||||
inline void passHitCallback(HART_HIT_CALLBACK callback)
|
||||
inline void submitQueue(std::vector<Ray*> queue)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mData);
|
||||
for (const auto& e: queue)
|
||||
mToTrace.push(e);
|
||||
}
|
||||
|
||||
inline void pushtoQueue(Ray* ray)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mData);
|
||||
mToTrace.push(ray);
|
||||
}
|
||||
|
||||
inline void passContext(void* context, HART_HIT_CALLBACK callback)
|
||||
{
|
||||
mCtx = context;
|
||||
Hit = callback;
|
||||
}
|
||||
|
||||
private:
|
||||
void* mCtx;
|
||||
HART_HIT_CALLBACK Hit = nullptr;
|
||||
|
||||
private:
|
||||
std::queue<Ray*> mToTrace;
|
||||
|
||||
std::mutex _mData;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
1
libhart/tracing/hit.hpp
Normal file
1
libhart/tracing/hit.hpp
Normal file
@@ -0,0 +1 @@
|
||||
#pragma once
|
||||
@@ -43,15 +43,21 @@ void HHM::newScene(Scene* scene)
|
||||
void HHM::notifySceneUpdate()
|
||||
{
|
||||
HARTModule* mod = mDirectory.getActiveModule();
|
||||
// same again
|
||||
mod->updateTris();
|
||||
}
|
||||
|
||||
void HHM::startTrace(RayField sourceScatter)
|
||||
{
|
||||
HARTModule* mod = mDirectory.getActiveModule();
|
||||
mod->passContext((void*)this, &rayHitCallback);
|
||||
mod->submitQueue(sourceScatter);
|
||||
}
|
||||
|
||||
void rayHitCallback(void* hhm, HitInfo* hit)
|
||||
{
|
||||
((HHM*)hhm)->rayReturn(hit);
|
||||
}
|
||||
|
||||
void HHM::rayReturn(HitInfo* hit)
|
||||
{
|
||||
HARTModule* mod = mDirectory.getActiveModule();
|
||||
@@ -63,4 +69,3 @@ void HHM::bounce(Ray* newRay)
|
||||
HARTModule* mod = mDirectory.getActiveModule();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ int Inferno::run()
|
||||
basicMaterial.setGlShader(&basicShader);
|
||||
|
||||
Mesh cornell;
|
||||
cornell.loadOBJ("res/sponza.obj");
|
||||
cornell.loadOBJ("res/cornell-box.obj");
|
||||
cornell.ready();
|
||||
cornell.setMaterial(&basicMaterial);
|
||||
mScene->addMesh(&cornell);
|
||||
|
||||
@@ -84,15 +84,17 @@ void RayRenderer::draw()
|
||||
RayField startRays = mRaySource->getInitialRays(true);
|
||||
mIface->startTrace(startRays);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->_mTarget);
|
||||
|
||||
for (int x = 0; x < mRenderTargetSize.x; x++)
|
||||
for (int y = 0; y < mRenderTargetSize.y; y++)
|
||||
{
|
||||
mTarget[y * mRenderTargetSize.x + x] = { startRays[y * mRenderTargetSize.x + x]->Direction, 1.0f };
|
||||
}
|
||||
}
|
||||
|
||||
// {
|
||||
// std::lock_guard<std::mutex> lock(this->_mTarget);
|
||||
|
||||
// for (int x = 0; x < mRenderTargetSize.x; x++)
|
||||
// for (int y = 0; y < mRenderTargetSize.y; y++)
|
||||
// {
|
||||
// mTarget[y * mRenderTargetSize.x + x] = { startRays[y * mRenderTargetSize.x + x]->Direction, 1.0f };
|
||||
// }
|
||||
// }
|
||||
|
||||
for (auto* ray : startRays)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user