#include <iostream>
#include <vector>
class TextureLoader;
class Texture
{
public:
typedef std::size_t Id;
static const Id NULL_ID = 0;
private:
// width, height, depth
Id _id = NULL_ID;
};
class TextureLoader
{
public:
virtual bool load(const std::string& filepath, Texture* texture) = 0;
virtual void destroy(Texture* texture) = 0;
};
class OglTextureLoader : public TextureLoader
{
public:
virtual bool load(const std::string& filepath, Texture* texture)
{
/*
// load the texture in an image
GLuint actualTexture = 0;
// gl specific code...
texture->_id = nextId();
// resize array if _actualTextures if required
_actualTextures[texture->id] = actualTexture;
*/
std::cout << "Loading image: " << filepath << "...\n";
std::cout << "Uploading image to OpenGL Texture...\n";
return true;
}
virtual void destroy(Texture* texture)
{
// glDeleteTextures(_oglTextures[texture->_id]);
std::cout << "Destroying OpenGL Texture\n";
}
private:
std::vector<unsigned int /* GLuint */> _oglTextures; // use texture id's for index
};
int main(int argc, char* argv[])
{
Texture texture;
TextureLoader* textureLoader = new OglTextureLoader;
if(!textureLoader->load("something.png", &texture))
{
std::cout << "Failed to load something.png";
}
textureLoader->destroy(&texture);
delete textureLoader;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKY2xhc3MgVGV4dHVyZUxvYWRlcjsKY2xhc3MgVGV4dHVyZQp7CnB1YmxpYzoKCiAgICB0eXBlZGVmIHN0ZDo6c2l6ZV90IElkOwogICAgc3RhdGljIGNvbnN0IElkIE5VTExfSUQgPSAwOwoKcHJpdmF0ZToKICAgIAogICAgLy8gd2lkdGgsIGhlaWdodCwgZGVwdGgKCiAgICBJZCBfaWQgPSBOVUxMX0lEOwp9OwoKY2xhc3MgVGV4dHVyZUxvYWRlcgp7CnB1YmxpYzoKICAgIAogICAgdmlydHVhbCBib29sIGxvYWQoY29uc3Qgc3RkOjpzdHJpbmcmIGZpbGVwYXRoLCBUZXh0dXJlKiB0ZXh0dXJlKSA9IDA7CiAgICB2aXJ0dWFsIHZvaWQgZGVzdHJveShUZXh0dXJlKiB0ZXh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