-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource_manager.cpp
More file actions
65 lines (49 loc) · 1.49 KB
/
resource_manager.cpp
File metadata and controls
65 lines (49 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "resource_manager.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
Shader* ResourceManager::Shaders;
Texture2D* ResourceManager::Textures;
void ResourceManager::clear() {
for (unsigned int i = 0; i < Shader::_count - 1; i++) {
glDeleteProgram(Shaders[i].getID());
}
Shader::_count = 0;
for (unsigned int i = 0; i < Texture2D::_count - 1; i++) {
glDeleteTextures(1, &(Textures[i].ID));
}
Texture2D::_count = 0;
}
void ResourceManager::loadShader(const char* const vsFile, const char* const fsFile) {
Shader shader;
std::string vs = Utility::getFileData(vsFile);
std::string fs = Utility::getFileData(fsFile);
const char* cvs = vs.c_str();
const char* cfs = fs.c_str();
shader.ID = 0;
shader.compile(cvs, cfs); //_count ++
Shaders[Shader::_count - 1] = shader;
}
/*Shader& ResourceManager::getShader(unsigned int index) {
return ResourceManager::Shaders[index];
}*/
void ResourceManager::loadTexture(const char* const file, const bool alpha) {
Texture2D texture;
if (alpha) {
texture.image_format = GL_RGBA;
texture.internal_format = GL_RGBA;
}
int w = 0, h = 0, nrC = 0;
unsigned char* data = stbi_load(file, &w, &h, &nrC, 0);
if (data) {
texture.generate(w, h, data);
}
stbi_image_free(data);
Textures[Texture2D::_count - 1] = texture;
}
/*Texture2D& ResourceManager::getTexture(const unsigned int index) {
if (index <= Texture2D::_count) {
return ResourceManager::Textures[index];
}
...
}
*/