skeleton hybridisation of whatever this is

This commit is contained in:
Ben Kyd
2022-11-22 15:43:05 +00:00
parent f13a25978c
commit 622ccd68dc
11 changed files with 112 additions and 35 deletions

View File

@@ -69,7 +69,8 @@
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"complex": "cpp"
"complex": "cpp",
"hash_map": "cpp"
},
"cmake.configureOnOpen": false
}

View File

@@ -18,6 +18,17 @@ public:
std::cout << "Goodbye Module HART CPU" << std::endl;
}
void submitTris(std::vector<glm::vec3>* vert,
std::vector<glm::vec3>* norm,
std::vector<Material*>* mats,
std::vector<int>* indicies) override {}
void updateTris(std::vector<glm::vec3>* vert,
std::vector<glm::vec3>* norm,
std::vector<Material*>* mats,
std::vector<int>* indicies) override {}
void submitQueue(std::queue<Ray*> queue) override {}
void pushtoQueue(Ray* ray) override {}
};
HART_INTERFACE void* _GET()

View File

@@ -17,7 +17,18 @@ public:
{
std::cout << "Goodbye Module HART GPU" << std::endl;
}
void submitTris(std::vector<glm::vec3>* vert,
std::vector<glm::vec3>* norm,
std::vector<Material*>* mats,
std::vector<int>* indicies) override {}
void updateTris(std::vector<glm::vec3>* vert,
std::vector<glm::vec3>* norm,
std::vector<Material*>* mats,
std::vector<int>* indicies) override {}
void submitQueue(std::queue<Ray*> queue) override {}
void pushtoQueue(Ray* ray) override {}
};
HART_INTERFACE void* _GET()

View File

@@ -1,5 +0,0 @@
#pragma once
namespace inferno {
}

View File

@@ -1,8 +1,9 @@
#pragma once
#include <string>
#include <queue>
#include "hardware_accelerator.hpp"
#include "hart_graphics.hpp"
namespace inferno {
@@ -16,10 +17,6 @@ namespace inferno {
#define HART_INTERFACE extern "C"
#endif
HART_INTERFACE typedef void* (*HART_INIT_F)(void);
HART_INTERFACE typedef void (*HART_DESTROY_F)(void*);
HART_INTERFACE typedef void* (*HART_CREDIT_F)(void);
struct ModuleCredit
{
const std::string ModuleName;
@@ -30,11 +27,42 @@ struct ModuleCredit
const int VersionBuild;
};
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);
class HARTModule
{
public:
// Constructor & destructor is done in the module
// virtual void takeScene() = 0;
virtual void submitTris(std::vector<glm::vec3>* vert,
std::vector<glm::vec3>* norm,
std::vector<Material*>* mats,
std::vector<int>* indicies) = 0;
virtual void updateTris(std::vector<glm::vec3>* vert,
std::vector<glm::vec3>* norm,
std::vector<Material*>* mats,
std::vector<int>* indicies) = 0;
virtual void submitQueue(std::queue<Ray*> queue) = 0;
virtual void pushtoQueue(Ray* ray) = 0;
inline void passHitCallback(HART_HIT_CALLBACK callback)
{
Hit = callback;
}
private:
HART_HIT_CALLBACK Hit = nullptr;
private:
std::queue<Ray*> mToTrace;
};
}

View File

@@ -1,9 +0,0 @@
#pragma once
#ifdef _WIN32
// TODO: DLLs
#else
#include <dlfcn.h>
#endif
#include <inferno_hart.hpp>

View File

@@ -68,10 +68,10 @@ HARTModuleDirectory::discoveryEntry HARTModuleDirectory::registerModule(std::fil
entry.InitCallback = (HART_INIT_F)GetProcAddress(entry.Handle, "_GET");
entry.DestroyCallback = (HART_DESTROY_F)GetProcAddress(entry.Handle, "_DESTROY");
#else // UNIX-Like
entry.Handle = dlopen(file.c_str(), RTLD_LAZY | RTLD_LOCAL);
entry.Handle = dlopen(file.c_str(), RTLD_NOW | RTLD_LOCAL);
if (entry.Handle == NULL)
{
spdlog::error("Cannot load module at {}.", file.c_str());
spdlog::error("Cannot load module at ", dlerror());
entry.Handle = NULL; entry.DidLink = false;
return entry;
}
@@ -101,11 +101,11 @@ HARTModuleDirectory::discoveryEntry HARTModuleDirectory::registerModule(std::fil
entry.Credit = (ModuleCredit*)credit();
spdlog::info("Module {} v{}.{}.{} by {}", entry.Credit->ModuleName,
entry.Credit->VersionMajor,
entry.Credit->VersionMinor,
entry.Credit->VersionBuild,
entry.Credit->AuthorName);
spdlog::info("Module {0} v{2}.{3}.{4} by {5}", entry.Credit->ModuleName,
entry.Credit->VersionMajor,
entry.Credit->VersionMinor,
entry.Credit->VersionBuild,
entry.Credit->AuthorName);
entry.DidLink = true;
mEntries[entry.Credit->ModuleName] = { entry, nullptr };
@@ -144,6 +144,11 @@ void HARTModuleDirectory::setActiveIndex(int index)
this->setActive(keys[index]);
}
HARTModule* HARTModuleDirectory::getActiveModule()
{
return mEntries[mActiveModule].Module;
}
std::string HARTModuleDirectory::getActive()
{
return mActiveModule;

View File

@@ -40,7 +40,8 @@ public:
bool Active;
};
std::vector<discoveryEntry> discoverModules(std::filesystem::path folder, bool recurse = false);
// This can take a file or a directory, and inside the directory discover recursively or not
std::vector<discoveryEntry> discoverModules(std::filesystem::path path, bool recurse = false);
discoveryEntry registerModule(std::filesystem::path file);
std::vector<std::string> getModules();
@@ -48,6 +49,7 @@ public:
void setActive(std::string moduleName);
void setActiveIndex(int index);
HARTModule* getActiveModule();
std::string getActive();
int getActiveIndex();
ModuleCredit* getActiveCredit();

38
src/hart_module.hpp Normal file
View File

@@ -0,0 +1,38 @@
#pragma once
// the HHM (Hamlin Hamlin McGill) aka the Head HART Module keeps track of the module
// and gives the renderer a cleaner interface to talk to a HART Module
namespace inferno {
class Scene;
class Ray;
class RaySouce;
class HitInfo;
class HARTModule;
class HHM
{
public:
HHM();
~HHM();
// needs to syncronusly stop the module's execution and
// prepare for setting up a new HART layer
void notifyModuleChange(HARTModule* newModule);
void newScene(Scene* scene);
void notifySceneUpdate();
void startTrace(RaySouce* sourceScatter);
void rayReturn(HitInfo* hit);
void bounce(Ray* newRay);
private:
HARTModule* activeModule;
};
}

View File

@@ -128,6 +128,7 @@ int Inferno::run()
Material basicMaterial("basic");
Shader basicShader;
basicShader.load("res/shaders/basic.glsl")->link();
basicMaterial.setGlShader(&basicShader);
Mesh cornell;
@@ -145,12 +146,6 @@ int Inferno::run()
Camera camera;
mScene->setCamera(&camera);
Mesh dragon;
dragon.loadOBJ("res/dragon-cornell-size.obj");
dragon.ready();
dragon.setMaterial(&basicMaterial);
mScene->addMesh(&dragon);
mRasterRenderer->setScene(mScene);
mRayRenderer->setScene(mScene);