diff --git a/hart/inferno-hart-cpu/src/main.cpp b/hart/inferno-hart-cpu/src/main.cpp index efb9181..8c3660a 100644 --- a/hart/inferno-hart-cpu/src/main.cpp +++ b/hart/inferno-hart-cpu/src/main.cpp @@ -1,4 +1,7 @@ #include +#include + +#include #include @@ -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 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() diff --git a/hart/inferno-hart-opencl/src/main.cpp b/hart/inferno-hart-opencl/src/main.cpp index 574d420..6503284 100644 --- a/hart/inferno-hart-opencl/src/main.cpp +++ b/hart/inferno-hart-opencl/src/main.cpp @@ -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 queue) override {} - void pushtoQueue(Ray* ray) override {} + void updateTris() override {} }; HART_INTERFACE void* _GET() diff --git a/libhart/hart_graphics.hpp b/libhart/hart_graphics.hpp index 34f8952..a14c79d 100644 --- a/libhart/hart_graphics.hpp +++ b/libhart/hart_graphics.hpp @@ -13,3 +13,4 @@ extern "C" // glm #include +#include diff --git a/libhart/inferno_hart.hpp b/libhart/inferno_hart.hpp index a1fb474..11c0a07 100644 --- a/libhart/inferno_hart.hpp +++ b/libhart/inferno_hart.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include 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 queue) = 0; - virtual void pushtoQueue(Ray* ray) = 0; - - inline void passHitCallback(HART_HIT_CALLBACK callback) + inline void submitQueue(std::vector queue) { + std::lock_guard lock(_mData); + for (const auto& e: queue) + mToTrace.push(e); + } + + inline void pushtoQueue(Ray* ray) + { + std::lock_guard 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 mToTrace; + + std::mutex _mData; }; } diff --git a/libhart/tracing/hit.hpp b/libhart/tracing/hit.hpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/libhart/tracing/hit.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/src/hart_module.cpp b/src/hart_module.cpp index 01bdb04..89b7ec8 100644 --- a/src/hart_module.cpp +++ b/src/hart_module.cpp @@ -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(); } - diff --git a/src/inferno.cpp b/src/inferno.cpp index e463c34..c73a3b1 100644 --- a/src/inferno.cpp +++ b/src/inferno.cpp @@ -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); diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index 5588747..c4a677f 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -84,15 +84,17 @@ void RayRenderer::draw() RayField startRays = mRaySource->getInitialRays(true); mIface->startTrace(startRays); - { - std::lock_guard 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 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) {