updated lol library

This commit is contained in:
Lauchmelder 2021-12-26 19:39:43 +01:00
parent f2974f0fe6
commit 458fe3f41c
5 changed files with 24 additions and 21 deletions

View file

@ -31,8 +31,7 @@ void Application::Quit()
{
delete topology;
lol::ShaderManager::GetInstance().Cleanup();
lol::ObjectManager<lol::Texture1D>::GetInstance().Cleanup();
manager.Clear();
glfwDestroyWindow(window);
window = nullptr;
@ -138,7 +137,7 @@ void Application::Init(int width, int height, const std::string& title)
data.camera = &camera;
data.aspectRatio = (float)width / (float)height;
topology = new Topology(glm::vec2(15.0f, 7.5f), glm::uvec2(200, 100));
topology = new Topology(manager, glm::vec2(15.0f, 7.5f), glm::uvec2(200, 100));
glm::uvec2 size = topology->GetSize();
float* pixels = topology->GetTopology();

View file

@ -43,6 +43,7 @@ public:
private:
GLFWwindow* window = nullptr;
WindowData data;
lol::ObjectManager manager;
OrbitingCamera camera;
float pitch, yaw, distance;

View file

@ -5,8 +5,8 @@
#include "Util.hpp"
#include "Colormaps.hpp"
Topology::Topology(const glm::vec2& size, const glm::uvec2& subdivisions) :
texture(nullptr)
Topology::Topology(lol::ObjectManager& manager, const glm::vec2& size, const glm::uvec2& subdivisions) :
texture(nullptr), manager(manager)
{
// Create VAO
vao = std::make_shared<lol::VertexArray>();
@ -52,10 +52,13 @@ Topology::Topology(const glm::vec2& size, const glm::uvec2& subdivisions) :
vao->SetElementBuffer(elementBuffer);
// Set up shader
shader = lol::ShaderManager::GetInstance().Get(TOPOLOGY_ID);
if (shader == nullptr)
try
{
shader = std::make_shared<lol::Shader>(
shader = manager.Get<lol::Shader>(TOPOLOGY_ID);
}
catch(const lol::ObjectNotFoundException& ex)
{
shader = manager.Create<lol::Shader>(TOPOLOGY_ID,
R"(
#version 460 core
@ -103,8 +106,6 @@ Topology::Topology(const glm::vec2& size, const glm::uvec2& subdivisions) :
}
)"
);
lol::ShaderManager::GetInstance().Register(TOPOLOGY_ID, shader);
}
// Generate image
@ -119,8 +120,7 @@ Topology::Topology(const glm::vec2& size, const glm::uvec2& subdivisions) :
Topology::~Topology()
{
lol::ShaderManager::GetInstance().CleanupUnused();
lol::ObjectManager<lol::Texture1D>::GetInstance().CleanupUnused();
manager.ClearUnused();
if (texture != nullptr)
delete texture;
@ -146,15 +146,18 @@ void Topology::PreRender(const lol::CameraBase& camera)
void Topology::SetColormap(const Colormap& cm)
{
colormap = lol::ObjectManager<lol::Texture1D>::GetInstance().Get(cm.id);
colormap = manager.Get<lol::Texture1D>(cm.id);
}
void Topology::RegisterColormap(const Colormap& cm)
{
std::shared_ptr<lol::Texture1D> texColormap = lol::ObjectManager<lol::Texture1D>::GetInstance().Get(cm.id);
if(texColormap == nullptr)
try
{
texColormap = std::make_shared<lol::Texture1D>(
manager.Get<lol::Texture1D>(cm.id);
}
catch(const lol::ObjectNotFoundException& e)
{
std::shared_ptr<lol::Texture1D> colormap = manager.Create<lol::Texture1D>(cm.id,
cm.data.size() / 3,
cm.data.data(),
lol::PixelFormat::RGB,
@ -162,9 +165,7 @@ void Topology::RegisterColormap(const Colormap& cm)
lol::TextureFormat::RGB32F
);
texColormap->SetWrap(lol::TextureWrap::ClampToEdge, lol::TextureWrap::Repeat);
lol::ObjectManager<lol::Texture1D>::GetInstance().Register(cm.id, texColormap);
colormap->SetWrap(lol::TextureWrap::ClampToEdge, lol::TextureWrap::Repeat);
}
}

View file

@ -11,7 +11,7 @@ inline float Map(const glm::vec2& from, const glm::vec2& to, float val)
class Topology : public lol::Drawable
{
public:
Topology(const glm::vec2& size, const glm::uvec2& subdivision);
Topology(lol::ObjectManager& manager, const glm::vec2& size, const glm::uvec2& subdivision);
~Topology();
void PreRender(const lol::CameraBase& camera) override;
@ -32,6 +32,8 @@ private:
private:
lol::Image image;
lol::Texture2D* texture;
lol::ObjectManager& manager;
std::shared_ptr<lol::Texture1D> colormap;
float offset = 0.0f;

2
vendor/lol vendored

@ -1 +1 @@
Subproject commit e23d22153c88822a2a15e798ad2643fdcbdf6dc3
Subproject commit 967bf6b161b7082e4e68f4a79330039cfc9c5569