diff --git a/hart/inferno-hart-cpu/src/main.cpp b/hart/inferno-hart-cpu/src/main.cpp index ce94941..efb9181 100644 --- a/hart/inferno-hart-cpu/src/main.cpp +++ b/hart/inferno-hart-cpu/src/main.cpp @@ -1,5 +1,4 @@ #include -#include #include @@ -19,14 +18,16 @@ public: } void submitTris(void* vert, - void* norm, - std::vector* mats, - std::vector* indicies) override {} + void* norm, + int vc, + void* indicies, + int ic) override {} void updateTris(void* vert, - void* norm, - std::vector* mats, - std::vector* indicies) override {} - + void* norm, + int vc, + void* indicies, + int ic) override {} + void submitQueue(std::vector queue) override { diff --git a/hart/inferno-hart-opencl/src/main.cpp b/hart/inferno-hart-opencl/src/main.cpp index 9f624eb..574d420 100644 --- a/hart/inferno-hart-opencl/src/main.cpp +++ b/hart/inferno-hart-opencl/src/main.cpp @@ -1,5 +1,4 @@ #include -#include #include @@ -19,13 +18,15 @@ public: } void submitTris(void* vert, - void* norm, - std::vector* mats, - std::vector* indicies) override {} + void* norm, + int vc, + void* indicies, + int ic) override {} void updateTris(void* vert, - void* norm, - std::vector* mats, - std::vector* indicies) override {} + void* norm, + int vc, + void* indicies, + int ic) override {} void submitQueue(std::vector queue) override {} void pushtoQueue(Ray* ray) override {} diff --git a/libhart/inferno_hart.hpp b/libhart/inferno_hart.hpp index 6734e6c..a1fb474 100644 --- a/libhart/inferno_hart.hpp +++ b/libhart/inferno_hart.hpp @@ -41,12 +41,14 @@ public: // Constructor & destructor is done in the module virtual void submitTris(void* vert, void* norm, - std::vector* mats, - std::vector* indicies) = 0; + int vc, + void* indicies, + int ic) = 0; virtual void updateTris(void* vert, void* norm, - std::vector* mats, - std::vector* indicies) = 0; + int vc, + void* indicies, + int ic) = 0; // module keeps queue reference virtual void submitQueue(std::vector queue) = 0; diff --git a/src/hart_module.cpp b/src/hart_module.cpp index 920afd7..01bdb04 100644 --- a/src/hart_module.cpp +++ b/src/hart_module.cpp @@ -28,10 +28,16 @@ void HHM::newScene(Scene* scene) { HARTModule* mod = mDirectory.getActiveModule(); std::vector meshs = scene->getRenderables(); - for (const auto* mesh : meshs) { - // mesh->getVerticies(); + // TODO: This may not be the way i want to approach it + // as submitTris should take maybe a mesh ID and then the mesh data + // as it is now, submitTris assumes it's getting the whole scene + // which would involve a lot of mesh copying (avoid!) if i were to chain them + for (auto* mesh : meshs) { + void* verticies; void* normals; void* indicies; + int vertexCount = mesh->getVerticies(verticies, normals); + int indexCount = mesh->getIndicies(indicies); + mod->submitTris(verticies, normals, vertexCount, indicies, indexCount); } - // mod->submitTris(); } void HHM::notifySceneUpdate() diff --git a/src/inferno.cpp b/src/inferno.cpp index da315b8..e463c34 100644 --- a/src/inferno.cpp +++ b/src/inferno.cpp @@ -261,8 +261,8 @@ int Inferno::run() ImGui::Text(activeCredit->ModuleName.c_str()); ImGui::SameLine(); ImGui::Text("v%i.%i.%i", activeCredit->VersionMajor, - activeCredit->VersionMinor, - activeCredit->VersionBuild); + activeCredit->VersionMinor, + activeCredit->VersionBuild); ImGui::BulletText(activeCredit->ModuleDesc.c_str()); ImGui::BulletText("Authored by %s", activeCredit->AuthorName.c_str()); diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index 5f3eb3a..5588747 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -71,11 +71,16 @@ glm::fvec4* RayRenderer::getRenderData() void RayRenderer::prepare() { assert(mCurrentScene != NULL); - mIface->newScene(mCurrentScene); + if (mCurrentScene->didUpdate()) + { + mIface->newScene(mCurrentScene); + } } void RayRenderer::draw() { + mCurrentScene->newFrame(); + RayField startRays = mRaySource->getInitialRays(true); mIface->startTrace(startRays); diff --git a/src/scene/material.cpp b/src/scene/material.cpp index 5c20b01..95918fc 100644 --- a/src/scene/material.cpp +++ b/src/scene/material.cpp @@ -1,4 +1,4 @@ -#include +#include "material.hpp" #include "preview_renderer/shader.hpp" diff --git a/libhart/scene/material.hpp b/src/scene/material.hpp similarity index 100% rename from libhart/scene/material.hpp rename to src/scene/material.hpp diff --git a/src/scene/mesh.cpp b/src/scene/mesh.cpp index 8792c91..d9a9e4d 100644 --- a/src/scene/mesh.cpp +++ b/src/scene/mesh.cpp @@ -1,4 +1,4 @@ -#include +#include "mesh.hpp" #include @@ -71,22 +71,20 @@ void Mesh::ready() glBindVertexArray(0); - spdlog::debug("MESH READY"); + spdlog::debug("PREVIEW MESH READY"); } -GLuint Mesh::getVAO() +int Mesh::getVerticies(void* v, void* n) { - return mVAO; + v = (void*)&mObjLoader->getPositions()[0]; + n = (void*)&mObjLoader->getNormals()[0]; + return mObjLoader->getVertCount(); } -GLuint Mesh::getVBO() +int Mesh::getIndicies(void* i) { - return mVBO; -} - -GLuint Mesh::getEBO() -{ - return mEBO; + i = (void*)&mObjLoader->getFaces()[0]; + return mObjLoader->getIndexCount(); } int Mesh::getIndexCount() @@ -103,3 +101,18 @@ Material* Mesh::getMaterial() { return mMaterial; } + +GLuint Mesh::getVAO() +{ + return mVAO; +} + +GLuint Mesh::getVBO() +{ + return mVBO; +} + +GLuint Mesh::getEBO() +{ + return mEBO; +} diff --git a/libhart/scene/mesh.hpp b/src/scene/mesh.hpp similarity index 81% rename from libhart/scene/mesh.hpp rename to src/scene/mesh.hpp index 6b4b85a..abcdc60 100644 --- a/libhart/scene/mesh.hpp +++ b/src/scene/mesh.hpp @@ -26,9 +26,8 @@ public: void loadOBJ(std::filesystem::path file); void ready(); - void getVerticies(std::vector* vert, - std::vector* norm, - std::vector* uv); + int getVerticies(void* v, void* n); + int getIndicies(void* i); int getIndexCount(); diff --git a/libhart/scene/object.hpp b/src/scene/object.hpp similarity index 100% rename from libhart/scene/object.hpp rename to src/scene/object.hpp diff --git a/src/scene/objloader.cpp b/src/scene/objloader.cpp index c0a4a5e..b5a0968 100644 --- a/src/scene/objloader.cpp +++ b/src/scene/objloader.cpp @@ -1,5 +1,5 @@ // Adapted from https://raw.githubusercontent.com/tamato/simple-obj-loader/master/objloader.cpp -#include +#include "objloader.hpp" #include diff --git a/libhart/scene/objloader.hpp b/src/scene/objloader.hpp similarity index 100% rename from libhart/scene/objloader.hpp rename to src/scene/objloader.hpp diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index e2d14a4..75e451a 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -1,4 +1,4 @@ -#include +#include "scene.hpp" #include #include @@ -19,6 +19,7 @@ Scene::~Scene() void Scene::setCamera(Camera* camera) { mCurrentCamera = camera; + mDidUpdate = true; } Camera* Scene::getCamera() @@ -29,6 +30,17 @@ Camera* Scene::getCamera() void Scene::addMesh(Mesh* mesh) { mMeshs.push_back(mesh); + mDidUpdate = true; +} + +bool Scene::didUpdate() +{ + return mDidUpdate; +} + +void Scene::newFrame() +{ + mDidUpdate = false; } const std::vector& Scene::getRenderables() diff --git a/libhart/scene/scene.hpp b/src/scene/scene.hpp similarity index 84% rename from libhart/scene/scene.hpp rename to src/scene/scene.hpp index 906950a..1de060e 100644 --- a/libhart/scene/scene.hpp +++ b/src/scene/scene.hpp @@ -19,6 +19,9 @@ public: Camera* getCamera(); void addMesh(Mesh* mesh); + bool didUpdate(); + void newFrame(); + const std::vector& getRenderables(); private: @@ -26,6 +29,9 @@ private: Camera* mCurrentCamera; Sky* mCurrentSky; + +private: + bool mDidUpdate = true; }; }