diff --git a/src/graphics/mesh/font.cpp b/src/graphics/mesh/font.cpp index 147d39e..b621267 100644 --- a/src/graphics/mesh/font.cpp +++ b/src/graphics/mesh/font.cpp @@ -8,6 +8,7 @@ #include #include +#include "mesh.hpp" #include "arrays.hpp" #include "font.hpp" @@ -89,7 +90,7 @@ void font::init() } } -void font::generate(mesh& m, const char* text, double size) +void mesh::load_text(const char* text, double size) { std::vector vertices; std::vector indices; @@ -135,7 +136,7 @@ void font::generate(mesh& m, const char* text, double size) x += ch.advance * size; } - m.set_vertices(&vertices[0], vertices.size(), GL_DYNAMIC_DRAW); - m.set_indices(&indices[0], indices.size(), GL_DYNAMIC_DRAW); + set_vertices(&vertices[0], vertices.size(), GL_DYNAMIC_DRAW); + set_indices(&indices[0], indices.size(), GL_DYNAMIC_DRAW); } diff --git a/src/graphics/mesh/font.hpp b/src/graphics/mesh/font.hpp index 7af4f77..52b6ee0 100644 --- a/src/graphics/mesh/font.hpp +++ b/src/graphics/mesh/font.hpp @@ -10,15 +10,6 @@ namespace sim::graphics::font { void init(); -void generate(mesh& m, const char* text, double size); - -template -void generate(mesh& m, const char* header, T* item, double size) -{ - std::stringstream ss; - ss << header << *item; - generate(m, ss.str().c_str(), size); -} }; diff --git a/src/graphics/mesh/mesh.hpp b/src/graphics/mesh/mesh.hpp index 0ff256e..863d9c1 100644 --- a/src/graphics/mesh/mesh.hpp +++ b/src/graphics/mesh/mesh.hpp @@ -4,7 +4,9 @@ #include #include "arrays.hpp" + #include +#include namespace sim::graphics { @@ -26,7 +28,16 @@ struct mesh void set_vertices(const arrays::vertex* data, size_t size, int mode); void set_indices(const unsigned int* data, size_t size, int mode); void load_model(std::string base, std::string path); + void load_text(const char* text, double size); void render(); + + template + void load_text(const char* header, T* item, double size) + { + std::stringstream ss; + ss << header << *item; + load_text(ss.str().c_str(), size); + } }; }; diff --git a/src/graphics/window.cpp b/src/graphics/window.cpp index c93fec6..0e94afa 100644 --- a/src/graphics/window.cpp +++ b/src/graphics/window.cpp @@ -56,7 +56,20 @@ void window::create() if(err != GLEW_OK) { - std::cout << "GLEW Init Failed: " << glewGetErrorString(err) << "\n"; + std::cerr << "GLEW Init Failed: " << glewGetErrorString(err) << "\n"; + close(); + return; + } + + if(!glGetTextureHandleARB || !glMakeTextureHandleResidentARB) + { + std::cerr << "Fatal: Bindless textures not supported\n"; + + if(!glGetTextureHandleARB) + std::cerr << " Missing: glGetTextureHandleARB\n"; + if(!glMakeTextureHandleResidentARB) + std::cerr << " Missing: glMakeTextureHandleResidentARB\n"; + close(); return; } @@ -130,14 +143,10 @@ void window::create() void window::loop() { - MeshText.bind(); - font::generate(MeshText, "Reactor Core\n\nTODO", 0.1); - MeshMon1.bind(); - font::generate(MeshMon1, "Reactor Vessel\n\n", parts::vessel, 0.1); - MeshMon2.bind(); - font::generate(MeshMon2, "Steam Valve\n\n", parts::valve, 0.1); - MeshMon3.bind(); - font::generate(MeshMon3, "Coolant Pump\n\n", parts::pump, 0.1); + MeshText.bind(); MeshText.load_text("Reactor Core\n\nTODO", 0.1); + MeshMon1.bind(); MeshMon1.load_text("Reactor Vessel\n\n", parts::vessel, 0.1); + MeshMon2.bind(); MeshMon2.load_text("Steam Valve\n\n", parts::valve, 0.1); + MeshMon3.bind(); MeshMon3.load_text("Coolant Pump\n\n", parts::pump, 0.1); glm::mat4 mat_projection = glm::perspective(glm::radians(80.0f), resize::get_aspect(), 0.01f, 20.f); glUniformMatrix4fv(shader::gl_projection, 1, false, &mat_projection[0][0]); @@ -145,16 +154,11 @@ void window::loop() glClearColor(0, 0, 0, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - MeshScene.bind(); - MeshScene.render(); - MeshText.bind(); - MeshText.render(); - MeshMon1.bind(); - MeshMon1.render(); - MeshMon2.bind(); - MeshMon2.render(); - MeshMon3.bind(); - MeshMon3.render(); + MeshScene.bind(); MeshScene.render(); + MeshText.bind(); MeshText.render(); + MeshMon1.bind(); MeshMon1.render(); + MeshMon2.bind(); MeshMon2.render(); + MeshMon3.bind(); MeshMon3.render(); glfwSwapBuffers(win); glfwPollEvents(); diff --git a/src/reactor/control/control_rod.hpp b/src/reactor/control/control_rod.hpp index 806a47d..655b74d 100644 --- a/src/reactor/control/control_rod.hpp +++ b/src/reactor/control/control_rod.hpp @@ -17,6 +17,7 @@ class control_rod : public sim::reactor::coolant::pipe virtual void display(std::ostream& o) const; virtual const char* get_name() const { return "Control Rod"; } + virtual rod* clone() const { return new control_rod(*this); }; public: diff --git a/src/reactor/control/graphite_rod.hpp b/src/reactor/control/graphite_rod.hpp index 202381c..698f742 100644 --- a/src/reactor/control/graphite_rod.hpp +++ b/src/reactor/control/graphite_rod.hpp @@ -13,6 +13,7 @@ class graphite_rod : public sim::reactor::rod virtual void display(std::ostream& o) const; virtual const char* get_name() const { return "Graphite Rod"; } + virtual rod* clone() const { return new graphite_rod(*this); }; virtual double get_k(val_t type) const; public: diff --git a/src/reactor/coolant/heater.hpp b/src/reactor/coolant/heater.hpp index 05cab44..f9fa1a4 100644 --- a/src/reactor/coolant/heater.hpp +++ b/src/reactor/coolant/heater.hpp @@ -14,6 +14,7 @@ class heater : public sim::reactor::rod virtual const char* get_name() const { return "Heater"; } virtual double get_k(val_t type) const { return 0.5; } + virtual rod* clone() const { return new heater(*this); }; public: diff --git a/src/reactor/coolant/pipe.hpp b/src/reactor/coolant/pipe.hpp index 1e877bd..b184bec 100644 --- a/src/reactor/coolant/pipe.hpp +++ b/src/reactor/coolant/pipe.hpp @@ -16,6 +16,8 @@ protected: virtual double get_k(sim::reactor::rod::val_t type) const; virtual const char* get_name() const { return "Coolant"; } + virtual rod* clone() const { return new pipe(*this); }; + void update_pipe(double secs); public: diff --git a/src/reactor/fuel/fuel_rod.hpp b/src/reactor/fuel/fuel_rod.hpp index 892cd55..68a6635 100644 --- a/src/reactor/fuel/fuel_rod.hpp +++ b/src/reactor/fuel/fuel_rod.hpp @@ -15,6 +15,7 @@ class fuel_rod : public sim::reactor::rod virtual void display(std::ostream& o) const; virtual const char* get_name() const { return "Fuel"; } + virtual rod* clone() const { return new fuel_rod(*this); }; public: diff --git a/src/reactor/reactor.cpp b/src/reactor/reactor.cpp index be7991e..5722292 100644 --- a/src/reactor/reactor.cpp +++ b/src/reactor/reactor.cpp @@ -22,6 +22,16 @@ reactor::reactor(reactor&& o) : width(o.width), height(o.height), size(o.size) o.rods = nullptr; } +reactor::reactor(const reactor& o) : width(o.width), height(o.height), size(o.size) +{ + rods = new std::unique_ptr[width * height]; + + for(int i = 0; i < size; i++) + { + this->rods[i] = std::unique_ptr(o.rods[i]->clone()); + } +} + reactor::~reactor() { if(rods != nullptr) diff --git a/src/reactor/reactor.hpp b/src/reactor/reactor.hpp index aecd1ab..f34d917 100644 --- a/src/reactor/reactor.hpp +++ b/src/reactor/reactor.hpp @@ -21,6 +21,7 @@ struct reactor int cursor = 0; reactor(std::unique_ptr* rods, int width, int height); + reactor(const reactor& r); reactor(reactor&& r); ~reactor(); diff --git a/src/reactor/rod.hpp b/src/reactor/rod.hpp index eac3b50..685cb86 100644 --- a/src/reactor/rod.hpp +++ b/src/reactor/rod.hpp @@ -24,6 +24,7 @@ public: virtual void add(val_t type, double v); virtual double extract(val_t type, double s, double k, double o); virtual double get(val_t type) const; + virtual rod* clone() const { return new rod(*this); }; virtual bool should_display() const { return false; } virtual bool should_select() const { return false; }