-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexture.cpp
More file actions
50 lines (44 loc) · 1.28 KB
/
Texture.cpp
File metadata and controls
50 lines (44 loc) · 1.28 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
#define STB_IMAGE_IMPLEMENTATION
#include "Texture.h"
#include "stb_image.h"
namespace violet {
void Texture::loadFile(const std::string&file) {
int _channels;
_dataUint8 = stbi_load(file.c_str(), &_width, &_height, &_channels, 0);
Assert(_dataUint8 != nullptr);
switch (_channels) {
case 1:_format = TEX_FORMAT::R; break;
case 2:_format = TEX_FORMAT::RG; break;
case 3:_format = TEX_FORMAT::RGB; break;
case 4:_format = TEX_FORMAT::RGBA; break;
}
_dataType = TEX_DATA_TYPE::Uint8;
_file = file;
_warping = TEX_WARPING_TYPE::Repeat;
_filter = TEX_FILTER_METHOD::Nearest;
}
Texture::Texture(const std::string&file) :_inGpu{ false } {
loadFile(file);
}
void Texture::free() {
stbi_image_free(_dataUint8);
}
void Texture::insertParam1f(const string&name, float param) {
_param1f[name] = param;
}
void Texture::insertParam2f(const string&name, const glm::vec2& param) {
_param2f[name] = param;
}
void Texture::insertParam3f(const string&name, const glm::vec3& param) {
_param3f[name] = param;
}
float Texture::getParam1f(const string&name)const {
return _param1f.at(name);
}
glm::vec2 Texture::getParam2f(const string&name)const {
return _param2f.at(name);
}
glm::vec3 Texture::getParam3f(const string&name)const {
return _param3f.at(name);
}
}