Abstract asset loading to asset manager

This commit is contained in:
2016-06-04 22:42:22 +10:00
parent d08cc4621b
commit 7295d4712c
10 changed files with 331 additions and 102 deletions
+34
View File
@@ -0,0 +1,34 @@
#ifndef DENGINE_ASSET_MANAGER_H
#define DENGINE_ASSET_MANAGER_H
#include <Dengine\Common.h>
#include <Dengine\Texture.h>
#include <Dengine\Shader.h>
#include <map>
#include <string>
#include <iostream>
namespace Dengine
{
class AssetManager
{
public:
AssetManager();
~AssetManager();
/* Texture */
Texture *getTexture(std::string name);
i32 loadTextureImage(std::string path, std::string name);
/* Shaders */
Shader *getShader(std::string name);
i32 loadShaderFiles(std::string vertexPath, std::string fragmentPath,
std::string name);
private:
std::map<std::string, Texture> mTextures;
std::map<std::string, Shader> mShaders;
};
}
#endif
+9 -8
View File
@@ -7,17 +7,18 @@
namespace Dengine
{
class Shader
{
public:
GLuint mProgram;
class Shader
{
public:
GLuint mProgram;
Shader(std::string vertexPath, std::string fragmentPath);
~Shader();
Shader();
~Shader();
void use();
i32 loadProgram(GLuint vertexShader, GLuint fragmentShader);
};
void use();
};
}
#endif
+43
View File
@@ -0,0 +1,43 @@
#ifndef DENGINE_TEXTURE_H
#define DENGINE_TEXTURE_H
#include <Dengine\OpenGL.h>
#include <Dengine\Common.h>
namespace Dengine
{
class Texture
{
public:
// Holds the ID of the texture object, used for all texture operations to
// reference to this particlar texture
GLuint mId;
// Texture image dimensions
GLuint mWidth;
GLuint mHeight;
// Texture Format
GLuint mInternalFormat; // Format of texture object
GLuint mImageFormat; // Format of loaded image
// Texture configuration
GLuint mWrapS; // Wrapping mode on S axis
GLuint mWrapT; // Wrapping mode on T axis
// Filtering mode if texture pixels < screen pixels
GLuint mFilterMinification;
// Filtering mode if texture pixels > screen pixels
GLuint mFilterMagnification;
// Constructor (sets default texture modes)
Texture();
// Generates texture from image data
void generate(GLuint width, GLuint height, unsigned char *data);
// Binds the texture as the current active GL_TEXTURE_2D texture object
void bind() const;
};
}
#endif