From 7b462801d500b43bd7ebebe69c2e8a9d5e3f1261 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 25 Jan 2024 23:49:27 +0000 Subject: Remove the static texture cache Static variables persist too long, destruction is unmanaged and occurs after the gl context is gone. --- game/network/network.cpp | 3 +-- game/terrain.cpp | 4 ++-- gfx/gl/shadowMapper.h | 4 ++-- gfx/models/texture.cpp | 3 --- gfx/models/texture.h | 4 ---- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/game/network/network.cpp b/game/network/network.cpp index 8aa9adb..500742c 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -2,7 +2,6 @@ #include "routeWalker.h" #include #include -#include #include #include #include @@ -10,7 +9,7 @@ #include #include -Network::Network(const std::string & tn) : texture {Texture::cachedTexture.get(tn)} { } +Network::Network(const std::string & tn) : texture {std::make_shared(tn)} { } Node::Ptr Network::nodeAt(GlobalPosition3D pos) diff --git a/game/terrain.cpp b/game/terrain.cpp index 3778f3d..a4b6510 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -18,8 +18,8 @@ #include Terrain::Terrain(std::shared_ptr tm) : - geoData {std::move(tm)}, grass {Texture::cachedTexture.get("grass.png")}, - water {Texture::cachedTexture.get("water.png")} + geoData {std::move(tm)}, grass {std::make_shared("grass.png")}, + water {std::make_shared("water.png")} { generateMeshes(); } diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index bf571f8..d1e4e10 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -3,13 +3,13 @@ #include "config/types.h" #include "lib/glArrays.h" #include "program.h" +#include #include +#include class SceneProvider; class Camera; -#include - class ShadowMapper { public: explicit ShadowMapper(const TextureAbsCoord & size); diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index 0ebba08..51223aa 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -2,7 +2,6 @@ #include "config/types.h" #include "glArrays.h" #include "tga.h" -#include #include #include #include @@ -13,8 +12,6 @@ #include #include -Cache Texture::cachedTexture; - GLint TextureOptions::glMapMode(TextureOptions::MapMode mm) { diff --git a/gfx/models/texture.h b/gfx/models/texture.h index 5d40b39..689d378 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -1,12 +1,10 @@ #pragma once #include "config/types.h" -#include #include #include #include -// IWYU pragma: no_forward_declare Cache class Image; struct TextureOptions { @@ -32,8 +30,6 @@ public: explicit Texture(GLsizei width, GLsizei height, TextureOptions = {}); explicit Texture(GLsizei width, GLsizei height, const void * data, TextureOptions = {}); - static Cache cachedTexture; - virtual void bind(GLenum unit = GL_TEXTURE0) const; void save(const char * path) const; -- cgit v1.2.3