Fixed texture freeing. Destructor was never called because base destructors weren't virtual.
This commit is contained in:
@@ -19,6 +19,7 @@ class Resource
|
||||
|
||||
protected:
|
||||
Resource() { }
|
||||
virtual ~Resource() = default;
|
||||
|
||||
public:
|
||||
//Should be thrown in a Resource's constructor if it cannot complete because another resource is still loading.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "PNG.h"
|
||||
|
||||
class CubeMapPass
|
||||
{
|
||||
@@ -21,7 +22,7 @@ private:
|
||||
IRenderer* m_Renderer;
|
||||
std::string m_PreviusCubeMapTexture;
|
||||
|
||||
std::vector<Texture*> m_CubeMapTextures;
|
||||
std::vector<std::string> m_CubeMapTextures;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
struct Image
|
||||
{
|
||||
virtual ~Image() = default;
|
||||
|
||||
enum class ImageFormat
|
||||
{
|
||||
Unknown,
|
||||
|
||||
@@ -14,8 +14,6 @@ protected:
|
||||
TextureSprite(std::string path);
|
||||
|
||||
public:
|
||||
~TextureSprite();
|
||||
|
||||
void Bind(GLenum textureUnit = GL_TEXTURE0);
|
||||
|
||||
GLuint m_Texture = 0;
|
||||
|
||||
@@ -6,18 +6,16 @@ CubeMapPass::CubeMapPass(IRenderer* renderer)
|
||||
LoadTextures("Nevada");
|
||||
}
|
||||
|
||||
void CubeMapPass::LoadTextures(std::string input)
|
||||
void CubeMapPass::LoadTextures(std::string cubemapName)
|
||||
{
|
||||
if (m_PreviusCubeMapTexture != input) {
|
||||
if (m_PreviusCubeMapTexture != cubemapName) {
|
||||
m_CubeMapTextures.clear();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
std::string str;
|
||||
str = "Textures/Test/CubeMap/" + input + "/CubeMapTest0" + std::to_string(i) + ".png";
|
||||
Texture* img = ResourceManager::Load<Texture>(str);
|
||||
m_CubeMapTextures.push_back(img);
|
||||
std::string path = "Textures/Test/CubeMap/" + cubemapName + "/CubeMapTest0" + std::to_string(i) + ".png";
|
||||
m_CubeMapTextures.push_back(path);
|
||||
}
|
||||
GenerateCubeMapTexture();
|
||||
m_PreviusCubeMapTexture = input;
|
||||
m_PreviusCubeMapTexture = cubemapName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +27,9 @@ void CubeMapPass::GenerateCubeMapTexture()
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapTexture);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA32F, m_CubeMapTextures[0]->Width, m_CubeMapTextures[0]->Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_CubeMapTextures[i]->Data);
|
||||
PNG* img = ResourceManager::Load<PNG>(m_CubeMapTextures[i]);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA32F, img->Width, img->Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->Data);
|
||||
ResourceManager::Release("PNG", m_CubeMapTextures[i]);
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
@@ -19,7 +19,6 @@ Texture::Texture(std::string path)
|
||||
}
|
||||
|
||||
// Construct the OpenGL texture
|
||||
|
||||
glGenTextures(1, &m_Texture);
|
||||
glBindTexture(GL_TEXTURE_2D, m_Texture);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
@@ -30,6 +29,8 @@ Texture::Texture(std::string path)
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
GLERROR("Texture load");
|
||||
|
||||
ResourceManager::Release("PNG", path);
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ Game::Game(int argc, char* argv[])
|
||||
ResourceManager::RegisterType<RawModel>("RawModel");
|
||||
ResourceManager::RegisterType<Texture>("Texture");
|
||||
ResourceManager::RegisterType<TextureSprite>("TextureSprite");
|
||||
ResourceManager::RegisterType<PNG>("Png");
|
||||
ResourceManager::RegisterType<PNG>("PNG");
|
||||
ResourceManager::RegisterType<ShaderProgram>("ShaderProgram");
|
||||
ResourceManager::RegisterType<EntityFile>("EntityFile");
|
||||
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
|
||||
|
||||
Reference in New Issue
Block a user