-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleTexture.cpp
More file actions
116 lines (95 loc) · 2.79 KB
/
ModuleTexture.cpp
File metadata and controls
116 lines (95 loc) · 2.79 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "ModuleTexture.h"
#include "ModuleRender.h"
#include "Application.h"
#include "SceneImporter.h"
#include "MaterialImporter.h"
#include "GL/glew.h"
#include <DevIL/il.h>
#include <DevIL/ilu.h>
#include <DevIL/ilut.h>
update_status ModuleTexture::PreUpdate()
{
return UPDATE_CONTINUE;
}
update_status ModuleTexture::Update()
{
return UPDATE_CONTINUE;
}
update_status ModuleTexture::PostUpdate()
{
return UPDATE_CONTINUE;
}
bool ModuleTexture::CleanUp()
{
for(unsigned int i = 0; i < textures_loaded.size();++i)
{
glDeleteTextures(1, &textures_loaded[i].id);
}
textures_loaded.clear();
return true;
}
void ModuleTexture::LoadTexture(Texture & texture)
{
for (unsigned int i = 0; i < textures_loaded.size(); i++)
{
if (strcmp(textures_loaded[i].path.data(), texture.path.data()) == 0)
{
texture = textures_loaded[i];
return;
}
}
unsigned int textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
if (texture.data)
{
//Binding texture and generating mipmaps
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.width, texture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else
{
LOG("Failed to load texture.");
}
//Filtering and Wrapping texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
texture.id = textureID;
}
void ModuleTexture::LoadSkybox(const char * path, int index) const
{
Texture skybox;
unsigned int image;
Importer->materialImp->LoadSkyBox(path, skybox, image);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, GL_RGBA, skybox.width, skybox.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, skybox.data);
iluDeleteImage(image);
return;
}
void ModuleTexture::LoadWhiteFallbackTexture()
{
float pixels[] = {1.0f, 1.0f, 1.0f};
unsigned int whiteTex;
glGenTextures(1, &whiteTex);
glBindTexture(GL_TEXTURE_2D, whiteTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, pixels);
white_fallback.id = whiteTex;
white_fallback.width = 1;
white_fallback.height = 1;
white_fallback.depth = 1;
//white_fallback.format = 0;
//white_fallback.data = fallbackImage;
white_fallback.type = "white_fallback";
white_fallback.path = "";
LOG("White for texture fallback loaded.");
}
Texture* ModuleTexture::getWhiteFallbackTexture()
{
return &white_fallback;
}